Bug 586624 - support for nsIBrowserDOMWindow.OPEN_NEWWINDOW is broken [r=mfinkle]
authorFabrice Desré <fabrice@mozilla.com>
Thu, 26 Aug 2010 21:59:20 -0400
changeset 66504 45ec3ab316d60ba213d36bb9e9a293efc6cf4710
parent 66503 53f04a81773e07250a430e0529dd23a7837f54e5
child 66505 a4acd6e37bb5f50b20316f3b754476507d9c9127
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)
reviewersmfinkle
bugs586624
Bug 586624 - support for nsIBrowserDOMWindow.OPEN_NEWWINDOW is broken [r=mfinkle]
mobile/chrome/content/browser.js
--- a/mobile/chrome/content/browser.js
+++ b/mobile/chrome/content/browser.js
@@ -509,41 +509,46 @@ var Browser = {
 
     // Command line arguments/initial homepage
     let whereURI = this.getHomePage();
     if (needOverride == "new profile")
         whereURI = "about:firstrun";
 
     // If this is an intial window launch (was a nsICommandLine passed via window params)
     // we execute some logic to load the initial launch page
-    if (window.arguments && window.arguments[0] &&
-        window.arguments[0] instanceof Ci.nsICommandLine) {
-      try {
-        var cmdLine = window.arguments[0];
-
-        // Check for and use a single commandline parameter
-        if (cmdLine.length == 1) {
-          // Assume the first arg is a URI if it is not a flag
-          var uri = cmdLine.getArgument(0);
-          if (uri != "" && uri[0] != '-') {
-            whereURI = cmdLine.resolveURI(uri);
+    if (window.arguments && window.arguments[0]) {
+      if (window.arguments[0] instanceof Ci.nsICommandLine) {
+        try {
+          var cmdLine = window.arguments[0];
+
+          // Check for and use a single commandline parameter
+          if (cmdLine.length == 1) {
+            // Assume the first arg is a URI if it is not a flag
+            var uri = cmdLine.getArgument(0);
+            if (uri != "" && uri[0] != '-') {
+              whereURI = cmdLine.resolveURI(uri);
+              if (whereURI)
+                whereURI = whereURI.spec;
+            }
+          }
+
+          // Check for the "url" flag
+          var uriFlag = cmdLine.handleFlagWithParam("url", false);
+          if (uriFlag) {
+            whereURI = cmdLine.resolveURI(uriFlag);
             if (whereURI)
               whereURI = whereURI.spec;
           }
-        }
-
-        // Check for the "url" flag
-        var uriFlag = cmdLine.handleFlagWithParam("url", false);
-        if (uriFlag) {
-          whereURI = cmdLine.resolveURI(uriFlag);
-          if (whereURI)
-            whereURI = whereURI.spec;
-        }
-      } catch (e) {}
-    }
+        } catch (e) {}
+      }
+      else {
+        // This window could have been opened by nsIBrowserDOMWindow.openURI
+        whereURI = window.arguments[0];
+      }
+    } 
 
     this.addTab(whereURI, true);
 
     // JavaScript Error Console
     if (Services.prefs.getBoolPref("browser.console.showInPanel")){
       let button = document.getElementById("tool-console");
       button.hidden = false;
     }
@@ -1464,17 +1469,18 @@ nsBrowserAccess.prototype = {
       }
     }
 
     let browser;
     if (aWhere == Ci.nsIBrowserDOMWindow.OPEN_NEWWINDOW) {
       let url = aURI ? aURI.spec : "about:blank";
       let newWindow = openDialog("chrome://browser/content/browser.xul", "_blank",
                                  "all,dialog=no", url, null, null, null);
-      browser = newWindow.Browser.selectedBrowser;
+      // since newWindow.Browser doesn't exist yet, just return null
+      return null;
     } else if (aWhere == Ci.nsIBrowserDOMWindow.OPEN_NEWTAB) {
       browser = Browser.addTab("about:blank", true, Browser.selectedTab).browser;
     } else { // OPEN_CURRENTWINDOW and illegal values
       browser = Browser.selectedBrowser;
     }
 
     try {
       let referrer;