Bug 795015 - Set the initial state of the per-docshell private browsing flag based on the state of the global PB service; r=jdm,bzbarsky
authorEhsan Akhgari <ehsan@mozilla.com>
Sun, 30 Sep 2012 21:55:42 -0400
changeset 108813 4a7836f11aa7d751b7c974cf707d312617ee0982
parent 108812 31ae286fff781d9cedf951358c19750543740bc7
child 108814 281019df934376a248ff555dd6a328271696edb5
push id82
push usershu@rfrn.org
push dateFri, 05 Oct 2012 13:20:22 +0000
reviewersjdm, bzbarsky
bugs795015
milestone18.0a1
Bug 795015 - Set the initial state of the per-docshell private browsing flag based on the state of the global PB service; r=jdm,bzbarsky
browser/components/privatebrowsing/src/nsPrivateBrowsingService.js
docshell/base/nsDocShell.cpp
--- a/browser/components/privatebrowsing/src/nsPrivateBrowsingService.js
+++ b/browser/components/privatebrowsing/src/nsPrivateBrowsingService.js
@@ -56,17 +56,16 @@ const STATE_RESTORE_FINISHED = 3;
 function PrivateBrowsingService() {
   this._obs = Cc["@mozilla.org/observer-service;1"].
               getService(Ci.nsIObserverService);
   this._obs.addObserver(this, "profile-after-change", true);
   this._obs.addObserver(this, "quit-application-granted", true);
   this._obs.addObserver(this, "private-browsing", true);
   this._obs.addObserver(this, "command-line-startup", true);
   this._obs.addObserver(this, "sessionstore-browser-state-restored", true);
-  this._obs.addObserver(this, "domwindowopened", true);
 
   // List of nsIXULWindows we are going to be closing during the transition
   this._windowsToClose = [];
 }
 
 PrivateBrowsingService.prototype = {
   // Preferences Service
   get _prefs() {
@@ -492,28 +491,16 @@ PrivateBrowsingService.prototype = {
         }
         break;
       case "sessionstore-browser-state-restored":
         if (this._currentStatus == STATE_WAITING_FOR_RESTORE) {
           this._currentStatus = STATE_RESTORE_FINISHED;
           this._notifyIfTransitionComplete();
         }
         break;
-      case "domwindowopened":
-        let aWindow = aSubject;
-        let self = this;
-        aWindow.addEventListener("load", function PBS__onWindowLoad(aEvent) {
-          aWindow.removeEventListener("load", arguments.callee);
-          if (aWindow.document
-                     .documentElement
-                     .getAttribute("windowtype") == "navigator:browser") {
-            self._setPerWindowPBFlag(aWindow, self._inPrivateBrowsing);
-          }
-        }, false);
-        break;
     }
   },
 
   // nsICommandLineHandler
 
   handle: function PBS_handle(aCmdLine) {
     if (aCmdLine.handleFlag("private", false))
       aCmdLine.preventDefault = true; // It has already been handled
--- a/docshell/base/nsDocShell.cpp
+++ b/docshell/base/nsDocShell.cpp
@@ -188,16 +188,20 @@
 
 #include "nsDOMNavigationTiming.h"
 #include "nsITimedChannel.h"
 #include "mozilla/StartupTimeline.h"
 
 #include "mozilla/Telemetry.h"
 #include "nsISecurityUITelemetry.h"
 
+#ifndef MOZ_PER_WINDOW_PRIVATE_BROWSING
+#include "nsIPrivateBrowsingService.h"
+#endif
+
 static NS_DEFINE_CID(kDOMScriptObjectFactoryCID,
                      NS_DOM_SCRIPT_OBJECT_FACTORY_CID);
 static NS_DEFINE_CID(kAppShellCID, NS_APPSHELL_CID);
 
 #if defined(DEBUG_bryner) || defined(DEBUG_chb)
 //#define DEBUG_DOCSHELL_FOCUS
 #define DEBUG_PAGE_CACHE
 #endif
@@ -2717,22 +2721,33 @@ nsDocShell::SetDocLoaderParent(nsDocLoad
         {
             SetIsActive(value);
         }
         if (NS_FAILED(parentAsDocShell->GetAllowDNSPrefetch(&value))) {
             value = false;
         }
         SetAllowDNSPrefetch(value);
     }
+#ifndef MOZ_PER_WINDOW_PRIVATE_BROWSING
+    // Set the PB flag on the docshell based on the global PB mode for now
+    nsCOMPtr<nsIPrivateBrowsingService> pbs =
+        do_GetService(NS_PRIVATE_BROWSING_SERVICE_CONTRACTID);
+    if (pbs) {
+        bool inPrivateBrowsing = false;
+        pbs->GetPrivateBrowsingEnabled(&inPrivateBrowsing);
+        SetUsePrivateBrowsing(inPrivateBrowsing);
+    }
+#else
     nsCOMPtr<nsILoadContext> parentAsLoadContext(do_QueryInterface(parent));
     if (parentAsLoadContext &&
         NS_SUCCEEDED(parentAsLoadContext->GetUsePrivateBrowsing(&value)))
     {
         SetUsePrivateBrowsing(value);
     }
+#endif
 
     nsCOMPtr<nsIURIContentListener> parentURIListener(do_GetInterface(parent));
     if (parentURIListener)
         mContentListener->SetParentContentListener(parentURIListener);
     return NS_OK;
 }
 
 NS_IMETHODIMP