Skip to content

Commit

Permalink
Ignore PDF documents opened from "data:"-URLs when handling internal …
Browse files Browse the repository at this point in the history
…links (bug 1803050)

This patch has been successfully tested in a local, artifact, Firefox build.

*Please note:* The only thing that'll no longer work for PDF documents opened using "data:"-URLs is middle-clicking on internal/outline links, in order to open the destination in a new tab. This is however an extremely small loss of functionality, and as can be seen in the bug the alternative (i.e. doing nothing) is surely much worse.
  • Loading branch information
Snuffleupagus committed Nov 29, 2022
1 parent 5d79cc5 commit 0d648f5
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/pdf.js
Expand Up @@ -52,6 +52,7 @@ import {
getFilenameFromUrl,
getPdfFilenameFromUrl,
getXfaPageViewport,
isDataScheme,
isPdfFile,
isValidFetchUrl,
loadScript,
Expand Down Expand Up @@ -125,6 +126,7 @@ export {
getXfaPageViewport,
GlobalWorkerOptions,
InvalidPDFException,
isDataScheme,
isPdfFile,
loadScript,
MissingPDFException,
Expand Down
22 changes: 20 additions & 2 deletions web/app.js
Expand Up @@ -42,6 +42,7 @@ import {
getPdfFilenameFromUrl,
GlobalWorkerOptions,
InvalidPDFException,
isDataScheme,
isPdfFile,
loadScript,
MissingPDFException,
Expand Down Expand Up @@ -731,6 +732,9 @@ const PDFViewerApplication = {
this._downloadUrl =
downloadUrl === url ? this.baseUrl : downloadUrl.split("#")[0];
}
if (isDataScheme(url)) {
this._hideViewBookmark();
}
let title = getPdfFilenameFromUrl(url, "");
if (!title) {
try {
Expand Down Expand Up @@ -766,8 +770,17 @@ const PDFViewerApplication = {
* @private
*/
_hideViewBookmark() {
const { viewBookmarkButton, presentationModeButton } =
this.appConfig.secondaryToolbar;

// URL does not reflect proper document location - hiding some buttons.
this.appConfig.secondaryToolbar.viewBookmarkButton.hidden = true;
viewBookmarkButton.hidden = true;

// Avoid displaying multiple consecutive separators in the secondaryToolbar.
if (presentationModeButton.hidden) {
const element = document.getElementById("viewBookmarkSeparator");
element.hidden = true;
}
},

/**
Expand Down Expand Up @@ -1124,6 +1137,11 @@ const PDFViewerApplication = {
} else if (PDFJSDev.test("CHROME")) {
baseDocumentUrl = location.href.split("#")[0];
}
if (baseDocumentUrl && isDataScheme(baseDocumentUrl)) {
// 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, baseDocumentUrl);
this.pdfDocumentProperties.setDocument(pdfDocument);

Expand Down Expand Up @@ -2137,7 +2155,7 @@ function webViewerInitialized() {
}

if (!PDFViewerApplication.supportsFullscreen) {
appConfig.secondaryToolbar.presentationModeButton.classList.add("hidden");
appConfig.secondaryToolbar.presentationModeButton.hidden = true;
}

if (PDFViewerApplication.supportsIntegratedFind) {
Expand Down
2 changes: 1 addition & 1 deletion web/viewer.html
Expand Up @@ -208,7 +208,7 @@
<span data-l10n-id="bookmark_label">Current View</span>
</a>

<div class="horizontalToolbarSeparator"></div>
<div id="viewBookmarkSeparator" class="horizontalToolbarSeparator"></div>

<button id="firstPage" class="secondaryToolbarButton" title="Go to First Page" tabindex="56" data-l10n-id="first_page">
<span data-l10n-id="first_page_label">Go to First Page</span>
Expand Down

0 comments on commit 0d648f5

Please sign in to comment.