Backed out changesets c63d33a0f879 and 9293ce14dd71 (bug 1317173) for bustage.
authorRyan VanderMeulen <ryanvm@gmail.com>
Thu, 15 Dec 2016 22:56:41 -0500
changeset 452580 28be1a348351539bd5341c44120a0829d21a7a35
parent 452579 2d1fa1d56e385da834601974ba2744c27f7b84cc
child 452581 5d44c320d982d1c240117a356101937889013675
push id39418
push userbmo:twointofive@gmail.com
push dateWed, 21 Dec 2016 20:59:30 +0000
bugs1317173
milestone51.0
backs outc63d33a0f879980cb056d3276232029d10ba59fb
9293ce14dd71bc02649afd79b72d69a6319b010c
Backed out changesets c63d33a0f879 and 9293ce14dd71 (bug 1317173) for bustage.
embedding/components/windowwatcher/nsWindowWatcher.cpp
--- 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));