From 8bbfcd3bef0d265c928a776fcdd66f2100fbb554 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Fri, 3 Nov 2023 09:56:37 +0100 Subject: [PATCH 1/3] Re-factor how the `canvasMaxAreaInBytes`-option is handled in `PDFViewerApplication.open` (PR 17208 follow-up) With the changes in PR 17208, where browser-preferences are now handled as "regular" viewer-options, we can tweak the definition of `canvasMaxAreaInBytes` to slightly simplify things in the `PDFViewerApplication.open` method. --- web/app.js | 1 - web/app_options.js | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/web/app.js b/web/app.js index 36ef5d47a..2f0018e81 100644 --- a/web/app.js +++ b/web/app.js @@ -1023,7 +1023,6 @@ const PDFViewerApplication = { // Set the necessary API parameters, using all the available options. const apiParams = AppOptions.getAll(OptionKind.API); const params = { - canvasMaxAreaInBytes: AppOptions.get("canvasMaxAreaInBytes"), ...apiParams, ...args, }; diff --git a/web/app_options.js b/web/app_options.js index 970b0ba83..dbde2ed7b 100644 --- a/web/app_options.js +++ b/web/app_options.js @@ -57,7 +57,7 @@ const defaultOptions = { canvasMaxAreaInBytes: { /** @type {number} */ value: -1, - kind: OptionKind.BROWSER, + kind: OptionKind.BROWSER + OptionKind.API, }, isInAutomation: { /** @type {boolean} */ From e20dabb65bf208d3d1a6bba23e2c28fdf8aaa2dd Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Fri, 3 Nov 2023 10:07:18 +0100 Subject: [PATCH 2/3] Simplify how the `docBaseUrl`-option is handled in `PDFViewerApplication.open` Reduce the "special" handling a bit here, by setting the viewer-option such that it'll be automatically included in the API-parameters. --- web/app.js | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/web/app.js b/web/app.js index 2f0018e81..cc464a8a4 100644 --- a/web/app.js +++ b/web/app.js @@ -1020,19 +1020,20 @@ const PDFViewerApplication = { /* downloadUrl = */ args.url ); } + // Always set `docBaseUrl` in development mode, and in the (various) + // extension builds. + if (typeof PDFJSDev === "undefined") { + AppOptions.set("docBaseUrl", document.URL.split("#")[0]); + } else if (PDFJSDev.test("MOZCENTRAL || CHROME")) { + AppOptions.set("docBaseUrl", this.baseUrl); + } + // Set the necessary API parameters, using all the available options. const apiParams = AppOptions.getAll(OptionKind.API); - const params = { + const loadingTask = getDocument({ ...apiParams, ...args, - }; - - if (typeof PDFJSDev === "undefined") { - params.docBaseUrl ||= document.URL.split("#")[0]; - } else if (PDFJSDev.test("MOZCENTRAL || CHROME")) { - params.docBaseUrl ||= this.baseUrl; - } - const loadingTask = getDocument(params); + }); this.pdfLoadingTask = loadingTask; loadingTask.onPassword = (updateCallback, reason) => { From 84aaafcd3e5ff54390e302f3dff385f04e0b49ae Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Fri, 3 Nov 2023 10:46:23 +0100 Subject: [PATCH 3/3] Use a limit when splitting URL-strings in `web/app.js` This should be a *tiny* bit more efficient, since it avoids parsing substrings that we don't care about. --- web/app.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/web/app.js b/web/app.js index cc464a8a4..6014948eb 100644 --- a/web/app.js +++ b/web/app.js @@ -870,10 +870,10 @@ const PDFViewerApplication = { setTitleUsingUrl(url = "", downloadUrl = null) { this.url = url; - this.baseUrl = url.split("#")[0]; + this.baseUrl = url.split("#", 1)[0]; if (downloadUrl) { this._downloadUrl = - downloadUrl === url ? this.baseUrl : downloadUrl.split("#")[0]; + downloadUrl === url ? this.baseUrl : downloadUrl.split("#", 1)[0]; } if (isDataScheme(url)) { this._hideViewBookmark(); @@ -1023,7 +1023,7 @@ const PDFViewerApplication = { // Always set `docBaseUrl` in development mode, and in the (various) // extension builds. if (typeof PDFJSDev === "undefined") { - AppOptions.set("docBaseUrl", document.URL.split("#")[0]); + AppOptions.set("docBaseUrl", document.URL.split("#", 1)[0]); } else if (PDFJSDev.test("MOZCENTRAL || CHROME")) { AppOptions.set("docBaseUrl", this.baseUrl); } @@ -1252,7 +1252,7 @@ const PDFViewerApplication = { this.secondaryToolbar?.setPagesCount(pdfDocument.numPages); if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("CHROME")) { - const baseUrl = location.href.split("#")[0]; + const baseUrl = location.href.split("#", 1)[0]; // Ignore "data:"-URLs for performance reasons, even though it may cause // internal links to not work perfectly in all cases (see bug 1803050). this.pdfLinkService.setDocument(