Bug 819202 - Simplify the semantics of OpenBrowserWindow: new windows are public unless explicitly passed a 'private' option or global private browsing is in effect. r=dao DONTBUILD
authorJosh Matthews <josh@joshmatthews.net>
Mon, 10 Dec 2012 06:39:00 -0500
changeset 121596 032490690d651535e1d9ec2017403db8e166d29c
parent 121595 0a05fb0f9addff5e86827abc658b1fd83d92a148
child 121597 4fb4bbc6b029987b32f0eb82d86c8b40ae7b7fa6
push idunknown
push userunknown
push dateunknown
reviewersdao
bugs819202
milestone20.0a1
Bug 819202 - Simplify the semantics of OpenBrowserWindow: new windows are public unless explicitly passed a 'private' option or global private browsing is in effect. r=dao DONTBUILD
browser/base/content/browser.js
browser/base/content/test/browser_private_browsing_window.js
browser/components/privatebrowsing/test/browser/global/browser_privatebrowsing_ui.js
browser/components/privatebrowsing/test/browser/obsolete/browser_privatebrowsing_newwindow_stopcmd.js
--- a/browser/base/content/browser.js
+++ b/browser/base/content/browser.js
@@ -3489,27 +3489,26 @@ function OpenBrowserWindow(options)
 
   var charsetArg = new String();
   var handler = Components.classes["@mozilla.org/browser/clh;1"]
                           .getService(Components.interfaces.nsIBrowserHandler);
   var defaultArgs = handler.defaultArgs;
   var wintype = document.documentElement.getAttribute('windowtype');
 
   var extraFeatures = "";
-  var forcePrivate = false;
 #ifdef MOZ_PER_WINDOW_PRIVATE_BROWSING
-  forcePrivate = typeof options == "object" && "private" in options && options.private;
+  if (typeof options == "object" && options.private) {
 #else
-  forcePrivate = gPrivateBrowsingUI.privateBrowsingEnabled;
+  if (gPrivateBrowsingUI.privateBrowsingEnabled) {
 #endif
-
-  if (forcePrivate) {
     extraFeatures = ",private";
     // Force the new window to load about:privatebrowsing instead of the default home page
     defaultArgs = "about:privatebrowsing";
+  } else {
+    extraFeatures = ",non-private";
   }
 
   // if and only if the current window is a browser window and it has a document with a character
   // set, then extract the current charset menu setting from the current document and use it to
   // initialize the new browser window...
   var win;
   if (window && (wintype == "navigator:browser") && window.content && window.content.document)
   {
--- a/browser/base/content/test/browser_private_browsing_window.js
+++ b/browser/base/content/test/browser_private_browsing_window.js
@@ -1,11 +1,24 @@
 // Make sure that we can open private browsing windows
 
 function test() {
+  waitForExplicitFinish();
   var nonPrivateWin = OpenBrowserWindow();
   ok(!PrivateBrowsingUtils.isWindowPrivate(nonPrivateWin), "OpenBrowserWindow() should open a normal window");
   nonPrivateWin.close();
+
   var privateWin = OpenBrowserWindow({private: true});
   ok(PrivateBrowsingUtils.isWindowPrivate(privateWin), "OpenBrowserWindow({private: true}) should open a private window");
-  privateWin.close();
+
+  nonPrivateWin = OpenBrowserWindow({private: false});
+  ok(!PrivateBrowsingUtils.isWindowPrivate(nonPrivateWin), "OpenBrowserWindow({private: false}) should open a normal window");
+  nonPrivateWin.close();
+
+  whenDelayedStartupFinished(privateWin, function() {
+    nonPrivateWin = privateWin.OpenBrowserWindow({private: false});
+    ok(!PrivateBrowsingUtils.isWindowPrivate(nonPrivateWin), "privateWin.OpenBrowserWindow({private: false}) should open a normal window");
+    nonPrivateWin.close();
+    privateWin.close();
+    finish();
+  });
 }
 
--- a/browser/components/privatebrowsing/test/browser/global/browser_privatebrowsing_ui.js
+++ b/browser/components/privatebrowsing/test/browser/global/browser_privatebrowsing_ui.js
@@ -35,17 +35,17 @@ function test() {
             aCallback();
             Services.obs.removeObserver(observer2, "domwindowclosed");
           }, "domwindowclosed", false);
           aSubject.close();
         });
         Services.obs.removeObserver(observer1, "domwindowopened");
       }, false);
     }, "domwindowopened", false);
-    OpenBrowserWindow();
+    OpenBrowserWindow({private: PrivateBrowsingUtils.isWindowPrivate(window)});
   }
 
   // test the gPrivateBrowsingUI object
   ok(gPrivateBrowsingUI, "The gPrivateBrowsingUI object exists");
   is(pb.privateBrowsingEnabled, false, "The private browsing mode should not be started initially");
   is(gPrivateBrowsingUI.privateBrowsingEnabled, false, "gPrivateBrowsingUI should expose the correct private browsing status");
   is(PrivateBrowsingUtils.isWindowPrivate(window), false, "PrivateBrowsingUtils should expose the correct per-window private browsing status");
   ok(pbMenuItem, "The Private Browsing menu item exists");
--- a/browser/components/privatebrowsing/test/browser/obsolete/browser_privatebrowsing_newwindow_stopcmd.js
+++ b/browser/components/privatebrowsing/test/browser/obsolete/browser_privatebrowsing_newwindow_stopcmd.js
@@ -8,17 +8,17 @@
 function test() {
   // initialization
   let pb = Cc["@mozilla.org/privatebrowsing;1"].
            getService(Ci.nsIPrivateBrowsingService);
   waitForExplicitFinish();
 
   pb.privateBrowsingEnabled = true;
 
-  let win = OpenBrowserWindow();
+  let win = OpenBrowserWindow({private: PrivateBrowsingUtils.isWindowPrivate(window)});
   win.addEventListener("load", function() {
     win.removeEventListener("load", arguments.callee, false);
     executeSoon(function() {
       let cmd = win.document.getElementById("Tools:PrivateBrowsing");
       ok(!cmd.hasAttribute("disabled"),
          "The Private Browsing command in a new window should be enabled");
 
       win.close();