Bug 528732 - getMostRecentBrowserWindow should skip closed windows. r=gavin
authorDão Gottwald <dao@mozilla.com>
Sun, 24 Jan 2010 11:20:10 +0100
changeset 37447 36a5be172c9120ae11edcd6df4e4ececb4866371
parent 37446 86a6b2485640d162919cb32124629c23299968c7
child 37448 f077fca0d235919894a3703b553accee7ef87024
push id11308
push userdgottwald@mozilla.com
push dateSun, 24 Jan 2010 11:40:56 +0000
treeherdermozilla-central@f565b53ba490 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgavin
bugs528732
milestone1.9.3a1pre
Bug 528732 - getMostRecentBrowserWindow should skip closed windows. r=gavin
browser/components/nsBrowserGlue.js
--- a/browser/components/nsBrowserGlue.js
+++ b/browser/components/nsBrowserGlue.js
@@ -1069,47 +1069,47 @@ BrowserGlue.prototype = {
 
 #ifndef XP_WIN
 #define BROKEN_WM_Z_ORDER
 #endif
 
   // this returns the most recent non-popup browser window
   getMostRecentBrowserWindow: function BG_getMostRecentBrowserWindow() {
     var wm = Cc["@mozilla.org/appshell/window-mediator;1"].
-             getService(Components.interfaces.nsIWindowMediator);
+             getService(Ci.nsIWindowMediator);
+
+    function isFullBrowserWindow(win) {
+      return !win.closed &&
+             !win.document.documentElement.getAttribute("chromehidden");
+    }
 
 #ifdef BROKEN_WM_Z_ORDER
-    var win = wm.getMostRecentWindow("navigator:browser", true);
+    var win = wm.getMostRecentWindow("navigator:browser");
 
     // if we're lucky, this isn't a popup, and we can just return this
-    if (win && win.document.documentElement.getAttribute("chromehidden")) {
+    if (win && !isFullBrowserWindow(win)) {
       win = null;
-      var windowList = wm.getEnumerator("navigator:browser", true);
+      let windowList = wm.getEnumerator("navigator:browser");
       // this is oldest to newest, so this gets a bit ugly
       while (windowList.hasMoreElements()) {
-        var nextWin = windowList.getNext();
-        if (!nextWin.document.documentElement.getAttribute("chromehidden"))
+        let nextWin = windowList.getNext();
+        if (isFullBrowserWindow(nextWin))
           win = nextWin;
       }
     }
+    return win;
 #else
     var windowList = wm.getZOrderDOMWindowEnumerator("navigator:browser", true);
-    if (!windowList.hasMoreElements())
-      return null;
-
-    var win = windowList.getNext();
-    while (win.document.documentElement.getAttribute("chromehidden")) {
-      if (!windowList.hasMoreElements())
-        return null;
-
-      win = windowList.getNext();
+    while (windowList.hasMoreElements()) {
+      let win = windowList.getNext();
+      if (isFullBrowserWindow(win))
+        return win;
     }
+    return null;
 #endif
-
-    return win;
   },
 
 
   // for XPCOM
   classDescription: "Firefox Browser Glue Service",
   classID:          Components.ID("{eab9012e-5f74-4cbc-b2b5-a590235513cc}"),
   contractID:       "@mozilla.org/browser/browserglue;1",