diff --git a/gulpfile.js b/gulpfile.js index 142b4e72b79ab..fcc189e9c877c 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -97,7 +97,6 @@ const DEFINES = Object.freeze({ PRODUCTION: true, SKIP_BABEL: true, TESTING: false, - ENABLE_SCRIPTING: false, // The main build targets: GENERIC: false, MOZCENTRAL: false, @@ -682,7 +681,6 @@ gulp.task("default_preferences-pre", function () { LIB: true, BUNDLE_VERSION: 0, // Dummy version BUNDLE_BUILD: 0, // Dummy build - ENABLE_SCRIPTING: process.env.ENABLE_SCRIPTING === "true", }), map: { "pdfjs-lib": "../pdf", @@ -1551,46 +1549,29 @@ gulp.task("testing-pre", function (done) { done(); }); -gulp.task("enable-scripting", function (done) { - process.env.ENABLE_SCRIPTING = "true"; - done(); -}); - gulp.task( "test", - gulp.series( - "enable-scripting", - "testing-pre", - "generic", - "components", - function () { - return streamqueue( - { objectMode: true }, - createTestSource("unit"), - createTestSource("browser"), - createTestSource("integration") - ); - } - ) + gulp.series("testing-pre", "generic", "components", function () { + return streamqueue( + { objectMode: true }, + createTestSource("unit"), + createTestSource("browser"), + createTestSource("integration") + ); + }) ); gulp.task( "bottest", - gulp.series( - "enable-scripting", - "testing-pre", - "generic", - "components", - function () { - return streamqueue( - { objectMode: true }, - createTestSource("unit", true), - createTestSource("font", true), - createTestSource("browser (no reftest)", true), - createTestSource("integration") - ); - } - ) + gulp.series("testing-pre", "generic", "components", function () { + return streamqueue( + { objectMode: true }, + createTestSource("unit", true), + createTestSource("font", true), + createTestSource("browser (no reftest)", true), + createTestSource("integration") + ); + }) ); gulp.task( @@ -1609,7 +1590,7 @@ gulp.task( gulp.task( "integrationtest", - gulp.series("enable-scripting", "testing-pre", "generic", function () { + gulp.series("testing-pre", "generic", function () { return createTestSource("integration"); }) ); diff --git a/src/display/annotation_layer.js b/src/display/annotation_layer.js index 8a6f900729f86..b51d14d8dd54e 100644 --- a/src/display/annotation_layer.js +++ b/src/display/annotation_layer.js @@ -47,6 +47,7 @@ import { ColorConverters } from "../shared/scripting_utils.js"; * @property {Object} svgFactory * @property {boolean} [enableScripting] * @property {boolean} [hasJSActions] + * @property {Object} [mouseState] */ class AnnotationElementFactory { @@ -155,6 +156,7 @@ class AnnotationElement { this.annotationStorage = parameters.annotationStorage; this.enableScripting = parameters.enableScripting; this.hasJSActions = parameters.hasJSActions; + this._mouseState = parameters.mouseState; if (isRenderable) { this.container = this._createContainer(ignoreBorder); @@ -397,7 +399,7 @@ class LinkAnnotationElement extends AnnotationElement { this.enableScripting && this.hasJSActions ) { - this._bindJSAction(link); + this._bindJSAction(link, data); } else { this._bindLink(link, ""); } @@ -463,9 +465,8 @@ class LinkAnnotationElement extends AnnotationElement { * @param {Object} data * @memberof LinkAnnotationElement */ - _bindJSAction(link) { - link.href = this.linkService.getAnchorUrl("#"); - const { data } = this; + _bindJSAction(link, data) { + link.href = this.linkService.getAnchorUrl(""); const map = new Map([ ["Action", "onclick"], ["MouseUp", "onmouseup"], @@ -477,14 +478,13 @@ class LinkAnnotationElement extends AnnotationElement { continue; } link[jsName] = () => { - window.dispatchEvent( - new CustomEvent("dispatchEventInSandbox", { - detail: { - id: data.id, - name, - }, - }) - ); + this.linkService.eventBus?.dispatch("dispatcheventinsandbox", { + source: this, + detail: { + id: data.id, + name, + }, + }); return false; }; } @@ -544,40 +544,42 @@ class WidgetAnnotationElement extends AnnotationElement { } _setEventListener(element, baseName, eventName, valueGetter) { - if (this.data.actions && eventName.replace(" ", "") in this.data.actions) { - if (baseName.includes("mouse")) { - // Mouse events - element.addEventListener(baseName, event => { - window.dispatchEvent( - new CustomEvent("dispatchEventInSandbox", { - detail: { - id: this.data.id, - name: eventName, - value: valueGetter(event), - shift: event.shiftKey, - modifier: this._getKeyModifier(event), - }, - }) - ); + if (this.data.actions[eventName.replace(" ", "")] === undefined) { + return; + } + if (baseName.includes("mouse")) { + // Mouse events + element.addEventListener(baseName, event => { + this.linkService.eventBus?.dispatch("dispatcheventinsandbox", { + source: this, + detail: { + id: this.data.id, + name: eventName, + value: valueGetter(event), + shift: event.shiftKey, + modifier: this._getKeyModifier(event), + }, }); - } else { - // Non mouse event - element.addEventListener(baseName, event => { - window.dispatchEvent( - new CustomEvent("dispatchEventInSandbox", { - detail: { - id: this.data.id, - name: eventName, - value: event.target.checked, - }, - }) - ); + }); + } else { + // Non mouse event + element.addEventListener(baseName, event => { + this.linkService.eventBus?.dispatch("dispatcheventinsandbox", { + source: this, + detail: { + id: this.data.id, + name: eventName, + value: event.target.checked, + }, }); - } + }); } } _setEventListeners(element, names, getter) { + if (!this.data.actions) { + return; + } for (const [baseName, eventName] of names) { this._setEventListener(element, baseName, eventName, getter); } @@ -590,7 +592,6 @@ class TextWidgetAnnotationElement extends WidgetAnnotationElement { parameters.renderInteractiveForms || (!parameters.data.hasAppearance && !!parameters.data.fieldValue); super(parameters, { isRenderable }); - this.mouseState = parameters.mouseState; } render() { @@ -646,7 +647,7 @@ class TextWidgetAnnotationElement extends WidgetAnnotationElement { } }); - element.addEventListener("updateFromSandbox", function (event) { + element.addEventListener("updatefromsandbox", function (event) { const { detail } = event; const actions = { value() { @@ -717,39 +718,37 @@ class TextWidgetAnnotationElement extends WidgetAnnotationElement { } // Save the entered value elementData.userValue = event.target.value; - window.dispatchEvent( - new CustomEvent("dispatchEventInSandbox", { + this.linkService.eventBus?.dispatch("dispatcheventinsandbox", { + source: this, + detail: { + id, + name: "Keystroke", + value: event.target.value, + willCommit: true, + commitKey, + selStart: event.target.selectionStart, + selEnd: event.target.selectionEnd, + }, + }); + }); + const _blurListener = blurListener; + blurListener = null; + element.addEventListener("blur", event => { + if (this._mouseState.isDown) { + // Focus out using the mouse: data are committed + elementData.userValue = event.target.value; + this.linkService.eventBus?.dispatch("dispatcheventinsandbox", { + source: this, detail: { id, name: "Keystroke", value: event.target.value, willCommit: true, - commitKey, + commitKey: 1, selStart: event.target.selectionStart, selEnd: event.target.selectionEnd, }, - }) - ); - }); - const _blurListener = blurListener; - blurListener = null; - element.addEventListener("blur", event => { - if (this.mouseState.isDown) { - // Focus out using the mouse: data are committed - elementData.userValue = event.target.value; - window.dispatchEvent( - new CustomEvent("dispatchEventInSandbox", { - detail: { - id, - name: "Keystroke", - value: event.target.value, - willCommit: true, - commitKey: 1, - selStart: event.target.selectionStart, - selEnd: event.target.selectionEnd, - }, - }) - ); + }); } _blurListener(event); }); @@ -779,19 +778,18 @@ class TextWidgetAnnotationElement extends WidgetAnnotationElement { if (elementData.beforeInputSelectionRange) { [selStart, selEnd] = elementData.beforeInputSelectionRange; } - window.dispatchEvent( - new CustomEvent("dispatchEventInSandbox", { - detail: { - id, - name: "Keystroke", - value: elementData.beforeInputValue, - change: event.data, - willCommit: false, - selStart, - selEnd, - }, - }) - ); + this.linkService.eventBus?.dispatch("dispatcheventinsandbox", { + source: this, + detail: { + id, + name: "Keystroke", + value: elementData.beforeInputValue, + change: event.data, + willCommit: false, + selStart, + selEnd, + }, + }); }); } @@ -925,7 +923,7 @@ class CheckboxWidgetAnnotationElement extends WidgetAnnotationElement { }); if (this.enableScripting && this.hasJSActions) { - element.addEventListener("updateFromSandbox", event => { + element.addEventListener("updatefromsandbox", event => { const { detail } = event; const actions = { value() { @@ -996,8 +994,8 @@ class RadioButtonWidgetAnnotationElement extends WidgetAnnotationElement { element.setAttribute("id", id); element.addEventListener("change", function (event) { - const target = event.target; - for (const radio of document.getElementsByName(event.target.name)) { + const { target } = event; + for (const radio of document.getElementsByName(target.name)) { if (radio !== target) { storage.setValue(radio.getAttribute("id"), { value: false }); } @@ -1006,7 +1004,7 @@ class RadioButtonWidgetAnnotationElement extends WidgetAnnotationElement { }); if (this.enableScripting && this.hasJSActions) { - element.addEventListener("updateFromSandbox", event => { + element.addEventListener("updatefromsandbox", event => { const { detail } = event; const actions = { value() { @@ -1128,7 +1126,7 @@ class ChoiceWidgetAnnotationElement extends WidgetAnnotationElement { } if (this.enableScripting && this.hasJSActions) { - selectElement.addEventListener("updateFromSandbox", event => { + selectElement.addEventListener("updatefromsandbox", event => { const { detail } = event; const actions = { value() { @@ -1158,22 +1156,21 @@ class ChoiceWidgetAnnotationElement extends WidgetAnnotationElement { .forEach(name => actions[name]()); }); - selectElement.addEventListener("input", function (event) { + selectElement.addEventListener("input", event => { const value = getValue(event); storage.setValue(id, { value }); - window.dispatchEvent( - new CustomEvent("dispatchEventInSandbox", { - detail: { - id, - name: "Keystroke", - changeEx: value, - willCommit: true, - commitKey: 1, - keyDown: false, - }, - }) - ); + this.linkService.eventBus?.dispatch("dispatcheventinsandbox", { + source: this, + detail: { + id, + name: "Keystroke", + changeEx: value, + willCommit: true, + commitKey: 1, + keyDown: false, + }, + }); }); this._setEventListeners( @@ -1848,14 +1845,12 @@ class FileAttachmentAnnotationElement extends AnnotationElement { this.filename = getFilenameFromUrl(filename); this.content = content; - if (this.linkService.eventBus) { - this.linkService.eventBus.dispatch("fileattachmentannotation", { - source: this, - id: stringToPDFString(filename), - filename, - content, - }); - } + this.linkService.eventBus?.dispatch("fileattachmentannotation", { + source: this, + id: stringToPDFString(filename), + filename, + content, + }); } render() { @@ -1951,7 +1946,7 @@ class AnnotationLayer { parameters.annotationStorage || new AnnotationStorage(), enableScripting: parameters.enableScripting, hasJSActions: parameters.hasJSActions, - mouseState: parameters.mouseState, + mouseState: parameters.mouseState || { isDown: false }, }); if (element.isRenderable) { const rendered = element.render(); diff --git a/src/pdf.sandbox.external.js b/src/pdf.sandbox.external.js index 89b2fecf08db7..38b9faaebe93d 100644 --- a/src/pdf.sandbox.external.js +++ b/src/pdf.sandbox.external.js @@ -148,7 +148,7 @@ class SandboxSupportBase { if (!data) { return; } - const event = new this.win.CustomEvent("updateFromSandbox", { + const event = new this.win.CustomEvent("updatefromsandbox", { detail: this.importValueFromSandbox(data), }); this.win.dispatchEvent(event); diff --git a/src/pdf.sandbox.js b/src/pdf.sandbox.js index cda7e4380ed4d..df4ce16324535 100644 --- a/src/pdf.sandbox.js +++ b/src/pdf.sandbox.js @@ -63,8 +63,6 @@ class Sandbox { } const sandboxData = JSON.stringify(data); const code = [ - // Next line is replaced by code from initialization.js - // when we create the bundle for the sandbox. PDFJSDev.eval("PDF_SCRIPTING_JS_SOURCE"), `pdfjsScripting.initSandbox({ data: ${sandboxData} })`, ]; diff --git a/test/integration/scripting_spec.js b/test/integration/scripting_spec.js index bde715249aa67..43fc949d173c7 100644 --- a/test/integration/scripting_spec.js +++ b/test/integration/scripting_spec.js @@ -30,9 +30,12 @@ describe("Interaction", () => { it("must check that first text field has focus", async () => { await Promise.all( pages.map(async ([browserName, page]) => { + await page.waitForFunction( + "window.PDFViewerApplication.scriptingReady === true" + ); + // The document has an open action in order to give // the focus to 401R. - await page.waitForTimeout(1000); const id = await page.evaluate( () => window.document.activeElement.id ); diff --git a/web/annotation_layer_builder.js b/web/annotation_layer_builder.js index e81b7a5540e17..761ad50861003 100644 --- a/web/annotation_layer_builder.js +++ b/web/annotation_layer_builder.js @@ -30,6 +30,7 @@ import { SimpleLinkService } from "./pdf_link_service.js"; * @property {IL10n} l10n - Localization service. * @property {boolean} [enableScripting] * @property {Promise} [hasJSActionsPromise] + * @property {Object} [mouseState] */ class AnnotationLayerBuilder { diff --git a/web/app.js b/web/app.js index df37f0c669778..67f558778fc4f 100644 --- a/web/app.js +++ b/web/app.js @@ -784,16 +784,22 @@ const PDFViewerApplication = { if (!this._scriptingInstance) { return; } - const { scripting, events } = this._scriptingInstance; + const { scripting, internalEvents, domEvents } = this._scriptingInstance; try { await scripting.destroySandbox(); } catch (ex) {} - for (const [name, listener] of events) { + for (const [name, listener] of internalEvents) { + this.eventBus._off(name, listener); + } + internalEvents.clear(); + + for (const [name, listener] of domEvents) { window.removeEventListener(name, listener); } - events.clear(); + domEvents.clear(); + delete this._mouseState.isDown; this._scriptingInstance = null; }, @@ -1030,13 +1036,10 @@ const PDFViewerApplication = { this.download({ sourceEventType }); return; } - - if (this._scriptingInstance) { - this._scriptingInstance.scripting.dispatchEventInSandbox({ - id: "doc", - name: "WillSave", - }); - } + this._scriptingInstance?.scripting.dispatchEventInSandbox({ + id: "doc", + name: "WillSave", + }); this._saveInProgress = true; this.pdfDocument @@ -1045,12 +1048,10 @@ const PDFViewerApplication = { const blob = new Blob([data], { type: "application/pdf" }); downloadManager.download(blob, url, filename, sourceEventType); - if (this._scriptingInstance) { - this._scriptingInstance.scripting.dispatchEventInSandbox({ - id: "doc", - name: "DidSave", - }); - } + this._scriptingInstance?.scripting.dispatchEventInSandbox({ + id: "doc", + name: "DidSave", + }); }) .catch(() => { this.download({ sourceEventType }); @@ -1467,16 +1468,24 @@ const PDFViewerApplication = { pdfDocument.getJSActions(), ]); - if ((!objects && !docActions) || pdfDocument !== this.pdfDocument) { - // No FieldObjects were found in the document, no JS Actions at doc level - // or the document was closed while the data resolved. + if (!objects && !docActions) { + // No FieldObjects or JavaScript actions were found in the document. return; } - + if (pdfDocument !== this.pdfDocument) { + return; // The document was closed while the data resolved. + } const scripting = this.externalServices.createScripting(); // Store a reference to the current scripting-instance, to allow destruction // of the sandbox and removal of the event listeners at document closing. - this._scriptingInstance = { scripting, events: new Map() }; + const internalEvents = new Map(), + domEvents = new Map(); + this._scriptingInstance = { + scripting, + ready: false, + internalEvents, + domEvents, + }; if (!this.documentInfo) { // It should be *extremely* rare for metadata to not have been resolved @@ -1493,8 +1502,7 @@ const PDFViewerApplication = { } } - const updateFromSandbox = event => { - const { detail } = event; + const updateFromSandbox = ({ detail }) => { const { id, command, value } = detail; if (!id) { switch (command) { @@ -1506,24 +1514,20 @@ const PDFViewerApplication = { break; case "layout": this.pdfViewer.spreadMode = apiPageLayoutToSpreadMode(value); - return; + break; case "page-num": this.pdfViewer.currentPageNumber = value + 1; - return; + break; case "print": this.pdfViewer.pagesPromise.then(() => { this.triggerPrinting(); }); - return; + break; case "println": console.log(value); break; case "zoom": - if (typeof value === "string") { - this.pdfViewer.currentScaleValue = value; - } else { - this.pdfViewer.currentScale = value; - } + this.pdfViewer.currentScaleValue = value; break; } return; @@ -1531,7 +1535,7 @@ const PDFViewerApplication = { const element = document.getElementById(id); if (element) { - element.dispatchEvent(new CustomEvent("updateFromSandbox", { detail })); + element.dispatchEvent(new CustomEvent("updatefromsandbox", { detail })); } else { if (value !== undefined && value !== null) { // The element hasn't been rendered yet, use the AnnotationStorage. @@ -1539,30 +1543,29 @@ const PDFViewerApplication = { } } }; - window.addEventListener("updateFromSandbox", updateFromSandbox); - // Ensure that the event listener can be removed at document closing. - this._scriptingInstance.events.set("updateFromSandbox", updateFromSandbox); + internalEvents.set("updatefromsandbox", updateFromSandbox); - const dispatchEventInSandbox = event => { - scripting.dispatchEventInSandbox(event.detail); + const dispatchEventInSandbox = ({ detail }) => { + scripting.dispatchEventInSandbox(detail); }; - window.addEventListener("dispatchEventInSandbox", dispatchEventInSandbox); - // Ensure that the event listener can be removed at document closing. - this._scriptingInstance.events.set( - "dispatchEventInSandbox", - dispatchEventInSandbox - ); + internalEvents.set("dispatcheventinsandbox", dispatchEventInSandbox); const mouseDown = event => { this._mouseState.isDown = true; }; + domEvents.set("mousedown", mouseDown); + const mouseUp = event => { this._mouseState.isDown = false; }; - window.addEventListener("mousedown", mouseDown); - this._scriptingInstance.events.set("mousedown", mouseDown); - window.addEventListener("mouseup", mouseUp); - this._scriptingInstance.events.set("mouseup", mouseUp); + domEvents.set("mouseup", mouseUp); + + for (const [name, listener] of internalEvents) { + this.eventBus._on(name, listener); + } + for (const [name, listener] of domEvents) { + window.addEventListener(name, listener); + } if (!this._contentLength) { // Always waiting for the entire PDF document to be loaded will, most @@ -1601,19 +1604,28 @@ const PDFViewerApplication = { }); if (this.externalServices.isInAutomation) { - this.eventBus.dispatch("sandboxcreated", { - source: this, - }); + this.eventBus.dispatch("sandboxcreated", { source: this }); } } catch (error) { - console.error(error); + console.error(`_initializeJavaScript: "${error?.message}".`); + this._destroyScriptingInstance(); + return; } scripting.dispatchEventInSandbox({ id: "doc", name: "Open", }); + + // Used together with the integration-tests, see the `scriptingReady` + // getter, to enable awaiting full initialization of the scripting/sandbox. + // (Defer this slightly, to make absolutely sure that everything is done.) + Promise.resolve().then(() => { + if (this._scriptingInstance) { + this._scriptingInstance.ready = true; + } + }); }, /** @@ -2032,21 +2044,17 @@ const PDFViewerApplication = { if (!this.supportsPrinting) { return; } - if (this._scriptingInstance) { - this._scriptingInstance.scripting.dispatchEventInSandbox({ - id: "doc", - name: "WillPrint", - }); - } + this._scriptingInstance?.scripting.dispatchEventInSandbox({ + id: "doc", + name: "WillPrint", + }); window.print(); - if (this._scriptingInstance) { - this._scriptingInstance.scripting.dispatchEventInSandbox({ - id: "doc", - name: "DidPrint", - }); - } + this._scriptingInstance?.scripting.dispatchEventInSandbox({ + id: "doc", + name: "DidPrint", + }); }, bindEvents() { @@ -2124,6 +2132,12 @@ const PDFViewerApplication = { _boundEvents.windowAfterPrint = () => { eventBus.dispatch("afterprint", { source: window }); }; + _boundEvents.windowUpdateFromSandbox = event => { + eventBus.dispatch("updatefromsandbox", { + source: window, + detail: event.detail, + }); + }; window.addEventListener("visibilitychange", webViewerVisibilityChange); window.addEventListener("wheel", webViewerWheel, { passive: false }); @@ -2137,6 +2151,10 @@ const PDFViewerApplication = { window.addEventListener("hashchange", _boundEvents.windowHashChange); window.addEventListener("beforeprint", _boundEvents.windowBeforePrint); window.addEventListener("afterprint", _boundEvents.windowAfterPrint); + window.addEventListener( + "updatefromsandbox", + _boundEvents.windowUpdateFromSandbox + ); }, unbindEvents() { @@ -2211,11 +2229,16 @@ const PDFViewerApplication = { window.removeEventListener("hashchange", _boundEvents.windowHashChange); window.removeEventListener("beforeprint", _boundEvents.windowBeforePrint); window.removeEventListener("afterprint", _boundEvents.windowAfterPrint); + window.removeEventListener( + "updatefromsandbox", + _boundEvents.windowUpdateFromSandbox + ); _boundEvents.windowResize = null; _boundEvents.windowHashChange = null; _boundEvents.windowBeforePrint = null; _boundEvents.windowAfterPrint = null; + _boundEvents.windowUpdateFromSandbox = null; }, accumulateWheelTicks(ticks) { @@ -2233,6 +2256,14 @@ const PDFViewerApplication = { this._wheelUnusedTicks -= wholeTicks; return wholeTicks; }, + + /** + * Used together with the integration-tests, to enable awaiting full + * initialization of the scripting/sandbox. + */ + get scriptingReady() { + return this._scriptingInstance?.ready || false; + }, }; let validateFileURL; diff --git a/web/app_options.js b/web/app_options.js index 19c12344856e0..2b67f4e0aa502 100644 --- a/web/app_options.js +++ b/web/app_options.js @@ -67,7 +67,7 @@ const defaultOptions = { }, enableScripting: { /** @type {boolean} */ - value: typeof PDFJSDev !== "undefined" && PDFJSDev.test("ENABLE_SCRIPTING"), + value: typeof PDFJSDev !== "undefined" && PDFJSDev.test("TESTING"), kind: OptionKind.VIEWER + OptionKind.PREFERENCE, }, enableWebGL: { @@ -249,7 +249,7 @@ if ( ) { defaultOptions.disablePreferences = { /** @type {boolean} */ - value: false, + value: typeof PDFJSDev !== "undefined" && PDFJSDev.test("TESTING"), kind: OptionKind.VIEWER, }; defaultOptions.locale = { @@ -260,8 +260,7 @@ if ( defaultOptions.sandboxBundleSrc = { /** @type {string} */ value: - typeof PDFJSDev === "undefined" || - PDFJSDev.test("!PRODUCTION && !ENABLE_SCRIPTING") + typeof PDFJSDev === "undefined" || !PDFJSDev.test("PRODUCTION") ? "../build/dev-sandbox/pdf.sandbox.js" : "../build/pdf.sandbox.js", kind: OptionKind.VIEWER, diff --git a/web/base_viewer.js b/web/base_viewer.js index df50b37611ca7..0103797ba027d 100644 --- a/web/base_viewer.js +++ b/web/base_viewer.js @@ -79,7 +79,8 @@ const DEFAULT_CACHE_SIZE = 10; * @property {IL10n} l10n - Localization service. * @property {boolean} [enableScripting] - Enable embedded script execution. * The default value is `false`. - * @property {Object} [mouseState] - The mouse button state. + * @property {Object} [mouseState] - The mouse button state. The default value + * is `null`. */ function PDFPageViewBuffer(size) { @@ -195,7 +196,7 @@ class BaseViewer { this.maxCanvasPixels = options.maxCanvasPixels; this.l10n = options.l10n || NullL10n; this.enableScripting = options.enableScripting || false; - this.mouseState = options.mouseState || null; + this._mouseState = options.mouseState || null; this.defaultRenderingQueue = !options.renderingQueue; if (this.defaultRenderingQueue) { @@ -540,7 +541,6 @@ class BaseViewer { maxCanvasPixels: this.maxCanvasPixels, l10n: this.l10n, enableScripting: this.enableScripting, - mouseState: this.mouseState, }); this._pages.push(pageView); } @@ -1301,7 +1301,7 @@ class BaseViewer { enableScripting, hasJSActionsPromise: hasJSActionsPromise || this.pdfDocument?.hasJSActions(), - mouseState, + mouseState: mouseState || this._mouseState, }); } diff --git a/web/firefoxcom.js b/web/firefoxcom.js index f126d40a66783..9af65e8638929 100644 --- a/web/firefoxcom.js +++ b/web/firefoxcom.js @@ -255,12 +255,12 @@ class FirefoxComDataRangeTransport extends PDFDataRangeTransport { } class FirefoxScripting { - static createSandbox(data) { + static async createSandbox(data) { return new Promise(resolve => { FirefoxCom.request("createSandbox", data, resolve); }).then(success => { if (!success) { - throw new Error("Cannot start sandbox"); + throw new Error("Cannot create sandbox."); } }); } diff --git a/web/pdf_page_view.js b/web/pdf_page_view.js index 0aa4271788ecb..da8d86a6dc88b 100644 --- a/web/pdf_page_view.js +++ b/web/pdf_page_view.js @@ -63,7 +63,6 @@ import { viewerCompatibilityParams } from "./viewer_compatibility.js"; * @property {IL10n} l10n - Localization service. * @property {boolean} [enableScripting] - Enable embedded script execution. * The default value is `false`. - * @property {Object} [mouseState] - The mouse button state. */ const MAX_CANVAS_PIXELS = viewerCompatibilityParams.maxCanvasPixels || 16777216; @@ -110,7 +109,6 @@ class PDFPageView { this.enableWebGL = options.enableWebGL || false; this.l10n = options.l10n || NullL10n; this.enableScripting = options.enableScripting || false; - this.mouseState = options.mouseState || null; this.paintTask = null; this.paintedViewportMap = new WeakMap(); @@ -554,7 +552,7 @@ class PDFPageView { this.l10n, this.enableScripting, /* hasJSActionsPromise = */ null, - this.mouseState + /* mouseState = */ null ); } this._renderAnnotationLayer();