Bug 1125916 - Fix code that miss proper flags and originAttributes in LoadInfo. Also fix some tests. r=sicking, r=jduell

--HG--
extra : rebase_source : 2a08f0208496671439ce62a576b5f8a728bbdf3c
extra : amend_source : 30412ab68cc0ee4469a88e41b6ce81c908a26535
extra : histedit_source : 1faae352f7fbf7c4c7a9e1e571ca395c853a1334
This commit is contained in:
Dragana Damjanovic 2016-04-13 15:34:36 +02:00
parent e72aa9a9f1
commit 645513565f
13 changed files with 139 additions and 7 deletions

View File

@ -497,10 +497,33 @@ function mainThreadFetch(aURL, aOptions={ loadFromCache: true,
* @param {Object} options - The options object passed to @method fetch.
* @return {nsIChannel} - The newly created channel. Throws on failure.
*/
function newChannelForURL(url, { policy }) {
function newChannelForURL(url, { policy, window }) {
var securityFlags = Ci.nsILoadInfo.SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL;
if (window) {
// Respect private browsing.
var req = window.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIWebNavigation)
.QueryInterface(Ci.nsIDocumentLoader)
.loadGroup;
if (req) {
var nc = req.notificationCallbacks;
if (nc) {
try {
var lc = nc.getInterface(Ci.nsILoadContext);
if (lc) {
if (lc.usePrivateBrowsing) {
securityFlags |= Ci.nsILoadInfo.SEC_FORCE_PRIVATE_BROWSING;
}
}
} catch(ex) {}
}
}
}
let channelOptions = {
contentPolicyType: policy,
loadUsingSystemPrincipal: true,
securityFlags: securityFlags,
uri: url
};

View File

@ -10688,12 +10688,24 @@ nsDocShell::DoURILoad(nsIURI* aURI,
securityFlags |= nsILoadInfo::SEC_SANDBOXED;
}
if (mInPrivateBrowsing) {
securityFlags |= nsILoadInfo::SEC_FORCE_PRIVATE_BROWSING;
}
nsCOMPtr<nsILoadInfo> loadInfo =
(aContentPolicyType == nsIContentPolicy::TYPE_DOCUMENT) ?
new LoadInfo(loadingWindow, triggeringPrincipal,
securityFlags) :
new LoadInfo(loadingPrincipal, triggeringPrincipal, loadingNode,
securityFlags, aContentPolicyType);
// We have to do this in case our OriginAttributes are different from the
// OriginAttributes of the parent document. Or in case there isn't a
// parent document.
NeckoOriginAttributes neckoAttrs;
neckoAttrs.InheritFromDocShellToNecko(GetOriginAttributes());
loadInfo->SetOriginAttributes(neckoAttrs);
if (!isSrcdoc) {
rv = NS_NewChannelInternal(getter_AddRefs(channel),
aURI,
@ -10717,6 +10729,7 @@ nsDocShell::DoURILoad(nsIURI* aURI,
}
return rv;
}
if (aBaseURI) {
nsCOMPtr<nsIViewSourceChannel> vsc = do_QueryInterface(channel);
if (vsc) {

View File

@ -2287,6 +2287,11 @@ this.DOMApplicationRegistry = {
.createInstance(Ci.nsIXMLHttpRequest);
xhr.open("GET", aData.manifestURL, true);
xhr.channel.loadFlags |= Ci.nsIRequest.INHIBIT_CACHING;
if (xhr.channel.loadInfo) {
xhr.channel.loadInfo.originAttributes = { appId: app.installerAppId,
inIsolatedMozBrowser: app.installerIsBrowser
};
}
headers.forEach(function(aHeader) {
debug("Adding header: " + aHeader.name + ": " + aHeader.value);
xhr.setRequestHeader(aHeader.name, aHeader.value);
@ -2596,6 +2601,10 @@ this.DOMApplicationRegistry = {
.createInstance(Ci.nsIXMLHttpRequest);
xhr.open("GET", app.manifestURL, true);
xhr.channel.loadFlags |= Ci.nsIRequest.INHIBIT_CACHING;
if (xhr.channel.loadInfo) {
xhr.channel.loadInfo.originAttributes = { appId: aData.appId,
inIsolatedMozBrowser: aData.isBrowser};
}
xhr.channel.notificationCallbacks = AppsUtils.createLoadContext(aData.appId,
aData.isBrowser);
xhr.responseType = "json";
@ -2711,6 +2720,10 @@ this.DOMApplicationRegistry = {
.createInstance(Ci.nsIXMLHttpRequest);
xhr.open("GET", app.manifestURL, true);
xhr.channel.loadFlags |= Ci.nsIRequest.INHIBIT_CACHING;
if (xhr.channel.loadInfo) {
xhr.channel.loadInfo.originAttributes = { appId: aData.appId,
inIsolatedMozBrowser: aData.isBrowser};
}
xhr.channel.notificationCallbacks = AppsUtils.createLoadContext(aData.appId,
aData.isBrowser);
xhr.responseType = "json";

View File

@ -1307,6 +1307,16 @@ nsresult HTMLMediaElement::LoadResource()
nsContentPolicyType contentPolicyType = IsHTMLElement(nsGkAtoms::audio) ?
nsIContentPolicy::TYPE_INTERNAL_AUDIO : nsIContentPolicy::TYPE_INTERNAL_VIDEO;
nsDocShell* docShellPtr;
if (docShell) {
docShellPtr = nsDocShell::Cast(docShell);
bool privateBrowsing;
docShellPtr->GetUsePrivateBrowsing(&privateBrowsing);
if (privateBrowsing) {
securityFlags |= nsILoadInfo::SEC_FORCE_PRIVATE_BROWSING;
}
}
nsCOMPtr<nsILoadGroup> loadGroup = GetDocumentLoadGroup();
nsCOMPtr<nsIChannel> channel;
nsresult rv = NS_NewChannel(getter_AddRefs(channel),
@ -1323,6 +1333,14 @@ nsresult HTMLMediaElement::LoadResource()
NS_ENSURE_SUCCESS(rv,rv);
// This is a workaround and it will be fix in bug 1264230.
nsCOMPtr<nsILoadInfo> loadInfo = channel->GetLoadInfo();
if (loadInfo) {
NeckoOriginAttributes originAttrs;
NS_GetOriginAttributes(channel, originAttrs);
loadInfo->SetOriginAttributes(originAttrs);
}
// The listener holds a strong reference to us. This creates a
// reference cycle, once we've set mChannel, which is manually broken
// in the listener's OnStartRequest method after it is finished with

View File

@ -717,7 +717,8 @@ NewImageChannel(nsIChannel** aResult,
nsLoadFlags aLoadFlags,
nsContentPolicyType aPolicyType,
nsIPrincipal* aLoadingPrincipal,
nsISupports* aRequestingContext)
nsISupports* aRequestingContext,
bool aRespectPrivacy)
{
MOZ_ASSERT(aResult);
@ -764,6 +765,10 @@ NewImageChannel(nsIChannel** aResult,
securityFlags |= nsILoadInfo::SEC_FORCE_INHERIT_PRINCIPAL;
}
if (aRespectPrivacy) {
securityFlags |= nsILoadInfo::SEC_FORCE_PRIVATE_BROWSING;
}
// Note we are calling NS_NewChannelWithTriggeringPrincipal() here with a
// node and a principal. This is for things like background images that are
// specified by user stylesheets, where the document is being styled, but
@ -840,6 +845,21 @@ NewImageChannel(nsIChannel** aResult,
}
(*aResult)->SetLoadGroup(loadGroup);
// This is a workaround and a real fix in bug 1264231.
if (callbacks) {
nsCOMPtr<nsILoadContext> loadContext = do_GetInterface(callbacks);
if (loadContext) {
nsCOMPtr<nsILoadInfo> loadInfo;
rv = (*aResult)->GetLoadInfo(getter_AddRefs(loadInfo));
NS_ENSURE_SUCCESS(rv, rv);
DocShellOriginAttributes originAttrs;
loadContext->GetOriginAttributes(originAttrs);
NeckoOriginAttributes neckoOriginAttrs;
neckoOriginAttrs.InheritFromDocShellToNecko(originAttrs);
loadInfo->SetOriginAttributes(neckoOriginAttrs);
}
}
return NS_OK;
}
@ -1621,7 +1641,8 @@ imgLoader::ValidateRequestWithNewChannel(imgRequest* request,
aLoadFlags,
aLoadPolicyType,
aLoadingPrincipal,
aCX);
aCX,
mRespectPrivacy);
if (NS_FAILED(rv)) {
return false;
}
@ -2156,7 +2177,8 @@ imgLoader::LoadImage(nsIURI* aURI,
requestFlags,
aContentPolicyType,
aLoadingPrincipal,
aContext);
aContext,
mRespectPrivacy);
if (NS_FAILED(rv)) {
return NS_ERROR_FAILURE;
}

View File

@ -55,7 +55,12 @@ var gImgPath = 'http://localhost:' + server.identity.primaryPort + '/image.png';
function setup_chan(path, isPrivate, callback) {
var uri = NetUtil.newURI(gImgPath);
var chan = NetUtil.newChannel({uri: uri, loadUsingSystemPrincipal: true});
var securityFlags = Ci.nsILoadInfo.SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL;
if (isPrivate) {
securityFlags |= Ci.nsILoadInfo.SEC_FORCE_PRIVATE_BROWSING;
}
var chan = NetUtil.newChannel({uri: uri, loadUsingSystemPrincipal: true,
securityFlags: securityFlags});
chan.notificationCallbacks = new NotificationCallbacks(isPrivate);
var channelListener = new ChannelListener();
chan.asyncOpen2(channelListener);

View File

@ -22,6 +22,9 @@ function cached_handler(metadata, response) {
function makeChan(url, appId, inIsolatedMozBrowser) {
var chan = NetUtil.newChannel({uri: url, loadUsingSystemPrincipal: true})
.QueryInterface(Ci.nsIHttpChannel);
chan.loadInfo.originAttributes = { appId: appId,
inIsolatedMozBrowser: inIsolatedMozBrowser
};
chan.notificationCallbacks = {
appId: appId,
isInIsolatedMozBrowserElement: inIsolatedMozBrowser,

View File

@ -44,10 +44,15 @@ LoadContext.prototype = {
PrivateBrowsingLoadContext = new LoadContext(true);
function make_channel(url, flags, usePrivateBrowsing) {
var req = NetUtil.newChannel({uri: url, loadUsingSystemPrincipal: true});
var securityFlags = Ci.nsILoadInfo.SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL;
if (usePrivateBrowsing) {
securityFlags |= Ci.nsILoadInfo.SEC_FORCE_PRIVATE_BROWSING;
}
var req = NetUtil.newChannel({uri: url, loadUsingSystemPrincipal: true,
securityFlags: securityFlags});
req.loadFlags = flags;
if (usePrivateBrowsing) {
req.notificationCallbacks = PrivateBrowsingLoadContext;
req.notificationCallbacks = PrivateBrowsingLoadContext;
}
return req;
}

View File

@ -51,6 +51,9 @@ var i = 0;
function setupChannel(path)
{
var chan = NetUtil.newChannel({uri: URL + path, loadUsingSystemPrincipal: true});
chan.loadInfo.originAttributes = { appId: tests[i].loadContext.appId,
inIsolatedMozBrowser: tests[i].loadContext.isInIsolatedMozBrowserElement
};
chan.notificationCallbacks = tests[i].loadContext;
chan.QueryInterface(Ci.nsIHttpChannel);
return chan;

View File

@ -223,6 +223,9 @@ function run_test()
function test_channel_with_bad_signature() {
var channel = make_channel(uri+"/package_with_bad_signature!//index.html");
channel.loadInfo.originAttributes = { appId: 1024,
inIsolatedMozBrowser: false
};
channel.notificationCallbacks = new LoadContextCallback(1024, false, false, false);
channel.asyncOpen2(new Listener(function(l) {
do_check_true(l.gotFileNotFound);
@ -237,6 +240,9 @@ function test_channel_with_bad_signature_from_trusted_origin() {
origin.data = uri;
Services.prefs.setComplexValue(pref, Ci.nsISupportsString, origin);
var channel = make_channel(uri+"/package_with_bad_signature!//index.html");
channel.loadInfo.originAttributes = { appId: 1024,
inIsolatedMozBrowser: false
};
channel.notificationCallbacks = new LoadContextCallback(1024, false, false, false);
channel.asyncOpen2(new Listener(function(l) {
do_check_true(l.gotStopRequestOK);
@ -247,6 +253,9 @@ function test_channel_with_bad_signature_from_trusted_origin() {
function test_channel_with_good_signature() {
var channel = make_channel(uri+"/package_with_good_signature!//index.html");
channel.loadInfo.originAttributes = { appId: 1024,
inIsolatedMozBrowser: false
};
channel.notificationCallbacks = new LoadContextCallback(1024, false, false, false);
channel.asyncOpen2(new Listener(function(l) {
do_check_true(l.gotStopRequestOK);
@ -256,6 +265,9 @@ function test_channel_with_good_signature() {
function test_channel(aNullNotificationCallbacks) {
var channel = make_channel(uri+"/package!//index.html");
channel.loadInfo.originAttributes = { appId: 1024,
inIsolatedMozBrowser: false
};
if (!aNullNotificationCallbacks) {
channel.notificationCallbacks = new LoadContextCallback(1024, false, false, false);

View File

@ -81,9 +81,15 @@ function getChannelForURL(url, notificationCallbacks) {
});
if (notificationCallbacks) {
tmpChannel.loadInfo.originAttributes = { appId: 1024,
inIsolatedMozBrowser: false
};
// Use custom notificationCallbacks if any.
tmpChannel.notificationCallbacks = notificationCallbacks;
} else {
tmpChannel.loadInfo.originAttributes = { appId: principal.appId,
inIsolatedMozBrowser: principal.isInIsolatedMozBrowserElement
};
tmpChannel.notificationCallbacks =
new LoadContextCallback(principal.appId,
principal.isInIsolatedMozBrowserElement,

View File

@ -9,6 +9,9 @@ function inChildProcess() {
function makeChan(url, appId, inIsolatedMozBrowser) {
var chan = NetUtil.newChannel({uri: url, loadUsingSystemPrincipal: true})
.QueryInterface(Ci.nsIHttpChannel);
chan.loadInfo.originAttributes = { appId: appId,
inIsolatedMozBrowser: inIsolatedMozBrowser
};
chan.notificationCallbacks = {
appId: appId,
isInIsolatedMozBrowserElement: inIsolatedMozBrowser,

View File

@ -988,6 +988,12 @@ PendingLookup::SendRemoteQueryInternal()
getter_AddRefs(mChannel));
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsILoadInfo> loadInfo = mChannel->GetLoadInfo();
if (loadInfo) {
loadInfo->SetOriginAttributes(
mozilla::NeckoOriginAttributes(NECKO_SAFEBROWSING_APP_ID, false));
}
nsCOMPtr<nsIHttpChannel> httpChannel(do_QueryInterface(mChannel, &rv));
NS_ENSURE_SUCCESS(rv, rv);