Bug 816527 - Disable switch to tab for private windows in per-window private browsing builds; r=gavin

This patch makes sure that when you have a tab open in a private window,
we would never switch to it from either a private or non-private window.
Also, this disabled switching to tabs inside private windows.

This patch uses the autocompletesearchparam attribute to convey whether
the autocomplete search is coming from a private window, to disable
finding open pages in nsPlacesAutoComplete.  It also changes the
behavior of switchToTabHavingURI to make sure that switch to tab
actually fails if somehow attempted (this is used in the test.)  It also
prevents pages opened in a private window to be registered with
nsPlacesAutoComplete as open pages, in order to make sure that those
pages do not appear as switch to tab entries in the autocomplete list
for other windows.

The test for this patch is based on browser_bug555767.js, and tests all
of the four possible interactions here.
This commit is contained in:
Ehsan Akhgari 2012-11-30 02:40:47 -05:00
Родитель 8c6ec2229f
Коммит 2a1cf21b66
4 изменённых файлов: 140 добавлений и 1 удалений

Просмотреть файл

@ -7053,6 +7053,11 @@ let gPrivateBrowsingUI = {
docElement.setAttribute("privatebrowsingmode", "temporary");
gBrowser.updateTitlebar();
}
if (gURLBar) {
// Disable switch to tab autocompletion for private windows
gURLBar.setAttribute("autocompletesearchparam", "");
}
}
};
@ -7310,6 +7315,15 @@ let gPrivateBrowsingUI = {
function switchToTabHavingURI(aURI, aOpenNew) {
// This will switch to the tab in aWindow having aURI, if present.
function switchIfURIInWindow(aWindow) {
#ifdef MOZ_PER_WINDOW_PRIVATE_BROWSING
// Only switch to the tab if neither the source and desination window are
// private.
if (PrivateBrowsingUtils.isWindowPrivate(window) ||
PrivateBrowsingUtils.isWindowPrivate(aWindow)) {
return false;
}
#endif
let browsers = aWindow.gBrowser.browsers;
for (let i = 0; i < browsers.length; i++) {
let browser = browsers[i];

Просмотреть файл

@ -624,7 +624,13 @@
autocomplete.unregisterOpenPage(this.mBrowser.registeredOpenURI);
delete this.mBrowser.registeredOpenURI;
}
if (!isBlankPageURL(aLocation.spec)) {
if (!isBlankPageURL(aLocation.spec)
#ifdef MOZ_PER_WINDOW_PRIVATE_BROWSING
// Tabs in private windows aren't registered as "Open" so
// that they don't appear as switch-to-tab candidates.
&& !PrivateBrowsingUtils.isWindowPrivate(window)
#endif
) {
autocomplete.registerOpenPage(aLocation);
this.mBrowser.registeredOpenURI = aLocation;
}

Просмотреть файл

@ -314,6 +314,7 @@ ifdef MOZ_PER_WINDOW_PRIVATE_BROWSING
_BROWSER_FILES += \
browser_bug763468_perwindowpb.js \
browser_bug767836_perwindowpb.js \
browser_bug816527.js \
browser_private_browsing_window.js \
browser_save_link-perwindowpb.js \
browser_save_private_link_perwindowpb.js \

Просмотреть файл

@ -0,0 +1,118 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
function test() {
waitForExplicitFinish();
let testURL = "http://example.org/browser/browser/base/content/test/dummy_page.html";
function testOnWindow(aOptions, aCallback) {
whenNewWindowLoaded(aOptions, function(aWin) {
// execute should only be called when need, like when you are opening
// web pages on the test. If calling executeSoon() is not necesary, then
// call whenNewWindowLoaded() instead of testOnWindow() on your test.
executeSoon(function() aCallback(aWin));
});
};
testOnWindow({}, function(aNormalWindow) {
testOnWindow({private: true}, function(aPrivateWindow) {
runTest(aNormalWindow, aPrivateWindow, function() {
aNormalWindow.close();
aPrivateWindow.close();
testOnWindow({}, function(aNormalWindow) {
testOnWindow({private: true}, function(aPrivateWindow) {
runTest(aPrivateWindow, aNormalWindow, function() {
aNormalWindow.close();
aPrivateWindow.close();
testOnWindow({private: true}, function(aPrivateWindow) {
runTest(aPrivateWindow, aPrivateWindow, function() {
aPrivateWindow.close();
testOnWindow({}, function(aNormalWindow) {
runTest(aNormalWindow, aNormalWindow, function() {
aNormalWindow.close();
finish();
});
});
});
});
});
});
});
});
});
});
function runTest(aSourceWindow, aDestWindow, aCallback) {
// Open the base tab
let baseTab = aSourceWindow.gBrowser.addTab(testURL);
baseTab.linkedBrowser.addEventListener("load", function() {
// Wait for the tab to be fully loaded so matching happens correctly
if (baseTab.linkedBrowser.currentURI.spec == "about:blank")
return;
baseTab.linkedBrowser.removeEventListener("load", arguments.callee, true);
let testTab = aDestWindow.gBrowser.addTab();
waitForFocus(function() {
// Select the testTab
aDestWindow.gBrowser.selectedTab = testTab;
// Ensure that this tab has no history entries
ok(testTab.linkedBrowser.sessionHistory.count < 2,
"The test tab has 1 or less history entries");
// Ensure that this tab is on about:blank
is(testTab.linkedBrowser.currentURI.spec, "about:blank",
"The test tab is on about:blank");
// Ensure that this tab's document has no child nodes
ok(!testTab.linkedBrowser.contentDocument.body.hasChildNodes(),
"The test tab has no child nodes");
ok(!testTab.hasAttribute("busy"),
"The test tab doesn't have the busy attribute");
// Set the urlbar to include the moz-action
aDestWindow.gURLBar.value = "moz-action:switchtab," + testURL;
// Focus the urlbar so we can press enter
aDestWindow.gURLBar.focus();
// We want to see if the switchtab action works. If it does, the
// current tab will get closed, and that's what we detect with the
// TabClose handler. If pressing enter triggers a load in that tab,
// then the load handler will get called. Neither of these are
// the desired effect here. So if the test goes successfully, it is
// the timeout handler which gets called.
//
// The reason that we can't avoid the timeout here is because we are
// trying to test something which should not happen, so we just need
// to wait for a while and then check whether any bad things have
// happened.
function onTabClose(aEvent) {
aDestWindow.gBrowser.tabContainer.removeEventListener("TabClose", onTabClose, false);
aDestWindow.gBrowser.removeEventListener("load", onLoad, false);
// Should only happen when we expect success
ok(false, "Tab closed as expected");
aCallback();
}
function onLoad(aEvent) {
aDestWindow.gBrowser.tabContainer.removeEventListener("TabClose", onTabClose, false);
aDestWindow.gBrowser.removeEventListener("load", onLoad, false);
// Should only happen when we expect success
ok(false, "Tab loaded as expected");
aCallback();
}
aDestWindow.gBrowser.tabContainer.addEventListener("TabClose", onTabClose, false);
aDestWindow.gBrowser.addEventListener("load", onLoad, false);
setTimeout(function() {
aCallback();
}, 500);
// Press enter!
EventUtils.synthesizeKey("VK_RETURN", {});
}, aDestWindow);
}, true);
}
}