From 0baabf69db7c83dec424b5004348f46529467ea8 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Fri, 24 Apr 2020 11:29:33 +0200 Subject: [PATCH] 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`. --- web/firefoxcom.js | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/web/firefoxcom.js b/web/firefoxcom.js index 64514c9eb..e14cdcfc2 100644 --- a/web/firefoxcom.js +++ b/web/firefoxcom.js @@ -14,8 +14,8 @@ */ import "../extensions/firefox/tools/l10n.js"; -import { createObjectURL, PDFDataRangeTransport, shadow } from "pdfjs-lib"; import { DefaultExternalServices, PDFViewerApplication } from "./app.js"; +import { PDFDataRangeTransport, shadow } from "pdfjs-lib"; import { BasePreferences } from "./preferences.js"; import { DEFAULT_SCALE_VALUE } from "./ui_utils.js"; @@ -100,14 +100,23 @@ class DownloadManager { } 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", { - blobUrl, - originalUrl: blobUrl, - filename, - isAttachment: true, - }); + FirefoxCom.request( + "download", + { + blobUrl, + originalUrl: blobUrl, + filename, + isAttachment: true, + }, + onResponse + ); } download(blob, url, filename) {