Backed out changeset 88c2a0b2dde5 (bug 1319111) for crashing Talos. r=backout

This commit is contained in:
Sebastian Hengst 2017-04-28 00:16:39 +02:00
Родитель 775a8cfe8d
Коммит 0936d33fb8
38 изменённых файлов: 118 добавлений и 219 удалений

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

@ -145,7 +145,6 @@ function testRegister(assert, text) {
var channel = ios.newChannelFromURIWithLoadInfo(uri, aLoadInfo); var channel = ios.newChannelFromURIWithLoadInfo(uri, aLoadInfo);
channel.originalURI = aURI; channel.originalURI = aURI;
aLoadInfo.resultPrincipalURI = aURI;
return channel; return channel;
}, },
getURIFlags: function(aURI) { getURIFlags: function(aURI) {

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

@ -172,23 +172,27 @@ AboutRedirector::NewChannel(nsIURI* aURI,
rv = NS_NewURI(getter_AddRefs(tempURI), url); rv = NS_NewURI(getter_AddRefs(tempURI), url);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
// If tempURI links to an internal URI (chrome://, resource://) // If tempURI links to an external URI (i.e. something other than
// then set the result principal URL on the channel's load info. // chrome:// or resource://) then set the LOAD_REPLACE flag on the
// Otherwise, we leave it null which forces the channel principal // channel which forces the channel owner to reflect the displayed
// to reflect the displayed URL rather than being the systemPrincipal. // URL rather then being the systemPrincipal.
bool isUIResource = false; bool isUIResource = false;
rv = NS_URIChainHasFlags(tempURI, nsIProtocolHandler::URI_IS_UI_RESOURCE, rv = NS_URIChainHasFlags(tempURI, nsIProtocolHandler::URI_IS_UI_RESOURCE,
&isUIResource); &isUIResource);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
nsLoadFlags loadFlags = isUIResource
? static_cast<nsLoadFlags>(nsIChannel::LOAD_NORMAL)
: static_cast<nsLoadFlags>(nsIChannel::LOAD_REPLACE);
rv = NS_NewChannelInternal(getter_AddRefs(tempChannel), rv = NS_NewChannelInternal(getter_AddRefs(tempChannel),
tempURI, tempURI,
aLoadInfo); aLoadInfo,
nullptr, // aLoadGroup
nullptr, // aCallbacks
loadFlags);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
if (isUIResource) {
aLoadInfo->SetResultPrincipalURI(aURI);
}
tempChannel->SetOriginalURI(aURI); tempChannel->SetOriginalURI(aURI);
NS_ADDREF(*result = tempChannel); NS_ADDREF(*result = tempChannel);

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

@ -253,7 +253,6 @@ FeedConverter.prototype = {
let aboutFeedsURI = ios.newURI("about:feeds"); let aboutFeedsURI = ios.newURI("about:feeds");
chromeChannel = ios.newChannelFromURIWithLoadInfo(aboutFeedsURI, loadInfo); chromeChannel = ios.newChannelFromURIWithLoadInfo(aboutFeedsURI, loadInfo);
chromeChannel.originalURI = result.uri; chromeChannel.originalURI = result.uri;
loadInfo.resultPrincipalURI = result.uri;
// carry the origin attributes from the channel that loaded the feed. // carry the origin attributes from the channel that loaded the feed.
chromeChannel.owner = chromeChannel.owner =
@ -561,12 +560,10 @@ GenericProtocolHandler.prototype = {
const schemeId = this._getTelemetrySchemeId(); const schemeId = this._getTelemetrySchemeId();
Services.telemetry.getHistogramById("FEED_PROTOCOL_USAGE").add(schemeId); Services.telemetry.getHistogramById("FEED_PROTOCOL_USAGE").add(schemeId);
if (channel instanceof Components.interfaces.nsIHttpChannel) { if (channel instanceof Components.interfaces.nsIHttpChannel)
// Set this so we know this is supposed to be a feed // Set this so we know this is supposed to be a feed
channel.setRequestHeader("X-Moz-Is-Feed", "1", false); channel.setRequestHeader("X-Moz-Is-Feed", "1", false);
}
channel.originalURI = aUri; channel.originalURI = aUri;
aLoadInfo.resultPrincipalURI = aUri;
return channel; return channel;
}, },

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

@ -26,7 +26,6 @@ let TestAboutPage = {
let channel = Services.io.newChannelFromURIWithLoadInfo(newURI, let channel = Services.io.newChannelFromURIWithLoadInfo(newURI,
aLoadInfo); aLoadInfo);
channel.originalURI = aURI; channel.originalURI = aURI;
aLoadInfo.resultPrincipalURI = aURI;
return channel; return channel;
}, },

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

@ -1003,7 +1003,6 @@ PdfStreamConverter.prototype = {
// Keep the URL the same so the browser sees it as the same. // Keep the URL the same so the browser sees it as the same.
channel.originalURI = aRequest.URI; channel.originalURI = aRequest.URI;
channel.loadInfo.resultPrincipalURI = aRequest.loadInfo.resultPrincipalURI;
channel.loadGroup = aRequest.loadGroup; channel.loadGroup = aRequest.loadGroup;
channel.loadInfo.originAttributes = aRequest.loadInfo.originAttributes; channel.loadInfo.originAttributes = aRequest.loadInfo.originAttributes;

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

@ -40,7 +40,6 @@ AboutPage.prototype = {
let channel = Services.io.newChannelFromURIWithLoadInfo(newURI, let channel = Services.io.newChannelFromURIWithLoadInfo(newURI,
aLoadInfo); aLoadInfo);
channel.originalURI = aURI; channel.originalURI = aURI;
aLoadInfo.resultPrincipalURI = aURI;
if (this.uriFlags & Ci.nsIAboutModule.URI_SAFE_FOR_UNTRUSTED_CONTENT) { if (this.uriFlags & Ci.nsIAboutModule.URI_SAFE_FOR_UNTRUSTED_CONTENT) {
let principal = Services.scriptSecurityManager.getNoAppCodebasePrincipal(aURI); let principal = Services.scriptSecurityManager.getNoAppCodebasePrincipal(aURI);

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

@ -168,11 +168,12 @@ nsChromeProtocolHandler::NewChannel2(nsIURI* aURI,
// Make sure that the channel remembers where it was // Make sure that the channel remembers where it was
// originally loaded from. // originally loaded from.
nsLoadFlags loadFlags = 0;
result->GetLoadFlags(&loadFlags);
result->SetLoadFlags(loadFlags & ~nsIChannel::LOAD_REPLACE);
rv = result->SetOriginalURI(aURI); rv = result->SetOriginalURI(aURI);
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
aLoadInfo->SetResultPrincipalURI(aURI);
// Get a system principal for content files and set the owner // Get a system principal for content files and set the owner
// property of the result // property of the result
nsCOMPtr<nsIURL> url = do_QueryInterface(aURI); nsCOMPtr<nsIURL> url = do_QueryInterface(aURI);

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

@ -26,10 +26,6 @@ AboutURL.prototype = {
newChannel: function (aURI, aLoadInfo) { newChannel: function (aURI, aLoadInfo) {
let chan = Services.io.newChannelFromURIWithLoadInfo(this.uri, aLoadInfo); let chan = Services.io.newChannelFromURIWithLoadInfo(this.uri, aLoadInfo);
chan.owner = Services.scriptSecurityManager.getSystemPrincipal(); chan.owner = Services.scriptSecurityManager.getSystemPrincipal();
// Must set the result principal URI _after_ we've created the channel
// since the chrome protocol would overwrite it with a chrome:// URL.
aLoadInfo.resultPrincipalURI = aURI;
return chan; return chan;
}, },

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

@ -174,10 +174,10 @@ nsAboutRedirector::NewChannel(nsIURI* aURI,
rv = NS_NewURI(getter_AddRefs(tempURI), kRedirMap[i].url); rv = NS_NewURI(getter_AddRefs(tempURI), kRedirMap[i].url);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
// If tempURI links to an internal URI (chrome://, resource://, about:) // If tempURI links to an external URI (i.e. something other than
// then set the result principal URL on the channel's load info. // chrome:// or resource://) then set the LOAD_REPLACE flag on the
// Otherwise, we leave it null which forces the channel principal // channel which forces the channel owner to reflect the displayed
// to reflect the displayed URL rather than being the systemPrincipal. // URL rather then being the systemPrincipal.
bool isUIResource = false; bool isUIResource = false;
rv = NS_URIChainHasFlags(tempURI, nsIProtocolHandler::URI_IS_UI_RESOURCE, rv = NS_URIChainHasFlags(tempURI, nsIProtocolHandler::URI_IS_UI_RESOURCE,
&isUIResource); &isUIResource);
@ -185,14 +185,18 @@ nsAboutRedirector::NewChannel(nsIURI* aURI,
bool isAboutBlank = NS_IsAboutBlank(tempURI); bool isAboutBlank = NS_IsAboutBlank(tempURI);
nsLoadFlags loadFlags = isUIResource || isAboutBlank
? static_cast<nsLoadFlags>(nsIChannel::LOAD_NORMAL)
: static_cast<nsLoadFlags>(nsIChannel::LOAD_REPLACE);
rv = NS_NewChannelInternal(getter_AddRefs(tempChannel), rv = NS_NewChannelInternal(getter_AddRefs(tempChannel),
tempURI, tempURI,
aLoadInfo); aLoadInfo,
nullptr, // aLoadGroup
nullptr, // aCallbacks
loadFlags);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
if (isUIResource || isAboutBlank) {
aLoadInfo->SetResultPrincipalURI(aURI);
}
tempChannel->SetOriginalURI(aURI); tempChannel->SetOriginalURI(aURI);
tempChannel.forget(aResult); tempChannel.forget(aResult);

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

@ -11168,12 +11168,6 @@ nsDocShell::DoURILoad(nsIURI* aURI,
if (aOriginalURI) { if (aOriginalURI) {
channel->SetOriginalURI(aOriginalURI); channel->SetOriginalURI(aOriginalURI);
// The LOAD_REPLACE flag and its handling here will be removed as part
// of bug 1319110. For now preserve its restoration here to not break
// any code expecting it being set specially on redirected channels.
// If the flag has originally been set to change result of
// NS_GetFinalChannelURI it won't have any effect and also won't cause
// any harm.
if (aLoadReplace) { if (aLoadReplace) {
uint32_t loadFlags; uint32_t loadFlags;
channel->GetLoadFlags(&loadFlags); channel->GetLoadFlags(&loadFlags);

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

@ -864,8 +864,6 @@ nsHostObjectProtocolHandler::NewChannel2(nsIURI* uri,
} }
channel->SetOriginalURI(uri); channel->SetOriginalURI(uri);
aLoadInfo->SetResultPrincipalURI(uri);
channel->SetContentType(NS_ConvertUTF16toUTF8(contentType)); channel->SetContentType(NS_ConvertUTF16toUTF8(contentType));
channel->SetContentLength(size); channel->SetContentLength(size);

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

@ -2412,7 +2412,6 @@ nsHTMLDocument::CreateAndAddWyciwygChannel(void)
channel->SetLoadFlags(loadFlags); channel->SetLoadFlags(loadFlags);
channel->SetOriginalURI(wcwgURI); channel->SetOriginalURI(wcwgURI);
loadInfo->SetResultPrincipalURI(wcwgURI);
rv = loadGroup->AddRequest(mWyciwygChannel, nullptr); rv = loadGroup->AddRequest(mWyciwygChannel, nullptr);
NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to add request to load group."); NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to add request to load group.");

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

@ -123,7 +123,6 @@ AboutRedirector.prototype = {
} }
channel.originalURI = aURI; channel.originalURI = aURI;
aLoadInfo.resultPrincipalURI = aURI;
return channel; return channel;
} }

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

@ -38,7 +38,6 @@ AboutFlyWeb.prototype = Object.freeze({
let uri = Services.io.newURI("chrome://flyweb/content/aboutFlyWeb.xhtml"); let uri = Services.io.newURI("chrome://flyweb/content/aboutFlyWeb.xhtml");
let channel = Services.io.newChannelFromURIWithLoadInfo(uri, aLoadInfo); let channel = Services.io.newChannelFromURIWithLoadInfo(uri, aLoadInfo);
channel.originalURI = aURI; channel.originalURI = aURI;
aLoadInfo.resultPrincipalURI = aURI;
return channel; return channel;
} }
}); });

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

@ -269,7 +269,6 @@ LoadInfo::LoadInfo(const LoadInfo& rhs)
, mTriggeringPrincipal(rhs.mTriggeringPrincipal) , mTriggeringPrincipal(rhs.mTriggeringPrincipal)
, mPrincipalToInherit(rhs.mPrincipalToInherit) , mPrincipalToInherit(rhs.mPrincipalToInherit)
, mSandboxedLoadingPrincipal(rhs.mSandboxedLoadingPrincipal) , mSandboxedLoadingPrincipal(rhs.mSandboxedLoadingPrincipal)
, mResultPrincipalURI(rhs.mResultPrincipalURI)
, mLoadingContext(rhs.mLoadingContext) , mLoadingContext(rhs.mLoadingContext)
, mSecurityFlags(rhs.mSecurityFlags) , mSecurityFlags(rhs.mSecurityFlags)
, mInternalContentPolicyType(rhs.mInternalContentPolicyType) , mInternalContentPolicyType(rhs.mInternalContentPolicyType)
@ -937,19 +936,5 @@ LoadInfo::GetIsTopLevelLoad(bool *aResult)
return NS_OK; return NS_OK;
} }
NS_IMETHODIMP
LoadInfo::GetResultPrincipalURI(nsIURI **aURI)
{
NS_IF_ADDREF(*aURI = mResultPrincipalURI);
return NS_OK;
}
NS_IMETHODIMP
LoadInfo::SetResultPrincipalURI(nsIURI *aURI)
{
mResultPrincipalURI = aURI;
return NS_OK;
}
} // namespace net } // namespace net
} // namespace mozilla } // namespace mozilla

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

@ -128,7 +128,6 @@ private:
nsCOMPtr<nsIPrincipal> mTriggeringPrincipal; nsCOMPtr<nsIPrincipal> mTriggeringPrincipal;
nsCOMPtr<nsIPrincipal> mPrincipalToInherit; nsCOMPtr<nsIPrincipal> mPrincipalToInherit;
nsCOMPtr<nsIPrincipal> mSandboxedLoadingPrincipal; nsCOMPtr<nsIPrincipal> mSandboxedLoadingPrincipal;
nsCOMPtr<nsIURI> mResultPrincipalURI;
nsWeakPtr mLoadingContext; nsWeakPtr mLoadingContext;
nsSecurityFlags mSecurityFlags; nsSecurityFlags mSecurityFlags;
nsContentPolicyType mInternalContentPolicyType; nsContentPolicyType mInternalContentPolicyType;

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

@ -10,7 +10,6 @@
interface nsIDOMDocument; interface nsIDOMDocument;
interface nsINode; interface nsINode;
interface nsIPrincipal; interface nsIPrincipal;
interface nsIURI;
%{C++ %{C++
#include "nsTArray.h" #include "nsTArray.h"
@ -741,14 +740,6 @@ interface nsILoadInfo : nsISupports
*/ */
[infallible] readonly attribute boolean isTopLevelLoad; [infallible] readonly attribute boolean isTopLevelLoad;
/**
* If this is non-null, this property represents two things: (1) the
* URI to be used for the principal if the channel with this loadinfo
* gets a principal based on URI and (2) the URI to use for a document
* created from the channel with this loadinfo.
*/
attribute nsIURI resultPrincipalURI;
/** /**
* Returns the null principal of the resulting resource if the SEC_SANDBOXED * Returns the null principal of the resulting resource if the SEC_SANDBOXED
* flag is set. Otherwise returns null. This is used by * flag is set. Otherwise returns null. This is used by

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

@ -189,21 +189,13 @@ NS_NewChannelInternal(nsIChannel **outChannel,
} }
if (aLoadFlags != nsIRequest::LOAD_NORMAL) { if (aLoadFlags != nsIRequest::LOAD_NORMAL) {
rv = channel->SetLoadFlags(aLoadFlags); // Retain the LOAD_REPLACE load flag if set.
nsLoadFlags normalLoadFlags = 0;
channel->GetLoadFlags(&normalLoadFlags);
rv = channel->SetLoadFlags(aLoadFlags | (normalLoadFlags & nsIChannel::LOAD_REPLACE));
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
} }
#ifdef DEBUG
nsLoadFlags channelLoadFlags = 0;
channel->GetLoadFlags(&channelLoadFlags);
// Will be removed when we remove LOAD_REPLACE altogether
// This check is trying to catch protocol handlers that still
// try to set the LOAD_REPLACE flag. Only exception is when
// this flag is carried in the aLoadFlags argument (e.g. when
// cloning redirected channels for CORS preflight.)
MOZ_ASSERT(!((channelLoadFlags & ~aLoadFlags) & nsIChannel::LOAD_REPLACE));
#endif
channel.forget(outChannel); channel.forget(outChannel);
return NS_OK; return NS_OK;
} }
@ -276,21 +268,13 @@ NS_NewChannelInternal(nsIChannel **outChannel,
} }
if (aLoadFlags != nsIRequest::LOAD_NORMAL) { if (aLoadFlags != nsIRequest::LOAD_NORMAL) {
rv = channel->SetLoadFlags(aLoadFlags); // Retain the LOAD_REPLACE load flag if set.
nsLoadFlags normalLoadFlags = 0;
channel->GetLoadFlags(&normalLoadFlags);
rv = channel->SetLoadFlags(aLoadFlags | (normalLoadFlags & nsIChannel::LOAD_REPLACE));
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
} }
#ifdef DEBUG
nsLoadFlags channelLoadFlags = 0;
channel->GetLoadFlags(&channelLoadFlags);
// Will be removed when we remove LOAD_REPLACE altogether
// This check is trying to catch protocol handlers that still
// try to set the LOAD_REPLACE flag. Only exception is when
// this flag is carried in the aLoadFlags argument (e.g. when
// cloning redirected channels for CORS preflight.)
MOZ_ASSERT(!((channelLoadFlags & ~aLoadFlags) & nsIChannel::LOAD_REPLACE));
#endif
channel.forget(outChannel); channel.forget(outChannel);
return NS_OK; return NS_OK;
} }
@ -1902,18 +1886,15 @@ nsresult
NS_GetFinalChannelURI(nsIChannel *channel, nsIURI **uri) NS_GetFinalChannelURI(nsIChannel *channel, nsIURI **uri)
{ {
*uri = nullptr; *uri = nullptr;
nsLoadFlags loadFlags = 0;
nsresult rv = channel->GetLoadFlags(&loadFlags);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsILoadInfo> loadInfo = channel->GetLoadInfo(); if (loadFlags & nsIChannel::LOAD_REPLACE) {
if (loadInfo) { return channel->GetURI(uri);
nsCOMPtr<nsIURI> resultPrincipalURI;
loadInfo->GetResultPrincipalURI(getter_AddRefs(resultPrincipalURI));
if (resultPrincipalURI) {
resultPrincipalURI.forget(uri);
return NS_OK;
}
} }
return channel->GetURI(uri); return channel->GetOriginalURI(uri);
} }
nsresult nsresult

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

@ -782,9 +782,11 @@ nsresult NS_URIChainHasFlags(nsIURI *uri,
already_AddRefed<nsIURI> NS_GetInnermostURI(nsIURI *aURI); already_AddRefed<nsIURI> NS_GetInnermostURI(nsIURI *aURI);
/** /**
* Get the "final" URI for a channel. This is either channel's load info * Get the "final" URI for a channel. This is either the same as GetURI or
* resultPrincipalURI, if set, or GetURI. In most cases (but not all) load * GetOriginalURI, depending on whether this channel has
* info resultPrincipalURI, if set, corresponds to originalURI of the channel. * nsIChanel::LOAD_REPLACE set. For channels without that flag set, the final
* URI is the original URI, while for ones with the flag the final URI is the
* channel URI.
*/ */
nsresult NS_GetFinalChannelURI(nsIChannel *channel, nsIURI **uri); nsresult NS_GetFinalChannelURI(nsIChannel *channel, nsIURI **uri);

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

@ -290,6 +290,9 @@ nsFileChannel::nsFileChannel(nsIURI *uri)
SetURI(targetURI); SetURI(targetURI);
SetOriginalURI(uri); SetOriginalURI(uri);
nsLoadFlags loadFlags = 0;
GetLoadFlags(&loadFlags);
SetLoadFlags(loadFlags | nsIChannel::LOAD_REPLACE);
} else { } else {
SetURI(uri); SetURI(uri);
} }

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

@ -2953,64 +2953,6 @@ void HttpBaseChannel::AssertPrivateBrowsingId()
} }
#endif #endif
already_AddRefed<nsILoadInfo>
HttpBaseChannel::CloneLoadInfoForRedirect(nsIURI * newURI, uint32_t redirectFlags)
{
// make a copy of the loadinfo, append to the redirectchain
// this will be set on the newly created channel for the redirect target.
if (!mLoadInfo) {
return nullptr;
}
nsCOMPtr<nsILoadInfo> newLoadInfo =
static_cast<mozilla::LoadInfo*>(mLoadInfo.get())->Clone();
nsContentPolicyType contentPolicyType = mLoadInfo->GetExternalContentPolicyType();
if (contentPolicyType == nsIContentPolicy::TYPE_DOCUMENT ||
contentPolicyType == nsIContentPolicy::TYPE_SUBDOCUMENT) {
nsCOMPtr<nsIPrincipal> nullPrincipalToInherit = NullPrincipal::Create();
newLoadInfo->SetPrincipalToInherit(nullPrincipalToInherit);
}
// re-compute the origin attributes of the loadInfo if it's top-level load.
bool isTopLevelDoc =
newLoadInfo->GetExternalContentPolicyType() == nsIContentPolicy::TYPE_DOCUMENT;
if (isTopLevelDoc) {
nsCOMPtr<nsILoadContext> loadContext;
NS_QueryNotificationCallbacks(this, loadContext);
OriginAttributes docShellAttrs;
if (loadContext) {
loadContext->GetOriginAttributes(docShellAttrs);
}
OriginAttributes attrs = newLoadInfo->GetOriginAttributes();
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 = docShellAttrs;
attrs.SetFirstPartyDomain(true, newURI);
newLoadInfo->SetOriginAttributes(attrs);
}
// Drop the target principal URI from the cloned load info because we want
// NS_GetFinalChannelURI to return either the URI of the target channel
// or anything that the target protocol handler potentially sets itself.
newLoadInfo->SetResultPrincipalURI(nullptr);
bool isInternalRedirect =
(redirectFlags & (nsIChannelEventSink::REDIRECT_INTERNAL |
nsIChannelEventSink::REDIRECT_STS_UPGRADE));
newLoadInfo->AppendRedirectedPrincipal(GetURIPrincipal(), isInternalRedirect);
return newLoadInfo.forget();
}
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// nsHttpChannel::nsITraceableChannel // nsHttpChannel::nsITraceableChannel
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -3199,6 +3141,57 @@ HttpBaseChannel::SetupReplacementChannel(nsIURI *newURI,
} }
} }
// make a copy of the loadinfo, append to the redirectchain
// and set it on the new channel
if (mLoadInfo) {
nsCOMPtr<nsILoadInfo> newLoadInfo =
static_cast<mozilla::LoadInfo*>(mLoadInfo.get())->Clone();
nsContentPolicyType contentPolicyType = mLoadInfo->GetExternalContentPolicyType();
if (contentPolicyType == nsIContentPolicy::TYPE_DOCUMENT ||
contentPolicyType == nsIContentPolicy::TYPE_SUBDOCUMENT) {
nsCOMPtr<nsIPrincipal> nullPrincipalToInherit = NullPrincipal::Create();
newLoadInfo->SetPrincipalToInherit(nullPrincipalToInherit);
}
// re-compute the origin attributes of the loadInfo if it's top-level load.
bool isTopLevelDoc =
newLoadInfo->GetExternalContentPolicyType() == nsIContentPolicy::TYPE_DOCUMENT;
if (isTopLevelDoc) {
nsCOMPtr<nsILoadContext> loadContext;
NS_QueryNotificationCallbacks(this, loadContext);
OriginAttributes docShellAttrs;
if (loadContext) {
loadContext->GetOriginAttributes(docShellAttrs);
}
OriginAttributes attrs = newLoadInfo->GetOriginAttributes();
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 = docShellAttrs;
attrs.SetFirstPartyDomain(true, newURI);
newLoadInfo->SetOriginAttributes(attrs);
}
bool isInternalRedirect =
(redirectFlags & (nsIChannelEventSink::REDIRECT_INTERNAL |
nsIChannelEventSink::REDIRECT_STS_UPGRADE));
newLoadInfo->AppendRedirectedPrincipal(GetURIPrincipal(), isInternalRedirect);
newChannel->SetLoadInfo(newLoadInfo);
}
else {
// the newChannel was created with a dummy loadInfo, we should clear
// it in case the original channel does not have a loadInfo
newChannel->SetLoadInfo(nullptr);
}
nsCOMPtr<nsIHttpChannel> httpChannel = do_QueryInterface(newChannel); nsCOMPtr<nsIHttpChannel> httpChannel = do_QueryInterface(newChannel);
if (!httpChannel) if (!httpChannel)
return NS_OK; // no other options to set return NS_OK; // no other options to set

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

