From e72aa9a9f1469d03e486a8f3054afad6edb4d9e1 Mon Sep 17 00:00:00 2001
From: Dragana Damjanovic
Date: Wed, 13 Apr 2016 10:23:26 +0200
Subject: [PATCH] Bug 1125916 - Check whether loadInfo and loadContext match.
r=sicking, r=jduell
--HG--
extra : rebase_source : 582977113d0e3e15913120232300478835ef1384
extra : histedit_source : 7d3f02b68874f16bb63974f8b41facf947385917
---
netwerk/base/nsBaseChannel.cpp | 2 +
netwerk/base/nsNetUtil.cpp | 66 +++++++++++++++++++++++++
netwerk/base/nsNetUtil.h | 1 +
netwerk/protocol/http/nsHttpChannel.cpp | 2 +
4 files changed, 71 insertions(+)
diff --git a/netwerk/base/nsBaseChannel.cpp b/netwerk/base/nsBaseChannel.cpp
index be7154299fe5..1229342dbc47 100644
--- a/netwerk/base/nsBaseChannel.cpp
+++ b/netwerk/base/nsBaseChannel.cpp
@@ -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)) {
diff --git a/netwerk/base/nsNetUtil.cpp b/netwerk/base/nsNetUtil.cpp
index 40ae8f55ca81..c21cbd1c9e87 100644
--- a/netwerk/base/nsNetUtil.cpp
+++ b/netwerk/base/nsNetUtil.cpp
@@ -2363,6 +2363,72 @@ NS_GetSecureUpgradedURI(nsIURI* aURI, nsIURI** aUpgradedURI)
return NS_OK;
}
+nsresult
+NS_CompareLoadInfoAndLoadContext(nsIChannel *aChannel)
+{
+ nsCOMPtr loadInfo;
+ aChannel->GetLoadInfo(getter_AddRefs(loadInfo));
+
+ nsCOMPtr 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 {
diff --git a/netwerk/base/nsNetUtil.h b/netwerk/base/nsNetUtil.h
index 9d0eb47cdde8..d99a0d11a4a0 100644
--- a/netwerk/base/nsNetUtil.h
+++ b/netwerk/base/nsNetUtil.h
@@ -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 {
diff --git a/netwerk/protocol/http/nsHttpChannel.cpp b/netwerk/protocol/http/nsHttpChannel.cpp
index f63d2e5c76a9..c61f695af232 100644
--- a/netwerk/protocol/http/nsHttpChannel.cpp
+++ b/netwerk/protocol/http/nsHttpChannel.cpp
@@ -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);