From c8329979cd80459712469f329f5da64fbb25b94e Mon Sep 17 00:00:00 2001 From: Yoshi Huang Date: Mon, 29 Aug 2016 12:41:02 +0800 Subject: [PATCH] Bug 1260931 - Part 4: update OriginAttributes when http redirect. r=smaug --- netwerk/protocol/http/HttpBaseChannel.cpp | 30 +++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/netwerk/protocol/http/HttpBaseChannel.cpp b/netwerk/protocol/http/HttpBaseChannel.cpp index 7fec5c8a709c..9c3cff1b466e 100644 --- a/netwerk/protocol/http/HttpBaseChannel.cpp +++ b/netwerk/protocol/http/HttpBaseChannel.cpp @@ -2901,6 +2901,36 @@ HttpBaseChannel::SetupReplacementChannel(nsIURI *newURI, if (mLoadInfo) { nsCOMPtr newLoadInfo = static_cast(mLoadInfo.get())->Clone(); + + // re-compute the origin attributes of the loadInfo if it's top-level load. + bool isTopLevelDoc = + newLoadInfo->GetExternalContentPolicyType() == nsIContentPolicy::TYPE_DOCUMENT; + + if (isTopLevelDoc) { + nsCOMPtr loadContext; + NS_QueryNotificationCallbacks(this, loadContext); + DocShellOriginAttributes docShellAttrs; + if (loadContext) { + loadContext->GetOriginAttributes(docShellAttrs); + } + MOZ_ASSERT(docShellAttrs.mFirstPartyDomain.IsEmpty(), + "top-level docshell shouldn't have firstPartyDomain attribute."); + + NeckoOriginAttributes attrs = newLoadInfo->GetOriginAttributes(); + + MOZ_ASSERT(docShellAttrs.mAppId == attrs.mAppId, + "docshell and necko should have the same appId attribute."); + MOZ_ASSERT(docShellAttrs.mUserContextId == attrs.mUserContextId, + "docshell and necko should have the same userContextId attribute."); + MOZ_ASSERT(docShellAttrs.mInIsolatedMozBrowser == attrs.mInIsolatedMozBrowser, + "docshell and necko should have the same inIsolatedMozBrowser attribute."); + MOZ_ASSERT(docShellAttrs.mPrivateBrowsingId == attrs.mPrivateBrowsingId, + "docshell and necko should have the same privateBrowsingId attribute."); + + attrs.InheritFromDocShellToNecko(docShellAttrs, true, newURI); + newLoadInfo->SetOriginAttributes(attrs); + } + bool isInternalRedirect = (redirectFlags & (nsIChannelEventSink::REDIRECT_INTERNAL | nsIChannelEventSink::REDIRECT_STS_UPGRADE));