Bug 1139914 - Downloads with blocked data should be persisted across sessions. r=mak
MozReview-Commit-ID: 4XkSTaNZcLo
--- a/browser/components/downloads/DownloadsCommon.jsm
+++ b/browser/components/downloads/DownloadsCommon.jsm
@@ -723,17 +723,21 @@ DownloadsDataCtor.prototype = {
try {
let downloadMetaData = {
state: DownloadsCommon.stateOfDownload(download),
endTime: download.endTime,
};
if (download.succeeded) {
downloadMetaData.fileSize = download.target.size;
}
-
+ if (download.error && download.error.reputationCheckVerdict) {
+ downloadMetaData.reputationCheckVerdict =
+ download.error.reputationCheckVerdict;
+ }
+
PlacesUtils.annotations.setPageAnnotation(
NetUtil.newURI(download.source.url),
"downloads/metaData",
JSON.stringify(downloadMetaData), 0,
PlacesUtils.annotations.EXPIRE_WITH_HISTORY);
} catch (ex) {
Cu.reportError(ex);
}
--- a/browser/components/downloads/content/allDownloadsViewOverlay.js
+++ b/browser/components/downloads/content/allDownloadsViewOverlay.js
@@ -67,27 +67,34 @@ HistoryDownload.prototype = {
.getService(Ci.nsIFileProtocolHandler)
.getFileFromURLSpec(metaData.targetFileSpec).path;
} catch (ex) {
this.target.path = undefined;
}
if ("state" in metaData) {
this.succeeded = metaData.state == nsIDM.DOWNLOAD_FINISHED;
- this.error = metaData.state == nsIDM.DOWNLOAD_FAILED
- ? { message: "History download failed." }
- : metaData.state == nsIDM.DOWNLOAD_BLOCKED_PARENTAL
- ? { becauseBlockedByParentalControls: true }
- : metaData.state == nsIDM.DOWNLOAD_DIRTY
- ? { becauseBlockedByReputationCheck: true }
- : null;
this.canceled = metaData.state == nsIDM.DOWNLOAD_CANCELED ||
metaData.state == nsIDM.DOWNLOAD_PAUSED;
this.endTime = metaData.endTime;
+ // Recreate partial error information from the state saved in history.
+ if (metaData.state == nsIDM.DOWNLOAD_FAILED) {
+ this.error = { message: "History download failed." };
+ } else if (metaData.state == nsIDM.DOWNLOAD_BLOCKED_PARENTAL) {
+ this.error = { becauseBlockedByParentalControls: true };
+ } else if (metaData.state == nsIDM.DOWNLOAD_DIRTY) {
+ this.error = {
+ becauseBlockedByReputationCheck: true,
+ reputationCheckVerdict: metaData.reputationCheckVerdict || "",
+ };
+ } else {
+ this.error = null;
+ }
+
// Normal history downloads are assumed to exist until the user interface
// is refreshed, at which point these values may be updated.
this.target.exists = true;
this.target.size = metaData.fileSize;
} else {
// Metadata might be missing from a download that has started but hasn't
// stopped already. Normally, this state is overridden with the one from
// the corresponding in-progress session download. But if the browser is
--- a/toolkit/components/jsdownloads/src/DownloadIntegration.jsm
+++ b/toolkit/components/jsdownloads/src/DownloadIntegration.jsm
@@ -344,31 +344,35 @@ this.DownloadIntegration = {
* from a private browsing window. The item may have been removed
* from the list since the save operation started, though in this case
* the save operation will be repeated later.
*
* @return True to save the download, false otherwise.
*/
shouldPersistDownload: function (aDownload)
{
- // In the default implementation, we save all the downloads currently in
- // progress, as well as stopped downloads for which we retained partially
- // downloaded data. Stopped downloads for which we don't need to track the
- // presence of a ".part" file are only retained in the browser history.
- // On b2g, we keep a few days of history. On Android we store all history.
+ // On all platforms, we save all the downloads currently in progress, as
+ // well as stopped downloads for which we retained partially downloaded
+ // data or we have blocked data.
+ if (!aDownload.stopped || aDownload.hasPartialData ||
+ aDownload.hasBlockedData) {
+ return true;
+ }
#ifdef MOZ_B2G
+ // On B2G we keep a few days of history.
let maxTime = Date.now() -
Services.prefs.getIntPref("dom.downloads.max_retention_days") * 24 * 60 * 60 * 1000;
- return (aDownload.startTime > maxTime) ||
- aDownload.hasPartialData ||
- !aDownload.stopped;
+ return aDownload.startTime > maxTime;
#elif defined(MOZ_WIDGET_ANDROID)
+ // On Android we store all history.
return true;
#else
- return aDownload.hasPartialData || !aDownload.stopped;
+ // On Desktop, stopped downloads for which we don't need to track the
+ // presence of a ".part" file are only retained in the browser history.
+ return false;
#endif
},
/**
* Returns the system downloads directory asynchronously.
*
* @return {Promise}
* @resolves The downloads directory string path.