Bug 748477 - Switch chrome privateWindow getter to check currentTab and remove setter; r=ehsan

This commit is contained in:
Saurabh Anand 2012-06-08 07:11:40 +05:30
parent 8bc88ec370
commit ae364922c7
4 changed files with 20 additions and 22 deletions

View File

@ -7167,25 +7167,9 @@ let gPrivateBrowsingUI = {
* 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;
}
};

View File

@ -19,7 +19,7 @@ function test() {
}
};
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;

View File

@ -70,9 +70,9 @@ function test() {
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

View File

@ -23,3 +23,17 @@ function waitForClearHistory(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;
}