Merge pull request #16776 from calixteman/gv_print_or_save
[GeckoView] Allow to query pdf.js to know if we can avoid to print a pdf (bug 1846296)
This commit is contained in:
commit
4735ed8f16
@ -3021,7 +3021,7 @@ class WorkerTransport {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getDocJSActions() {
|
getDocJSActions() {
|
||||||
return this.messageHandler.sendWithPromise("GetDocJSActions", null);
|
return this.#cacheSimpleMethod("GetDocJSActions");
|
||||||
}
|
}
|
||||||
|
|
||||||
getPageJSActions(pageIndex) {
|
getPageJSActions(pageIndex) {
|
||||||
|
@ -208,7 +208,7 @@ class OptionalContentConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
get hasInitialVisibility() {
|
get hasInitialVisibility() {
|
||||||
return this.getHash() === this.#initialHash;
|
return this.#initialHash === null || this.getHash() === this.#initialHash;
|
||||||
}
|
}
|
||||||
|
|
||||||
getOrder() {
|
getOrder() {
|
||||||
|
@ -285,6 +285,50 @@ class MozL10n {
|
|||||||
window.addEventListener("editingaction", handleEvent);
|
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 {
|
class FirefoxComDataRangeTransport extends PDFDataRangeTransport {
|
||||||
requestDataRange(begin, end) {
|
requestDataRange(begin, end) {
|
||||||
FirefoxCom.request("requestDataRange", { begin, end });
|
FirefoxCom.request("requestDataRange", { begin, end });
|
||||||
|
Loading…
Reference in New Issue
Block a user