diff --git a/web/app.js b/web/app.js index 3a01bfa25..27c93fea2 100644 --- a/web/app.js +++ b/web/app.js @@ -152,6 +152,10 @@ class DefaultExternalServices { static get canvasMaxAreaInBytes() { return shadow(this, "canvasMaxAreaInBytes", -1); } + + static getNimbusExperimentData() { + return shadow(this, "getNimbusExperimentData", Promise.resolve(null)); + } } const PDFViewerApplication = { @@ -230,12 +234,21 @@ const PDFViewerApplication = { _printAnnotationStoragePromise: null, _touchInfo: null, _isCtrlKeyDown: false, + _nimbusDataPromise: null, // Called once when the document is loaded. async initialize(appConfig) { this.preferences = this.externalServices.createPreferences(); this.appConfig = appConfig; + if ( + typeof PDFJSDev === "undefined" + ? window.isGECKOVIEW + : PDFJSDev.test("GECKOVIEW") + ) { + this._nimbusDataPromise = this.externalServices.getNimbusExperimentData(); + } + await this._initializeOptions(); this._forceCssTheme(); await this._initializeL10n(); @@ -587,7 +600,12 @@ const PDFViewerApplication = { : PDFJSDev.test("GECKOVIEW") ) { if (AppOptions.get("enableFloatingToolbar")) { - this.toolbar = new Toolbar(appConfig.toolbar, eventBus, this.l10n); + this.toolbar = new Toolbar( + appConfig.toolbar, + eventBus, + this.l10n, + await this._nimbusDataPromise + ); } } else { this.toolbar = new Toolbar(appConfig.toolbar, eventBus, this.l10n); diff --git a/web/firefoxcom.js b/web/firefoxcom.js index b8cb4a417..6d8b35250 100644 --- a/web/firefoxcom.js +++ b/web/firefoxcom.js @@ -446,6 +446,14 @@ class FirefoxExternalServices extends DefaultExternalServices { const maxArea = FirefoxCom.requestSync("getCanvasMaxArea"); return shadow(this, "canvasMaxAreaInBytes", maxArea); } + + static async getNimbusExperimentData() { + const nimbusData = await FirefoxCom.requestAsync( + "getNimbusExperimentData", + null + ); + return nimbusData && JSON.parse(nimbusData); + } } PDFViewerApplication.externalServices = FirefoxExternalServices; diff --git a/web/toolbar-geckoview.js b/web/toolbar-geckoview.js index 37888e019..544f76671 100644 --- a/web/toolbar-geckoview.js +++ b/web/toolbar-geckoview.js @@ -29,14 +29,43 @@ class Toolbar { * @param {ToolbarOptions} options * @param {EventBus} eventBus * @param {IL10n} _l10n - Localization service. + * @param {Object} nimbusData - Nimbus configuration. */ - constructor(options, eventBus, _l10n) { + constructor(options, eventBus, _l10n, nimbusData) { this.#eventBus = eventBus; - this.#buttons = [ - { element: options.download, eventName: "download" }, - { element: options.openInApp, eventName: "openinexternalapp" }, + const buttons = [ + { + element: options.download, + eventName: "download", + nimbusName: "download-button", + }, + { + element: options.openInApp, + eventName: "openinexternalapp", + nimbusName: "open-in-app-button", + }, ]; + if (nimbusData) { + this.#buttons = []; + for (const button of buttons) { + if (nimbusData[button.nimbusName]) { + this.#buttons.push(button); + } else { + button.element.remove(); + } + } + if (this.#buttons.length > 0) { + options.container.classList.add("show"); + } else { + options.container.remove(); + options.mainContainer.classList.add("noToolbar"); + } + } else { + options.container.classList.add("show"); + this.#buttons = buttons; + } + // Bind the event listeners for click and various other actions. this.#bindListeners(options); } diff --git a/web/viewer-geckoview.css b/web/viewer-geckoview.css index 45f228d0c..eb27003e2 100644 --- a/web/viewer-geckoview.css +++ b/web/viewer-geckoview.css @@ -102,10 +102,15 @@ body { #viewerContainer { overflow: auto; position: absolute; - inset: 41px 0 0; + inset-block: 41px 0; + inset-inline: 0; outline: none; } +#viewerContainer.noToolbar { + inset-block-start: 0; +} + .dialogButton { border: none; background: none; diff --git a/web/viewer-geckoview.html b/web/viewer-geckoview.html index 4c4997f67..9e244e019 100644 --- a/web/viewer-geckoview.html +++ b/web/viewer-geckoview.html @@ -81,7 +81,7 @@ See https://github.com/adobe-type-tools/cmap-resources