Add stateOfDownload() to DownloadsCommon.jsm

This commit is contained in:
JustOff
2017-01-08 13:27:01 +02:00
committed by roytam1
parent c7f08141e4
commit 04cfe23841
@@ -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.