summaryrefslogtreecommitdiffstats
path: root/application/palemoon/components/downloads/DownloadsCommon.jsm
diff options
context:
space:
mode:
authorjanekptacijarabaci <janekptacijarabaci@seznam.cz>2018-07-29 07:23:54 +0200
committerjanekptacijarabaci <janekptacijarabaci@seznam.cz>2018-07-29 07:23:54 +0200
commita970e88a1753101d2d55139bd7ae44d005c33f44 (patch)
treefc2a06ce42e69e58bf2c3d4810f7a943e9f29283 /application/palemoon/components/downloads/DownloadsCommon.jsm
parent43cebecade19978f231253b221cb36bc7039661b (diff)
downloadUXP-a970e88a1753101d2d55139bd7ae44d005c33f44.tar
UXP-a970e88a1753101d2d55139bd7ae44d005c33f44.tar.gz
UXP-a970e88a1753101d2d55139bd7ae44d005c33f44.tar.lz
UXP-a970e88a1753101d2d55139bd7ae44d005c33f44.tar.xz
UXP-a970e88a1753101d2d55139bd7ae44d005c33f44.zip
[PALEMOON] Bug 1115369 - Use notifications instead of getViewItem for DownloadsView
Diffstat (limited to 'application/palemoon/components/downloads/DownloadsCommon.jsm')
-rw-r--r--application/palemoon/components/downloads/DownloadsCommon.jsm93
1 files changed, 40 insertions, 53 deletions
diff --git a/application/palemoon/components/downloads/DownloadsCommon.jsm b/application/palemoon/components/downloads/DownloadsCommon.jsm
index bd5d55a73..0a3af7878 100644
--- a/application/palemoon/components/downloads/DownloadsCommon.jsm
+++ b/application/palemoon/components/downloads/DownloadsCommon.jsm
@@ -773,7 +773,7 @@ DownloadsDataCtor.prototype = {
if (oldState != aDataItem.state) {
for (let view of this._views) {
try {
- view.getViewItem(aDataItem).onStateChange(oldState);
+ view.onDataItemStateChanged(aDataItem, oldState);
} catch (ex) {
Cu.reportError(ex);
}
@@ -812,7 +812,7 @@ DownloadsDataCtor.prototype = {
}
for (let view of this._views) {
- view.getViewItem(aDataItem).onProgressChange();
+ view.onDataItemChanged(aDataItem);
}
},
@@ -1889,17 +1889,26 @@ const DownloadsViewPrototype = {
},
/**
- * Returns the view item associated with the provided data item for this view.
+ * Called when the "state" property of a DownloadsDataItem has changed.
*
- * @param aDataItem
- * DownloadsDataItem object for which the view item is requested.
+ * The onDataItemChanged notification will be sent afterwards.
*
- * @return Object that can be used to notify item status events.
+ * @note Subclasses should override this.
+ */
+ onDataItemStateChanged(aDataItem) {
+ throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
+ },
+
+ /**
+ * Called every time any state property of a DownloadsDataItem may have
+ * changed, including progress properties and the "state" property.
+ *
+ * Note that progress notification changes are throttled at the Downloads.jsm
+ * API level, and there is no throttling mechanism in the front-end.
*
* @note Subclasses should override this.
*/
- getViewItem: function DID_getViewItem(aDataItem)
- {
+ onDataItemChanged(aDataItem) {
throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
},
@@ -2014,37 +2023,21 @@ DownloadsIndicatorDataCtor.prototype = {
this._updateViews();
},
- /**
- * Returns the view item associated with the provided data item for this view.
- *
- * @param aDataItem
- * DownloadsDataItem object for which the view item is requested.
- *
- * @return Object that can be used to notify item status events.
- */
- getViewItem: function DID_getViewItem(aDataItem)
- {
- let data = this._isPrivate ? PrivateDownloadsIndicatorData
- : DownloadsIndicatorData;
- return Object.freeze({
- onStateChange: function DIVI_onStateChange(aOldState)
- {
- if (aDataItem.state == nsIDM.DOWNLOAD_FINISHED ||
- aDataItem.state == nsIDM.DOWNLOAD_FAILED) {
- data.attention = true;
- }
+ // DownloadsView
+ onDataItemStateChanged(aDataItem, aOldState) {
+ if (aDataItem.state == nsIDM.DOWNLOAD_FINISHED ||
+ aDataItem.state == nsIDM.DOWNLOAD_FAILED) {
+ this.attention = true;
+ }
- // Since the state of a download changed, reset the estimated time left.
- data._lastRawTimeLeft = -1;
- data._lastTimeLeft = -1;
+ // Since the state of a download changed, reset the estimated time left.
+ this._lastRawTimeLeft = -1;
+ this._lastTimeLeft = -1;
+ },
- data._updateViews();
- },
- onProgressChange: function DIVI_onProgressChange()
- {
- data._updateViews();
- }
- });
+ // DownloadsView
+ onDataItemChanged() {
+ this._updateViews();
},
//////////////////////////////////////////////////////////////////////////////
@@ -2298,22 +2291,16 @@ DownloadsSummaryData.prototype = {
this._updateViews();
},
- getViewItem: function DSD_getViewItem(aDataItem)
- {
- let self = this;
- return Object.freeze({
- onStateChange: function DIVI_onStateChange(aOldState)
- {
- // Since the state of a download changed, reset the estimated time left.
- self._lastRawTimeLeft = -1;
- self._lastTimeLeft = -1;
- self._updateViews();
- },
- onProgressChange: function DIVI_onProgressChange()
- {
- self._updateViews();
- }
- });
+ // DownloadsView
+ onDataItemStateChanged(aOldState) {
+ // Since the state of a download changed, reset the estimated time left.
+ this._lastRawTimeLeft = -1;
+ this._lastTimeLeft = -1;
+ },
+
+ // DownloadsView
+ onDataItemChanged() {
+ this._updateViews();
},
//////////////////////////////////////////////////////////////////////////////