Bug 1087442 - Attach LoadInfo inside each individual ProtocolHandler - netwerk/ changes (r=sworkman,sicking)

This commit is contained in:
Christoph Kerschbaumer 2014-12-12 09:07:36 -08:00
parent 6d6fa71cc0
commit c5658b66eb
16 changed files with 168 additions and 36 deletions

View File

@ -27,6 +27,7 @@ interface nsIProxiedProtocolHandler : nsIProtocolHandler
* effect), except in the case of websockets which wants to bootstrap
* to an http:// channel but make its proxy determination based on
* a ws:// uri.
* @param aLoadInfo used to evaluate who initated the resource request.
*/
nsIChannel newProxiedChannel2(in nsIURI uri, in nsIProxyInfo proxyInfo,
in unsigned long proxyResolveFlags,

View File

@ -23,6 +23,19 @@ nsAboutBlank::NewChannel(nsIURI* aURI,
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIChannel> channel;
// Bug 1087720 (and Bug 1099296):
// Once all callsites have been updated to call NewChannel2()
// instead of NewChannel() we should have a non-null loadInfo
// consistently. Until then we have to branch on the loadInfo.
if (aLoadInfo) {
rv = NS_NewInputStreamChannelInternal(getter_AddRefs(channel),
aURI,
in,
NS_LITERAL_CSTRING("text/html"),
NS_LITERAL_CSTRING("utf-8"),
aLoadInfo);
}
else {
rv = NS_NewInputStreamChannel(getter_AddRefs(channel),
aURI,
in,
@ -31,6 +44,7 @@ nsAboutBlank::NewChannel(nsIURI* aURI,
nsIContentPolicy::TYPE_OTHER,
NS_LITERAL_CSTRING("text/html"),
NS_LITERAL_CSTRING("utf-8"));
}
if (NS_FAILED(rv)) return rv;
channel.forget(result);

View File

@ -112,6 +112,19 @@ nsAboutBloat::NewChannel(nsIURI* aURI,
}
nsIChannel* channel = nullptr;
// Bug 1087720 (and Bug 1099296):
// Once all callsites have been updated to call NewChannel2()
// instead of NewChannel() we should have a non-null loadInfo
// consistently. Until then we have to branch on the loadInfo.
if (aLoadInfo) {
rv = NS_NewInputStreamChannelInternal(&channel,
aURI,
inStr,
NS_LITERAL_CSTRING("text/plain"),
NS_LITERAL_CSTRING("utf-8"),
aLoadInfo);
}
else {
rv = NS_NewInputStreamChannel(&channel,
aURI,
inStr,
@ -120,6 +133,7 @@ nsAboutBloat::NewChannel(nsIURI* aURI,
nsIContentPolicy::TYPE_OTHER,
NS_LITERAL_CSTRING("text/plain"),
NS_LITERAL_CSTRING("utf-8"));
}
if (NS_FAILED(rv)) return rv;
*result = channel;

View File

@ -64,6 +64,19 @@ nsAboutCache::NewChannel(nsIURI* aURI,
mEntriesHeaderAdded = false;
nsCOMPtr<nsIChannel> channel;
// Bug 1087720 (and Bug 1099296):
// Once all callsites have been updated to call NewChannel2()
// instead of NewChannel() we should have a non-null loadInfo
// consistently. Until then we have to branch on the loadInfo.
if (aLoadInfo) {
rv = NS_NewInputStreamChannelInternal(getter_AddRefs(channel),
aURI,
inputStream,
NS_LITERAL_CSTRING("text/html"),
NS_LITERAL_CSTRING("utf-8"),
aLoadInfo);
}
else {
rv = NS_NewInputStreamChannel(getter_AddRefs(channel),
aURI,
inputStream,
@ -72,6 +85,7 @@ nsAboutCache::NewChannel(nsIURI* aURI,
nsIContentPolicy::TYPE_OTHER,
NS_LITERAL_CSTRING("text/html"),
NS_LITERAL_CSTRING("utf-8"));
}
if (NS_FAILED(rv)) return rv;
mBuffer.AssignLiteral(

View File

@ -99,7 +99,18 @@ nsAboutCacheEntry::NewChannel(nsIURI* uri,
nsCOMPtr<nsIInputStream> stream;
rv = GetContentStream(uri, getter_AddRefs(stream));
if (NS_FAILED(rv)) return rv;
// Bug 1087720 (and Bug 1099296):
// Once all callsites have been updated to call NewChannel2()
// instead of NewChannel() we should have a non-null loadInfo
// consistently. Until then we have to branch on the loadInfo.
if (aLoadInfo) {
return NS_NewInputStreamChannelInternal(result,
uri,
stream,
NS_LITERAL_CSTRING("text/html"),
NS_LITERAL_CSTRING("utf-8"),
aLoadInfo);
}
return NS_NewInputStreamChannel(result,
uri,
stream,

View File

@ -142,6 +142,16 @@ nsAboutProtocolHandler::NewChannel2(nsIURI* uri,
// The standard return case:
rv = aboutMod->NewChannel(uri, aLoadInfo, result);
if (NS_SUCCEEDED(rv)) {
// Not all implementations of nsIAboutModule::NewChannel()
// set the LoadInfo on the newly created channel yet, as
// an interim solution we set the LoadInfo here if not
// available on the channel. Bug 1087720
nsCOMPtr<nsILoadInfo> loadInfo;
(*result)->GetLoadInfo(getter_AddRefs(loadInfo));
if (!loadInfo) {
(*result)->SetLoadInfo(aLoadInfo);
}
// If this URI is safe for untrusted content, enforce that its
// principal be based on the channel's originalURI by setting the
// owner to null.

View File

@ -423,7 +423,9 @@ AppProtocolHandler::NewChannel2(nsIURI* aUri,
if (NS_FAILED(rv) || !jsInfo.isObject()) {
// Return a DummyChannel.
printf_stderr("!! Creating a dummy channel for %s (no appInfo)\n", host.get());
NS_IF_ADDREF(*aResult = new DummyChannel());
nsRefPtr<nsIChannel> dummyChannel = new DummyChannel();
dummyChannel->SetLoadInfo(aLoadInfo);
dummyChannel.forget(aResult);
return NS_OK;
}
@ -432,7 +434,9 @@ AppProtocolHandler::NewChannel2(nsIURI* aUri,
if (!appInfo->Init(cx, jsInfo) || appInfo->mPath.IsEmpty()) {
// Return a DummyChannel.
printf_stderr("!! Creating a dummy channel for %s (invalid appInfo)\n", host.get());
NS_IF_ADDREF(*aResult = new DummyChannel());
nsRefPtr<nsIChannel> dummyChannel = new DummyChannel();
dummyChannel->SetLoadInfo(aLoadInfo);
dummyChannel.forget(aResult);
return NS_OK;
}
mAppInfoCache.Put(host, appInfo);
@ -456,6 +460,10 @@ AppProtocolHandler::NewChannel2(nsIURI* aUri,
rv = channel->Init(jarURI);
NS_ENSURE_SUCCESS(rv, rv);
// set the loadInfo on the new channel
rv = channel->SetLoadInfo(aLoadInfo);
NS_ENSURE_SUCCESS(rv, rv);
rv = channel->SetAppURI(aUri);
NS_ENSURE_SUCCESS(rv, rv);

View File

@ -119,6 +119,13 @@ nsDataHandler::NewChannel2(nsIURI* uri,
return rv;
}
// set the loadInfo on the new channel
rv = channel->SetLoadInfo(aLoadInfo);
if (NS_FAILED(rv)) {
NS_RELEASE(channel);
return rv;
}
*result = channel;
return NS_OK;
}

View File

@ -62,6 +62,10 @@ nsDeviceProtocolHandler::NewChannel2(nsIURI* aURI,
nsresult rv = channel->Init(aURI);
NS_ENSURE_SUCCESS(rv, rv);
// set the loadInfo on the new channel
rv = channel->SetLoadInfo(aLoadInfo);
NS_ENSURE_SUCCESS(rv, rv);
return CallQueryInterface(channel, aResult);
}

View File

@ -192,6 +192,13 @@ nsFileProtocolHandler::NewChannel2(nsIURI* uri,
return rv;
}
// set the loadInfo on the new channel
rv = chan->SetLoadInfo(aLoadInfo);
if (NS_FAILED(rv)) {
NS_RELEASE(chan);
return rv;
}
*result = chan;
return NS_OK;
}

View File

@ -207,7 +207,7 @@ nsFtpProtocolHandler::NewChannel2(nsIURI* url,
nsILoadInfo* aLoadInfo,
nsIChannel** result)
{
return NewProxiedChannel(url, nullptr, 0, nullptr, result);
return NewProxiedChannel2(url, nullptr, 0, nullptr, aLoadInfo, result);
}
NS_IMETHODIMP
@ -235,6 +235,12 @@ nsFtpProtocolHandler::NewProxiedChannel2(nsIURI* uri, nsIProxyInfo* proxyInfo,
return rv;
}
// set the loadInfo on the new channel
rv = channel->SetLoadInfo(aLoadInfo);
if (NS_FAILED(rv)) {
return rv;
}
channel.forget(result);
return rv;
}

View File

@ -1725,7 +1725,7 @@ nsHttpHandler::NewChannel2(nsIURI* uri,
}
}
return NewProxiedChannel(uri, nullptr, 0, nullptr, result);
return NewProxiedChannel2(uri, nullptr, 0, nullptr, aLoadInfo, result);
}
NS_IMETHODIMP
@ -1793,6 +1793,12 @@ nsHttpHandler::NewProxiedChannel2(nsIURI *uri,
if (NS_FAILED(rv))
return rv;
// set the loadInfo on the new channel
rv = httpChannel->SetLoadInfo(aLoadInfo);
if (NS_FAILED(rv)) {
return rv;
}
httpChannel.forget(result);
return NS_OK;
}
@ -2107,7 +2113,7 @@ nsHttpsHandler::NewChannel2(nsIURI* aURI,
MOZ_ASSERT(gHttpHandler);
if (!gHttpHandler)
return NS_ERROR_UNEXPECTED;
return gHttpHandler->NewChannel(aURI, _retval);
return gHttpHandler->NewChannel2(aURI, aLoadInfo, _retval);
}
NS_IMETHODIMP

View File

@ -284,14 +284,27 @@ nsResProtocolHandler::NewChannel2(nsIURI* uri,
nsIChannel** result)
{
NS_ENSURE_ARG_POINTER(uri);
nsresult rv;
nsAutoCString spec;
nsresult rv = ResolveURI(uri, spec);
NS_ENSURE_SUCCESS(rv, rv);
rv = ResolveURI(uri, spec);
if (NS_FAILED(rv)) return rv;
// Bug 1087720 (and Bug 1099296):
// Once all callsites have been updated to call NewChannel2() instead of NewChannel()
// we should have a non-null loadInfo consistently. Until then we have to branch on the
// loadInfo.
nsCOMPtr<nsIURI> newURI;
rv = NS_NewURI(getter_AddRefs(newURI), spec);
NS_ENSURE_SUCCESS(rv, rv);
rv = mIOService->NewChannel(spec, nullptr, nullptr, result);
if (NS_FAILED(rv)) return rv;
if (aLoadInfo) {
rv = NS_NewChannelInternal(result,
newURI,
aLoadInfo);
}
else {
rv = mIOService->NewChannelFromURI(newURI, result);
}
NS_ENSURE_SUCCESS(rv, rv);
nsLoadFlags loadFlags = 0;
(*result)->GetLoadFlags(&loadFlags);

View File

@ -86,6 +86,10 @@ RtspHandler::NewChannel2(nsIURI* aURI,
rv = rtspChannel->Init();
NS_ENSURE_SUCCESS(rv, rv);
// set the loadInfo on the new channel
rv = rtspChannel->SetLoadInfo(aLoadInfo);
NS_ENSURE_SUCCESS(rv, rv);
rtspChannel.forget(aResult);
return NS_OK;
}

View File

@ -106,6 +106,13 @@ nsViewSourceHandler::NewChannel2(nsIURI* uri,
return rv;
}
// set the loadInfo on the new channel
rv = channel->SetLoadInfo(aLoadInfo);
if (NS_FAILED(rv)) {
NS_RELEASE(channel);
return rv;
}
*result = static_cast<nsIViewSourceChannel*>(channel);
return NS_OK;
}

View File

@ -131,6 +131,12 @@ nsWyciwygProtocolHandler::NewChannel2(nsIURI* url,
if (NS_FAILED(rv))
return rv;
// set the loadInfo on the new channel
rv = channel->SetLoadInfo(aLoadInfo);
if (NS_FAILED(rv)) {
return rv;
}
channel.forget(result);
return NS_OK;
}