Merge pull request #12804 from Snuffleupagus/DownloadManager-rm-onerror

Remove the `DownloadManager.onerror` functionality, since its only usage is unlikely to be helpful
This commit is contained in:
Tim van der Meij 2021-01-03 12:42:42 +01:00 committed by GitHub
commit 1810e65d96
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 28 deletions

View File

@ -763,6 +763,12 @@ const PDFViewerApplication = {
document.title = title; document.title = title;
}, },
get _docFilename() {
// Use `this.url` instead of `this.baseUrl` to perform filename detection
// based on the reference fragment as ultimate fallback if needed.
return this._contentDispositionFilename || getPDFFileNameFromURL(this.url);
},
/** /**
* @private * @private
*/ */
@ -984,17 +990,9 @@ const PDFViewerApplication = {
downloadManager.downloadUrl(url, filename); downloadManager.downloadUrl(url, filename);
} }
const url = this.baseUrl; const downloadManager = this.downloadManager,
// Use this.url instead of this.baseUrl to perform filename detection based url = this.baseUrl,
// on the reference fragment as ultimate fallback if needed. filename = this._docFilename;
const filename =
this._contentDispositionFilename || getPDFFileNameFromURL(this.url);
const downloadManager = this.downloadManager;
downloadManager.onerror = err => {
// This error won't really be helpful because it's likely the
// fallback won't work either (or is already open).
this.error(`PDF failed to download: ${err}`);
};
// When the PDF document isn't ready, or the PDF file is still downloading, // When the PDF document isn't ready, or the PDF file is still downloading,
// simply download using the URL. // simply download using the URL.
@ -1017,17 +1015,9 @@ const PDFViewerApplication = {
return; return;
} }
const url = this.baseUrl; const downloadManager = this.downloadManager,
// Use this.url instead of this.baseUrl to perform filename detection based url = this.baseUrl,
// on the reference fragment as ultimate fallback if needed. filename = this._docFilename;
const filename =
this._contentDispositionFilename || getPDFFileNameFromURL(this.url);
const downloadManager = this.downloadManager;
downloadManager.onerror = err => {
// This error won't really be helpful because it's likely the
// fallback won't work either (or is already open).
this.error(`PDF failed to be saved: ${err}`);
};
// When the PDF document isn't ready, or the PDF file is still downloading, // When the PDF document isn't ready, or the PDF file is still downloading,
// simply download using the URL. // simply download using the URL.
@ -1587,8 +1577,6 @@ const PDFViewerApplication = {
} }
this._contentLength = length; this._contentLength = length;
} }
const filename =
this._contentDispositionFilename || getPDFFileNameFromURL(this.url);
try { try {
await scripting.createSandbox({ await scripting.createSandbox({
@ -1602,7 +1590,7 @@ const PDFViewerApplication = {
...this.documentInfo, ...this.documentInfo,
baseURL: this.baseUrl, baseURL: this.baseUrl,
filesize: this._contentLength, filesize: this._contentLength,
filename, filename: this._docFilename,
metadata: this.metadata, metadata: this.metadata,
numPages: pdfDocument.numPages, numPages: pdfDocument.numPages,
URL: this.url, URL: this.url,

View File

@ -71,7 +71,6 @@ class DownloadManager {
this.downloadUrl(url, filename); this.downloadUrl(url, filename);
return; return;
} }
const blobUrl = URL.createObjectURL(blob); const blobUrl = URL.createObjectURL(blob);
download(blobUrl, filename); download(blobUrl, filename);
} }

View File

@ -130,8 +130,10 @@ class DownloadManager {
filename, filename,
sourceEventType, sourceEventType,
}).then(error => { }).then(error => {
if (error && this.onerror) { if (error) {
this.onerror(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); URL.revokeObjectURL(blobUrl);
}); });