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] Allow PDF attachments to, once again, be opened directly in the browser (bug 1632644) #11917

Merged
merged 2 commits into from
May 20, 2020

Conversation

Snuffleupagus
Copy link
Collaborator

Apparently the old link format used in MOZCENTRAL-builds, with the blob URL separated from the filename with a ? character violates the specification; see https://bugzilla.mozilla.org/show_bug.cgi?id=1632644#c5

Obviously just removing the ?-part of the URL would have worked, but that would also have meant that we'd no longer be able to provide the correct filename when the user attempts to download the opened PDF attachment.
To fix this we'll instead append the filename in the hash-part of the URL, which however required using a custom hash-parameter to avoid triggering the fallback "named destination" code-paths in the viewer.

Note that only changing the web/pdf_attachment_viewer.js file wasn't sufficient to fix the bug, and we also need to tweak the webViewerInitialized function in web/app.js since MOZCENTRAL-builds used to ignore everything in the URL hash.
This particular code is very old, but changing it should be completely safe given that the PDFViewerApplication.setTitleUsingUrl method since some time now stores both the original URL (in this.url) as well as one without the hash (in this.baseUrl). The latter one is already used everywhere where it matters, so this change seem fine to me.

This patch thus restores the original behaviour for PDF attachments in the MOZCENTRAL-build, by once again allowing them to be opened directly in the browser without downloading. (The fallback added in PR #11845 is obviously kept, since it seems generally useful to have.)

Fixes https://bugzilla.mozilla.org/show_bug.cgi?id=1632644

… the browser (bug 1632644)

Apparently the old link format used in MOZCENTRAL-builds, with the blob URL separated from the filename with a `?` character violates the specification; see https://bugzilla.mozilla.org/show_bug.cgi?id=1632644#c5

Obviously just removing the `?`-part of the URL would have worked, but that would also have meant that we'd no longer be able to provide the correct filename when the user attempts to download the opened PDF attachment.
To fix this we'll instead append the filename in the hash-part of the URL, which however required using a *custom* hash-parameter to avoid triggering the fallback "named destination" code-paths in the viewer.

Note that only changing the `web/pdf_attachment_viewer.js` file wasn't sufficient to fix the bug, and we also need to tweak the `webViewerInitialized` function in `web/app.js` since MOZCENTRAL-builds used to ignore *everything* in the URL hash.
This particular code is very old, but changing it *should* be completely safe given that the `PDFViewerApplication.setTitleUsingUrl` method since some time now stores both the original URL (in `this.url`) as well as one without the hash (in `this.baseUrl`). The latter one is already used everywhere where it matters, so this change seem fine to me.

This patch thus restores the original behaviour for PDF attachments in the MOZCENTRAL-build, by once again allowing them to be opened *directly* in the browser without downloading. (The fallback added in PR 11845 is obviously kept, since it seems generally useful to have.)
…URL` call in `web/pdf_document_properties.js` (PR 10114 follow-up)

Given that the `getPDFFileNameFromURL` helper function has a specific code-path for handling non-string inputs, this empty string fallback really isn't necessary at the call-site in `web/pdf_document_properties.js`.
@timvandermeij
Copy link
Contributor

/botio-linux preview

@pdfjsbot
Copy link

From: Bot.io (Linux m4)


Received

Command cmd_preview from @timvandermeij received. Current queue size: 0

Live output at: http://54.67.70.0:8877/c295039c9f36c26/output.txt

@pdfjsbot
Copy link

From: Bot.io (Linux m4)


Success

Full output at http://54.67.70.0:8877/c295039c9f36c26/output.txt

Total script time: 3.42 mins

Published

@timvandermeij timvandermeij merged commit 0960e6c into mozilla:master May 20, 2020
@timvandermeij
Copy link
Contributor

Looks good to me; thanks!

@Snuffleupagus Snuffleupagus deleted the bug-1632644 branch May 20, 2020 11:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants