Bug 1199841 - Restructure private browsing to remember status after OnStopRequest r=jdm

This commit is contained in:
Jason Duell 2015-12-30 17:51:21 -05:00
parent f037c9c215
commit 90dc49a329
6 changed files with 29 additions and 10 deletions

View File

@ -48,7 +48,7 @@ public:
NS_IMETHOD GetIsChannelPrivate(bool *aResult)
{
NS_ENSURE_ARG_POINTER(aResult);
*aResult = NS_UsePrivateBrowsing(static_cast<Channel*>(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<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.

View File

@ -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<nsIPrivateBrowsingChannel> 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;
}

View File

@ -1220,13 +1220,12 @@ 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();

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;