diff --git a/netwerk/base/PrivateBrowsingChannel.h b/netwerk/base/PrivateBrowsingChannel.h index 165bea03c46..0fe96bd1a29 100644 --- a/netwerk/base/PrivateBrowsingChannel.h +++ b/netwerk/base/PrivateBrowsingChannel.h @@ -48,7 +48,7 @@ public: NS_IMETHOD GetIsChannelPrivate(bool *aResult) { NS_ENSURE_ARG_POINTER(aResult); - *aResult = NS_UsePrivateBrowsing(static_cast(this)); + *aResult = mPrivateBrowsing; return NS_OK; } @@ -63,6 +63,21 @@ public: 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 loadContext; + NS_QueryNotificationCallbacks(static_cast(this), loadContext); + if (loadContext) { + mPrivateBrowsing = loadContext->UsePrivateBrowsing(); + } + } + bool CanSetCallbacks(nsIInterfaceRequestor* aCallbacks) const { // Make sure that the private bit override flag is not set. diff --git a/netwerk/base/nsBaseChannel.cpp b/netwerk/base/nsBaseChannel.cpp index 4bf5dc076ae..0a6829349b2 100644 --- a/netwerk/base/nsBaseChannel.cpp +++ b/netwerk/base/nsBaseChannel.cpp @@ -101,7 +101,7 @@ nsBaseChannel::Redirect(nsIChannel *newChannel, uint32_t redirectFlags, 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 newPBChannel = do_QueryInterface(newChannel); @@ -424,6 +424,7 @@ nsBaseChannel::SetLoadGroup(nsILoadGroup *aLoadGroup) mLoadGroup = aLoadGroup; CallbacksChanged(); + UpdatePrivateBrowsing(); return NS_OK; } @@ -497,6 +498,7 @@ nsBaseChannel::SetNotificationCallbacks(nsIInterfaceRequestor *aCallbacks) mCallbacks = aCallbacks; CallbacksChanged(); + UpdatePrivateBrowsing(); return NS_OK; } diff --git a/netwerk/base/nsNetUtil.cpp b/netwerk/base/nsNetUtil.cpp index a1a7025b802..6991af98f89 100644 --- a/netwerk/base/nsNetUtil.cpp +++ b/netwerk/base/nsNetUtil.cpp @@ -1220,13 +1220,12 @@ bool NS_UsePrivateBrowsing(nsIChannel *channel) { bool isPrivate = false; - bool isOverriden = false; nsCOMPtr 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 loadContext; NS_QueryNotificationCallbacks(channel, loadContext); return loadContext && loadContext->UsePrivateBrowsing(); diff --git a/netwerk/protocol/http/HttpBaseChannel.cpp b/netwerk/protocol/http/HttpBaseChannel.cpp index 3cbda7ed274..046a45059fd 100644 --- a/netwerk/protocol/http/HttpBaseChannel.cpp +++ b/netwerk/protocol/http/HttpBaseChannel.cpp @@ -261,7 +261,7 @@ HttpBaseChannel::SetLoadGroup(nsILoadGroup *aLoadGroup) mLoadGroup = aLoadGroup; mProgressSink = nullptr; - mPrivateBrowsing = NS_UsePrivateBrowsing(this); + UpdatePrivateBrowsing(); return NS_OK; } @@ -419,7 +419,7 @@ HttpBaseChannel::SetNotificationCallbacks(nsIInterfaceRequestor *aCallbacks) mCallbacks = aCallbacks; mProgressSink = nullptr; - mPrivateBrowsing = NS_UsePrivateBrowsing(this); + UpdatePrivateBrowsing(); return NS_OK; } diff --git a/netwerk/protocol/wyciwyg/WyciwygChannelChild.cpp b/netwerk/protocol/wyciwyg/WyciwygChannelChild.cpp index c7a55275b42..f4f7c1a266e 100644 --- a/netwerk/protocol/wyciwyg/WyciwygChannelChild.cpp +++ b/netwerk/protocol/wyciwyg/WyciwygChannelChild.cpp @@ -433,6 +433,8 @@ WyciwygChannelChild::SetLoadGroup(nsILoadGroup * aLoadGroup) mLoadGroup, NS_GET_IID(nsIProgressEventSink), getter_AddRefs(mProgressSink)); + + UpdatePrivateBrowsing(); return NS_OK; } @@ -525,6 +527,7 @@ WyciwygChannelChild::SetNotificationCallbacks(nsIInterfaceRequestor * aCallbacks mLoadGroup, NS_GET_IID(nsIProgressEventSink), getter_AddRefs(mProgressSink)); + UpdatePrivateBrowsing(); return NS_OK; } diff --git a/netwerk/protocol/wyciwyg/nsWyciwygChannel.cpp b/netwerk/protocol/wyciwyg/nsWyciwygChannel.cpp index 20e69e660d8..dd58105547c 100644 --- a/netwerk/protocol/wyciwyg/nsWyciwygChannel.cpp +++ b/netwerk/protocol/wyciwyg/nsWyciwygChannel.cpp @@ -231,7 +231,7 @@ nsWyciwygChannel::SetLoadGroup(nsILoadGroup* aLoadGroup) mLoadGroup, NS_GET_IID(nsIProgressEventSink), getter_AddRefs(mProgressSink)); - mPrivateBrowsing = NS_UsePrivateBrowsing(this); + UpdatePrivateBrowsing(); NS_GetOriginAttributes(this, mOriginAttributes); return NS_OK; @@ -328,7 +328,7 @@ nsWyciwygChannel::SetNotificationCallbacks(nsIInterfaceRequestor* aNotificationC NS_GET_IID(nsIProgressEventSink), getter_AddRefs(mProgressSink)); - mPrivateBrowsing = NS_UsePrivateBrowsing(this); + UpdatePrivateBrowsing(); NS_GetOriginAttributes(this, mOriginAttributes); return NS_OK;