@ -424,8 +424,6 @@ protected:
void AssertPrivateBrowsingId(); void AssertPrivateBrowsingId();
#endif #endif
already_AddRefed<nsILoadInfo> CloneLoadInfoForRedirect(nsIURI *newURI, uint32_t redirectFlags);
friend class PrivateBrowsingChannel<HttpBaseChannel>; friend class PrivateBrowsingChannel<HttpBaseChannel>;
friend class InterceptFailedOnStop; friend class InterceptFailedOnStop;

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

@ -1493,10 +1493,9 @@ HttpChannelChild::SetupRedirect(nsIURI* uri,
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIChannel> newChannel; nsCOMPtr<nsIChannel> newChannel;
nsCOMPtr<nsILoadInfo> redirectLoadInfo = CloneLoadInfoForRedirect(uri, redirectFlags);
rv = NS_NewChannelInternal(getter_AddRefs(newChannel), rv = NS_NewChannelInternal(getter_AddRefs(newChannel),
uri, uri,
redirectLoadInfo, mLoadInfo,
nullptr, // aLoadGroup nullptr, // aLoadGroup
nullptr, // aCallbacks nullptr, // aCallbacks
nsIRequest::LOAD_NORMAL, nsIRequest::LOAD_NORMAL,

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

@ -2617,8 +2617,6 @@ nsHttpChannel::StartRedirectChannelToURI(nsIURI *upgradedURI, uint32_t flags)
LOG(("nsHttpChannel::StartRedirectChannelToURI()\n")); LOG(("nsHttpChannel::StartRedirectChannelToURI()\n"));
nsCOMPtr<nsIChannel> newChannel; nsCOMPtr<nsIChannel> newChannel;
nsCOMPtr<nsILoadInfo> redirectLoadInfo = CloneLoadInfoForRedirect(upgradedURI,
flags);
nsCOMPtr<nsIIOService> ioService; nsCOMPtr<nsIIOService> ioService;
rv = gHttpHandler->GetIOService(getter_AddRefs(ioService)); rv = gHttpHandler->GetIOService(getter_AddRefs(ioService));
@ -2626,7 +2624,7 @@ nsHttpChannel::StartRedirectChannelToURI(nsIURI *upgradedURI, uint32_t flags)
rv = NS_NewChannelInternal(getter_AddRefs(newChannel), rv = NS_NewChannelInternal(getter_AddRefs(newChannel),
upgradedURI, upgradedURI,
redirectLoadInfo, mLoadInfo,
nullptr, // aLoadGroup nullptr, // aLoadGroup
nullptr, // aCallbacks nullptr, // aCallbacks
nsIRequest::LOAD_NORMAL, nsIRequest::LOAD_NORMAL,
@ -5476,23 +5474,22 @@ nsHttpChannel::ContinueProcessRedirectionAfterFallback(nsresult rv)
rv = gHttpHandler->GetIOService(getter_AddRefs(ioService)); rv = gHttpHandler->GetIOService(getter_AddRefs(ioService));
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
uint32_t redirectFlags;
if (nsHttp::IsPermanentRedirect(mRedirectType))
redirectFlags = nsIChannelEventSink::REDIRECT_PERMANENT;
else
redirectFlags = nsIChannelEventSink::REDIRECT_TEMPORARY;
nsCOMPtr<nsIChannel> newChannel; nsCOMPtr<nsIChannel> newChannel;
nsCOMPtr<nsILoadInfo> redirectLoadInfo = CloneLoadInfoForRedirect(mRedirectURI, redirectFlags);
rv = NS_NewChannelInternal(getter_AddRefs(newChannel), rv = NS_NewChannelInternal(getter_AddRefs(newChannel),
mRedirectURI, mRedirectURI,
redirectLoadInfo, mLoadInfo,
nullptr, // aLoadGroup nullptr, // aLoadGroup
nullptr, // aCallbacks nullptr, // aCallbacks
nsIRequest::LOAD_NORMAL, nsIRequest::LOAD_NORMAL,
ioService); ioService);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
uint32_t redirectFlags;
if (nsHttp::IsPermanentRedirect(mRedirectType))
redirectFlags = nsIChannelEventSink::REDIRECT_PERMANENT;
else
redirectFlags = nsIChannelEventSink::REDIRECT_TEMPORARY;
rv = SetupReplacementChannel(mRedirectURI, newChannel, rv = SetupReplacementChannel(mRedirectURI, newChannel,
!rewriteToGET, redirectFlags); !rewriteToGET, redirectFlags);
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;

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

@ -33,10 +33,6 @@ protected:
const nsACString& aPathname, const nsACString& aPathname,
nsACString& aResult) override; nsACString& aResult) override;
// |result| is an inout param. On entry to this function, *result
// is expected to be non-null and already addrefed. This function
// may release the object stored in *result on entry and write
// a new pointer to an already addrefed channel to *result.
virtual MOZ_MUST_USE nsresult SubstituteChannel(nsIURI* uri, virtual MOZ_MUST_USE nsresult SubstituteChannel(nsIURI* uri,
nsILoadInfo* aLoadInfo, nsILoadInfo* aLoadInfo,
nsIChannel** result) override; nsIChannel** result) override;

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

@ -257,21 +257,12 @@ SubstitutingProtocolHandler::NewChannel2(nsIURI* uri,
rv = NS_NewChannelInternal(result, newURI, aLoadInfo); rv = NS_NewChannelInternal(result, newURI, aLoadInfo);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
nsLoadFlags loadFlags = 0;
(*result)->GetLoadFlags(&loadFlags);
(*result)->SetLoadFlags(loadFlags & ~nsIChannel::LOAD_REPLACE);
rv = (*result)->SetOriginalURI(uri); rv = (*result)->SetOriginalURI(uri);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
// We must set result principal URL prior to calling SubstituteChannel
// because it may call NS_GetFinalChannelURI and the correct result
// (in this case |uri|) is already expected.
//
// We don't want to reset the result principal URL to |uri| after calling
// SubstituteChannel since whatever substituting protocol handler(s) set
// has to override anything we set here.
if (aLoadInfo) {
rv = aLoadInfo->SetResultPrincipalURI(uri);
NS_ENSURE_SUCCESS(rv, rv);
}
return SubstituteChannel(uri, aLoadInfo, result); return SubstituteChannel(uri, aLoadInfo, result);
} }

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

@ -116,12 +116,6 @@ nsViewSourceHandler::NewChannel2(nsIURI* uri,
return rv; return rv;
} }
if (aLoadInfo) {
// The underlying channel is created for a different URI.
// Original URI on the resulting channel has been set to |uri|.
aLoadInfo->SetResultPrincipalURI(uri);
}
*result = static_cast<nsIViewSourceChannel*>(channel); *result = static_cast<nsIViewSourceChannel*>(channel);
return NS_OK; return NS_OK;
} }
@ -147,12 +141,6 @@ nsViewSourceHandler::NewSrcdocChannel(nsIURI *aURI,
return rv; return rv;
} }
if (aLoadInfo) {
// The underlying channel is created for a different URI.
// Original URI on the resulting channel has been set to |aURI|.
aLoadInfo->SetResultPrincipalURI(aURI);
}
*outChannel = static_cast<nsIViewSourceChannel*>(channel.forget().take()); *outChannel = static_cast<nsIViewSourceChannel*>(channel.forget().take());
return NS_OK; return NS_OK;
} }

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

