From 40a96a2524e6c8da2ee3643d7021efeb5f731731 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Thu, 30 Mar 2023 11:51:25 +0200 Subject: [PATCH] [Firefox] Stop using a `baseUrl` in the `PDFLinkService` (PR 16153 follow-up) With the changes in PR 16153 we're no longer setting a `` in the Firefox PDF Viewer, hence it shouldn't be necessary to keep setting a `baseUrl` in the `PDFLinkService`-class. Given that the original document URL is now kept, the browser itself will handle relative URLs and we can thus slightly reduce the amount of string parsing required when handling various links in the viewer. --- web/app.js | 19 ++++++++----------- web/pdf_link_service.js | 2 +- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/web/app.js b/web/app.js index 685930551..9ad2a40da 100644 --- a/web/app.js +++ b/web/app.js @@ -1174,20 +1174,17 @@ const PDFViewerApplication = { this.toolbar?.setPagesCount(pdfDocument.numPages, false); this.secondaryToolbar?.setPagesCount(pdfDocument.numPages); - let baseDocumentUrl; - if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) { - baseDocumentUrl = null; - } else if (PDFJSDev.test("MOZCENTRAL")) { - baseDocumentUrl = this.baseUrl; - } else if (PDFJSDev.test("CHROME")) { - baseDocumentUrl = location.href.split("#")[0]; - } - if (baseDocumentUrl && isDataScheme(baseDocumentUrl)) { + if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("CHROME")) { + const baseUrl = location.href.split("#")[0]; // Ignore "data:"-URLs for performance reasons, even though it may cause // internal links to not work perfectly in all cases (see bug 1803050). - baseDocumentUrl = null; + this.pdfLinkService.setDocument( + pdfDocument, + isDataScheme(baseUrl) ? null : baseUrl + ); + } else { + this.pdfLinkService.setDocument(pdfDocument); } - this.pdfLinkService.setDocument(pdfDocument, baseDocumentUrl); this.pdfDocumentProperties?.setDocument(pdfDocument); const pdfViewer = this.pdfViewer; diff --git a/web/pdf_link_service.js b/web/pdf_link_service.js index 249dce587..f98d3708c 100644 --- a/web/pdf_link_service.js +++ b/web/pdf_link_service.js @@ -336,7 +336,7 @@ class PDFLinkService { * @returns {string} The hyperlink to the PDF object. */ getAnchorUrl(anchor) { - return (this.baseUrl || "") + anchor; + return this.baseUrl ? this.baseUrl + anchor : anchor; } /**