Bug 1125916 - Check whether loadInfo and loadContext match. r=sicking, r=jduell
authorDragana Damjanovic <dd.mozilla@gmail.com>
Wed, 13 Apr 2016 10:23:26 +0200
changeset 331083 1324f1d0dcd0c2730866c171c9e6beed007e17a8
parent 331082 23c4b279a2b1e6ffcb18a026dfa913598ebed3a9
child 331084 b8b7fa0549657d31f7bdf907683d72dd76b83ba2
push id6048
push userkmoir@mozilla.com
push dateMon, 06 Jun 2016 19:02:08 +0000
treeherdermozilla-beta@46d72a56c57d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssicking, jduell
bugs1125916
milestone48.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1125916 - Check whether loadInfo and loadContext match. r=sicking, r=jduell
netwerk/base/nsBaseChannel.cpp
netwerk/base/nsNetUtil.cpp
netwerk/base/nsNetUtil.h
netwerk/protocol/http/nsHttpChannel.cpp
--- a/netwerk/base/nsBaseChannel.cpp
+++ b/netwerk/base/nsBaseChannel.cpp
@@ -642,16 +642,18 @@ nsBaseChannel::AsyncOpen(nsIStreamListen
               nsContentUtils::IsSystemPrincipal(mLoadInfo->LoadingPrincipal())),
              "security flags in loadInfo but asyncOpen2() not called");
 
   NS_ENSURE_TRUE(mURI, NS_ERROR_NOT_INITIALIZED);
   NS_ENSURE_TRUE(!mPump, NS_ERROR_IN_PROGRESS);
   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)) {
     mCallbacks = nullptr;
     return rv;
   }
 
   // Store the listener and context early so that OpenContentStream and the
--- a/netwerk/base/nsNetUtil.cpp
+++ b/netwerk/base/nsNetUtil.cpp
@@ -2358,16 +2358,82 @@ NS_GetSecureUpgradedURI(nsIURI* aURI, ns
         upgradedURI->SetPort(oldPort);
     }
   }
 
   upgradedURI.forget(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 {
 
 bool
 InScriptableRange(int64_t val)
 {
     return (val <= kJS_MAX_SAFE_INTEGER) && (val >= kJS_MIN_SAFE_INTEGER);
 }
--- a/netwerk/base/nsNetUtil.h
+++ b/netwerk/base/nsNetUtil.h
@@ -998,16 +998,17 @@ nsresult NS_ShouldSecureUpgrade(nsIURI* 
                                 bool aAllowSTS,
                                 bool& aShouldUpgrade);
 
 /**
  * Returns an https URI for channels that need to go through secure upgrades.
  */
 nsresult NS_GetSecureUpgradedURI(nsIURI* aURI, nsIURI** aUpgradedURI);
 
+nsresult NS_CompareLoadInfoAndLoadContext(nsIChannel *aChannel);
 
 namespace mozilla {
 namespace net {
 
 const static uint64_t kJS_MAX_SAFE_UINTEGER = +9007199254740991ULL;
 const static  int64_t kJS_MIN_SAFE_INTEGER  = -9007199254740991LL;
 const static  int64_t kJS_MAX_SAFE_INTEGER  = +9007199254740991LL;
 
--- a/netwerk/protocol/http/nsHttpChannel.cpp
+++ b/netwerk/protocol/http/nsHttpChannel.cpp
@@ -5104,16 +5104,18 @@ nsHttpChannel::AsyncOpen(nsIStreamListen
                mLoadInfo->GetSecurityMode() == 0 ||
                mLoadInfo->GetInitialSecurityCheckDone() ||
                (mLoadInfo->GetSecurityMode() == nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL &&
                 nsContentUtils::IsSystemPrincipal(mLoadInfo->LoadingPrincipal())),
                "security flags in loadInfo but asyncOpen2() not called");
 
     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);
 
     nsresult rv;
 
     MOZ_ASSERT(NS_IsMainThread());