diff --git a/web/app.js b/web/app.js index bb4808b26e59f..8f70f532fe471 100644 --- a/web/app.js +++ b/web/app.js @@ -811,7 +811,7 @@ const PDFViewerApplication = { ) { try { // Trigger saving, to prevent data loss in forms; see issue 12257. - await this.save({ sourceEventType: "save" }); + await this.save(); } catch (reason) { // Ignoring errors, to ensure that document closing won't break. } @@ -964,7 +964,7 @@ const PDFViewerApplication = { throw new Error("PDF document not downloaded."); }, - async download({ sourceEventType = "download" } = {}) { + async download() { const url = this._downloadUrl, filename = this._docFilename; try { @@ -973,7 +973,7 @@ const PDFViewerApplication = { const data = await this.pdfDocument.getData(); const blob = new Blob([data], { type: "application/pdf" }); - await this.downloadManager.download(blob, url, filename, sourceEventType); + await this.downloadManager.download(blob, url, filename); } catch (reason) { // When the PDF document isn't ready, or the PDF file is still // downloading, simply download using the URL. @@ -981,7 +981,7 @@ const PDFViewerApplication = { } }, - async save({ sourceEventType = "download" } = {}) { + async save() { if (this._saveInProgress) { return; } @@ -996,23 +996,23 @@ const PDFViewerApplication = { const data = await this.pdfDocument.saveDocument(); const blob = new Blob([data], { type: "application/pdf" }); - await this.downloadManager.download(blob, url, filename, sourceEventType); + await this.downloadManager.download(blob, url, filename); } catch (reason) { // When the PDF document isn't ready, or the PDF file is still // downloading, simply fallback to a "regular" download. console.error(`Error when saving the document: ${reason.message}`); - await this.download({ sourceEventType }); + await this.download(); } finally { await this.pdfScriptingManager.dispatchDidSave(); this._saveInProgress = false; } }, - downloadOrSave(options) { + downloadOrSave() { if (this.pdfDocument?.annotationStorage.size > 0) { - this.save(options); + this.save(); } else { - this.download(options); + this.download(); } }, @@ -1875,7 +1875,6 @@ const PDFViewerApplication = { eventBus._on("presentationmode", webViewerPresentationMode); eventBus._on("print", webViewerPrint); eventBus._on("download", webViewerDownload); - eventBus._on("save", webViewerSave); eventBus._on("firstpage", webViewerFirstPage); eventBus._on("lastpage", webViewerLastPage); eventBus._on("nextpage", webViewerNextPage); @@ -1973,7 +1972,6 @@ const PDFViewerApplication = { eventBus._off("presentationmode", webViewerPresentationMode); eventBus._off("print", webViewerPrint); eventBus._off("download", webViewerDownload); - eventBus._off("save", webViewerSave); eventBus._off("firstpage", webViewerFirstPage); eventBus._off("lastpage", webViewerLastPage); eventBus._off("nextpage", webViewerNextPage); @@ -2330,7 +2328,7 @@ function webViewerNamedAction(evt) { break; case "SaveAs": - webViewerSave(); + PDFViewerApplication.downloadOrSave(); break; } } @@ -2461,10 +2459,7 @@ function webViewerPrint() { PDFViewerApplication.triggerPrinting(); } function webViewerDownload() { - PDFViewerApplication.downloadOrSave({ sourceEventType: "download" }); -} -function webViewerSave() { - PDFViewerApplication.downloadOrSave({ sourceEventType: "save" }); + PDFViewerApplication.downloadOrSave(); } function webViewerFirstPage() { if (PDFViewerApplication.pdfDocument) { diff --git a/web/download_manager.js b/web/download_manager.js index 27609563fc2f0..91b24ee610d13 100644 --- a/web/download_manager.js +++ b/web/download_manager.js @@ -109,13 +109,7 @@ class DownloadManager { return false; } - /** - * @param sourceEventType {string} Used to signal what triggered the download. - * The version of PDF.js integrated with Firefox uses this to to determine - * which dialog to show. "save" triggers "save as" and "download" triggers - * the "open with" dialog. - */ - download(blob, url, filename, sourceEventType = "download") { + download(blob, url, filename) { const blobUrl = URL.createObjectURL(blob); download(blobUrl, filename); } diff --git a/web/firefoxcom.js b/web/firefoxcom.js index aa9c876542034..ecbb10eebd57a 100644 --- a/web/firefoxcom.js +++ b/web/firefoxcom.js @@ -116,13 +116,11 @@ class DownloadManager { new Blob([data], { type: contentType }) ); - FirefoxCom.requestAsync("download", { + FirefoxCom.request("download", { blobUrl, originalUrl: blobUrl, filename, isAttachment: true, - }).then(error => { - URL.revokeObjectURL(blobUrl); }); } @@ -158,21 +156,13 @@ class DownloadManager { return false; } - download(blob, url, filename, sourceEventType = "download") { + download(blob, url, filename) { const blobUrl = URL.createObjectURL(blob); - FirefoxCom.requestAsync("download", { + FirefoxCom.request("download", { blobUrl, originalUrl: url, filename, - sourceEventType, - }).then(error => { - if (error) { - // If downloading failed in `PdfStreamConverter.jsm` it's very unlikely - // that attempting to fallback and re-download would be helpful here. - console.error("`ChromeActions.download` failed."); - } - URL.revokeObjectURL(blobUrl); }); } } @@ -275,7 +265,7 @@ class MozL10n { if (!PDFViewerApplication.initialized) { return; } - PDFViewerApplication.eventBus.dispatch(type, { source: window }); + PDFViewerApplication.eventBus.dispatch("download", { source: window }); }; window.addEventListener("save", handleEvent); diff --git a/web/interfaces.js b/web/interfaces.js index 93b4f34899069..7630b5051f0a5 100644 --- a/web/interfaces.js +++ b/web/interfaces.js @@ -267,9 +267,8 @@ class IDownloadManager { * @param {Blob} blob * @param {string} url * @param {string} filename - * @param {string} [sourceEventType] */ - download(blob, url, filename, sourceEventType = "download") {} + download(blob, url, filename) {} } /** diff --git a/web/pdf_scripting_manager.js b/web/pdf_scripting_manager.js index a65d2c02adcc1..32a2f173243ba 100644 --- a/web/pdf_scripting_manager.js +++ b/web/pdf_scripting_manager.js @@ -311,7 +311,7 @@ class PDFScriptingManager { this._pdfViewer.currentScaleValue = value; break; case "SaveAs": - this._eventBus.dispatch("save", { source: this }); + this._eventBus.dispatch("download", { source: this }); break; case "FirstPage": this._pdfViewer.currentPageNumber = 1;