Bug 1570453 - Port Bug 913855 "Fix consumers of window mediator to be more consistent in their checking for closed windows" to SeaMonkey". r=frg a=frg
authorIan Neal <iann_cvs@blueyonder.co.uk>
Sun, 11 Aug 2019 14:11:10 +0200
changeset 32260 b8df6618678c0e9d483e1eddef9ba8835f48da7f
parent 32259 bee6a4cc555f5f324936c6029cbc6a46ceab14dc
child 32261 fbd3fd31c479d6d76a6f43a1d52cdfbaa0bbaf41
push id209
push userfrgrahl@gmx.net
push dateSun, 11 Aug 2019 12:21:39 +0000
treeherdercomm-esr60@7a01e33fff91 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfrg, frg
bugs1570453, 913855
Bug 1570453 - Port Bug 913855 "Fix consumers of window mediator to be more consistent in their checking for closed windows" to SeaMonkey". r=frg a=frg
editor/ui/composer/content/ComposerCommands.js
editor/ui/composer/content/editor.js
editor/ui/composer/content/editorApplicationOverlay.js
suite/base/content/tasksOverlay.js
suite/browser/navigator.js
suite/components/bindings/prefwindow.xml
suite/components/nsSuiteGlue.js
--- a/editor/ui/composer/content/ComposerCommands.js
+++ b/editor/ui/composer/content/ComposerCommands.js
@@ -2134,17 +2134,18 @@ var nsPreviewCommand =
       try {
         // Find a browser with this URL
         let enumerator = Services.wm.getEnumerator("navigator:browser");
 
         var documentURI = GetDocumentUrl();
         while (enumerator.hasMoreElements())
         {
           browser = enumerator.getNext();
-          if (browser && (documentURI == browser.getBrowser().currentURI.spec))
+          if (browser && !browser.closed &&
+              (documentURI == browser.getBrowser().currentURI.spec))
             break;
 
           browser = null;
         }
       }
       catch (ex) {}
 
       // If none found, open a new browser
--- a/editor/ui/composer/content/editor.js
+++ b/editor/ui/composer/content/editor.js
@@ -2907,18 +2907,18 @@ function FindEditorWithInsertCharDialog(
   try {
     // Find window with an InsertCharsWindow and switch association to this one
     let enumerator = Services.wm.getEnumerator(null);
 
     while (enumerator.hasMoreElements())
     {
       var tempWindow = enumerator.getNext();
 
-      if (tempWindow != window && "InsertCharWindow" in tempWindow &&
-          tempWindow.InsertCharWindow)
+      if (!tempWindow.closed && tempWindow != window &&
+          "InsertCharWindow" in tempWindow && tempWindow.InsertCharWindow)
       {
         return tempWindow;
       }
     }
   }
   catch(e) {}
   return null;
 }
