Merge pull request #15762 from Snuffleupagus/bug-1803050

Ignore PDF documents opened from "data:"-URLs when handling internal links (bug 1803050)
This commit is contained in:
Jonas Jenwald 2022-11-29 15:16:33 +01:00 committed by GitHub
commit ff9d21ff0e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 3 deletions

View File

@ -52,6 +52,7 @@ import {
getFilenameFromUrl, getFilenameFromUrl,
getPdfFilenameFromUrl, getPdfFilenameFromUrl,
getXfaPageViewport, getXfaPageViewport,
isDataScheme,
isPdfFile, isPdfFile,
isValidFetchUrl, isValidFetchUrl,
loadScript, loadScript,
@ -125,6 +126,7 @@ export {
getXfaPageViewport, getXfaPageViewport,
GlobalWorkerOptions, GlobalWorkerOptions,
InvalidPDFException, InvalidPDFException,
isDataScheme,
isPdfFile, isPdfFile,
loadScript, loadScript,
MissingPDFException, MissingPDFException,

View File

@ -42,6 +42,7 @@ import {
getPdfFilenameFromUrl, getPdfFilenameFromUrl,
GlobalWorkerOptions, GlobalWorkerOptions,
InvalidPDFException, InvalidPDFException,
isDataScheme,
isPdfFile, isPdfFile,
loadScript, loadScript,
MissingPDFException, MissingPDFException,
@ -731,6 +732,9 @@ const PDFViewerApplication = {
this._downloadUrl = this._downloadUrl =
downloadUrl === url ? this.baseUrl : downloadUrl.split("#")[0]; downloadUrl === url ? this.baseUrl : downloadUrl.split("#")[0];
} }
if (isDataScheme(url)) {
this._hideViewBookmark();
}
let title = getPdfFilenameFromUrl(url, ""); let title = getPdfFilenameFromUrl(url, "");
if (!title) { if (!title) {
try { try {
@ -766,8 +770,17 @@ const PDFViewerApplication = {
* @private * @private
*/ */
_hideViewBookmark() { _hideViewBookmark() {
const { viewBookmarkButton, presentationModeButton } =
this.appConfig.secondaryToolbar;
// URL does not reflect proper document location - hiding some buttons. // 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;
}
}, },
/** /**
@ -1124,6 +1137,11 @@ const PDFViewerApplication = {
} else if (PDFJSDev.test("CHROME")) { } else if (PDFJSDev.test("CHROME")) {
baseDocumentUrl = location.href.split("#")[0]; 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.pdfLinkService.setDocument(pdfDocument, baseDocumentUrl);
this.pdfDocumentProperties.setDocument(pdfDocument); this.pdfDocumentProperties.setDocument(pdfDocument);
@ -2137,7 +2155,7 @@ function webViewerInitialized() {
} }
if (!PDFViewerApplication.supportsFullscreen) { if (!PDFViewerApplication.supportsFullscreen) {
appConfig.secondaryToolbar.presentationModeButton.classList.add("hidden"); appConfig.secondaryToolbar.presentationModeButton.hidden = true;
} }
if (PDFViewerApplication.supportsIntegratedFind) { if (PDFViewerApplication.supportsIntegratedFind) {

View File

@ -208,7 +208,7 @@ See https://github.com/adobe-type-tools/cmap-resources
<span data-l10n-id="bookmark_label">Current View</span> <span data-l10n-id="bookmark_label">Current View</span>
</a> </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"> <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> <span data-l10n-id="first_page_label">Go to First Page</span>