Bug 1199841 - Restructure private browsing to remember status after OnStopRequest r=jdm
authorJason Duell <jduell.mcbugs@gmail.com>
Wed, 30 Dec 2015 17:51:21 -0500
changeset 278052 e47415eaddef22a28f61b5aa780e96d85eaeeec9
parent 278051 cf35918cb3baff6e2c67209fa3cf0b0d03771073
child 278053 7da07459ce20c444c070ba8061c687c77bbc5400
push id29841
push userryanvm@gmail.com
push dateSat, 02 Jan 2016 00:29:52 +0000
treeherdermozilla-central@f7fbc524f9f3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjdm
bugs1199841
milestone46.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 1199841 - Restructure private browsing to remember status after OnStopRequest r=jdm
netwerk/base/PrivateBrowsingChannel.h
netwerk/base/nsBaseChannel.cpp
netwerk/base/nsNetUtil.cpp
netwerk/protocol/http/HttpBaseChannel.cpp
netwerk/protocol/wyciwyg/WyciwygChannelChild.cpp
netwerk/protocol/wyciwyg/nsWyciwygChannel.cpp
--- a/netwerk/base/PrivateBrowsingChannel.h
+++ b/netwerk/base/PrivateBrowsingChannel.h
@@ -43,31 +43,46 @@ public:
       mPrivateBrowsingOverriden = true;
       mPrivateBrowsing = aPrivate;
       return NS_OK;
   }
 
   NS_IMETHOD GetIsChannelPrivate(bool *aResult)
   {
       NS_ENSURE_ARG_POINTER(aResult);
-      *aResult = NS_UsePrivateBrowsing(static_cast<Channel*>(this));
+      *aResult = mPrivateBrowsing;
       return NS_OK;
   }
 
   NS_IMETHOD IsPrivateModeOverriden(bool* aValue, bool *aResult)
   {
       NS_ENSURE_ARG_POINTER(aValue);
       NS_ENSURE_ARG_POINTER(aResult);
       *aResult = mPrivateBrowsingOverriden;
       if (mPrivateBrowsingOverriden) {
           *aValue = mPrivateBrowsing;
       }
       return NS_OK;
   }
 
