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 289411 0f1094755092eac4685f88516bc6928a4f18aad7
parent 289410 9ac72490a8cc3c9b8da291740be69bb7777d4746
child 289412 ae7a9ec96e3b5edd82e84f8b10fd1f0bee165035
push id5112
push usercbook@mozilla.com
push dateTue, 29 Sep 2015 12:42:33 +0000
treeherdermozilla-beta@6972fe930f3f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfelipe, sylvestre
bugs1196144
milestone42.0
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 {