Merge pull request #14926 from Snuffleupagus/rm-sourceEventType

Remove the `sourceEventType` from the viewer (bug 1757771 follow-up)
This commit is contained in:
Tim van der Meij 2022-05-21 12:34:54 +02:00 committed by GitHub
commit 42a6217427
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 18 additions and 40 deletions

View File

@ -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) {

View File

@ -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);
}

View File

@ -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);

View File

@ -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) {}
}
/**

View File

@ -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;