Bug 748477 - Switch chrome privateWindow getter to check currentTab and remove setter; r=ehsan
authorSaurabh Anand <saurabhanandiit@gmail.com>
Fri, 08 Jun 2012 07:11:40 +0530
changeset 96134 3e22b1ebabf49b488ab04c665c5073c512017273
parent 96133 a02ae7ddd7977ee15549af1fb692df9a29e8dbb7
child 96135 81bb0865aee235ef08401ee7fa65dcc53f901712
push id22875
push useremorley@mozilla.com
push dateFri, 08 Jun 2012 10:26:24 +0000
treeherdermozilla-central@22bb7d46bb23 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersehsan
bugs748477
milestone16.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 748477 - Switch chrome privateWindow getter to check currentTab and remove setter; r=ehsan
browser/base/content/browser.js
browser/components/privatebrowsing/test/browser/browser_privatebrowsing_lastpbcontextexited.js
browser/components/privatebrowsing/test/browser/browser_privatebrowsing_ui.js
browser/components/privatebrowsing/test/browser/head.js
--- a/browser/base/content/browser.js
+++ b/browser/base/content/browser.js
@@ -7162,35 +7162,19 @@ let gPrivateBrowsingUI = {
   },
 
   /**
    * These accessors are used to support per-window Private Browsing mode.
    * For now the getter returns nsIPrivateBrowsingService.privateBrowsingEnabled,
    * and the setter should only be used in tests.
    */
   get privateWindow() {
-    return window.QueryInterface(Ci.nsIInterfaceRequestor)
-                 .getInterface(Ci.nsIWebNavigation)
-                 .QueryInterface(Ci.nsIDocShellTreeItem)
-                 .treeOwner
-                 .QueryInterface(Ci.nsIInterfaceRequestor)
-                 .getInterface(Ci.nsIXULWindow)
-                 .docShell.QueryInterface(Ci.nsILoadContext)
-                 .usePrivateBrowsing;
-  },
-
-  set privateWindow(val) {
-    return window.QueryInterface(Ci.nsIInterfaceRequestor)
-                 .getInterface(Ci.nsIWebNavigation)
-                 .QueryInterface(Ci.nsIDocShellTreeItem)
-                 .treeOwner
-                 .QueryInterface(Ci.nsIInterfaceRequestor)
-                 .getInterface(Ci.nsIXULWindow)
-                 .docShell.QueryInterface(Ci.nsILoadContext)
-                 .usePrivateBrowsing = val;
+    return gBrowser.selectedTab.linkedBrowser
+                               .docShell.QueryInterface(Ci.nsILoadContext)
+                               .usePrivateBrowsing;
   }
 };
 
 
 /**
  * Switch to a tab that has a given URI, and focusses its browser window.
  * If a matching tab is in this window, it will be switched to. Otherwise, other
  * windows will be searched.
--- a/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_lastpbcontextexited.js
+++ b/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_lastpbcontextexited.js
@@ -14,15 +14,15 @@ function test() {
         is(aTopic, "last-pb-context-exited", "Correct topic should be dispatched");
         is(expected, true, "notification not expected yet");
         Services.obs.removeObserver(observer, "last-pb-context-exited", false);
         gPrefService.clearUserPref("browser.privatebrowsing.keep_current_session");
         finish();
       }
     };
     Services.obs.addObserver(observer, "last-pb-context-exited", false);
-    newWin.gPrivateBrowsingUI.privateWindow = true;
+    setPrivateWindow(newWin, true);
     expected = true;
     newWin.close(); // this will cause the docshells to leave PB mode
     newWin = null;
     SpecialPowers.forceGC();
   }, newWin);
 }
--- a/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_ui.js
+++ b/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_ui.js
@@ -65,19 +65,19 @@ function test() {
       is(gPrivateBrowsingUI.privateWindow, false, "gPrivateBrowsingUI should expose the correct per-window private browsing status");
       // check to see if the Private Browsing mode was deactivated successfully
       is(observerData, "exit", "Private Browsing mode was deactivated using the gPrivateBrowsingUI object");
       is(pbMenuItem.getAttribute("label"), pbMenuItem.getAttribute("startlabel"), "The Private Browsing menu item should read \"Start Private Browsing\"");
 
       testNewWindow(function() {
         // These are tests for the privateWindow setter.  Note that the setter should
         // not be used anywhere else for now!
-        gPrivateBrowsingUI.privateWindow = true;
+        setPrivateWindow(window, true);
         is(gPrivateBrowsingUI.privateWindow, true, "gPrivateBrowsingUI should accept the correct per-window private browsing status");
-        gPrivateBrowsingUI.privateWindow = false;
+        setPrivateWindow(window, false);
         is(gPrivateBrowsingUI.privateWindow, false, "gPrivateBrowsingUI should accept the correct per-window private browsing status");
 
         // now, test using the <command> object
         let cmd = document.getElementById("Tools:PrivateBrowsing");
         isnot(cmd, null, "XUL command object for the private browsing service exists");
         var func = new Function("", cmd.getAttribute("oncommand"));
         func.call(cmd);
         // check to see if the Private Browsing mode was activated successfully
--- a/browser/components/privatebrowsing/test/browser/head.js
+++ b/browser/components/privatebrowsing/test/browser/head.js
@@ -18,8 +18,22 @@ registerCleanupFunction(function() {
  */
 function waitForClearHistory(aCallback) {
   Services.obs.addObserver(function observeCH(aSubject, aTopic, aData) {
     Services.obs.removeObserver(observeCH, PlacesUtils.TOPIC_EXPIRATION_FINISHED);
     aCallback();
   }, PlacesUtils.TOPIC_EXPIRATION_FINISHED, false);
   PlacesUtils.bhistory.removeAllPages();
 }
+
+/*
+ * Function created to replace the |privateWindow| setter
+ */
+function setPrivateWindow(aWindow, aEnable) {
+  return aWindow.QueryInterface(Ci.nsIInterfaceRequestor)
+                 .getInterface(Ci.nsIWebNavigation)
+                 .QueryInterface(Ci.nsIDocShellTreeItem)
+                 .treeOwner
+                 .QueryInterface(Ci.nsIInterfaceRequestor)
+                 .getInterface(Ci.nsIXULWindow)
+                 .docShell.QueryInterface(Ci.nsILoadContext)
+                 .usePrivateBrowsing = aEnable;
+}