From 04cfe238417a1bea240f80de526364afd67bb46c Mon Sep 17 00:00:00 2001 From: JustOff Date: Sun, 8 Jan 2017 13:27:01 +0200 Subject: [PATCH] Add stateOfDownload() to DownloadsCommon.jsm --- .../components/downloads/DownloadsCommon.jsm | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/browser/components/downloads/DownloadsCommon.jsm b/browser/components/downloads/DownloadsCommon.jsm index dfb5550225..b90baaf9ca 100644 --- a/browser/components/downloads/DownloadsCommon.jsm +++ b/browser/components/downloads/DownloadsCommon.jsm @@ -353,6 +353,35 @@ this.DownloadsCommon = { _summary: null, _privateSummary: null, + /** + * Returns the legacy state integer value for the provided Download object. + */ + stateOfDownload(download) { + // Collapse state using the correct priority. + if (!download.stopped) { + return nsIDM.DOWNLOAD_DOWNLOADING; + } + if (download.succeeded) { + return nsIDM.DOWNLOAD_FINISHED; + } + if (download.error) { + if (download.error.becauseBlockedByParentalControls) { + return nsIDM.DOWNLOAD_BLOCKED_PARENTAL; + } + if (download.error.becauseBlockedByReputationCheck) { + return nsIDM.DOWNLOAD_DIRTY; + } + return nsIDM.DOWNLOAD_FAILED; + } + if (download.canceled) { + if (download.hasPartialData) { + return nsIDM.DOWNLOAD_PAUSED; + } + return nsIDM.DOWNLOAD_CANCELED; + } + return nsIDM.DOWNLOAD_NOTSTARTED; + }, + /** * Given an iterable collection of DownloadDataItems, generates and returns * statistics about that collection.