Avoid the getJavaScript API-call in PDFViewerApplication._initializeAutoPrint when "enableScripting" is set

Rather than calling `getJavaScript` in the API and then ignoring the result, when "enableScripting" is set, it should be more efficient/faster to simply skip it altogether instead.

Finally, the `setTimeout` call at the end of `PDFViewerApplication._initializeAutoPrint` is removed, since it doesn't seem necessary any more as far as I can tell.[1]
Note that when this functionality was originally added, back in PR 2839, it seems that `pagesPromise` simply waited for the `getPage` calls of *all* pages to resolve. Today, on the other hand, the viewer fetches *and* renders the first page *before* doing the remaining `getPage` calls, and only afterwards is `pagesPromise` resolved. Hence it's not really clear why we now need to delay printing even further with a `setTimeout` call.

---
[1] The patch was tested with the following documents: https://github.com/mozilla/pdf.js/blob/master/test/pdfs/bug1001080.pdf and https://github.com/mozilla/pdf.js/blob/master/test/pdfs/issue6106.pdf
This commit is contained in:
Jonas Jenwald 2020-12-21 11:43:54 +01:00
parent c3730c177a
commit 7bab8350c0

View File

@ -1652,7 +1652,7 @@ const PDFViewerApplication = {
async _initializeAutoPrint(pdfDocument, openActionPromise) {
const [openAction, javaScript] = await Promise.all([
openActionPromise,
pdfDocument.getJavaScript(),
!AppOptions.get("enableScripting") ? pdfDocument.getJavaScript() : null,
]);
if (pdfDocument !== this.pdfDocument) {
@ -1660,10 +1660,10 @@ const PDFViewerApplication = {
}
let triggerAutoPrint = false;
if (openAction && openAction.action === "Print") {
if (openAction?.action === "Print") {
triggerAutoPrint = true;
}
if (javaScript && !AppOptions.get("enableScripting")) {
if (javaScript) {
javaScript.some(js => {
if (!js) {
// Don't warn/fallback for empty JavaScript actions.
@ -1686,9 +1686,7 @@ const PDFViewerApplication = {
}
if (triggerAutoPrint) {
setTimeout(() => {
this.triggerPrinting();
});
this.triggerPrinting();
}
},