Skip to content

Commit

Permalink
Merge pull request #17397 from Snuffleupagus/app-createScripting-move…
Browse files Browse the repository at this point in the history
…-options

Re-factor how the `sandboxBundleSrc` option is passed to `PDFScriptingManager`
  • Loading branch information
Snuffleupagus authored Dec 9, 2023
2 parents 988d3a1 + 92c15a6 commit 5537298
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 28 deletions.
6 changes: 1 addition & 5 deletions web/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class DefaultExternalServices {
throw new Error("Not implemented: createL10n");
}

static createScripting(options) {
static createScripting() {
throw new Error("Not implemented: createScripting");
}

Expand Down Expand Up @@ -395,10 +395,6 @@ const PDFViewerApplication = {

const pdfScriptingManager = new PDFScriptingManager({
eventBus,
sandboxBundleSrc:
typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC || CHROME")
? AppOptions.get("sandboxBundleSrc")
: null,
externalServices,
docProperties: this._scriptingDocProperties.bind(this),
});
Expand Down
4 changes: 2 additions & 2 deletions web/chromecom.js
Original file line number Diff line number Diff line change
Expand Up @@ -439,8 +439,8 @@ class ChromeExternalServices extends DefaultExternalServices {
return new GenericL10n(navigator.language);
}

static createScripting({ sandboxBundleSrc }) {
return new GenericScripting(sandboxBundleSrc);
static createScripting() {
return new GenericScripting(AppOptions.get("sandboxBundleSrc"));
}
}
PDFViewerApplication.externalServices = ChromeExternalServices;
Expand Down
2 changes: 1 addition & 1 deletion web/firefoxcom.js
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ class FirefoxExternalServices extends DefaultExternalServices {
return new L10n(localeProperties, document.l10n);
}

static createScripting(options) {
static createScripting() {
return FirefoxScripting;
}

Expand Down
4 changes: 2 additions & 2 deletions web/genericcom.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ class GenericExternalServices extends DefaultExternalServices {
return new GenericL10n(AppOptions.get("locale"));
}

static createScripting({ sandboxBundleSrc }) {
return new GenericScripting(sandboxBundleSrc);
static createScripting() {
return new GenericScripting(AppOptions.get("sandboxBundleSrc"));
}
}
PDFViewerApplication.externalServices = GenericExternalServices;
Expand Down
4 changes: 2 additions & 2 deletions web/pdf_scripting_manager.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ class PDFScriptingManagerComponents extends PDFScriptingManager {
}

options.externalServices ||= {
createScripting: ({ sandboxBundleSrc }) => {
return new GenericScripting(sandboxBundleSrc);
createScripting: () => {
return new GenericScripting(options.sandboxBundleSrc);
},
};
options.docProperties ||= pdfDocument => {
Expand Down
20 changes: 4 additions & 16 deletions web/pdf_scripting_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import { PromiseCapability, shadow } from "pdfjs-lib";
/**
* @typedef {Object} PDFScriptingManagerOptions
* @property {EventBus} eventBus - The application event bus.
* @property {string} sandboxBundleSrc - The path and filename of the scripting
* bundle.
* @property {string} [sandboxBundleSrc] - The path and filename of the
* scripting bundle.
* @property {Object} [externalServices] - The factory that is used when
* initializing scripting; must contain a `createScripting` method.
* PLEASE NOTE: Primarily intended for the default viewer use-case.
Expand All @@ -47,25 +47,15 @@ class PDFScriptingManager {

#ready = false;

#sandboxBundleSrc = null;

#scripting = null;

#willPrintCapability = null;

/**
* @param {PDFScriptingManagerOptions} options
*/
constructor({
eventBus,
sandboxBundleSrc = null,
externalServices = null,
docProperties = null,
}) {
constructor({ eventBus, externalServices = null, docProperties = null }) {
this.#eventBus = eventBus;
if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC || CHROME")) {
this.#sandboxBundleSrc = sandboxBundleSrc;
}
this.#externalServices = externalServices;
this.#docProperties = docProperties;
}
Expand Down Expand Up @@ -421,9 +411,7 @@ class PDFScriptingManager {
if (this.#scripting) {
throw new Error("#initScripting: Scripting already exists.");
}
return this.#externalServices.createScripting({
sandboxBundleSrc: this.#sandboxBundleSrc,
});
return this.#externalServices.createScripting();
}

async #destroyScripting() {
Expand Down

0 comments on commit 5537298

Please sign in to comment.