Bug 1198181 - Part 2 - Unify the code that updates the state of download items. r=jaws
MozReview-Commit-ID: KptYcAGbMG2
--- a/browser/components/downloads/DownloadsViewUI.jsm
+++ b/browser/components/downloads/DownloadsViewUI.jsm
@@ -127,16 +127,21 @@ this.DownloadsViewUI.DownloadElementShel
// We only need to add or remove this attribute for succeeded downloads.
if (this.download.target.exists) {
this.element.setAttribute("exists", "true");
} else {
this.element.removeAttribute("exists");
}
}
+ // When a block is confirmed, the removal of blocked data will not trigger a
+ // state change for the download, so this class must be updated here.
+ this.element.classList.toggle("temporary-block",
+ !!this.download.hasBlockedData);
+
// The progress bar is only displayed for in-progress downloads.
if (this.download.hasProgress) {
this.element.setAttribute("progressmode", "normal");
this.element.setAttribute("progress", this.download.progress);
} else {
this.element.setAttribute("progressmode", "undetermined");
}
--- a/browser/components/downloads/content/allDownloadsViewOverlay.js
+++ b/browser/components/downloads/content/allDownloadsViewOverlay.js
@@ -293,19 +293,17 @@ HistoryDownloadElementShell.prototype =
status.text = status.tip;
}
status.tip = "";
return status;
},
onStateChanged() {
- this.element.setAttribute("image", this.image);
- this.element.setAttribute("state",
- DownloadsCommon.stateOfDownload(this.download));
+ this._updateState();
if (this.element.selected) {
goUpdateDownloadCommands();
} else {
goUpdateCommand("downloadsCmd_clearDownloads");
}
},
--- a/browser/components/downloads/content/downloads.js
+++ b/browser/components/downloads/content/downloads.js
@@ -1030,27 +1030,20 @@ DownloadsViewItem.prototype = {
__proto__: DownloadsViewUI.DownloadElementShell.prototype,
/**
* The XUL element corresponding to the associated richlistbox item.
*/
_element: null,
onStateChanged() {
- this.element.setAttribute("image", this.image);
- this.element.setAttribute("state",
- DownloadsCommon.stateOfDownload(this.download));
+ this._updateState();
},
onChanged() {
- // This cannot be placed within onStateChanged because
- // when a download goes from hasBlockedData to !hasBlockedData
- // it will still remain in the same state.
- this.element.classList.toggle("temporary-block",
- !!this.download.hasBlockedData);
this._updateProgress();
},
isCommandEnabled(aCommand) {
switch (aCommand) {
case "downloadsCmd_open": {
if (!this.download.succeeded) {
return false;