Skip to content

Commit

Permalink
Backed out changeset 95ff98f1c2e5 (bug 1319111) for talos failures a=…
Browse files Browse the repository at this point in the history
…backout

MozReview-Commit-ID: Gs09moFm5rQ
  • Loading branch information
KWierso committed May 13, 2017
1 parent 67d3ce0 commit 7413cac
Show file tree
Hide file tree
Showing 39 changed files with 220 additions and 119 deletions.
1 change: 1 addition & 0 deletions addon-sdk/source/test/test-xpcom.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ function testRegister(assert, text) {
var channel = ios.newChannelFromURIWithLoadInfo(uri, aLoadInfo);

channel.originalURI = aURI;
aLoadInfo.resultPrincipalURI = aURI;
return channel;
},
getURIFlags: function(aURI) {
Expand Down
20 changes: 8 additions & 12 deletions browser/components/about/AboutRedirector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,27 +172,23 @@ AboutRedirector::NewChannel(nsIURI* aURI,
rv = NS_NewURI(getter_AddRefs(tempURI), url);
NS_ENSURE_SUCCESS(rv, rv);

// If tempURI links to an external URI (i.e. something other than
// chrome:// or resource://) then set the LOAD_REPLACE flag on the
// channel which forces the channel owner to reflect the displayed
// URL rather then being the systemPrincipal.
// If tempURI links to an internal URI (chrome://, resource://)
// then set the result principal URL on the channel's load info.
// Otherwise, we leave it null which forces the channel principal
// to reflect the displayed URL rather than being the systemPrincipal.
bool isUIResource = false;
rv = NS_URIChainHasFlags(tempURI, nsIProtocolHandler::URI_IS_UI_RESOURCE,
&isUIResource);
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),
tempURI,
aLoadInfo,
nullptr, // aLoadGroup
nullptr, // aCallbacks
loadFlags);
aLoadInfo);
NS_ENSURE_SUCCESS(rv, rv);

if (isUIResource) {
aLoadInfo->SetResultPrincipalURI(aURI);
}
tempChannel->SetOriginalURI(aURI);

