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

Support file save triggered from the Firefox integrated version. #12248

Merged
merged 1 commit into from
Aug 21, 2020

Conversation

brendandahl
Copy link
Contributor

Related to https://bugzilla.mozilla.org/show_bug.cgi?id=1659753

This allows Firefox trigger a "download" event from ctrl/cmd+s or the "Save
Page As" context menu, which in turn lets pdf.js generate a new PDF if
there is form data to save.

I also now set an isFallback flag on downloads triggered from the
fallback bar so Firefox can keep launching the "open with" dialog instead
of the "save as" dialog.

Copy link
Collaborator

@Snuffleupagus Snuffleupagus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, modulo a couple of small suggestions.

web/app.js Outdated
@@ -874,7 +874,7 @@ const PDFViewerApplication = {
);
},

download() {
download(isFallback) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please change this to the following, to clearly mark the parameter as optional:

Suggested change
download(isFallback) {
download(isFallback = false) {

* from the fallback bar. The version of PDF.js integrated with Firefox uses
* this to to determine whether to show the "save as" or "open with" dialog.
*/
download(blob, url, filename, isFallback) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please change this to the following, to clearly mark the parameter as optional:

Suggested change
download(blob, url, filename, isFallback) {
download(blob, url, filename, isFallback = false) {

@@ -115,7 +115,7 @@ class DownloadManager {
);
}

download(blob, url, filename) {
download(blob, url, filename, isFallback) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please change this to the following, to clearly mark the parameter as optional:

Suggested change
download(blob, url, filename, isFallback) {
download(blob, url, filename, isFallback = false) {

web/app.js Outdated
@@ -988,7 +988,7 @@ const PDFViewerApplication = {
if (!download) {
return;
}
PDFViewerApplication.download();
PDFViewerApplication.download(true /* isFallback */);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: In the code-base, this is usually formatted the following way.

Suggested change
PDFViewerApplication.download(true /* isFallback */);
PDFViewerApplication.download(/* isFallback = */ true);

@@ -2540,7 +2540,7 @@ class WorkerTransport {
numPages: this._numPages,
annotationStorage:
(annotationStorage && annotationStorage.getAll()) || null,
filename: this._fullReader.filename,
filename: this._fullReader ? this._fullReader.filename : null,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch!

@brendandahl
Copy link
Contributor Author

This is still a bit WIP, will update in a bit here once we decide how things should work in the bugzilla bug.

@@ -2334,16 +2335,22 @@ function webViewerPresentationMode() {
function webViewerPrint() {
window.print();
}
function webViewerDownload() {
function webViewerDownloadOrSave(sourceEventType) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like that this handles either calling save or download. I think the PDFViewerApplication method should do that, but let's fix that in a follow up.

@@ -1722,6 +1722,7 @@ const PDFViewerApplication = {
eventBus._on("presentationmode", webViewerPresentationMode);
eventBus._on("print", webViewerPrint);
eventBus._on("download", webViewerDownload);
eventBus._on("save", webViewerSave);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This requires a corresponding eventBus._off(...) line in PDFViewerApplication.unbindEvents below.

Related to https://bugzilla.mozilla.org/show_bug.cgi?id=1659753

This allows Firefox trigger a "save" event from ctrl/cmd+s or the "Save
Page As" context menu, which in turn lets pdf.js generate a new PDF if
there is form data to save.

I also now use `sourceEventType` on downloads so Firefox can determine if
it should launch the "open with" dialog or "save as" dialog.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants