Bug 1125916 - Check whether loadInfo and loadContext match. r=sicking, r=jduell

--HG--
extra : rebase_source : 582977113d0e3e15913120232300478835ef1384
extra : histedit_source : 7d3f02b68874f16bb63974f8b41facf947385917
This commit is contained in:
Dragana Damjanovic 2016-04-13 10:23:26 +02:00
parent 4ca2619d53
commit e72aa9a9f1
4 changed files with 71 additions and 0 deletions

View File

@ -647,6 +647,8 @@ nsBaseChannel::AsyncOpen(nsIStreamListener *listener, nsISupports *ctxt)
NS_ENSURE_TRUE(!mWasOpened, NS_ERROR_ALREADY_OPENED);
NS_ENSURE_ARG(listener);
NS_CompareLoadInfoAndLoadContext(this);
// Ensure that this is an allowed port before proceeding.
nsresult rv = NS_CheckPortSafety(mURI);
if (NS_FAILED(rv)) {

View File

@ -2363,6 +2363,72 @@ NS_GetSecureUpgradedURI(nsIURI* aURI, nsIURI** aUpgradedURI)
return NS_OK;
}
nsresult
NS_CompareLoadInfoAndLoadContext(nsIChannel *aChannel)
{
nsCOMPtr<nsILoadInfo> loadInfo;
aChannel->GetLoadInfo(getter_AddRefs(loadInfo));
nsCOMPtr<nsILoadContext> loadContext;
NS_QueryNotificationCallbacks(aChannel, loadContext);
if (loadInfo && loadContext) {
uint32_t loadContextAppId = 0;
nsresult rv = loadContext->GetAppId(&loadContextAppId);
if (NS_FAILED(rv)) {
return NS_ERROR_UNEXPECTED;
}
bool loadContextIsInBE = false;
rv = loadContext->GetIsInIsolatedMozBrowserElement(&loadContextIsInBE);
if (NS_FAILED(rv)) {
return NS_ERROR_UNEXPECTED;
}
OriginAttributes originAttrsLoadInfo = loadInfo->GetOriginAttributes();
DocShellOriginAttributes originAttrsLoadContext;
loadContext->GetOriginAttributes(originAttrsLoadContext);
bool loadInfoUsePB = false;
rv = loadInfo->GetUsePrivateBrowsing(&loadInfoUsePB);
if (NS_FAILED(rv)) {
return NS_ERROR_UNEXPECTED;
}
bool loadContextUsePB = false;
rv = loadContext->GetUsePrivateBrowsing(&loadContextUsePB);
if (NS_FAILED(rv)) {
return NS_ERROR_UNEXPECTED;
}
LOG(("NS_CompareLoadInfoAndLoadContext - loadInfo: %d, %d, %d, %d; "
"loadContext: %d %d, %d, %d. [channel=%p]",
originAttrsLoadInfo.mAppId, originAttrsLoadInfo.mInIsolatedMozBrowser,
originAttrsLoadInfo.mUserContextId, loadInfoUsePB,
loadContextAppId, loadContextUsePB,
originAttrsLoadContext.mUserContextId, loadContextIsInBE,
aChannel));
MOZ_ASSERT(originAttrsLoadInfo.mAppId == loadContextAppId,
"AppId in the loadContext and in the loadInfo are not the "
"same!");
MOZ_ASSERT(originAttrsLoadInfo.mInIsolatedMozBrowser ==
loadContextIsInBE,
"The value of InIsolatedMozBrowser in the loadContext and in "
"the loadInfo are not the same!");
MOZ_ASSERT(originAttrsLoadInfo.mUserContextId ==
originAttrsLoadContext.mUserContextId,
"The value of mUserContextId in the loadContext and in the "
"loadInfo are not the same!");
MOZ_ASSERT(loadInfoUsePB == loadContextUsePB,
"The value of usePrivateBrowsing in the loadContext and in the loadInfo "
"are not the same!");
}
return NS_OK;
}
namespace mozilla {
namespace net {

View File

@ -1003,6 +1003,7 @@ nsresult NS_ShouldSecureUpgrade(nsIURI* aURI,
*/
nsresult NS_GetSecureUpgradedURI(nsIURI* aURI, nsIURI** aUpgradedURI);
nsresult NS_CompareLoadInfoAndLoadContext(nsIChannel *aChannel);
namespace mozilla {
namespace net {

View File

@ -5109,6 +5109,8 @@ nsHttpChannel::AsyncOpen(nsIStreamListener *listener, nsISupports *context)
LOG(("nsHttpChannel::AsyncOpen [this=%p]\n", this));
NS_CompareLoadInfoAndLoadContext(this);
NS_ENSURE_ARG_POINTER(listener);
NS_ENSURE_TRUE(!mIsPending, NS_ERROR_IN_PROGRESS);
NS_ENSURE_TRUE(!mWasOpened, NS_ERROR_ALREADY_OPENED);