From 47ff3195e459e6569c438fc37490444758f04f8c Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Sun, 20 Dec 2020 12:24:26 +0100 Subject: [PATCH] Pass in the "sandboxBundleSrc" option when calling `DefaultExternalServices.createScripting` Similar to e.g. the "locale" option, this in *only* done for those build-targets where the "sandboxBundleSrc" is actually defined. With these changes we can remove an `AppOptions` dependency from the `web/generic_scripting.js` file, thus limiting *direct* `AppOptions` usage in the default viewer files. --- web/app.js | 9 +++++++-- web/chromecom.js | 4 ++-- web/firefoxcom.js | 2 +- web/generic_scripting.js | 5 ++--- web/genericcom.js | 4 ++-- 5 files changed, 14 insertions(+), 10 deletions(-) diff --git a/web/app.js b/web/app.js index c2ddd2b48..fd29f83cd 100644 --- a/web/app.js +++ b/web/app.js @@ -167,7 +167,7 @@ class DefaultExternalServices { throw new Error("Not implemented: createL10n"); } - static createScripting() { + static createScripting(options) { throw new Error("Not implemented: createScripting"); } @@ -1476,7 +1476,12 @@ const PDFViewerApplication = { if (pdfDocument !== this.pdfDocument) { return; // The document was closed while the data resolved. } - const scripting = this.externalServices.createScripting(); + const scripting = this.externalServices.createScripting( + typeof PDFJSDev === "undefined" || + PDFJSDev.test("!PRODUCTION || GENERIC || CHROME") + ? { sandboxBundleSrc: AppOptions.get("sandboxBundleSrc") } + : null + ); // Store a reference to the current scripting-instance, to allow destruction // of the sandbox and removal of the event listeners at document closing. const internalEvents = new Map(), diff --git a/web/chromecom.js b/web/chromecom.js index 6694755e7..e29688c13 100644 --- a/web/chromecom.js +++ b/web/chromecom.js @@ -430,8 +430,8 @@ class ChromeExternalServices extends DefaultExternalServices { return new GenericL10n(navigator.language); } - static createScripting() { - return new GenericScripting(); + static createScripting({ sandboxBundleSrc }) { + return new GenericScripting(sandboxBundleSrc); } } PDFViewerApplication.externalServices = ChromeExternalServices; diff --git a/web/firefoxcom.js b/web/firefoxcom.js index 9af65e863..30b9ed791 100644 --- a/web/firefoxcom.js +++ b/web/firefoxcom.js @@ -366,7 +366,7 @@ class FirefoxExternalServices extends DefaultExternalServices { return new MozL10n(mozL10n); } - static createScripting() { + static createScripting(options) { return FirefoxScripting; } diff --git a/web/generic_scripting.js b/web/generic_scripting.js index 4c2f9164c..aef7ba177 100644 --- a/web/generic_scripting.js +++ b/web/generic_scripting.js @@ -13,13 +13,12 @@ * limitations under the License. */ -import { AppOptions } from "./app_options.js"; import { loadScript } from "pdfjs-lib"; class GenericScripting { - constructor() { + constructor(sandboxBundleSrc) { this._ready = loadScript( - AppOptions.get("sandboxBundleSrc"), + sandboxBundleSrc, /* removeScriptElement = */ true ).then(() => { return window.pdfjsSandbox.QuickJSSandbox(); diff --git a/web/genericcom.js b/web/genericcom.js index 2bf923a7b..df616133a 100644 --- a/web/genericcom.js +++ b/web/genericcom.js @@ -51,8 +51,8 @@ class GenericExternalServices extends DefaultExternalServices { return new GenericL10n(locale); } - static createScripting() { - return new GenericScripting(); + static createScripting({ sandboxBundleSrc }) { + return new GenericScripting(sandboxBundleSrc); } } PDFViewerApplication.externalServices = GenericExternalServices;