Bug 1319536: Part 1 - Take private browsing ID from load info when load context is unavailable. r=ehsan
authorKris Maglione <maglione.k@gmail.com>
Thu, 24 Nov 2016 15:51:15 -0800
changeset 324325 ce6bd69e09fb1927631d5a4aa0b66913e17a90a2
parent 324324 349bfd47d48b4af6eb1b8d8e1485d928e65606aa
child 324326 d0987b1b6e085e275e78bda81c2ef08e7ba87a00
push id24
push usermaklebus@msu.edu
push dateTue, 20 Dec 2016 03:11:33 +0000
reviewersehsan
bugs1319536
milestone53.0a1
Bug 1319536: Part 1 - Take private browsing ID from load info when load context is unavailable. r=ehsan MozReview-Commit-ID: IoXFofyiKR1
netwerk/base/PrivateBrowsingChannel.h
--- a/netwerk/base/PrivateBrowsingChannel.h
+++ b/netwerk/base/PrivateBrowsingChannel.h
@@ -9,16 +9,17 @@
 
 #include "nsIPrivateBrowsingChannel.h"
 #include "nsCOMPtr.h"
 #include "nsILoadGroup.h"
 #include "nsILoadContext.h"
 #include "nsIInterfaceRequestorUtils.h"
 #include "nsIInterfaceRequestor.h"
 #include "nsNetUtil.h"
+#include "mozilla/Unused.h"
 
 namespace mozilla {
 namespace net {
 
 template <class Channel>
 class PrivateBrowsingChannel : public nsIPrivateBrowsingChannel
 {
 public:
@@ -66,20 +67,30 @@ public:
   // 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;
       }
 
+      auto channel = static_cast<Channel*>(this);
+
       nsCOMPtr<nsILoadContext> loadContext;
-      NS_QueryNotificationCallbacks(static_cast<Channel*>(this), loadContext);
+      NS_QueryNotificationCallbacks(channel, loadContext);
       if (loadContext) {
           mPrivateBrowsing = loadContext->UsePrivateBrowsing();
+          return;
+      }
+
+      nsCOMPtr<nsILoadInfo> loadInfo;
+      Unused << channel->GetLoadInfo(getter_AddRefs(loadInfo));
+      if (loadInfo) {
+          NeckoOriginAttributes attrs = loadInfo->GetOriginAttributes();
+          mPrivateBrowsing = attrs.mPrivateBrowsingId > 0;
       }
   }
 
   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.