@ -217,11 +217,6 @@ WyciwygChannelParent::RecvAsyncOpen(const URIParams& aOriginal,
return IPC_OK(); return IPC_OK();
} }
nsCOMPtr<nsILoadInfo> loadInfo = mChannel->GetLoadInfo();
if (loadInfo) {
loadInfo->SetResultPrincipalURI(original);
}
rv = mChannel->SetLoadFlags(aLoadFlags); rv = mChannel->SetLoadFlags(aLoadFlags);
if (NS_FAILED(rv)) { if (NS_FAILED(rv)) {
if (!SendCancelEarly(rv)) { if (!SendCancelEarly(rv)) {
@ -242,6 +237,7 @@ WyciwygChannelParent::RecvAsyncOpen(const URIParams& aOriginal,
return IPC_OK(); return IPC_OK();
} }
nsCOMPtr<nsILoadInfo> loadInfo = mChannel->GetLoadInfo();
if (loadInfo && loadInfo->GetEnforceSecurity()) { if (loadInfo && loadInfo->GetEnforceSecurity()) {
rv = mChannel->AsyncOpen2(this); rv = mChannel->AsyncOpen2(this);
} }

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

@ -877,10 +877,6 @@ nsMultiMixedConv::SendStart()
mPartChannel->SetContentDisposition(mContentDisposition); mPartChannel->SetContentDisposition(mContentDisposition);
// Each part of a multipart/replace response can be used
// for the top level document. We must inform upper layers
// about this by setting the LOAD_REPLACE flag so that certain
// state assertions are evaluated as positive.
nsLoadFlags loadFlags = 0; nsLoadFlags loadFlags = 0;
mPartChannel->GetLoadFlags(&loadFlags); mPartChannel->GetLoadFlags(&loadFlags);
loadFlags |= nsIChannel::LOAD_REPLACE; loadFlags |= nsIChannel::LOAD_REPLACE;

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

@ -232,6 +232,9 @@ function test_load_replace() {
file = do_get_file("data/system_root.lnk", false); file = do_get_file("data/system_root.lnk", false);
var chan = new_file_channel(file); var chan = new_file_channel(file);
// The LOAD_REPLACE flag should be set
do_check_eq(chan.loadFlags & chan.LOAD_REPLACE, chan.LOAD_REPLACE);
// The original URI path should differ from the URI path // The original URI path should differ from the URI path
do_check_neq(chan.URI.path, chan.originalURI.path); do_check_neq(chan.URI.path, chan.originalURI.path);

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

@ -159,7 +159,6 @@ AboutWeaveLog.prototype = {
let channel = Services.io.newChannelFromURIWithLoadInfo(uri, aLoadInfo); let channel = Services.io.newChannelFromURIWithLoadInfo(uri, aLoadInfo);
channel.originalURI = aURI; channel.originalURI = aURI;
aLoadInfo.resultPrincipalURI = aURI;
// Ensure that the about page has the same privileges as a regular directory // Ensure that the about page has the same privileges as a regular directory
// view. That way links to files can be opened. make sure we use the correct // view. That way links to files can be opened. make sure we use the correct

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

@ -26,7 +26,6 @@ AboutPage.prototype = {
let channel = Services.io.newChannelFromURIWithLoadInfo(newURI, let channel = Services.io.newChannelFromURIWithLoadInfo(newURI,
aLoadInfo); aLoadInfo);
channel.originalURI = aURI; channel.originalURI = aURI;
aLoadInfo.resultPrincipalURI = aURI;
if (this.uriFlags & Ci.nsIAboutModule.URI_SAFE_FOR_UNTRUSTED_CONTENT) { if (this.uriFlags & Ci.nsIAboutModule.URI_SAFE_FOR_UNTRUSTED_CONTENT) {
channel.owner = null; channel.owner = null;

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

@ -14,7 +14,6 @@ class TabSwitchAboutModule {
let uri = Services.io.newURI(CHROME_URI); let uri = Services.io.newURI(CHROME_URI);
let chan = Services.io.newChannelFromURIWithLoadInfo(uri, aLoadInfo); let chan = Services.io.newChannelFromURIWithLoadInfo(uri, aLoadInfo);
chan.originalURI = aURI; chan.originalURI = aURI;
aLoadInfo.resultPrincipalURI = aURI;
return chan; return chan;
} }

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

@ -32,6 +32,7 @@ mozProtocolHandler.prototype = {
newChannel2(uri, loadInfo) { newChannel2(uri, loadInfo) {
let realURL = NetUtil.newURI(this.urlToLoad); let realURL = NetUtil.newURI(this.urlToLoad);
let channel = Services.io.newChannelFromURIWithLoadInfo(realURL, loadInfo) let channel = Services.io.newChannelFromURIWithLoadInfo(realURL, loadInfo)
channel.loadFlags |= Ci.nsIChannel.LOAD_REPLACE;
return channel; return channel;
}, },

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

@ -38,7 +38,6 @@ function* registerConverter() {
loadUsingSystemPrincipal: true, loadUsingSystemPrincipal: true,
}); });
channel.originalURI = aRequest.QueryInterface(Ci.nsIChannel).URI; channel.originalURI = aRequest.QueryInterface(Ci.nsIChannel).URI;
channel.loadInfo.resultPrincipalURI = channel.originalURI;
channel.loadGroup = aRequest.loadGroup; channel.loadGroup = aRequest.loadGroup;
channel.owner = Services.scriptSecurityManager channel.owner = Services.scriptSecurityManager
.createCodebasePrincipal(channel.URI, {}); .createCodebasePrincipal(channel.URI, {});

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

@ -17,7 +17,6 @@ function makeDefaultFaviconChannel(uri, loadInfo) {
let channel = Services.io.newChannelFromURIWithLoadInfo( let channel = Services.io.newChannelFromURIWithLoadInfo(
PlacesUtils.favicons.defaultFavicon, loadInfo); PlacesUtils.favicons.defaultFavicon, loadInfo);
channel.originalURI = uri; channel.originalURI = uri;
loadInfo.resultPrincipalURI = uri;
return channel; return channel;
} }

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

@ -88,7 +88,6 @@ Protocol.prototype = {
let fileuri = Services.io.newFileURI(file); let fileuri = Services.io.newFileURI(file);
let channel = Services.io.newChannelFromURIWithLoadInfo(fileuri, aLoadInfo); let channel = Services.io.newChannelFromURIWithLoadInfo(fileuri, aLoadInfo);
channel.originalURI = aURI; channel.originalURI = aURI;
aLoadInfo.resultPrincipalURI = aURI;
return channel; return channel;
}, },

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

@ -24,7 +24,6 @@ var CustomChromeProtocol = {
let url = Services.io.newURI("chrome:" + aURI.path); let url = Services.io.newURI("chrome:" + aURI.path);
let ch = Services.io.newChannelFromURIWithLoadInfo(url, aLoadInfo); let ch = Services.io.newChannelFromURIWithLoadInfo(url, aLoadInfo);
ch.originalURI = aURI; ch.originalURI = aURI;
aLoadInfo.resultPrincipalURI = aURI;
return ch; return ch;
}, },