Bug 743209 Hidden window should look for a minimised browser window r=stefanh
authorNeil Rashbrook <neil@parkwaycc.co.uk>
Fri, 13 Apr 2012 16:34:13 +0100
changeset 11612 d7f5b6eb94c7b9e74c2309ec3bd55ad6ad474972
parent 11611 e6d6ed8fee9d5bba4b4dcd0200b21f5eb320ae3c
child 11613 d9bc5710b9e22ed297e2ad24d494299a8f84a257
push idunknown
push userunknown
push dateunknown
reviewersstefanh
bugs743209
Bug 743209 Hidden window should look for a minimised browser window r=stefanh
suite/browser/navigator.js
--- a/suite/browser/navigator.js
+++ b/suite/browser/navigator.js
@@ -1119,38 +1119,36 @@ const BrowserSearch = {
 
   /**
    * Gives focus to the search bar, if it is present on the toolbar, or to the
    * search sidebar, if it is open, or loads the default engine's search form
    * otherwise. For Mac, opens a new window or focuses an existing window, if
    * necessary.
    */
   webSearch: function BrowserSearch_webSearch() {
-    if (/Mac/.test(navigator.platform)) {
-      if (window.location.href != getBrowserURL()) {
-        var win = getTopWin();
-        if (win) {
-          // If there's an open browser window, it should handle this command
-          win.focus();
-          win.BrowserSearch.webSearch();
-        } else {
-          // If there are no open browser windows, open a new one
-
-          // This needs to be in a timeout so that we don't end up refocused
-          // in the url bar
-          function webSearchCallback() {
-            setTimeout(BrowserSearch.webSearch, 0);
-          }
-
-          win = window.openDialog(getBrowserURL(), "_blank",
-                                  "chrome,all,dialog=no", "about:blank");
-          win.addEventListener("load", webSearchCallback, false);
-        }
+    if (!gBrowser) {
+      var win = getTopWin();
+      if (win) {
+        // If there's an open browser window, it should handle this command
+        win.focus();
+        win.BrowserSearch.webSearch();
         return;
       }
+
+      // If there are no open browser windows, open a new one
+      function webSearchCallback() {
+        // This needs to be in a timeout so that we don't end up refocused
+        // in the url bar
+        setTimeout(BrowserSearch.webSearch, 0);
+      }
+
+      win = window.openDialog(getBrowserURL(), "_blank",
+                              "chrome,all,dialog=no", "about:blank");
+      win.addEventListener("load", webSearchCallback, false);
+      return;
     }
 
     if (isElementVisible(this.searchBar)) {
       this.searchBar.select();
       this.searchBar.focus();
     } else if (this.searchSidebar) {
       this.searchSidebar.focus();
     } else {
@@ -1341,18 +1339,26 @@ function BrowserOpenTab()
       case 1:
         uriToLoad = GetLocalizedStringPref("browser.startup.homepage");
         break;
       case 2:
         uriToLoad = GetStringPref("browser.history.last_page_visited");
         break;
     }
 
-    // Open a new window if someone requests a new tab when no browser window is open
     if (!gBrowser) {
+      var win = getTopWin();
+      if (win) {
+        // If there's an open browser window, it should handle this command
+        win.focus();
+        win.BrowserOpenTab();
+        return;
+      }
+
+      // If there are no open browser windows, open a new one
       openDialog(getBrowserURL(), "_blank", "chrome,all,dialog=no", uriToLoad);
       return;
     }
 
     gBrowser.selectedTab = gBrowser.addTab(uriToLoad);
     if (uriToLoad == "about:blank" && isElementVisible(gURLBar))
       setTimeout(WindowFocusTimerCallback, 0, gURLBar);
     else