Bug 491481 Status feedback should remove itself as activity listener when the main window closes. r=bienvenu
authorMark Banner <bugzilla@standard8.plus.com>
Tue, 05 May 2009 20:46:36 +0100
changeset 2565 f7fa8d03e852f6f47f5b0b33d73ad122bca6071e
parent 2564 83e09049bbc6982033d476da6129e066c75742d3
child 2566 54f3c53dbc4355bd3ffe3eb39ae10123d87eca8a
push id2088
push userbugzilla@standard8.plus.com
push dateTue, 05 May 2009 19:49:02 +0000
treeherdercomm-central@54f3c53dbc43 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbienvenu
bugs491481
Bug 491481 Status feedback should remove itself as activity listener when the main window closes. r=bienvenu
mail/base/content/mailWindow.js
mail/components/activity/nsActivity.js
mail/components/activity/nsActivityManager.js
--- a/mail/base/content/mailWindow.js
+++ b/mail/base/content/mailWindow.js
@@ -78,16 +78,17 @@ function OnMailWindowUnload()
                               .getService(Components.interfaces.nsIMsgMailSession);
   mailSession.RemoveFolderListener(folderListener);
 
   mailSession.RemoveMsgWindow(msgWindow);
   messenger.setWindow(null, null);
 
   msgWindow.closeWindow();
 
+  window.MsgStatusFeedback.unload();
   Components.classes["@mozilla.org/activity-manager;1"]
             .getService(Components.interfaces.nsIActivityManager)
             .removeListener(window.MsgStatusFeedback);
 }
 
 function CreateMailWindowGlobals()
 {
   // get the messenger instance
@@ -179,16 +180,24 @@ nsMsgStatusFeedback.prototype =
   // How many start meteors have been requested.
   _startRequests: 0,
   _meteorsSpinning: false,
   _defaultStatusText: null,
   _progressBarVisible: false,
   _activeProcesses: null,
   _statusFeedbackProgress: -1,
 
+  // unload - call to remove links to listeners etc.
+  unload: function () {
+    // Remove listeners for any active processes we have hooked ourselves into.
+    this._activeProcesses.forEach(function (element) {
+        element.removeListener(this);
+      }, this);
+  },
+
   // nsIXULBrowserWindow implementation.
   setJSStatus: function(status) {
     if (status.length > 0)
       this.showStatusString(status);
   },
 
   setJSDefaultStatus: function(status) {
     if (status.length > 0) {
--- a/mail/components/activity/nsActivity.js
+++ b/mail/components/activity/nsActivity.js
@@ -73,17 +73,17 @@ nsActivity.prototype = {
     this.log = Log4Moz.getConfiguredLogger("nsActivity");
   },
 
   addListener: function(aListener) {
     this._listeners.push(aListener);
   },
 
   removeListener: function(aListener) {
-    for (i = 0; i < this._listeners.length; i++) {
+    for (let i = 0; i < this._listeners.length; i++) {
       if (this._listeners[i] == aListener) {
         this._listeners.splice(i, 1);
         break;
       }
     }
   },
 
   addSubject: function(aSubject) {
--- a/mail/components/activity/nsActivityManager.js
+++ b/mail/components/activity/nsActivityManager.js
@@ -186,17 +186,17 @@ nsActivityManager.prototype = {
 
   addListener: function(aListener) {
     this.log.info("addListener\n");
     this._listeners.push(aListener);
   },
 
   removeListener: function(aListener) {
     this.log.info("removeListener\n");
-    for (i = 0; i < this._listeners.length; i++) {
+    for (let i = 0; i < this._listeners.length; i++) {
       if (this._listeners[i] == aListener)
         this._listeners.splice(i, 1);
     }
   },
   
   //////////////////////////////////////////////////////////////////////////////
   //// nsISupports