Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Firefox] Restore opening of PDF attachments (issue 17353, bug 1867764) #17363

Merged
merged 1 commit into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions web/firefoxcom.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,11 @@ class DownloadManager {
this.#openBlobUrls.set(data, blobUrl);
}
// Let Firefox's content handler catch the URL and display the PDF.
let viewerUrl = blobUrl + "?filename=" + encodeURIComponent(filename);
// NOTE: This cannot use a query string for the filename, see
// https://bugzilla.mozilla.org/show_bug.cgi?id=1632644#c5
let viewerUrl = blobUrl + "#filename=" + encodeURIComponent(filename);
if (dest) {
viewerUrl += `#${escape(dest)}`;
viewerUrl += `&filedest=${escape(dest)}`;
}

try {
Expand Down
53 changes: 31 additions & 22 deletions web/pdf_link_service.js
Original file line number Diff line number Diff line change
Expand Up @@ -431,32 +431,41 @@ class PDFLinkService {
if (params.has("nameddest")) {
this.goToDestination(params.get("nameddest"));
}
} else {
// Named (or explicit) destination.
dest = unescape(hash);
try {
dest = JSON.parse(dest);

if (!Array.isArray(dest)) {
// Avoid incorrectly rejecting a valid named destination, such as
// e.g. "4.3" or "true", because `JSON.parse` converted its type.
dest = dest.toString();
}
} catch {}

if (
typeof dest === "string" ||
PDFLinkService.#isValidExplicitDestination(dest)
) {
this.goToDestination(dest);
if (typeof PDFJSDev === "undefined" || !PDFJSDev.test("MOZCENTRAL")) {
return;
}
console.error(
`PDFLinkService.setHash: "${unescape(
hash
)}" is not a valid destination.`
);
// Support opening of PDF attachments in the Firefox PDF Viewer,
// which uses a couple of non-standard hash parameters; refer to
// `DownloadManager.openOrDownloadData` in the firefoxcom.js file.
if (!params.has("filename") || !params.has("filedest")) {
return;
}
hash = params.get("filedest");
}

// Named (or explicit) destination.
dest = unescape(hash);
try {
dest = JSON.parse(dest);

if (!Array.isArray(dest)) {
// Avoid incorrectly rejecting a valid named destination, such as
// e.g. "4.3" or "true", because `JSON.parse` converted its type.
dest = dest.toString();
}
} catch {}

if (
typeof dest === "string" ||
PDFLinkService.#isValidExplicitDestination(dest)
) {
this.goToDestination(dest);
return;
}
console.error(
`PDFLinkService.setHash: "${unescape(hash)}" is not a valid destination.`
);
}

/**
Expand Down