mirror of
https://github.com/mozilla/pdf.js.git
synced 2026-06-05 17:51:03 +02:00
Add a pref-controlled method to notify embedders that mozPrintCallback has completed (bug 2036265)
Adds a `postMessageAfterPrintCallback` browser option (off by default). When enabled by Firefox, the print service posts "ready" or "error" to the window after each page's mozPrintCallback resolves, so embedders (e.g. print-preview test harnesses) can observe when rendering is done. Upstreams the viewer-side portion of Phabricator D297837. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> Co-authored-by: Daniel Holbert <dholbert@cs.stanford.edu>
This commit is contained in:
parent
5a4d93a238
commit
567f585def
@ -369,6 +369,11 @@ const defaultOptions = {
|
||||
value: typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING"),
|
||||
kind: OptionKind.VIEWER + OptionKind.PREFERENCE,
|
||||
},
|
||||
postMessageAfterPrintCallback: {
|
||||
/** @type {boolean} */
|
||||
value: false,
|
||||
kind: OptionKind.VIEWER + OptionKind.PREFERENCE,
|
||||
},
|
||||
printResolution: {
|
||||
/** @type {number} */
|
||||
value: 150,
|
||||
|
||||
@ -23,6 +23,7 @@ import {
|
||||
BasePrintServiceFactory,
|
||||
getXfaHtmlForPrinting,
|
||||
} from "./print_utils.js";
|
||||
import { AppOptions } from "./app_options.js";
|
||||
|
||||
// Creates a placeholder with div and canvas with right size for the page.
|
||||
function composePage(
|
||||
@ -31,6 +32,7 @@ function composePage(
|
||||
size,
|
||||
printContainer,
|
||||
printResolution,
|
||||
shouldPostMessageAfterPrintCallback,
|
||||
optionalContentConfigPromise,
|
||||
printAnnotationStoragePromise
|
||||
) {
|
||||
@ -94,6 +96,9 @@ function composePage(
|
||||
currentRenderTask = null;
|
||||
}
|
||||
obj.done();
|
||||
if (shouldPostMessageAfterPrintCallback) {
|
||||
window.postMessage("ready", "*");
|
||||
}
|
||||
},
|
||||
function (reason) {
|
||||
if (!(reason instanceof RenderingCancelledException)) {
|
||||
@ -112,6 +117,9 @@ function composePage(
|
||||
} else {
|
||||
obj.done();
|
||||
}
|
||||
if (shouldPostMessageAfterPrintCallback) {
|
||||
window.postMessage("error", "*");
|
||||
}
|
||||
}
|
||||
);
|
||||
};
|
||||
@ -171,6 +179,9 @@ class FirefoxPrintService {
|
||||
return;
|
||||
}
|
||||
|
||||
const shouldPostMessageAfterPrintCallback = AppOptions.get(
|
||||
"postMessageAfterPrintCallback"
|
||||
);
|
||||
for (let i = 0, ii = pagesOverview.length; i < ii; ++i) {
|
||||
composePage(
|
||||
pdfDocument,
|
||||
@ -178,6 +189,7 @@ class FirefoxPrintService {
|
||||
pagesOverview[i],
|
||||
printContainer,
|
||||
_printResolution,
|
||||
shouldPostMessageAfterPrintCallback,
|
||||
_optionalContentConfigPromise,
|
||||
_printAnnotationStoragePromise
|
||||
);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user