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

This commit is contained in:
Christoph Kerschbaumer 2014-12-11 20:46:47 -08:00
Родитель 26022ca095
Коммит 9266af2940
16 изменённых файлов: 168 добавлений и 36 удалений

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

@ -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,

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

@ -23,14 +23,28 @@ nsAboutBlank::NewChannel(nsIURI* aURI,
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIChannel> channel;
rv = NS_NewInputStreamChannel(getter_AddRefs(channel),
aURI,
in,
nsContentUtils::GetSystemPrincipal(),
nsILoadInfo::SEC_NORMAL,
nsIContentPolicy::TYPE_OTHER,
NS_LITERAL_CSTRING("text/html"),
NS_LITERAL_CSTRING("utf-8"));
// 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,
nsContentUtils::GetSystemPrincipal(),
nsILoadInfo::SEC_NORMAL,
nsIContentPolicy::TYPE_OTHER,
NS_LITERAL_CSTRING("text/html"),
NS_LITERAL_CSTRING("utf-8"));
}
if (NS_FAILED(rv)) return rv;
channel.forget(result);

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

@ -112,14 +112,28 @@ nsAboutBloat::NewChannel(nsIURI* aURI,
}
nsIChannel* channel = nullptr;
rv = NS_NewInputStreamChannel(&channel,
aURI,
inStr,
nsContentUtils::GetSystemPrincipal(),
nsILoadInfo::SEC_NORMAL,
nsIContentPolicy::TYPE_OTHER,
NS_LITERAL_CSTRING("text/plain"),
NS_LITERAL_CSTRING("utf-8"));
// 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,
nsContentUtils::GetSystemPrincipal(),
nsILoadInfo::SEC_NORMAL,
nsIContentPolicy::TYPE_OTHER,
NS_LITERAL_CSTRING("text/plain"),
NS_LITERAL_CSTRING("utf-8"));
}
if (NS_FAILED(rv)) return rv;
*result = channel;

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

@ -64,14 +64,28 @@ nsAboutCache::NewChannel(nsIURI* aURI,
mEntriesHeaderAdded = false;
nsCOMPtr<nsIChannel> channel;
rv = NS_NewInputStreamChannel(getter_AddRefs(channel),
aURI,
inputStream,
nsContentUtils::GetSystemPrincipal(),
nsILoadInfo::SEC_NORMAL,
nsIContentPolicy::TYPE_OTHER,
NS_LITERAL_CSTRING("text/html"),
NS_LITERAL_CSTRING("utf-8"));
// 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,
nsContentUtils::GetSystemPrincipal(),
nsILoadInfo::SEC_NORMAL,
nsIContentPolicy::TYPE_OTHER,
NS_LITERAL_CSTRING("text/html"),
NS_LITERAL_CSTRING("utf-8"));
}
if (NS_FAILED(rv)) return rv;
mBuffer.AssignLiteral(

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

@ -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,

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

@ -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.

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

@ -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);

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

@ -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;
}

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

@ -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);
}

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

@ -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;
}

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

@ -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;
}

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

@ -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

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

@ -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);

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

@ -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;
}

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

@ -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;
}

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

@ -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;
}