mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 798508 - Part 1: Implement the "private" window.open feature; r=bzbarsky
This patch adds support for a "private" window flag which can be used to open new chrome windows in private browsing mode. It also tests to make sure that the flag is not accessible from content. A test in the next part makes sure that the flag is accessible from chrome.
This commit is contained in:
parent
ae1754a188
commit
d443b4f6a0
@ -63,6 +63,9 @@ interface nsIWebBrowserChrome : nsISupports
|
||||
const unsigned long CHROME_WINDOW_MIN = 0x00004000;
|
||||
const unsigned long CHROME_WINDOW_POPUP = 0x00008000;
|
||||
|
||||
// private browsing windows
|
||||
const unsigned long CHROME_PRIVATE_WINDOW = 0x00010000;
|
||||
|
||||
// Prevents new window animations on Mac OS X Lion. Ignored on other
|
||||
// platforms.
|
||||
const unsigned long CHROME_MAC_SUPPRESS_ANIMATION = 0x01000000;
|
||||
|
@ -898,17 +898,25 @@ nsWindowWatcher::OpenWindowInternal(nsIDOMWindow *aParent,
|
||||
}
|
||||
|
||||
if (windowIsNew) {
|
||||
// For top level windows, we want to ensure that the privacy status of the parent
|
||||
// is propagated to the new child if it is available.
|
||||
nsCOMPtr<nsIDocShellTreeItem> parentItem;
|
||||
GetWindowTreeItem(aParent, getter_AddRefs(parentItem));
|
||||
nsCOMPtr<nsILoadContext> parentContext = do_QueryInterface(parentItem);
|
||||
// See if the caller has requested a private browsing window.
|
||||
bool isPrivateBrowsingWindow =
|
||||
!!(chromeFlags & nsIWebBrowserChrome::CHROME_PRIVATE_WINDOW);
|
||||
// Otherwise, propagate the privacy status of the parent window, if
|
||||
// available, to the child.
|
||||
if (!isPrivateBrowsingWindow) {
|
||||
nsCOMPtr<nsIDocShellTreeItem> parentItem;
|
||||
GetWindowTreeItem(aParent, getter_AddRefs(parentItem));
|
||||
nsCOMPtr<nsILoadContext> parentContext = do_QueryInterface(parentItem);
|
||||
if (parentContext) {
|
||||
isPrivateBrowsingWindow = parentContext->UsePrivateBrowsing();
|
||||
}
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIDocShellTreeItem> childRoot;
|
||||
newDocShellItem->GetRootTreeItem(getter_AddRefs(childRoot));
|
||||
nsCOMPtr<nsILoadContext> childContext = do_QueryInterface(childRoot);
|
||||
if (parentContext && childContext) {
|
||||
childContext->SetUsePrivateBrowsing(parentContext->UsePrivateBrowsing());
|
||||
if (childContext) {
|
||||
childContext->SetUsePrivateBrowsing(isPrivateBrowsingWindow);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1490,6 +1498,12 @@ uint32_t nsWindowWatcher::CalculateChromeFlags(nsIDOMWindow *aParent,
|
||||
}
|
||||
}
|
||||
|
||||
// Determine whether the window is a private browsing window
|
||||
if (isChrome) {
|
||||
chromeFlags |= WinHasOption(aFeatures, "private", 0, &presenceFlag) ?
|
||||
nsIWebBrowserChrome::CHROME_PRIVATE_WINDOW : 0;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIPrefBranch> prefBranch;
|
||||
nsCOMPtr<nsIPrefService> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID, &rv);
|
||||
NS_ENSURE_SUCCESS(rv, true);
|
||||
|
@ -19,6 +19,7 @@ MOCHITEST_FILES = \
|
||||
bug449141_page.html \
|
||||
test_bug499115.html \
|
||||
test_nsFind.html \
|
||||
test_private_window_from_content.html \
|
||||
test_window_open_units.html \
|
||||
$(NULL)
|
||||
|
||||
|
8
embedding/test/test_private_window_from_content.html
Normal file
8
embedding/test/test_private_window_from_content.html
Normal file
@ -0,0 +1,8 @@
|
||||
<!DOCTYPE html>
|
||||
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<script>
|
||||
// Make sure that we cannot open private browsing windows from unprivileged content
|
||||
var win = window.open("about:blank", "_blank", "private");
|
||||
ok(!SpecialPowers.isWindowPrivate(win));
|
||||
win.close();
|
||||
</script>
|
@ -11,6 +11,7 @@ var Cu = Components.utils;
|
||||
|
||||
Components.utils.import("resource://specialpowers/MockFilePicker.jsm");
|
||||
Components.utils.import("resource://gre/modules/Services.jsm");
|
||||
Components.utils.import("resource://gre/modules/PrivateBrowsingUtils.jsm");
|
||||
|
||||
function SpecialPowersAPI() {
|
||||
this._consoleListeners = [];
|
||||
@ -1242,4 +1243,8 @@ SpecialPowersAPI.prototype = {
|
||||
getMozFullPath: function(file) {
|
||||
return file.mozFullPath;
|
||||
},
|
||||
|
||||
isWindowPrivate: function(win) {
|
||||
return PrivateBrowsingUtils.isWindowPrivate(win);
|
||||
},
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user