Bug 1393418 - Fix initialization of the Downloads Indicator on startup. r=mak
MozReview-Commit-ID: GEQZoak5MFl
--- a/browser/components/downloads/DownloadsCommon.jsm
+++ b/browser/components/downloads/DownloadsCommon.jsm
@@ -945,16 +945,17 @@ const DownloadsViewPrototype = {
this._loading = true;
},
/**
* Called after data loading finished.
*/
onDownloadBatchEnded() {
this._loading = false;
+ this._updateViews();
},
/**
* Called when a new download data item is available, either during the
* asynchronous data load or when a new download is started.
*
* @param download
* Download object that was just added.
@@ -1024,16 +1025,29 @@ const DownloadsViewPrototype = {
/**
* Private function used to refresh an individual view.
*
* @note Subclasses should override this.
*/
_updateView() {
throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
},
+
+ /**
+ * Computes aggregate values and propagates the changes to our views.
+ */
+ _updateViews() {
+ // Do not update the status indicators during batch loads of download items.
+ if (this._loading) {
+ return;
+ }
+
+ this._refreshProperties();
+ this._views.forEach(this._updateView, this);
+ },
};
// DownloadsIndicatorData
/**
* This object registers itself with DownloadsData as a view, and transforms the
* notifications it receives into overall status data, that is then broadcast to
* the registered download status indicators.
@@ -1060,23 +1074,16 @@ DownloadsIndicatorDataCtor.prototype = {
removeView(aView) {
DownloadsViewPrototype.removeView.call(this, aView);
if (this._views.length == 0) {
this._itemCount = 0;
}
},
- // Callback functions from DownloadsData
-
- onDataLoadCompleted() {
- DownloadsViewPrototype.onDataLoadCompleted.call(this);
- this._updateViews();
- },
-
onDownloadAdded(download) {
DownloadsViewPrototype.onDownloadAdded.call(this, download);
this._itemCount++;
this._updateViews();
},
onDownloadStateChanged(download) {
if (!download.succeeded && download.error && download.error.reputationCheckVerdict) {
@@ -1145,30 +1152,16 @@ DownloadsIndicatorDataCtor.prototype = {
this._attentionSuppressed = aValue;
this._attention = DownloadsCommon.ATTENTION_NONE;
this._updateViews();
return aValue;
},
_attentionSuppressed: false,
/**
- * Computes aggregate values and propagates the changes to our views.
- */
- _updateViews() {
- // Do not update the status indicators during batch loads of download items.
- if (this._loading) {
- return;
- }
-
- this._refreshProperties();
-
- this._views.forEach(this._updateView, this);
- },
-
- /**
* Updates the specified view with the current aggregate values.
*
* @param aView
* DownloadsIndicatorView object to be updated.
*/
_updateView(aView) {
aView.hasDownloads = this._hasDownloads;
aView.percentComplete = this._percentComplete;
@@ -1292,25 +1285,16 @@ DownloadsSummaryData.prototype = {
if (this._views.length == 0) {
// Clear out our collection of Download objects. If we ever have
// another view registered with us, this will get re-populated.
this._downloads = [];
}
},
- // Callback functions from DownloadsData - see the documentation in
- // DownloadsViewPrototype for more information on what these functions
- // are used for.
-
- onDataLoadCompleted() {
- DownloadsViewPrototype.onDataLoadCompleted.call(this);
- this._updateViews();
- },
-
onDownloadAdded(download) {
DownloadsViewPrototype.onDownloadAdded.call(this, download);
this._downloads.unshift(download);
this._updateViews();
},
onDownloadStateChanged() {
// Since the state of a download changed, reset the estimated time left.
@@ -1327,29 +1311,16 @@ DownloadsSummaryData.prototype = {
let itemIndex = this._downloads.indexOf(download);
this._downloads.splice(itemIndex, 1);
this._updateViews();
},
// Propagation of properties to our views
/**
- * Computes aggregate values and propagates the changes to our views.
- */
- _updateViews() {
- // Do not update the status indicators during batch loads of download items.
- if (this._loading) {
- return;
- }
-
- this._refreshProperties();
- this._views.forEach(this._updateView, this);
- },
-
- /**
* Updates the specified view with the current aggregate values.
*
* @param aView
* DownloadsIndicatorView object to be updated.
*/
_updateView(aView) {
aView.showingProgress = this._showingProgress;
aView.percentComplete = this._percentComplete;