Bug 788275 - Part 1: Only check whether the PB state bit overridden condition holds for the cases where we actually have a load context around; r=jduell
authorEhsan Akhgari <ehsan@mozilla.com>
Wed, 26 Sep 2012 10:36:38 -0400
changeset 108143 4cda2cc454660949ec6faf5911c04f3dd09d71d9
parent 108142 490abcc57fec9442db09c9ebbb745fd102484cd1
child 108144 7c3acad5cf39d78d6ef42ba7d72f0e827e9bd46c
push id23539
push userryanvm@gmail.com
push dateWed, 26 Sep 2012 22:55:55 +0000
treeherderautoland@ec079fd92224 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjduell
bugs788275
milestone18.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 788275 - Part 1: Only check whether the PB state bit overridden condition holds for the cases where we actually have a load context around; r=jduell
netwerk/base/src/PrivateBrowsingChannel.h
netwerk/protocol/ftp/FTPChannelChild.cpp
netwerk/protocol/ftp/nsFTPChannel.cpp
netwerk/protocol/http/HttpBaseChannel.cpp
netwerk/protocol/wyciwyg/WyciwygChannelChild.cpp
netwerk/protocol/wyciwyg/nsWyciwygChannel.cpp
--- a/netwerk/base/src/PrivateBrowsingChannel.h
+++ b/netwerk/base/src/PrivateBrowsingChannel.h
@@ -6,16 +6,18 @@
 
 #ifndef mozilla_net_PrivateBrowsingChannel_h__
 #define mozilla_net_PrivateBrowsingChannel_h__
 
 #include "nsIPrivateBrowsingChannel.h"
 #include "nsCOMPtr.h"
 #include "nsILoadGroup.h"
 #include "nsILoadContext.h"
+#include "nsIInterfaceRequestorUtils.h"
+#include "nsIInterfaceRequestor.h"
 
 namespace mozilla {
 namespace net {
 
 template <class Channel>
 class PrivateBrowsingChannel : public nsIPrivateBrowsingChannel
 {
 public:
@@ -51,29 +53,45 @@ public:
       NS_ENSURE_ARG_POINTER(aResult);
       *aResult = mPrivateBrowsingOverriden;
       if (mPrivateBrowsingOverriden) {
           *aValue = mPrivateBrowsing;
       }
       return NS_OK;
   }
 
-  bool CanSetCallbacks() const
+  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;
+      }
+      nsCOMPtr<nsILoadContext> loadContext = do_GetInterface(aCallbacks);
+      if (!loadContext) {
+          return true;
+      }
       MOZ_ASSERT(!mPrivateBrowsingOverriden);
       return !mPrivateBrowsingOverriden;
   }
 
-  bool CanSetLoadGroup() const
+  bool CanSetLoadGroup(nsILoadGroup* aLoadGroup) const
   {
-      // We can set a load group whenever we can set a callback
-      return CanSetCallbacks();
+      // 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 (!aLoadGroup) {
+          return true;
+      }
+      nsCOMPtr<nsIInterfaceRequestor> callbacks;
+      aLoadGroup->GetNotificationCallbacks(getter_AddRefs(callbacks));
+      // From this point on, we just hand off the work to CanSetCallbacks,
+      // because the logic is exactly the same.
+      return CanSetCallbacks(callbacks);
   }
 
 protected:
   bool mPrivateBrowsingOverriden;
   bool mPrivateBrowsing;
 };
 
 }
--- a/netwerk/protocol/ftp/FTPChannelChild.cpp
+++ b/netwerk/protocol/ftp/FTPChannelChild.cpp
@@ -545,27 +545,27 @@ FTPChannelChild::CompleteRedirectSetup(n
   // listeners or load group observers canceled us, let the parent handle it
   // and send it back to us naturally.
   return NS_OK;
 }
 
 NS_IMETHODIMP
 FTPChannelChild::SetNotificationCallbacks(nsIInterfaceRequestor* aCallbacks)
 {
-  if (!CanSetCallbacks()) {
+  if (!CanSetCallbacks(aCallbacks)) {
     return NS_ERROR_FAILURE;
   }
 
   return nsBaseChannel::SetNotificationCallbacks(aCallbacks);
 }
 
 NS_IMETHODIMP
 FTPChannelChild::SetLoadGroup(nsILoadGroup * aLoadGroup)
 {
-  if (!CanSetLoadGroup()) {
+  if (!CanSetLoadGroup(aLoadGroup)) {
     return NS_ERROR_FAILURE;
   }
 
   return nsBaseChannel::SetLoadGroup(aLoadGroup);
 }
 
 } // namespace net
 } // namespace mozilla
