diff --git a/src/display/api.js b/src/display/api.js index 61a95bef6..c10ee1bbc 100644 --- a/src/display/api.js +++ b/src/display/api.js @@ -3021,7 +3021,7 @@ class WorkerTransport { } getDocJSActions() { - return this.messageHandler.sendWithPromise("GetDocJSActions", null); + return this.#cacheSimpleMethod("GetDocJSActions"); } getPageJSActions(pageIndex) { diff --git a/src/display/optional_content_config.js b/src/display/optional_content_config.js index d96c70024..aca8c3605 100644 --- a/src/display/optional_content_config.js +++ b/src/display/optional_content_config.js @@ -208,7 +208,7 @@ class OptionalContentConfig { } get hasInitialVisibility() { - return this.getHash() === this.#initialHash; + return this.#initialHash === null || this.getHash() === this.#initialHash; } getOrder() { diff --git a/web/firefoxcom.js b/web/firefoxcom.js index c522281b7..7c886fb7a 100644 --- a/web/firefoxcom.js +++ b/web/firefoxcom.js @@ -285,6 +285,50 @@ class MozL10n { window.addEventListener("editingaction", handleEvent); })(); +if (PDFJSDev.test("GECKOVIEW")) { + (function listenQueryEvents() { + window.addEventListener("pdf.js.query", async ({ detail: { queryId } }) => { + let result = null; + if (queryId === "canDownloadInsteadOfPrint") { + result = false; + const { pdfDocument, pdfViewer } = PDFViewerApplication; + if (pdfDocument) { + try { + const hasUnchangedAnnotations = + pdfDocument.annotationStorage.size === 0; + // WillPrint is called just before printing the document and could + // lead to have modified annotations. + const hasWillPrint = + pdfViewer.enableScripting && + !!(await pdfDocument.getJSActions())?.WillPrint; + const hasUnchangedOptionalContent = ( + await pdfViewer.optionalContentConfigPromise + ).hasInitialVisibility; + + result = + hasUnchangedAnnotations && + !hasWillPrint && + hasUnchangedOptionalContent; + } catch { + console.warn("Unable to check if the document can be downloaded."); + } + } + } + + window.dispatchEvent( + new CustomEvent("pdf.js.query.answer", { + bubbles: true, + cancelable: false, + detail: { + queryId, + value: result, + }, + }) + ); + }); + })(); +} + class FirefoxComDataRangeTransport extends PDFDataRangeTransport { requestDataRange(begin, end) { FirefoxCom.request("requestDataRange", { begin, end });