Bug 1277803 - Part 4: Make the NS_CompareLoadInfoAndLoadContext() skiping test if the request is the favicon loading from the XUL image. r=honzab

This commit is contained in:
Tim Huang 2016-10-06 00:57:00 -04:00
Родитель e3b1c6bb15
Коммит 33effa2da2
5 изменённых файлов: 38 добавлений и 9 удалений

Просмотреть файл

@ -2408,6 +2408,18 @@ NS_CompareLoadInfoAndLoadContext(nsIChannel *aChannel)
return NS_OK;
}
// We skip the favicon loading here. The favicon loading might be
// triggered by the XUL image. For that case, the loadContext will have
// default originAttributes since the XUL image uses SystemPrincipal, but
// the loadInfo will use originAttributes from the content. Thus, the
// originAttributes between loadInfo and loadContext will be different.
// That's why we have to skip the comparison for the favicon loading.
if (nsContentUtils::IsSystemPrincipal(loadInfo->LoadingPrincipal()) &&
loadInfo->InternalContentPolicyType() ==
nsIContentPolicy::TYPE_INTERNAL_IMAGE_FAVICON) {
return NS_OK;
}
uint32_t loadContextAppId = 0;
nsresult rv = loadContext->GetAppId(&loadContextAppId);
if (NS_FAILED(rv)) {

Просмотреть файл

@ -2664,18 +2664,33 @@ HttpBaseChannel::ShouldIntercept(nsIURI* aURI)
return shouldIntercept;
}
void HttpBaseChannel::CheckPrivateBrowsing()
#ifdef DEBUG
void HttpBaseChannel::AssertPrivateBrowsingId()
{
nsCOMPtr<nsILoadContext> loadContext;
NS_QueryNotificationCallbacks(this, loadContext);
// For addons it's possible that mLoadInfo is null.
if (mLoadInfo && loadContext) {
DocShellOriginAttributes docShellAttrs;
loadContext->GetOriginAttributes(docShellAttrs);
MOZ_ASSERT(mLoadInfo->GetOriginAttributes().mPrivateBrowsingId == docShellAttrs.mPrivateBrowsingId,
"PrivateBrowsingId values are not the same between LoadInfo and LoadContext.");
if (!mLoadInfo) {
return;
}
if (!loadContext) {
return;
}
// We skip testing of favicon loading here since it could be triggered by XUL image
// which uses SystemPrincipal. The SystemPrincpal doesn't have mPrivateBrowsingId.
if (nsContentUtils::IsSystemPrincipal(mLoadInfo->LoadingPrincipal()) &&
mLoadInfo->InternalContentPolicyType() == nsIContentPolicy::TYPE_INTERNAL_IMAGE_FAVICON) {
return;
}
DocShellOriginAttributes docShellAttrs;
loadContext->GetOriginAttributes(docShellAttrs);
MOZ_ASSERT(mLoadInfo->GetOriginAttributes().mPrivateBrowsingId == docShellAttrs.mPrivateBrowsingId,
"PrivateBrowsingId values are not the same between LoadInfo and LoadContext.");
}
#endif
//-----------------------------------------------------------------------------
// nsHttpChannel::nsITraceableChannel

Просмотреть файл

@ -382,8 +382,10 @@ protected:
// for a possible synthesized response instead.
bool ShouldIntercept(nsIURI* aURI = nullptr);
#ifdef DEBUG
// Check if mPrivateBrowsingId matches between LoadInfo and LoadContext.
void CheckPrivateBrowsing();
void AssertPrivateBrowsingId();
#endif
friend class PrivateBrowsingChannel<HttpBaseChannel>;
friend class InterceptFailedOnStop;

Просмотреть файл

@ -1796,7 +1796,7 @@ HttpChannelChild::AsyncOpen(nsIStreamListener *listener, nsISupports *aContext)
LOG(("HttpChannelChild::AsyncOpen [this=%p uri=%s]\n", this, mSpec.get()));
#ifdef DEBUG
CheckPrivateBrowsing();
AssertPrivateBrowsingId();
#endif
if (mCanceled)

Просмотреть файл

@ -5659,7 +5659,7 @@ nsHttpChannel::AsyncOpen(nsIStreamListener *listener, nsISupports *context)
NS_CompareLoadInfoAndLoadContext(this);
#ifdef DEBUG
CheckPrivateBrowsing();
AssertPrivateBrowsingId();
#endif
NS_ENSURE_ARG_POINTER(listener);