diff --git a/embedding/components/windowwatcher/nsWindowWatcher.cpp b/embedding/components/windowwatcher/nsWindowWatcher.cpp index a931a22588f1..b0e0ff398fe6 100644 --- a/embedding/components/windowwatcher/nsWindowWatcher.cpp +++ b/embedding/components/windowwatcher/nsWindowWatcher.cpp @@ -1093,7 +1093,8 @@ nsWindowWatcher::OpenWindowInternal(mozIDOMWindowProxy* aParent, nsContentUtils::GetCurrentJSContext() ? nsContentUtils::SubjectPrincipal() : nullptr; - bool shouldCheckPrivateBrowsingId = false; + bool isPrivateBrowsingWindow = false; + if (windowIsNew) { auto* docShell = static_cast(newDocShell.get()); @@ -1102,11 +1103,28 @@ nsWindowWatcher::OpenWindowInternal(mozIDOMWindowProxy* aParent, if (subjectPrincipal && !nsContentUtils::IsSystemOrExpandedPrincipal(subjectPrincipal) && docShell->ItemType() != nsIDocShellTreeItem::typeChrome) { - shouldCheckPrivateBrowsingId = true; DocShellOriginAttributes attrs; attrs.InheritFromDocToChildDocShell(BasePrincipal::Cast(subjectPrincipal)->OriginAttributesRef()); - + isPrivateBrowsingWindow = !!attrs.mPrivateBrowsingId; docShell->SetOriginAttributes(attrs); + } else { + nsCOMPtr parentItem; + GetWindowTreeItem(aParent, getter_AddRefs(parentItem)); + nsCOMPtr 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 @@ -1136,26 +1154,6 @@ nsWindowWatcher::OpenWindowInternal(mozIDOMWindowProxy* aParent, } } - // 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 parentItem; - GetWindowTreeItem(aParent, getter_AddRefs(parentItem)); - nsCOMPtr 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 = @@ -1235,11 +1233,6 @@ nsWindowWatcher::OpenWindowInternal(mozIDOMWindowProxy* aParent, do_QueryInterface(newDocShell); if (parentStorageManager && newStorageManager) { - if (shouldCheckPrivateBrowsingId) { - MOZ_DIAGNOSTIC_ASSERT( - (subjectPrincipal->GetPrivateBrowsingId() > 0) == isPrivateBrowsingWindow); - } - nsCOMPtr storage; nsCOMPtr pInnerWin = parentWindow->GetCurrentInnerWindow(); parentStorageManager->GetStorage(pInnerWin, subjectPrincipal,