@@ -2957,17 +2957,18 @@ function SwitchInsertCharToAnotherEditor
     catch(e) {}
     if (!enumerator) return;
 
     // TODO: Fix this to search for command controllers and look for "cmd_InsertChars"
     // For now, detect just Web Composer and HTML Mail Composer
     while ( enumerator.hasMoreElements()  )
     {
       var  tempWindow = enumerator.getNext();
-      if (tempWindow != window && tempWindow != window.InsertCharWindow &&
+      if (!tempWindow.closed && tempWindow != window &&
+          tempWindow != window.InsertCharWindow &&
           "GetCurrentEditor" in tempWindow && tempWindow.GetCurrentEditor())
       {
         tempWindow.InsertCharWindow = window.InsertCharWindow;
         window.InsertCharWindow = null;
         tempWindow.InsertCharWindow.opener = tempWindow;
         return;
       }
     }
--- a/editor/ui/composer/content/editorApplicationOverlay.js
+++ b/editor/ui/composer/content/editorApplicationOverlay.js
@@ -77,17 +77,17 @@ function editPage(url, aFileType)
   try {
     let uri = createURI(url, null, null);
 
     let enumerator = Services.wm.getEnumerator("composer:" + aFileType);
     let emptyWindow;
     while ( enumerator.hasMoreElements() )
     {
       var win = enumerator.getNext();
-      if ( win && win.IsWebComposer())
+      if (win && !win.closed && win.IsWebComposer())
       {
         if (CheckOpenWindowForURIMatch(uri, win))
         {
           // We found an editor with our url
           win.focus();
           return;
         }
         else if (!emptyWindow && win.PageIsEmptyAndUntouched())
--- a/suite/base/content/tasksOverlay.js
+++ b/suite/base/content/tasksOverlay.js
@@ -167,39 +167,46 @@ function OpenBrowserWindow()
   };
   const clh_prefix = "@mozilla.org/commandlinehandler/general-startup;1";
   Cc[clh_prefix + "?type=browser"]
     .getService(Ci.nsICommandLineHandler)
     .handle(cmdLine);
   return null;
 }
 
-function CycleWindow( aType )
-{
-  var topWindowOfType = Services.wm.getMostRecentWindow(aType);
-  var topWindow = Services.wm.getMostRecentWindow(null);
-
-  if ( topWindowOfType == null )
+function CycleWindow(aType) {
+  let topWindowOfType = Services.wm.getMostRecentWindow(aType);
+  if (topWindowOfType == null)
     return null;
 
-  if ( topWindowOfType != topWindow ) {
+  let topWindow = Services.wm.getMostRecentWindow(null);
+  if (topWindowOfType != topWindow) {
     toOpenWindow(topWindowOfType);
     return topWindowOfType;
   }
 
-  var enumerator = Services.wm.getEnumerator(aType);
-  var firstWindow = enumerator.getNext();
-  var iWindow = firstWindow;
-  while (iWindow != topWindow && enumerator.hasMoreElements())
+  let foundTop = false;
+  let enumerator = Services.wm.getEnumerator(aType);
+  let iWindow;
+  let firstWindow;
+
+  while (enumerator.hasMoreElements()) {
     iWindow = enumerator.getNext();
-
-  if (enumerator.hasMoreElements()) {
-    iWindow = enumerator.getNext();
-    toOpenWindow(iWindow);
-    return iWindow;
+    if (!iWindow.closed) {
+      if (!firstWindow) {
+        firstWindow = iWindow;
+      }
+      if (topFound) {
+        toOpenWindow(iWindow);
+        return iWindow;
+      }
+      if (iWindow == topWindow) {
+        topFound = true;
+      }
+    }
   }
 
   if (firstWindow == topWindow) // Only one window
     return null;
 
   toOpenWindow(firstWindow);
   return firstWindow;
 }
--- a/suite/browser/navigator.js
+++ b/suite/browser/navigator.js
@@ -2461,16 +2461,19 @@ function BrowserPageInfo(doc, initialTab
     doc = window.content.document;
   var relatedUrl = doc.location.toString();
   var args = {doc: doc, initialTab: initialTab, imageElement: imageElement};
 
   var enumerator = Services.wm.getEnumerator("Browser:page-info");
   // Check for windows matching the url
   while (enumerator.hasMoreElements()) {
     let win = enumerator.getNext();
+    if (win.closed) {
+      continue;
+    }
     if (win.document.documentElement
            .getAttribute("relatedUrl") == relatedUrl) {
       win.focus();
       win.resetPageInfo(args);
       return win;
     }
   }
   // We didn't find a matching window, so open a new one.
@@ -2991,17 +2994,17 @@ function isClosingLastBrowser() {
   // Popups aren't considered full browser windows.
   if (!toolbar.visible)
     return false;
 
   // Figure out if there's at least one other browser window around.
   var e = Services.wm.getEnumerator("navigator:browser");
   while (e.hasMoreElements()) {
     let win = e.getNext();
-    if (win != window && win.toolbar.visible)
+    if (!win.closed && win != window && win.toolbar.visible)
       return false;
   }
 
   return true;
 }
 
 /**
  * file upload support
--- a/suite/components/bindings/prefwindow.xml
+++ b/suite/components/bindings/prefwindow.xml
@@ -399,16 +399,18 @@
           const iterator = Services.wm.getEnumerator("suite:help");
           var topWindow = null;
           var aWindow;
 
           // Loop through help windows looking for one with selected helpFileURI
           while (iterator.hasMoreElements())
           {
             aWindow = iterator.getNext();
+            if (aWindow.closed)
+              continue;
             if (aWindow.getHelpFileURI() == helpFileURI)
               topWindow = aWindow;
           }
           return topWindow;
         ]]>
         </body>
       </method>
 
--- a/suite/components/nsSuiteGlue.js
+++ b/suite/components/nsSuiteGlue.js
@@ -714,16 +714,17 @@ SuiteGlue.prototype = {
     // If user has already dismissed quit request, then do nothing
     if ((aCancelQuit instanceof Ci.nsISupportsPRBool) && aCancelQuit.data)
       return;
 
     var windowcount = 0;
     var pagecount = 0;
     var browserEnum = Services.wm.getEnumerator("navigator:browser");
     while (browserEnum.hasMoreElements()) {
+      // XXXbz should we skip closed windows here?
       windowcount++;
 
       var browser = browserEnum.getNext();
       var tabbrowser = browser.document.getElementById("content");
       if (tabbrowser)
         pagecount += tabbrowser.browsers.length;
     }