Fix for bug 571159 (Leak nsGlobalWindow with unknown-content-type dialog). r=sdwilsh. a2.0=blocking.
authorPeter Van der Beken <peterv@propagandism.org>
Fri, 30 Jul 2010 16:48:57 -0700
changeset 48437 a8dd758e11f15fc0062cd0afbd0ea2473fafda60
parent 48436 55105cdc45c9c744aedeeb5ccb0c23687b865f56
child 48438 65e62e55194e66e269b43290dedb05d4017cc20d
push id14736
push userdbaron@mozilla.com
push dateFri, 30 Jul 2010 23:49:48 +0000
treeherderautoland@f7f9eb6c19d3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssdwilsh
bugs571159
milestone2.0b3pre
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Fix for bug 571159 (Leak nsGlobalWindow with unknown-content-type dialog). r=sdwilsh. a2.0=blocking.
toolkit/mozapps/downloads/nsHelperAppDlg.js
--- a/toolkit/mozapps/downloads/nsHelperAppDlg.js
+++ b/toolkit/mozapps/downloads/nsHelperAppDlg.js
@@ -56,16 +56,74 @@
  * @returns true if we can use the directory, false otherwise.
  */
 function isUsableDirectory(aDirectory)
 {
   return aDirectory.exists() && aDirectory.isDirectory() &&
          aDirectory.isWritable();
 }
 
+// Web progress listener so we can detect errors while mLauncher is
+// streaming the data to a temporary file.
+function nsUnkownContentTypeDialogProgressListener(aHelperAppDialog) {
+  this.helperAppDlg = aHelperAppDialog;
+}
+
+nsUnkownContentTypeDialogProgressListener.prototype = {
+  // nsIWebProgressListener methods.
+  // Look for error notifications and display alert to user.
+  onStatusChange: function( aWebProgress, aRequest, aStatus, aMessage ) {
+    if ( aStatus != Components.results.NS_OK ) {
+      // Get prompt service.
+      var prompter = Components.classes[ "@mozilla.org/embedcomp/prompt-service;1" ]
+                               .getService( Components.interfaces.nsIPromptService );
+      // Display error alert (using text supplied by back-end).
+      // FIXME this.dialog is undefined?
+      prompter.alert( this.dialog, this.helperAppDlg.mTitle, aMessage );
+      // Close the dialog.
+      this.helperAppDlg.onCancel();
+      if ( this.helperAppDlg.mDialog ) {
+        this.helperAppDlg.mDialog.close();
+      }
+    }
+  },
+
+  // Ignore onProgressChange, onProgressChange64, onStateChange, onLocationChange, onSecurityChange, and onRefreshAttempted notifications.
+  onProgressChange: function( aWebProgress,
+                              aRequest,
+                              aCurSelfProgress,
+                              aMaxSelfProgress,
+                              aCurTotalProgress,
+                              aMaxTotalProgress ) {
+  },
+
+  onProgressChange64: function( aWebProgress,
+                                aRequest,
+                                aCurSelfProgress,
+                                aMaxSelfProgress,
+                                aCurTotalProgress,
+                                aMaxTotalProgress ) {
+  },
+
+
+
+  onStateChange: function( aWebProgress, aRequest, aStateFlags, aStatus ) {
+  },
+
+  onLocationChange: function( aWebProgress, aRequest, aLocation ) {
+  },
+
+  onSecurityChange: function( aWebProgress, aRequest, state ) {
+  },
+
+  onRefreshAttempted: function( aWebProgress, aURI, aDelay, aSameURI ) {
+    return true;
+  }
+};
+
 ///////////////////////////////////////////////////////////////////////////////
 //// nsUnkownContentTypeDialog
 
 /* This file implements the nsIHelperAppLauncherDialog interface.
  *
  * The implementation consists of a JavaScript "class" named nsUnknownContentTypeDialog,
  * comprised of:
  *   - a JS constructor function
@@ -149,18 +207,18 @@ nsUnknownContentTypeDialog.prototype = {
 
     // Hook this object to the dialog.
     this.mDialog.dialog = this;
 
     // Hook up utility functions.
     this.getSpecialFolderKey = this.mDialog.getSpecialFolderKey;
 
     // Watch for error notifications.
-    this.progressListener.helperAppDlg = this;
-    this.mLauncher.setWebProgressListener(this.progressListener);
+    var progressListener = new nsUnkownContentTypeDialogProgressListener(this);
+    this.mLauncher.setWebProgressListener(progressListener);
   },
 
   // promptForSaveToFile:  Display file picker dialog and return selected file.
   //                       This is called by the External Helper App Service
   //                       after the ucth dialog calls |saveToDisk| with a null
   //                       target filename (no target, therefore user must pick).
   //
   //                       Alternatively, if the user has selected to have all
@@ -337,73 +395,16 @@ nsUnknownContentTypeDialog.prototype = {
     }
 #endif
 
     return createdFile;
   },
 
   // ---------- implementation methods ----------
 
-  // Web progress listener so we can detect errors while mLauncher is
-  // streaming the data to a temporary file.
-  progressListener: {
-    // Implementation properties.
-    helperAppDlg: null,
-
-    // nsIWebProgressListener methods.
-    // Look for error notifications and display alert to user.
-    onStatusChange: function( aWebProgress, aRequest, aStatus, aMessage ) {
-      if ( aStatus != Components.results.NS_OK ) {
-        // Get prompt service.
-        var prompter = Components.classes[ "@mozilla.org/embedcomp/prompt-service;1" ]
-                                 .getService( Components.interfaces.nsIPromptService );
-        // Display error alert (using text supplied by back-end).
-        prompter.alert( this.dialog, this.helperAppDlg.mTitle, aMessage );
-
-        // Close the dialog.
-        this.helperAppDlg.onCancel();
-        if ( this.helperAppDlg.mDialog ) {
-          this.helperAppDlg.mDialog.close();
-        }
-      }
-    },
-
-    // Ignore onProgressChange, onProgressChange64, onStateChange, onLocationChange, onSecurityChange, and onRefreshAttempted notifications.
-    onProgressChange: function( aWebProgress,
-                                aRequest,
-                                aCurSelfProgress,
-                                aMaxSelfProgress,
-                                aCurTotalProgress,
-                                aMaxTotalProgress ) {
-    },
-
-    onProgressChange64: function( aWebProgress,
-                                  aRequest,
-                                  aCurSelfProgress,
-                                  aMaxSelfProgress,
-                                  aCurTotalProgress,
-                                  aMaxTotalProgress ) {
-    },
-
-
-
-    onStateChange: function( aWebProgress, aRequest, aStateFlags, aStatus ) {
-    },
-
-    onLocationChange: function( aWebProgress, aRequest, aLocation ) {
-    },
-
-    onSecurityChange: function( aWebProgress, aRequest, state ) {
-    },
-
-    onRefreshAttempted: function( aWebProgress, aURI, aDelay, aSameURI ) {
-      return true;
-    }
-  },
-
   // initDialog:  Fill various dialog fields with initial content.
   initDialog : function() {
     // Put file name in window title.
     var suggestedFileName = this.mLauncher.suggestedFileName;
 
     // Some URIs do not implement nsIURL, so we can't just QI.
     var url   = this.mLauncher.source;
     var fname = "";