Bug 462478 - Make nsBrowserContentHandler use nsBrowserGlue's getMostRecentBrowserWindow(). r=gavin
authorJustin Dolske <dolske@mozilla.com>
Mon, 12 Jan 2009 16:26:48 -0800
changeset 23568 034f60a2969e335a606feaafd04669803a4331b2
parent 23567 a79a178b9ba84e275c2c931144025c58b60a485d
child 23570 48b12c9bb824ce04b0d366ce85622e88afd74117
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgavin
bugs462478
milestone1.9.2a1pre
Bug 462478 - Make nsBrowserContentHandler use nsBrowserGlue's getMostRecentBrowserWindow(). r=gavin
browser/base/content/browser.js
browser/components/nsBrowserContentHandler.js
--- a/browser/base/content/browser.js
+++ b/browser/base/content/browser.js
@@ -4389,63 +4389,24 @@ nsBrowserAccess.prototype =
           if(!gPrefService.getBoolPref("browser.tabs.loadDivertedInBackground"))
             content.focus();
         } catch(e) {
         }
     }
     return newWindow;
   },
 
-#ifdef XP_UNIX
-#ifndef XP_MACOSX
-#define BROKEN_WM_Z_ORDER
-#endif
-#endif
-#ifdef XP_OS2
-#define BROKEN_WM_Z_ORDER
-#endif
-
   // this returns the most recent non-popup browser window
   _getMostRecentBrowserWindow : function ()
   {
     if (!window.document.documentElement.getAttribute("chromehidden"))
       return window;
  
-    var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
-                       .getService(Components.interfaces.nsIWindowMediator);
- 
-#ifdef BROKEN_WM_Z_ORDER
-    var win = wm.getMostRecentWindow("navigator:browser", true);
- 
-    // if we're lucky, this isn't a popup, and we can just return this
-    if (win && win.document.documentElement.getAttribute("chromehidden")) {
-      win = null;
-      var windowList = wm.getEnumerator("navigator:browser", true);
-      // this is oldest to newest, so this gets a bit ugly
-      while (windowList.hasMoreElements()) {
-        var nextWin = windowList.getNext();
-        if (!nextWin.document.documentElement.getAttribute("chromehidden"))
-          win = nextWin;
-      }
-    }
-#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();
-    }
-#endif
-
-    return win;
+    var browserGlue = Cc[GLUE_CID].getService(Ci.nsIBrowserGlue);
+    return browserGlue.getMostRecentBrowserWindow();
   },
 
   isTabContentWindow : function(aWindow)
   {
     return gBrowser.browsers.some(function (browser) browser.contentWindow == aWindow);
   }
 }
 
--- a/browser/components/nsBrowserContentHandler.js
+++ b/browser/components/nsBrowserContentHandler.js
@@ -252,58 +252,21 @@ function openPreferences() {
 }
 
 function getMostRecentWindow(aType) {
   var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
                      .getService(nsIWindowMediator);
   return wm.getMostRecentWindow(aType);
 }
 
-#ifdef XP_UNIX
-#ifndef XP_MACOSX
-#define BROKEN_WM_Z_ORDER
-#endif
-#endif
-#ifdef XP_OS2
-#define BROKEN_WM_Z_ORDER
-#endif
-
 // this returns the most recent non-popup browser window
 function getMostRecentBrowserWindow() {
-  var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
-                     .getService(Components.interfaces.nsIWindowMediator);
-
-#ifdef BROKEN_WM_Z_ORDER
-  var win = wm.getMostRecentWindow("navigator:browser", true);
-
-  // if we're lucky, this isn't a popup, and we can just return this
-  if (win && win.document.documentElement.getAttribute("chromehidden")) {
-    var windowList = wm.getEnumerator("navigator:browser", true);
-    // this is oldest to newest, so this gets a bit ugly
-    while (windowList.hasMoreElements()) {
-      var nextWin = windowList.getNext();
-      if (!nextWin.document.documentElement.getAttribute("chromehidden"))
-        win = nextWin;
-    }
-  }
-#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();
-  }
-#endif
-
-  return win;
+  var browserGlue = Components.classes["@mozilla.org/browser/browserglue;1"]
+                              .getService(Components.interfaces.nsIBrowserGlue);
+  return browserGlue.getMostRecentBrowserWindow();
 }
 
 function doSearch(searchTerm, cmdLine) {
   var ss = Components.classes["@mozilla.org/browser/search-service;1"]
                      .getService(nsIBrowserSearchService);
 
   var submission = ss.defaultEngine.getSubmission(searchTerm, null);