From aa289b17b6a8f2af3fabaef552f3f90b8b6dc246 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Thu, 9 Sep 2021 14:21:15 +0200 Subject: [PATCH] Don't create `PDFViewerApplication.pdfHistory` when the browsing history is disabled Similar to other viewer components, e.g. the `PDFFindBar` and `PDFPresentationMode`, there's no need to create a `PDFHistory`-instance when it's not going to be used. --- web/app.js | 20 +++++++++++--------- web/pdf_link_service.js | 8 ++------ 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/web/app.js b/web/app.js index c2c6b7eae..b0d4be166 100644 --- a/web/app.js +++ b/web/app.js @@ -534,11 +534,15 @@ const PDFViewerApplication = { }); pdfRenderingQueue.setThumbnailViewer(this.pdfThumbnailViewer); - this.pdfHistory = new PDFHistory({ - linkService: pdfLinkService, - eventBus, - }); - pdfLinkService.setHistory(this.pdfHistory); + // The browsing history is only enabled when the viewer is standalone, + // i.e. not when it is embedded in a web page. + if (!this.isViewerEmbedded && !AppOptions.get("disableHistory")) { + this.pdfHistory = new PDFHistory({ + linkService: pdfLinkService, + eventBus, + }); + pdfLinkService.setHistory(this.pdfHistory); + } if (!this.supportsIntegratedFind) { this.findBar = new PDFFindBar(appConfig.findBar, eventBus, this.l10n); @@ -1631,9 +1635,7 @@ const PDFViewerApplication = { * @private */ _initializePdfHistory({ fingerprint, viewOnLoad, initialDest = null }) { - if (this.isViewerEmbedded || AppOptions.get("disableHistory")) { - // The browsing history is only enabled when the viewer is standalone, - // i.e. not when it is embedded in a web page. + if (!this.pdfHistory) { return; } this.pdfHistory.initialize({ @@ -2456,7 +2458,7 @@ function webViewerHashchange(evt) { } if (!PDFViewerApplication.isInitialViewSet) { PDFViewerApplication.initialBookmark = hash; - } else if (!PDFViewerApplication.pdfHistory.popStateInProgress) { + } else if (!PDFViewerApplication.pdfHistory?.popStateInProgress) { PDFViewerApplication.pdfLinkService.setHash(hash); } } diff --git a/web/pdf_link_service.js b/web/pdf_link_service.js index 32109f183..cd83e2711 100644 --- a/web/pdf_link_service.js +++ b/web/pdf_link_service.js @@ -380,15 +380,11 @@ class PDFLinkService { // See PDF reference, table 8.45 - Named action switch (action) { case "GoBack": - if (this.pdfHistory) { - this.pdfHistory.back(); - } + this.pdfHistory?.back(); break; case "GoForward": - if (this.pdfHistory) { - this.pdfHistory.forward(); - } + this.pdfHistory?.forward(); break; case "NextPage":