Merge pull request #13993 from Snuffleupagus/app-pdfHistory-init

Don't create `PDFViewerApplication.pdfHistory` when the browsing history is disabled
This commit is contained in:
Tim van der Meij 2021-09-11 13:21:42 +02:00 committed by GitHub
commit 9b42ae9612
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 15 deletions

View File

@ -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);
}
}

View File

@ -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":