Bug 1196144 - source window disappearance still breaks downloading to custom directories on windows, r=felipe, a=sylvestre
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Fri, 25 Sep 2015 16:17:27 +0100
changeset 296170 87eaa176fb4dda9a22e986b05d9722fa6b61db15
parent 296169 e16afc10c9750fee6e76f30df134582283058a05
child 296171 369c340650cc3d0f40f0c78142289c323572db65
push id5245
push userraliiev@mozilla.com
push dateThu, 29 Oct 2015 11:30:51 +0000
treeherdermozilla-beta@dac831dc1bd0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfelipe, sylvestre
bugs1196144
milestone43.0a2
Bug 1196144 - source window disappearance still breaks downloading to custom directories on windows, r=felipe, a=sylvestre
toolkit/mozapps/downloads/nsHelperAppDlg.js
--- a/toolkit/mozapps/downloads/nsHelperAppDlg.js
+++ b/toolkit/mozapps/downloads/nsHelperAppDlg.js
@@ -223,17 +223,31 @@ nsUnknownContentTypeDialog.prototype = {
 
     if (parent) {
       gDownloadLastDir = new downloadModule.DownloadLastDir(parent);
     } else {
       // Use the cached download info, but pick an arbitrary parent window
       // because the original one is definitely gone (and nsIFilePicker doesn't like
       // a null parent):
       gDownloadLastDir = this._mDownloadDir;
-      parent = Services.wm.getMostRecentWindow("");
+      let windowsEnum = Services.wm.getEnumerator("");
+      while (windowsEnum.hasMoreElements()) {
+        let someWin = windowsEnum.getNext();
+        // We need to make sure we don't end up with this dialog, because otherwise
+        // that's going to go away when the user clicks "Save", and that breaks the
+        // windows file picker that's supposed to show up if we let the user choose
+        // where to save files...
+        if (someWin != this.mDialog) {
+          parent = someWin;
+        }
+      }
+      if (!parent) {
+        Cu.reportError("No candidate parent windows were found for the save filepicker." +
+                       "This should never happen.");
+      }
     }
 
     Task.spawn(function() {
       if (!aForcePrompt) {
         // Check to see if the user wishes to auto save to the default download
         // folder without prompting. Note that preference might not be set.
         let autodownload = false;
         try {