Use the native URL.createObjectURL method more in web/firefoxcom.js

Given that `URL.createObjectURL` is assumed to always be available in MOZCENTRAL builds, note the existing usage in the file, there's no reason to depend on the PDF.js helper function `createObjectURL` at all here.

Furthermore this patch also changes `DownloadManager.downloadData` to actually revoke the `blobUrl` after downloading has completed, which is similar to the existing code in `DownloadManager.download`.
This commit is contained in:
Jonas Jenwald 2020-04-24 11:29:33 +02:00
parent cd2878755b
commit 0baabf69db

View File

@ -14,8 +14,8 @@
*/ */
import "../extensions/firefox/tools/l10n.js"; import "../extensions/firefox/tools/l10n.js";
import { createObjectURL, PDFDataRangeTransport, shadow } from "pdfjs-lib";
import { DefaultExternalServices, PDFViewerApplication } from "./app.js"; import { DefaultExternalServices, PDFViewerApplication } from "./app.js";
import { PDFDataRangeTransport, shadow } from "pdfjs-lib";
import { BasePreferences } from "./preferences.js"; import { BasePreferences } from "./preferences.js";
import { DEFAULT_SCALE_VALUE } from "./ui_utils.js"; import { DEFAULT_SCALE_VALUE } from "./ui_utils.js";
@ -100,14 +100,23 @@ class DownloadManager {
} }
downloadData(data, filename, contentType) { downloadData(data, filename, contentType) {
const blobUrl = createObjectURL(data, contentType); const blobUrl = URL.createObjectURL(
new Blob([data], { type: contentType })
);
const onResponse = err => {
URL.revokeObjectURL(blobUrl);
};
FirefoxCom.request("download", { FirefoxCom.request(
blobUrl, "download",
originalUrl: blobUrl, {
filename, blobUrl,
isAttachment: true, originalUrl: blobUrl,
}); filename,
isAttachment: true,
},
onResponse
);
} }
download(blob, url, filename) { download(blob, url, filename) {