--- a/netwerk/protocol/ftp/nsFTPChannel.cpp
+++ b/netwerk/protocol/ftp/nsFTPChannel.cpp
@@ -217,24 +217,24 @@ nsFtpChannel::GetFTPEventSink(nsCOMPtr<n
         }
     }
     aResult = mFTPEventSink;
 }
 
 NS_IMETHODIMP
 nsFtpChannel::SetNotificationCallbacks(nsIInterfaceRequestor* aCallbacks)
 {
-  if (!CanSetCallbacks()) {
+  if (!CanSetCallbacks(aCallbacks)) {
     return NS_ERROR_FAILURE;
   }
 
   return nsBaseChannel::SetNotificationCallbacks(aCallbacks);
 }
 
 NS_IMETHODIMP
 nsFtpChannel::SetLoadGroup(nsILoadGroup * aLoadGroup)
 {
-  if (!CanSetLoadGroup()) {
+  if (!CanSetLoadGroup(aLoadGroup)) {
     return NS_ERROR_FAILURE;
   }
 
   return nsBaseChannel::SetLoadGroup(aLoadGroup);
 }
--- a/netwerk/protocol/http/HttpBaseChannel.cpp
+++ b/netwerk/protocol/http/HttpBaseChannel.cpp
@@ -184,17 +184,17 @@ HttpBaseChannel::GetLoadGroup(nsILoadGro
   *aLoadGroup = mLoadGroup;
   NS_IF_ADDREF(*aLoadGroup);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 HttpBaseChannel::SetLoadGroup(nsILoadGroup *aLoadGroup)
 {
-  if (!CanSetLoadGroup()) {
+  if (!CanSetLoadGroup(aLoadGroup)) {
     return NS_ERROR_FAILURE;
   }
 
   mLoadGroup = aLoadGroup;
   mProgressSink = nullptr;
   mPrivateBrowsing = NS_UsePrivateBrowsing(this);
   return NS_OK;
 }
@@ -268,17 +268,17 @@ HttpBaseChannel::GetNotificationCallback
   *aCallbacks = mCallbacks;
   NS_IF_ADDREF(*aCallbacks);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 HttpBaseChannel::SetNotificationCallbacks(nsIInterfaceRequestor *aCallbacks)
 {
-  if (!CanSetCallbacks()) {
+  if (!CanSetCallbacks(aCallbacks)) {
     return NS_ERROR_FAILURE;
   }
 
   mCallbacks = aCallbacks;
   mProgressSink = nullptr;
 
   mPrivateBrowsing = NS_UsePrivateBrowsing(this);
   return NS_OK;
--- a/netwerk/protocol/wyciwyg/WyciwygChannelChild.cpp
+++ b/netwerk/protocol/wyciwyg/WyciwygChannelChild.cpp
@@ -380,17 +380,17 @@ WyciwygChannelChild::GetLoadGroup(nsILoa
 {
   *aLoadGroup = mLoadGroup;
   NS_IF_ADDREF(*aLoadGroup);
   return NS_OK;
 }
 NS_IMETHODIMP
 WyciwygChannelChild::SetLoadGroup(nsILoadGroup * aLoadGroup)
 {
-  if (!CanSetLoadGroup()) {
+  if (!CanSetLoadGroup(aLoadGroup)) {
     return NS_ERROR_FAILURE;
   }
 
   mLoadGroup = aLoadGroup;
   NS_QueryNotificationCallbacks(mCallbacks,
                                 mLoadGroup,
                                 NS_GET_IID(nsIProgressEventSink),
                                 getter_AddRefs(mProgressSink));
@@ -466,17 +466,17 @@ WyciwygChannelChild::GetNotificationCall
 {
   *aCallbacks = mCallbacks;
   NS_IF_ADDREF(*aCallbacks);
   return NS_OK;
 }
 NS_IMETHODIMP
 WyciwygChannelChild::SetNotificationCallbacks(nsIInterfaceRequestor * aCallbacks)
 {
-  if (!CanSetCallbacks()) {
+  if (!CanSetCallbacks(aCallbacks)) {
     return NS_ERROR_FAILURE;
   }
 
   mCallbacks = aCallbacks;
   NS_QueryNotificationCallbacks(mCallbacks,
                                 mLoadGroup,
                                 NS_GET_IID(nsIProgressEventSink),
                                 getter_AddRefs(mProgressSink));
--- a/netwerk/protocol/wyciwyg/nsWyciwygChannel.cpp
+++ b/netwerk/protocol/wyciwyg/nsWyciwygChannel.cpp
@@ -183,17 +183,17 @@ nsWyciwygChannel::GetLoadGroup(nsILoadGr
   *aLoadGroup = mLoadGroup;
   NS_IF_ADDREF(*aLoadGroup);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsWyciwygChannel::SetLoadGroup(nsILoadGroup* aLoadGroup)
 {
-  if (!CanSetLoadGroup()) {
+  if (!CanSetLoadGroup(aLoadGroup)) {
     return NS_ERROR_FAILURE;
   }
 
   mLoadGroup = aLoadGroup;
   NS_QueryNotificationCallbacks(mCallbacks,
                                 mLoadGroup,
                                 NS_GET_IID(nsIProgressEventSink),
                                 getter_AddRefs(mProgressSink));
@@ -266,17 +266,17 @@ nsWyciwygChannel::GetNotificationCallbac
   *aCallbacks = mCallbacks.get();
   NS_IF_ADDREF(*aCallbacks);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsWyciwygChannel::SetNotificationCallbacks(nsIInterfaceRequestor* aNotificationCallbacks)
 {
-  if (!CanSetCallbacks()) {
+  if (!CanSetCallbacks(aNotificationCallbacks)) {
     return NS_ERROR_FAILURE;
   }
 
   mCallbacks = aNotificationCallbacks;
   NS_QueryNotificationCallbacks(mCallbacks,
                                 mLoadGroup,
                                 NS_GET_IID(nsIProgressEventSink),
                                 getter_AddRefs(mProgressSink));