Backed out changesets c63d33a0f879 and 9293ce14dd71 (
bug 1317173) for bustage.
--- a/embedding/components/windowwatcher/nsWindowWatcher.cpp
+++ b/embedding/components/windowwatcher/nsWindowWatcher.cpp
@@ -978,28 +978,16 @@ nsWindowWatcher::OpenWindowInternal(mozI
}
NS_ASSERTION(mWindowCreator,
"attempted to open a new window with no WindowCreator");
rv = NS_ERROR_FAILURE;
if (mWindowCreator) {
nsCOMPtr<nsIWebBrowserChrome> newChrome;
- nsCOMPtr<nsPIDOMWindowInner> parentTopInnerWindow;
- if (parentWindow) {
- nsCOMPtr<nsPIDOMWindowOuter> parentTopWindow = parentWindow->GetTop();
- if (parentTopWindow) {
- parentTopInnerWindow = parentTopWindow->GetCurrentInnerWindow();
- }
- }
-
- if (parentTopInnerWindow) {
- parentTopInnerWindow->Suspend();
- }
-
/* If the window creator is an nsIWindowCreator2, we can give it
some hints. The only hint at this time is whether the opening window
is in a situation that's likely to mean this is an unrequested
popup window we're creating. However we're not completely honest:
we clear that indicator if the opener is chrome, so that the
downstream consumer can treat the indicator to mean simply
that the new window is subject to popup control. */
nsCOMPtr<nsIWindowCreator2> windowCreator2(
@@ -1026,20 +1014,16 @@ nsWindowWatcher::OpenWindowInternal(mozI
rv = CreateChromeWindow(features, parentChrome, chromeFlags, contextFlags,
nullptr, getter_AddRefs(newChrome));
} else {
rv = mWindowCreator->CreateChromeWindow(parentChrome, chromeFlags,
getter_AddRefs(newChrome));
}
- if (parentTopInnerWindow) {
- parentTopInnerWindow->Resume();
- }
-
if (newChrome) {
nsCOMPtr<nsIXULWindow> xulWin = do_GetInterface(newChrome);
if (xulWin) {
nsCOMPtr<nsIXULBrowserWindow> xulBrowserWin;
xulWin->GetXULBrowserWindow(getter_AddRefs(xulBrowserWin));
if (xulBrowserWin) {
xulBrowserWin->ForceInitialBrowserNonRemote();
}
@@ -1121,48 +1105,28 @@ nsWindowWatcher::OpenWindowInternal(mozI
//
// Note: The check for the current JSContext isn't necessarily sensical.
// It's just designed to preserve old semantics during a mass-conversion
// patch.
nsCOMPtr<nsIPrincipal> subjectPrincipal =
nsContentUtils::GetCurrentJSContext() ? nsContentUtils::SubjectPrincipal() :
nullptr;
- bool isPrivateBrowsingWindow = false;
-
if (windowIsNew) {
auto* docShell = static_cast<nsDocShell*>(newDocShell.get());
// If this is not a chrome docShell, we apply originAttributes from the
// subjectPrincipal unless if it's an expanded or system principal.
if (subjectPrincipal &&
!nsContentUtils::IsSystemOrExpandedPrincipal(subjectPrincipal) &&
docShell->ItemType() != nsIDocShellTreeItem::typeChrome) {
DocShellOriginAttributes attrs;
attrs.InheritFromDocToChildDocShell(BasePrincipal::Cast(subjectPrincipal)->OriginAttributesRef());
- isPrivateBrowsingWindow = !!attrs.mPrivateBrowsingId;
+
docShell->SetOriginAttributes(attrs);
- } else {
- nsCOMPtr<nsIDocShellTreeItem> parentItem;
- GetWindowTreeItem(aParent, getter_AddRefs(parentItem));
- nsCOMPtr<nsILoadContext> parentContext = do_QueryInterface(parentItem);
- if (parentContext) {
- isPrivateBrowsingWindow = parentContext->UsePrivateBrowsing();
- }
- }
-
- bool autoPrivateBrowsing =
- Preferences::GetBool("browser.privatebrowsing.autostart");
-
- if (!autoPrivateBrowsing &&
- (chromeFlags & nsIWebBrowserChrome::CHROME_NON_PRIVATE_WINDOW)) {
- isPrivateBrowsingWindow = false;
- } else if (autoPrivateBrowsing ||
- (chromeFlags & nsIWebBrowserChrome::CHROME_PRIVATE_WINDOW)) {
- isPrivateBrowsingWindow = true;
}
// Now set the opener principal on the new window. Note that we need to do
// this no matter whether we were opened from JS; if there is nothing on
// the JS stack, just use the principal of our parent window. In those
// cases we do _not_ set the parent window principal as the owner of the
// load--since we really don't know who the owner is, just leave it null.
nsCOMPtr<nsPIDOMWindowOuter> newWindow = do_QueryInterface(*aResult);
@@ -1172,16 +1136,36 @@ nsWindowWatcher::OpenWindowInternal(mozI
// nsWindowWatcher::AddWindow. Make sure to call it. In the common case
// this call already happened when the window was created, but
// SetInitialPrincipalToSubject is safe to call multiple times.
if (newWindow) {
newWindow->SetInitialPrincipalToSubject();
}
}
+ // If all windows should be private, make sure the new window is also
+ // private. Otherwise, see if the caller has explicitly requested a
+ // private or non-private window.
+ bool isPrivateBrowsingWindow =
+ Preferences::GetBool("browser.privatebrowsing.autostart") ||
+ (!!(chromeFlags & nsIWebBrowserChrome::CHROME_PRIVATE_WINDOW) &&
+ !(chromeFlags & nsIWebBrowserChrome::CHROME_NON_PRIVATE_WINDOW));
+
+ // Otherwise, propagate the privacy status of the parent window, if
+ // available, to the child.
+ if (!isPrivateBrowsingWindow &&
+ !(chromeFlags & nsIWebBrowserChrome::CHROME_NON_PRIVATE_WINDOW)) {
+ nsCOMPtr<nsIDocShellTreeItem> parentItem;
+ GetWindowTreeItem(aParent, getter_AddRefs(parentItem));
+ nsCOMPtr<nsILoadContext> parentContext = do_QueryInterface(parentItem);
+ if (parentContext) {
+ isPrivateBrowsingWindow = parentContext->UsePrivateBrowsing();
+ }
+ }
+
// We rely on CalculateChromeFlags to decide whether remote (out-of-process)
// tabs should be used.
bool isRemoteWindow =
!!(chromeFlags & nsIWebBrowserChrome::CHROME_REMOTE_WINDOW);
if (isNewToplevelWindow) {
nsCOMPtr<nsIDocShellTreeItem> childRoot;
newDocShellItem->GetRootTreeItem(getter_AddRefs(childRoot));