Bug 910618 - Clear progress on download cancel and on interaction with infobar. r=jmathies
authorMarina Samuel <msamuel@mozilla.com>
Tue, 10 Sep 2013 19:07:58 -0400
changeset 146677 35a772328e246abec98b50226213514ce9d5fe43
parent 146676 a1a846de1a8aff4c1bd00f7e72e2c912222f108f
child 146678 92b84e142f38cea863ff2ab3595588f70cb574eb
push idunknown
push userunknown
push dateunknown
reviewersjmathies
bugs910618
milestone26.0a1
Bug 910618 - Clear progress on download cancel and on interaction with infobar. r=jmathies
browser/metro/base/content/bindings/notification.xml
browser/metro/base/content/downloads.js
--- a/browser/metro/base/content/bindings/notification.xml
+++ b/browser/metro/base/content/bindings/notification.xml
@@ -48,16 +48,17 @@
           <![CDATA[
             if (aItem == this.currentNotification)
               this.removeCurrentNotification(aSkipAnimation);
             else if (aItem != this._closedNotification)
               this._removeNotificationElement(aItem);
 
             // Fire notification closed event.
             let event = new Event('AlertClose');
+            event.notification = aItem;
             this.dispatchEvent(event);
 
             return aItem;
           ]]>
         </body>
       </method>
       <method name="handleEvent">
         <parameter name="aEvent"/>
--- a/browser/metro/base/content/downloads.js
+++ b/browser/metro/base/content/downloads.js
@@ -52,16 +52,17 @@ var Downloads = {
 
     Services.obs.addObserver(this, "dl-start", true);
     Services.obs.addObserver(this, "dl-done", true);
     Services.obs.addObserver(this, "dl-run", true);
     Services.obs.addObserver(this, "dl-failed", true);
     Services.obs.addObserver(this, "dl-request", true);
 
     this._notificationBox = Browser.getNotificationBox();
+    this._notificationBox.addEventListener('AlertClose', this.handleEvent, true);
 
     this._progress = new DownloadProgressListener(this);
     this.manager.addListener(this._progress);
 
     this._downloadProgressIndicator = document.getElementById("download-progress");
 
     if (this.manager.activeDownloadCount) {
       setTimeout (this._restartWithActiveDownloads.bind(this), 0);
@@ -220,16 +221,17 @@ var Downloads = {
           Downloads.manager.retryDownload(aDownload.id);
         }
       },
       {
         label: cancelButtonText,
         accessKey: "",
         callback: function() {
           Downloads.cancelDownload(aDownload);
+          Downloads._downloadProgressIndicator.reset();
         }
       }
     ];
     this.showNotification("download-failed", message, buttons,
       this._notificationBox.PRIORITY_WARNING_HIGH);
   },
 
   _showDownloadCompleteNotification: function (aDownload) {
@@ -392,16 +394,17 @@ var Downloads = {
 
       let buttons = [
         {
           isDefault: false,
           label: cancelButtonText,
           accessKey: "",
           callback: function() {
             Downloads.cancelDownloads();
+            Downloads._downloadProgressIndicator.reset();
           }
         }
       ];
 
       this._progressNotification =
         this.showNotification("download-progress", message, buttons,
         this._notificationBox.PRIORITY_WARNING_LOW);
     } else {
@@ -426,16 +429,27 @@ var Downloads = {
       this._progressNotificationInfo.set(aDownload.guid, {});
     }
     if (!this._progressAlert) {
       this._progressAlert = new AlertDownloadProgressListener();
       this.manager.addListener(this._progressAlert);
     }
   },
 
+  handleEvent: function handleEvent(aEvent) {
+    switch (aEvent.type) {
+      case "AlertClose":
+        if (aEvent.notification.value == "download-complete" &&
+            !Downloads._notificationBox.getNotificationWithValue("download-complete")) {
+          Downloads._downloadProgressIndicator.reset();
+        }
+        break;
+    }
+  },
+
   observe: function (aSubject, aTopic, aData) {
     let message = "";
     let msgTitle = "";
 
     switch (aTopic) {
       case "dl-run":
         let file = aSubject.QueryInterface(Ci.nsIFile);
         this._runDownloadBooleanMap.set(file.path, (aData == 'true'));
@@ -454,27 +468,25 @@ var Downloads = {
         }
 
         this._runDownloadBooleanMap.delete(download.targetFile.path);
         if (this._downloadsInProgress == 0) {
           if (this._downloadCount > 1 || !runAfterDownload) {
             this._showDownloadCompleteToast(download);
             this._showDownloadCompleteNotification(download);
           }
-          this._downloadProgressIndicator.reset();
           this._progressNotificationInfo.clear();
           this._downloadCount = 0;
           this._notificationBox.removeNotification(this._progressNotification);
           this._progressNotification = null;
         }
         break;
       case "dl-failed":
         download = aSubject.QueryInterface(Ci.nsIDownload);
         this._showDownloadFailedNotification(download);
-        this._downloadProgressIndicator.reset();
         break;
       case "dl-request":
         setTimeout(function() {
           ContextUI.displayNavbar();
         }, 1000);
         break;
     }
   },