NS_ADDREF(*result = tempChannel);
Expand Down
5 changes: 4 additions & 1 deletion browser/components/feeds/FeedConverter.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ FeedConverter.prototype = {
let aboutFeedsURI = ios.newURI("about:feeds");
chromeChannel = ios.newChannelFromURIWithLoadInfo(aboutFeedsURI, loadInfo);
chromeChannel.originalURI = result.uri;
loadInfo.resultPrincipalURI = result.uri;

// carry the origin attributes from the channel that loaded the feed.
chromeChannel.owner =
Expand Down Expand Up @@ -560,10 +561,12 @@ GenericProtocolHandler.prototype = {
const schemeId = this._getTelemetrySchemeId();
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
channel.setRequestHeader("X-Moz-Is-Feed", "1", false);
}
channel.originalURI = aUri;
aLoadInfo.resultPrincipalURI = aUri;
return channel;
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ let TestAboutPage = {
let channel = Services.io.newChannelFromURIWithLoadInfo(newURI,
aLoadInfo);
channel.originalURI = aURI;
aLoadInfo.resultPrincipalURI = aURI;
return channel;
},

Expand Down
1 change: 1 addition & 0 deletions browser/extensions/pdfjs/content/PdfStreamConverter.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -1003,6 +1003,7 @@ PdfStreamConverter.prototype = {

// Keep the URL the same so the browser sees it as the same.
channel.originalURI = aRequest.URI;
channel.loadInfo.resultPrincipalURI = aRequest.loadInfo.resultPrincipalURI;
channel.loadGroup = aRequest.loadGroup;
channel.loadInfo.originAttributes = aRequest.loadInfo.originAttributes;

Expand Down
1 change: 1 addition & 0 deletions browser/extensions/pocket/content/AboutPocket.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ AboutPage.prototype = {
let channel = Services.io.newChannelFromURIWithLoadInfo(newURI,
aLoadInfo);
channel.originalURI = aURI;
aLoadInfo.resultPrincipalURI = aURI;

if (this.uriFlags & Ci.nsIAboutModule.URI_SAFE_FOR_UNTRUSTED_CONTENT) {
let principal = Services.scriptSecurityManager.getNoAppCodebasePrincipal(aURI);
Expand Down
5 changes: 2 additions & 3 deletions chrome/nsChromeProtocolHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,12 +168,11 @@ nsChromeProtocolHandler::NewChannel2(nsIURI* aURI,

// Make sure that the channel remembers where it was
// originally loaded from.
nsLoadFlags loadFlags = 0;
result->GetLoadFlags(&loadFlags);
result->SetLoadFlags(loadFlags & ~nsIChannel::LOAD_REPLACE);
rv = result->SetOriginalURI(aURI);
if (NS_FAILED(rv)) return rv;

aLoadInfo->SetResultPrincipalURI(aURI);

// Get a system principal for content files and set the owner
// property of the result
nsCOMPtr<nsIURL> url = do_QueryInterface(aURI);
Expand Down
4 changes: 4 additions & 0 deletions devtools/client/framework/about-devtools-toolbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ AboutURL.prototype = {
newChannel: function (aURI, aLoadInfo) {
let chan = Services.io.newChannelFromURIWithLoadInfo(this.uri, aLoadInfo);
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;
},

Expand Down
20 changes: 8 additions & 12 deletions docshell/base/nsAboutRedirector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,29 +174,25 @@ nsAboutRedirector::NewChannel(nsIURI* aURI,
rv = NS_NewURI(getter_AddRefs(tempURI), kRedirMap[i].url);
NS_ENSURE_SUCCESS(rv, rv);

// If tempURI links to an external URI (i.e. something other than
// chrome:// or resource://) then set the LOAD_REPLACE flag on the
// channel which forces the channel owner to reflect the displayed
// URL rather then being the systemPrincipal.
// If tempURI links to an internal URI (chrome://, resource://, about:)
// then set the result principal URL on the channel's load info.
// Otherwise, we leave it null which forces the channel principal
// to reflect the displayed URL rather than being the systemPrincipal.
bool isUIResource = false;
rv = NS_URIChainHasFlags(tempURI, nsIProtocolHandler::URI_IS_UI_RESOURCE,
&isUIResource);
NS_ENSURE_SUCCESS(rv, rv);

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),
tempURI,
aLoadInfo,
nullptr, // aLoadGroup
nullptr, // aCallbacks
loadFlags);
aLoadInfo);
NS_ENSURE_SUCCESS(rv, rv);

if (isUIResource || isAboutBlank) {
aLoadInfo->SetResultPrincipalURI(aURI);
}
tempChannel->SetOriginalURI(aURI);

tempChannel.forget(aResult);
Expand Down
6 changes: 6 additions & 0 deletions docshell/base/nsDocShell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11182,6 +11182,12 @@ nsDocShell::DoURILoad(nsIURI* aURI,

if (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) {
uint32_t loadFlags;
channel->GetLoadFlags(&loadFlags);
Expand Down
2 changes: 2 additions & 0 deletions dom/file/nsHostObjectProtocolHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -883,6 +883,8 @@ nsHostObjectProtocolHandler::NewChannel2(nsIURI* uri,
}

channel->SetOriginalURI(uri);
aLoadInfo->SetResultPrincipalURI(uri);

channel->SetContentType(NS_ConvertUTF16toUTF8(contentType));
channel->SetContentLength(size);

Expand Down
1 change: 1 addition & 0 deletions dom/html/nsHTMLDocument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2412,6 +2412,7 @@ nsHTMLDocument::CreateAndAddWyciwygChannel(void)
channel->SetLoadFlags(loadFlags);

channel->SetOriginalURI(wcwgURI);
loadInfo->SetResultPrincipalURI(wcwgURI);

rv = loadGroup->AddRequest(mWyciwygChannel, nullptr);
NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to add request to load group.");
Expand Down
1 change: 1 addition & 0 deletions mobile/android/components/AboutRedirector.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ AboutRedirector.prototype = {
}

channel.originalURI = aURI;
aLoadInfo.resultPrincipalURI = aURI;

return channel;
}
Expand Down
1 change: 1 addition & 0 deletions mobile/android/extensions/flyweb/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ AboutFlyWeb.prototype = Object.freeze({
let uri = Services.io.newURI("chrome://flyweb/content/aboutFlyWeb.xhtml");
let channel = Services.io.newChannelFromURIWithLoadInfo(uri, aLoadInfo);
channel.originalURI = aURI;
aLoadInfo.resultPrincipalURI = aURI;
return channel;
}
});
Expand Down
15 changes: 15 additions & 0 deletions netwerk/base/LoadInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ LoadInfo::LoadInfo(const LoadInfo& rhs)
, mTriggeringPrincipal(rhs.mTriggeringPrincipal)
, mPrincipalToInherit(rhs.mPrincipalToInherit)
, mSandboxedLoadingPrincipal(rhs.mSandboxedLoadingPrincipal)
, mResultPrincipalURI(rhs.mResultPrincipalURI)
, mLoadingContext(rhs.mLoadingContext)
, mSecurityFlags(rhs.mSecurityFlags)
, mInternalContentPolicyType(rhs.mInternalContentPolicyType)
Expand Down Expand Up @@ -936,5 +937,19 @@ LoadInfo::GetIsTopLevelLoad(bool *aResult)
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 mozilla
1 change: 1 addition & 0 deletions netwerk/base/LoadInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ class LoadInfo final : public nsILoadInfo
nsCOMPtr<nsIPrincipal> mTriggeringPrincipal;
nsCOMPtr<nsIPrincipal> mPrincipalToInherit;
nsCOMPtr<nsIPrincipal> mSandboxedLoadingPrincipal;
nsCOMPtr<nsIURI> mResultPrincipalURI;
nsWeakPtr mLoadingContext;
nsSecurityFlags mSecurityFlags;
nsContentPolicyType mInternalContentPolicyType;
Expand Down
9 changes: 9 additions & 0 deletions netwerk/base/nsILoadInfo.idl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
interface nsIDOMDocument;
interface nsINode;
interface nsIPrincipal;
interface nsIURI;

%{C++
#include "nsTArray.h"
Expand Down Expand Up @@ -740,6 +741,14 @@ interface nsILoadInfo : nsISupports
*/
[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
* flag is set. Otherwise returns null. This is used by
Expand Down
47 changes: 33 additions & 14 deletions netwerk/base/nsNetUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,13 +189,21 @@ NS_NewChannelInternal(nsIChannel **outChannel,
}

if (aLoadFlags != nsIRequest::LOAD_NORMAL) {
// Retain the LOAD_REPLACE load flag if set.
nsLoadFlags normalLoadFlags = 0;
channel->GetLoadFlags(&normalLoadFlags);
rv = channel->SetLoadFlags(aLoadFlags | (normalLoadFlags & nsIChannel::LOAD_REPLACE));
rv = channel->SetLoadFlags(aLoadFlags);
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);
return NS_OK;
}
Expand Down Expand Up @@ -268,13 +276,21 @@ NS_NewChannelInternal(nsIChannel **outChannel,
}

if (aLoadFlags != nsIRequest::LOAD_NORMAL) {
// Retain the LOAD_REPLACE load flag if set.
nsLoadFlags normalLoadFlags = 0;
channel->GetLoadFlags(&normalLoadFlags);
rv = channel->SetLoadFlags(aLoadFlags | (normalLoadFlags & nsIChannel::LOAD_REPLACE));
rv = channel->SetLoadFlags(aLoadFlags);
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);
return NS_OK;
}
Expand Down Expand Up @@ -1885,15 +1901,18 @@ nsresult
NS_GetFinalChannelURI(nsIChannel *channel, nsIURI **uri)
{
*uri = nullptr;
nsLoadFlags loadFlags = 0;
nsresult rv = channel->GetLoadFlags(&loadFlags);
NS_ENSURE_SUCCESS(rv, rv);

if (loadFlags & nsIChannel::LOAD_REPLACE) {
return channel->GetURI(uri);
nsCOMPtr<nsILoadInfo> loadInfo = channel->GetLoadInfo();
if (loadInfo) {
nsCOMPtr<nsIURI> resultPrincipalURI;
loadInfo->GetResultPrincipalURI(getter_AddRefs(resultPrincipalURI));
if (resultPrincipalURI) {
resultPrincipalURI.forget(uri);
return NS_OK;
}
}

return channel->GetOriginalURI(uri);
return channel->GetURI(uri);
}

nsresult
Expand Down
8 changes: 3 additions & 5 deletions netwerk/base/nsNetUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -781,11 +781,9 @@ nsresult NS_URIChainHasFlags(nsIURI *uri,
already_AddRefed<nsIURI> NS_GetInnermostURI(nsIURI *aURI);

/**
* Get the "final" URI for a channel. This is either the same as GetURI or
* GetOriginalURI, depending on whether this channel has
* 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.
* Get the "final" URI for a channel. This is either channel's load info
* resultPrincipalURI, if set, or GetURI. In most cases (but not all) load
* info resultPrincipalURI, if set, corresponds to originalURI of the channel.
*/
nsresult NS_GetFinalChannelURI(nsIChannel *channel, nsIURI **uri);

Expand Down
3 changes: 0 additions & 3 deletions netwerk/protocol/file/nsFileChannel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,9 +290,6 @@ nsFileChannel::nsFileChannel(nsIURI *uri)

SetURI(targetURI);
SetOriginalURI(uri);
nsLoadFlags loadFlags = 0;
GetLoadFlags(&loadFlags);
SetLoadFlags(loadFlags | nsIChannel::LOAD_REPLACE);
} else {
SetURI(uri);
}
Expand Down
Loading

0 comments on commit 7413cac

Please sign in to comment.