Bug 814275 - When the global service matters, force all new windows to conform to the global private browsing state. r=bz
authorJosh Matthews <josh@joshmatthews.net>
Thu, 22 Nov 2012 10:48:13 -0500
changeset 114305 c8766443985c6c82b3f35253bad3fb0a8d55dbfd
parent 114304 ae5e741238ccf7679ad78411dbe183b53af51523
child 114306 d9634ee8c1cc2aeedecef274a4d3d36585da886d
push id18680
push usereakhgari@mozilla.com
push dateWed, 28 Nov 2012 00:04:45 +0000
treeherdermozilla-inbound@c8766443985c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs814275
milestone20.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 814275 - When the global service matters, force all new windows to conform to the global private browsing state. r=bz
embedding/components/windowwatcher/src/nsWindowWatcher.cpp
--- a/embedding/components/windowwatcher/src/nsWindowWatcher.cpp
+++ b/embedding/components/windowwatcher/src/nsWindowWatcher.cpp
@@ -56,16 +56,20 @@
 #include "nsIPresShell.h"
 #include "nsPresContext.h"
 #include "nsContentUtils.h"
 #include "nsIPrefBranch.h"
 #include "nsIPrefService.h"
 #include "nsSandboxFlags.h"
 #include "mozilla/Preferences.h"
 
+#ifndef MOZ_PER_WINDOW_PRIVATE_BROWSING
+#include "nsIPrivateBrowsingService.h"
+#endif
+
 #ifdef USEWEAKREFS
 #include "nsIWeakReference.h"
 #endif
 
 using namespace mozilla;
 
 static const char *sJSStackContractID="@mozilla.org/js/xpc/ContextStack;1";
 
@@ -899,16 +903,27 @@ nsWindowWatcher::OpenWindowInternal(nsID
   }
 
   if (windowIsNew) {
     // See if the caller has requested a private browsing window, or if all
     // windows should be private.
     bool isPrivateBrowsingWindow =
       Preferences::GetBool("browser.privatebrowsing.autostart") ||
       !!(chromeFlags & nsIWebBrowserChrome::CHROME_PRIVATE_WINDOW);
+
+#ifndef MOZ_PER_WINDOW_PRIVATE_BROWSING
+    nsCOMPtr<nsIPrivateBrowsingService> pbs =
+      do_GetService(NS_PRIVATE_BROWSING_SERVICE_CONTRACTID);
+    if (pbs) {
+      bool inPrivateBrowsing = false;
+      pbs->GetPrivateBrowsingEnabled(&inPrivateBrowsing);
+      isPrivateBrowsingWindow |= inPrivateBrowsing;
+    }
+#endif
+
     // 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();