From 7322a24ce4c06cbb856849e168cf4eaad28a5b3b Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Wed, 8 Jan 2020 13:57:31 +0100 Subject: [PATCH 1/2] Remove the `FIREFOX` build flag, since it's completely unused After PR 9566, which removed all of the old Firefox extension code, the `FIREFOX` build flag is no longer used for anything. It thus seems to me that it should be removed, for a couple of reasons: - It's simply dead code now, which only serves to add confusion when looking at the `PDFJSDev` calls. - It used to be that `MOZCENTRAL` and `FIREFOX` was *almost* always used together. However, ever since PR 9566 there's obviously been no effort put into keeping the `FIREFOX` build flags up to date. - In the event that a new, Webextension based, Firefox addon is created in the future you'd still need to audit all `MOZCENTRAL` (and possibly `CHROME`) build flags to see what'd make sense for the addon. --- gulpfile.js | 2 -- src/display/network.js | 5 ++--- src/display/text_layer.js | 2 +- web/app.js | 20 +++++++------------- web/firefoxcom.js | 8 ++------ web/pdf_attachment_viewer.js | 2 +- web/pdf_page_view.js | 4 ++-- web/pdf_presentation_mode.js | 10 ++-------- web/pdf_thumbnail_view.js | 4 ++-- web/text_layer_builder.js | 18 ++++-------------- web/view_history.js | 14 ++++---------- web/viewer.html | 4 ++-- web/viewer.js | 2 +- 13 files changed, 30 insertions(+), 65 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index fcf570759..7171d8092 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -88,7 +88,6 @@ var DEFINES = { TESTING: false, // The main build targets: GENERIC: false, - FIREFOX: false, MOZCENTRAL: false, CHROME: false, MINIFIED: false, @@ -173,7 +172,6 @@ function createWebpackConfig(defines, output) { .readFileSync("./src/license_header_libre.js") .toString(); var enableSourceMaps = - !bundleDefines.FIREFOX && !bundleDefines.MOZCENTRAL && !bundleDefines.CHROME && !bundleDefines.TESTING; diff --git a/src/display/network.js b/src/display/network.js index abd5fb4e5..f24ee1f92 100644 --- a/src/display/network.js +++ b/src/display/network.js @@ -25,10 +25,9 @@ import { validateRangeRequestCapabilities, } from "./network_utils.js"; -if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("FIREFOX || MOZCENTRAL")) { +if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) { throw new Error( - 'Module "./network" shall not ' + - "be used with FIREFOX or MOZCENTRAL build." + 'Module "./network.js" shall not be used with MOZCENTRAL builds.' ); } diff --git a/src/display/text_layer.js b/src/display/text_layer.js index 8cbaeded0..5861110f8 100644 --- a/src/display/text_layer.js +++ b/src/display/text_layer.js @@ -601,7 +601,7 @@ var renderTextLayer = (function renderTextLayerClosure() { let canvas = document.createElement("canvas"); if ( typeof PDFJSDev === "undefined" || - PDFJSDev.test("FIREFOX || MOZCENTRAL || GENERIC") + PDFJSDev.test("MOZCENTRAL || GENERIC") ) { canvas.mozOpaque = true; } diff --git a/web/app.js b/web/app.js index 58984c9e3..843ab8927 100644 --- a/web/app.js +++ b/web/app.js @@ -578,7 +578,7 @@ const PDFViewerApplication = { initPassiveLoading() { if ( typeof PDFJSDev === "undefined" || - !PDFJSDev.test("FIREFOX || MOZCENTRAL || CHROME") + !PDFJSDev.test("MOZCENTRAL || CHROME") ) { throw new Error("Not implemented: initPassiveLoading"); } @@ -733,7 +733,7 @@ const PDFViewerApplication = { value = document.URL.split("#")[0]; } else if ( typeof PDFJSDev !== "undefined" && - PDFJSDev.test("FIREFOX || MOZCENTRAL || CHROME") + PDFJSDev.test("MOZCENTRAL || CHROME") ) { value = this.baseUrl; } @@ -927,10 +927,7 @@ const PDFViewerApplication = { } } - if ( - typeof PDFJSDev === "undefined" || - !PDFJSDev.test("FIREFOX || MOZCENTRAL") - ) { + if (typeof PDFJSDev === "undefined" || !PDFJSDev.test("MOZCENTRAL")) { const errorWrapperConfig = this.appConfig.errorWrapper; const errorWrapper = errorWrapperConfig.container; errorWrapper.removeAttribute("hidden"); @@ -1045,7 +1042,7 @@ const PDFViewerApplication = { let baseDocumentUrl; if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) { baseDocumentUrl = null; - } else if (PDFJSDev.test("FIREFOX || MOZCENTRAL")) { + } else if (PDFJSDev.test("MOZCENTRAL")) { baseDocumentUrl = this.baseUrl; } else if (PDFJSDev.test("CHROME")) { baseDocumentUrl = location.href.split("#")[0]; @@ -1809,7 +1806,7 @@ function webViewerInitialized() { const params = parseQueryString(queryString); file = "file" in params ? params.file : AppOptions.get("defaultUrl"); validateFileURL(file); - } else if (PDFJSDev.test("FIREFOX || MOZCENTRAL")) { + } else if (PDFJSDev.test("MOZCENTRAL")) { file = window.location.href.split("#")[0]; } else if (PDFJSDev.test("CHROME")) { file = AppOptions.get("defaultUrl"); @@ -1943,7 +1940,7 @@ if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) { PDFViewerApplication.open(file); } }; -} else if (PDFJSDev.test("FIREFOX || MOZCENTRAL || CHROME")) { +} else if (PDFJSDev.test("MOZCENTRAL || CHROME")) { webViewerOpenFileViaURL = function webViewerOpenFileViaURL(file) { PDFViewerApplication.setTitleUsingUrl(file); PDFViewerApplication.initPassiveLoading(); @@ -2521,10 +2518,7 @@ function webViewerKeyDown(evt) { } } - if ( - typeof PDFJSDev === "undefined" || - !PDFJSDev.test("FIREFOX || MOZCENTRAL") - ) { + if (typeof PDFJSDev === "undefined" || !PDFJSDev.test("MOZCENTRAL")) { // CTRL or META without shift if (cmd === 1 || cmd === 8) { switch (evt.keyCode) { diff --git a/web/firefoxcom.js b/web/firefoxcom.js index bd00ac446..75e55a2db 100644 --- a/web/firefoxcom.js +++ b/web/firefoxcom.js @@ -19,13 +19,9 @@ import { DefaultExternalServices, PDFViewerApplication } from "./app.js"; import { BasePreferences } from "./preferences.js"; import { DEFAULT_SCALE_VALUE } from "./ui_utils.js"; -if ( - typeof PDFJSDev === "undefined" || - !PDFJSDev.test("FIREFOX || MOZCENTRAL") -) { +if (typeof PDFJSDev === "undefined" || !PDFJSDev.test("MOZCENTRAL")) { throw new Error( - 'Module "pdfjs-web/firefoxcom" shall not be used outside ' + - "FIREFOX and MOZCENTRAL builds." + 'Module "./firefoxcom.js" shall not be used outside MOZCENTRAL builds.' ); } diff --git a/web/pdf_attachment_viewer.js b/web/pdf_attachment_viewer.js index 61b11a238..a7e6a2411 100644 --- a/web/pdf_attachment_viewer.js +++ b/web/pdf_attachment_viewer.js @@ -100,7 +100,7 @@ class PDFAttachmentViewer { chrome.runtime.getURL("/content/web/viewer.html") + "?file=" + encodeURIComponent(blobUrl + "#" + filename); - } else if (PDFJSDev.test("FIREFOX || MOZCENTRAL")) { + } else if (PDFJSDev.test("MOZCENTRAL")) { // Let Firefox's content handler catch the URL and display the PDF. viewerUrl = blobUrl + "?" + encodeURIComponent(filename); } diff --git a/web/pdf_page_view.js b/web/pdf_page_view.js index 856f5bb4c..7dd696f93 100644 --- a/web/pdf_page_view.js +++ b/web/pdf_page_view.js @@ -581,7 +581,7 @@ class PDFPageView { if ( typeof PDFJSDev === "undefined" || - PDFJSDev.test("MOZCENTRAL || FIREFOX || GENERIC") + PDFJSDev.test("MOZCENTRAL || GENERIC") ) { canvas.mozOpaque = true; } @@ -658,7 +658,7 @@ class PDFPageView { paintOnSvg(wrapper) { if ( typeof PDFJSDev !== "undefined" && - PDFJSDev.test("FIREFOX || MOZCENTRAL || CHROME") + PDFJSDev.test("MOZCENTRAL || CHROME") ) { // Return a mock object, to prevent errors such as e.g. // "TypeError: paintTask.promise is undefined". diff --git a/web/pdf_presentation_mode.js b/web/pdf_presentation_mode.js index b69ea7553..41bf8df57 100644 --- a/web/pdf_presentation_mode.js +++ b/web/pdf_presentation_mode.js @@ -471,10 +471,7 @@ class PDFPresentationMode { window.addEventListener("fullscreenchange", this.fullscreenChangeBind); window.addEventListener("mozfullscreenchange", this.fullscreenChangeBind); - if ( - typeof PDFJSDev === "undefined" || - !PDFJSDev.test("FIREFOX || MOZCENTRAL") - ) { + if (typeof PDFJSDev === "undefined" || !PDFJSDev.test("MOZCENTRAL")) { window.addEventListener( "webkitfullscreenchange", this.fullscreenChangeBind @@ -492,10 +489,7 @@ class PDFPresentationMode { "mozfullscreenchange", this.fullscreenChangeBind ); - if ( - typeof PDFJSDev === "undefined" || - !PDFJSDev.test("FIREFOX || MOZCENTRAL") - ) { + if (typeof PDFJSDev === "undefined" || !PDFJSDev.test("MOZCENTRAL")) { window.removeEventListener( "webkitfullscreenchange", this.fullscreenChangeBind diff --git a/web/pdf_thumbnail_view.js b/web/pdf_thumbnail_view.js index 6ab9be758..a2a5b95ce 100644 --- a/web/pdf_thumbnail_view.js +++ b/web/pdf_thumbnail_view.js @@ -54,7 +54,7 @@ const TempImageFactory = (function TempImageFactoryClosure() { // background ourselves. `_getPageDrawContext` uses CSS rules for this. if ( typeof PDFJSDev === "undefined" || - PDFJSDev.test("MOZCENTRAL || FIREFOX || GENERIC") + PDFJSDev.test("MOZCENTRAL || GENERIC") ) { tempCanvas.mozOpaque = true; } @@ -228,7 +228,7 @@ class PDFThumbnailView { if ( typeof PDFJSDev === "undefined" || - PDFJSDev.test("MOZCENTRAL || FIREFOX || GENERIC") + PDFJSDev.test("MOZCENTRAL || GENERIC") ) { canvas.mozOpaque = true; } diff --git a/web/text_layer_builder.js b/web/text_layer_builder.js index 9b8d11953..a7b5fb0e2 100644 --- a/web/text_layer_builder.js +++ b/web/text_layer_builder.js @@ -373,8 +373,7 @@ class TextLayerBuilder { if (this.enhanceTextSelection && this.textLayerRenderTask) { this.textLayerRenderTask.expandTextDivs(true); if ( - (typeof PDFJSDev === "undefined" || - !PDFJSDev.test("FIREFOX || MOZCENTRAL")) && + (typeof PDFJSDev === "undefined" || !PDFJSDev.test("MOZCENTRAL")) && expandDivsTimer ) { clearTimeout(expandDivsTimer); @@ -387,10 +386,7 @@ class TextLayerBuilder { if (!end) { return; } - if ( - typeof PDFJSDev === "undefined" || - !PDFJSDev.test("FIREFOX || MOZCENTRAL") - ) { + if (typeof PDFJSDev === "undefined" || !PDFJSDev.test("MOZCENTRAL")) { // On non-Firefox browsers, the selection will feel better if the height // of the `endOfContent` div is adjusted to start at mouse click // location. This avoids flickering when the selection moves up. @@ -414,10 +410,7 @@ class TextLayerBuilder { div.addEventListener("mouseup", () => { if (this.enhanceTextSelection && this.textLayerRenderTask) { - if ( - typeof PDFJSDev === "undefined" || - !PDFJSDev.test("FIREFOX || MOZCENTRAL") - ) { + if (typeof PDFJSDev === "undefined" || !PDFJSDev.test("MOZCENTRAL")) { expandDivsTimer = setTimeout(() => { if (this.textLayerRenderTask) { this.textLayerRenderTask.expandTextDivs(false); @@ -434,10 +427,7 @@ class TextLayerBuilder { if (!end) { return; } - if ( - typeof PDFJSDev === "undefined" || - !PDFJSDev.test("FIREFOX || MOZCENTRAL") - ) { + if (typeof PDFJSDev === "undefined" || !PDFJSDev.test("MOZCENTRAL")) { end.style.top = ""; } end.classList.remove("active"); diff --git a/web/view_history.js b/web/view_history.js index e150d1e36..eb37673e1 100644 --- a/web/view_history.js +++ b/web/view_history.js @@ -21,8 +21,8 @@ const DEFAULT_VIEW_HISTORY_CACHE_SIZE = 20; * * The way that the view parameters are stored depends on how PDF.js is built, * for 'gulp ' the following cases exist: - * - FIREFOX or MOZCENTRAL - uses sessionStorage. - * - GENERIC or CHROME - uses localStorage, if it is available. + * - MOZCENTRAL - uses sessionStorage. + * - GENERIC or CHROME - uses localStorage, if it is available. */ class ViewHistory { constructor(fingerprint, cacheSize = DEFAULT_VIEW_HISTORY_CACHE_SIZE) { @@ -57,10 +57,7 @@ class ViewHistory { async _writeToStorage() { const databaseStr = JSON.stringify(this.database); - if ( - typeof PDFJSDev !== "undefined" && - PDFJSDev.test("FIREFOX || MOZCENTRAL") - ) { + if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) { sessionStorage.setItem("pdfjs.history", databaseStr); return; } @@ -68,10 +65,7 @@ class ViewHistory { } async _readFromStorage() { - if ( - typeof PDFJSDev !== "undefined" && - PDFJSDev.test("FIREFOX || MOZCENTRAL") - ) { + if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) { return sessionStorage.getItem("pdfjs.history"); } return localStorage.getItem("pdfjs.history"); diff --git a/web/viewer.html b/web/viewer.html index f2a284108..70d306adc 100644 --- a/web/viewer.html +++ b/web/viewer.html @@ -32,7 +32,7 @@ See https://github.com/adobe-type-tools/cmap-resources PDF.js viewer - + @@ -391,7 +391,7 @@ See https://github.com/adobe-type-tools/cmap-resources - +