+  // Must be called every time the channel's callbacks or loadGroup is updated
+  void UpdatePrivateBrowsing()
+  {
+      // once marked as private we never go un-private
+      if (mPrivateBrowsing) {
+          return;
+      }
+
+      nsCOMPtr<nsILoadContext> loadContext;
+      NS_QueryNotificationCallbacks(static_cast<Channel*>(this), loadContext);
+      if (loadContext) {
+          mPrivateBrowsing = loadContext->UsePrivateBrowsing();
+      }
+  }
+
   bool CanSetCallbacks(nsIInterfaceRequestor* aCallbacks) const
   {
       // Make sure that the private bit override flag is not set.
       // This is a fatal error in debug builds, and a runtime error in release
       // builds.
       if (!aCallbacks) {
           return true;
       }
--- a/netwerk/base/nsBaseChannel.cpp
+++ b/netwerk/base/nsBaseChannel.cpp
@@ -96,17 +96,17 @@ nsBaseChannel::Redirect(nsIChannel *newC
     newChannel->SetLoadInfo(newLoadInfo);
   }
   else {
     // the newChannel was created with a dummy loadInfo, we should clear
     // it in case the original channel does not have a loadInfo
     newChannel->SetLoadInfo(nullptr);
   }
 
-  // Try to preserve the privacy bit if it has been overridden
+  // Preserve the privacy bit if it has been overridden
   if (mPrivateBrowsingOverriden) {
     nsCOMPtr<nsIPrivateBrowsingChannel> newPBChannel =
       do_QueryInterface(newChannel);
     if (newPBChannel) {
       newPBChannel->SetPrivate(mPrivateBrowsing);
     }
   }
 
@@ -419,16 +419,17 @@ NS_IMETHODIMP
 nsBaseChannel::SetLoadGroup(nsILoadGroup *aLoadGroup)
 {
   if (!CanSetLoadGroup(aLoadGroup)) {
     return NS_ERROR_FAILURE;
   }
 
   mLoadGroup = aLoadGroup;
   CallbacksChanged();
+  UpdatePrivateBrowsing();
   return NS_OK;
 }
 
 //-----------------------------------------------------------------------------
 // nsBaseChannel::nsIChannel
 
 NS_IMETHODIMP
 nsBaseChannel::GetOriginalURI(nsIURI **aURI)
@@ -492,16 +493,17 @@ NS_IMETHODIMP
 nsBaseChannel::SetNotificationCallbacks(nsIInterfaceRequestor *aCallbacks)
 {
   if (!CanSetCallbacks(aCallbacks)) {
     return NS_ERROR_FAILURE;
   }
 
   mCallbacks = aCallbacks;
   CallbacksChanged();
+  UpdatePrivateBrowsing();
   return NS_OK;
 }
 
 NS_IMETHODIMP 
 nsBaseChannel::GetSecurityInfo(nsISupports **aSecurityInfo)
 {
   NS_IF_ADDREF(*aSecurityInfo = mSecurityInfo);
   return NS_OK;
--- a/netwerk/base/nsNetUtil.cpp
+++ b/netwerk/base/nsNetUtil.cpp
@@ -1215,23 +1215,22 @@ NS_LoadPersistentPropertiesFromURISpec(n
     properties.swap(*outResult);
     return NS_OK;
 }
 
 bool
 NS_UsePrivateBrowsing(nsIChannel *channel)
 {
     bool isPrivate = false;
-    bool isOverriden = false;
     nsCOMPtr<nsIPrivateBrowsingChannel> pbChannel = do_QueryInterface(channel);
-    if (pbChannel &&
-        NS_SUCCEEDED(pbChannel->IsPrivateModeOverriden(&isPrivate, &isOverriden)) &&
-        isOverriden) {
+    if (pbChannel && NS_SUCCEEDED(pbChannel->GetIsChannelPrivate(&isPrivate))) {
         return isPrivate;
     }
+
+    // Some channels may not implement nsIPrivateBrowsingChannel
     nsCOMPtr<nsILoadContext> loadContext;
     NS_QueryNotificationCallbacks(channel, loadContext);
     return loadContext && loadContext->UsePrivateBrowsing();
 }
 
 bool
 NS_GetOriginAttributes(nsIChannel *aChannel,
                        mozilla::NeckoOriginAttributes &aAttributes)
--- a/netwerk/protocol/http/HttpBaseChannel.cpp
+++ b/netwerk/protocol/http/HttpBaseChannel.cpp
@@ -256,17 +256,17 @@ HttpBaseChannel::SetLoadGroup(nsILoadGro
   MOZ_ASSERT(NS_IsMainThread(), "Should only be called on the main thread.");
 
   if (!CanSetLoadGroup(aLoadGroup)) {
     return NS_ERROR_FAILURE;
   }
 
   mLoadGroup = aLoadGroup;
   mProgressSink = nullptr;
-  mPrivateBrowsing = NS_UsePrivateBrowsing(this);
+  UpdatePrivateBrowsing();
   return NS_OK;
 }
 
 NS_IMETHODIMP
 HttpBaseChannel::GetLoadFlags(nsLoadFlags *aLoadFlags)
 {
   NS_ENSURE_ARG_POINTER(aLoadFlags);
   *aLoadFlags = mLoadFlags;
@@ -414,17 +414,17 @@ HttpBaseChannel::SetNotificationCallback
 
   if (!CanSetCallbacks(aCallbacks)) {
     return NS_ERROR_FAILURE;
   }
 
   mCallbacks = aCallbacks;
   mProgressSink = nullptr;
 
-  mPrivateBrowsing = NS_UsePrivateBrowsing(this);
+  UpdatePrivateBrowsing();
   return NS_OK;
 }
 
 NS_IMETHODIMP
 HttpBaseChannel::GetContentType(nsACString& aContentType)
 {
   if (!mResponseHead) {
     aContentType.Truncate();
--- a/netwerk/protocol/wyciwyg/WyciwygChannelChild.cpp
+++ b/netwerk/protocol/wyciwyg/WyciwygChannelChild.cpp
@@ -428,16 +428,18 @@ WyciwygChannelChild::SetLoadGroup(nsILoa
     return NS_ERROR_FAILURE;
   }
 
   mLoadGroup = aLoadGroup;
   NS_QueryNotificationCallbacks(mCallbacks,
                                 mLoadGroup,
                                 NS_GET_IID(nsIProgressEventSink),
                                 getter_AddRefs(mProgressSink));
+
+  UpdatePrivateBrowsing();
   return NS_OK;
 }
 
 NS_IMETHODIMP
 WyciwygChannelChild::GetLoadFlags(nsLoadFlags *aLoadFlags)
 {
   *aLoadFlags = mLoadFlags;
   return NS_OK;
@@ -520,16 +522,17 @@ WyciwygChannelChild::SetNotificationCall
     return NS_ERROR_FAILURE;
   }
 
   mCallbacks = aCallbacks;
   NS_QueryNotificationCallbacks(mCallbacks,
                                 mLoadGroup,
                                 NS_GET_IID(nsIProgressEventSink),
                                 getter_AddRefs(mProgressSink));
+  UpdatePrivateBrowsing();
   return NS_OK;
 }
 
 NS_IMETHODIMP
 WyciwygChannelChild::GetSecurityInfo(nsISupports * *aSecurityInfo)
 {
   NS_IF_ADDREF(*aSecurityInfo = mSecurityInfo);
 
--- a/netwerk/protocol/wyciwyg/nsWyciwygChannel.cpp
+++ b/netwerk/protocol/wyciwyg/nsWyciwygChannel.cpp
@@ -226,17 +226,17 @@ nsWyciwygChannel::SetLoadGroup(nsILoadGr
     return NS_ERROR_FAILURE;
   }
 
   mLoadGroup = aLoadGroup;
   NS_QueryNotificationCallbacks(mCallbacks,
                                 mLoadGroup,
                                 NS_GET_IID(nsIProgressEventSink),
                                 getter_AddRefs(mProgressSink));
-  mPrivateBrowsing = NS_UsePrivateBrowsing(this);
+  UpdatePrivateBrowsing();
   NS_GetOriginAttributes(this, mOriginAttributes);
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsWyciwygChannel::SetLoadFlags(uint32_t aLoadFlags)
 {
@@ -323,17 +323,17 @@ nsWyciwygChannel::SetNotificationCallbac
   }
 
   mCallbacks = aNotificationCallbacks;
   NS_QueryNotificationCallbacks(mCallbacks,
                                 mLoadGroup,
                                 NS_GET_IID(nsIProgressEventSink),
                                 getter_AddRefs(mProgressSink));
 
-  mPrivateBrowsing = NS_UsePrivateBrowsing(this);
+  UpdatePrivateBrowsing();
   NS_GetOriginAttributes(this, mOriginAttributes);
 
   return NS_OK;
 }
 
 NS_IMETHODIMP 
 nsWyciwygChannel::GetSecurityInfo(nsISupports * *aSecurityInfo)
 {