From abcc32ade08e2d0a1de70874038ad0db988f5c7e Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Fri, 17 Jun 2022 11:18:26 +0200 Subject: [PATCH 1/2] Simplify setting the `defaultUrl`-option in the CHROME viewer (PR 12470 follow-up) This should really have been done as part of PR 12470, since it's now possible to directly set the `defaultUrl`-option without having to fallback to `var`-usage. --- web/viewer.js | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/web/viewer.js b/web/viewer.js index 8acc7c8d4b904..72616c65bdb36 100644 --- a/web/viewer.js +++ b/web/viewer.js @@ -27,14 +27,12 @@ window.PDFViewerApplication = PDFViewerApplication; window.PDFViewerApplicationOptions = AppOptions; if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("CHROME")) { - var defaultUrl; // eslint-disable-line no-var - (function rewriteUrlClosure() { // Run this code outside DOMContentLoaded to make sure that the URL // is rewritten as soon as possible. const queryString = document.location.search.slice(1); const m = /(^|&)file=([^&]*)/.exec(queryString); - defaultUrl = m ? decodeURIComponent(m[2]) : ""; + const defaultUrl = m ? decodeURIComponent(m[2]) : ""; // Example: chrome-extension://.../http://example.com/file.pdf const humanReadableUrl = "/" + defaultUrl + location.hash; @@ -43,6 +41,8 @@ if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("CHROME")) { // eslint-disable-next-line no-undef chrome.runtime.sendMessage("showPageAction"); } + + AppOptions.set("defaultUrl", defaultUrl); })(); } @@ -222,10 +222,6 @@ function webViewerLoad() { PDFViewerApplication.run(config); }); } else { - if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("CHROME")) { - AppOptions.set("defaultUrl", defaultUrl); - } - if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("GENERIC")) { // Give custom implementations of the default viewer a simpler way to // set various `AppOptions`, by dispatching an event once all viewer From 77aa86e275897be4cfa816be1a68ef663a93e311 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Fri, 17 Jun 2022 11:25:55 +0200 Subject: [PATCH 2/2] Stop defining the `defaultUrl`-option in the MOZCENTRAL viewer This option is not used, nor has it ever been used, in the *built-in* Firefox PDF Viewer. Hence we can define it only for the environments where it makes sense instead. --- web/app_options.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/web/app_options.js b/web/app_options.js index d75277c568254..5447c42380b67 100644 --- a/web/app_options.js +++ b/web/app_options.js @@ -74,11 +74,6 @@ const defaultOptions = { value: 0, kind: OptionKind.VIEWER + OptionKind.PREFERENCE, }, - defaultUrl: { - /** @type {string} */ - value: "compressed.tracemonkey-pldi-09.pdf", - kind: OptionKind.VIEWER, - }, defaultZoomValue: { /** @type {string} */ value: "", @@ -296,6 +291,11 @@ if ( typeof PDFJSDev === "undefined" || PDFJSDev.test("!PRODUCTION || GENERIC") ) { + defaultOptions.defaultUrl = { + /** @type {string} */ + value: "compressed.tracemonkey-pldi-09.pdf", + kind: OptionKind.VIEWER, + }; defaultOptions.disablePreferences = { /** @type {boolean} */ value: typeof PDFJSDev !== "undefined" && PDFJSDev.test("TESTING"), @@ -320,6 +320,11 @@ if ( defaultOptions.renderer.kind += OptionKind.PREFERENCE; } else if (PDFJSDev.test("CHROME")) { + defaultOptions.defaultUrl = { + /** @type {string} */ + value: "", + kind: OptionKind.VIEWER, + }; defaultOptions.disableTelemetry = { /** @type {boolean} */ value: false,