From 9266af29403ecb5dac772e5a9bda71689f96d6cd Mon Sep 17 00:00:00 2001 From: Christoph Kerschbaumer Date: Thu, 11 Dec 2014 20:46:47 -0800 Subject: [PATCH] Bug 1087442 - Attach LoadInfo inside each individual ProtocolHandler - netwerk/ changes (r=sworkman,sicking) --- .../base/public/nsIProxiedProtocolHandler.idl | 1 + netwerk/protocol/about/nsAboutBlank.cpp | 30 ++++++++++++++----- netwerk/protocol/about/nsAboutBloat.cpp | 30 ++++++++++++++----- netwerk/protocol/about/nsAboutCache.cpp | 30 ++++++++++++++----- netwerk/protocol/about/nsAboutCacheEntry.cpp | 13 +++++++- .../protocol/about/nsAboutProtocolHandler.cpp | 10 +++++++ netwerk/protocol/app/AppProtocolHandler.cpp | 12 ++++++-- netwerk/protocol/data/nsDataHandler.cpp | 7 +++++ .../device/nsDeviceProtocolHandler.cpp | 4 +++ .../protocol/file/nsFileProtocolHandler.cpp | 7 +++++ netwerk/protocol/ftp/nsFtpProtocolHandler.cpp | 10 +++++-- netwerk/protocol/http/nsHttpHandler.cpp | 10 +++++-- netwerk/protocol/res/nsResProtocolHandler.cpp | 23 ++++++++++---- netwerk/protocol/rtsp/RtspHandler.cpp | 4 +++ .../viewsource/nsViewSourceHandler.cpp | 7 +++++ .../wyciwyg/nsWyciwygProtocolHandler.cpp | 6 ++++ 16 files changed, 168 insertions(+), 36 deletions(-) diff --git a/netwerk/base/public/nsIProxiedProtocolHandler.idl b/netwerk/base/public/nsIProxiedProtocolHandler.idl index 995e576fe3df..604177c12430 100644 --- a/netwerk/base/public/nsIProxiedProtocolHandler.idl +++ b/netwerk/base/public/nsIProxiedProtocolHandler.idl @@ -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, diff --git a/netwerk/protocol/about/nsAboutBlank.cpp b/netwerk/protocol/about/nsAboutBlank.cpp index 9326b285cdd9..fd4d3b8ec9ce 100644 --- a/netwerk/protocol/about/nsAboutBlank.cpp +++ b/netwerk/protocol/about/nsAboutBlank.cpp @@ -23,14 +23,28 @@ nsAboutBlank::NewChannel(nsIURI* aURI, if (NS_FAILED(rv)) return rv; nsCOMPtr 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); diff --git a/netwerk/protocol/about/nsAboutBloat.cpp b/netwerk/protocol/about/nsAboutBloat.cpp index 235858ed5cc5..8dee932d0adf 100644 --- a/netwerk/protocol/about/nsAboutBloat.cpp +++ b/netwerk/protocol/about/nsAboutBloat.cpp @@ -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; diff --git a/netwerk/protocol/about/nsAboutCache.cpp b/netwerk/protocol/about/nsAboutCache.cpp index b1a12c70b421..36dcdb7c5b3e 100644 --- a/netwerk/protocol/about/nsAboutCache.cpp +++ b/netwerk/protocol/about/nsAboutCache.cpp @@ -64,14 +64,28 @@ nsAboutCache::NewChannel(nsIURI* aURI, mEntriesHeaderAdded = false; nsCOMPtr 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( diff --git a/netwerk/protocol/about/nsAboutCacheEntry.cpp b/netwerk/protocol/about/nsAboutCacheEntry.cpp index 5fdc2871e3c7..c2030e8ed00e 100644 --- a/netwerk/protocol/about/nsAboutCacheEntry.cpp +++ b/netwerk/protocol/about/nsAboutCacheEntry.cpp @@ -99,7 +99,18 @@ nsAboutCacheEntry::NewChannel(nsIURI* uri, nsCOMPtr 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, diff --git a/netwerk/protocol/about/nsAboutProtocolHandler.cpp b/netwerk/protocol/about/nsAboutProtocolHandler.cpp index 8a81437e3ec5..13af35bb8b72 100644 --- a/netwerk/protocol/about/nsAboutProtocolHandler.cpp +++ b/netwerk/protocol/about/nsAboutProtocolHandler.cpp @@ -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 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. diff --git a/netwerk/protocol/app/AppProtocolHandler.cpp b/netwerk/protocol/app/AppProtocolHandler.cpp index 6a95c68bd657..fda2ce8112ba 100644 --- a/netwerk/protocol/app/AppProtocolHandler.cpp +++ b/netwerk/protocol/app/AppProtocolHandler.cpp @@ -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 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 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); diff --git a/netwerk/protocol/data/nsDataHandler.cpp b/netwerk/protocol/data/nsDataHandler.cpp index e5d2ed7bb32a..b242593d29bc 100644 --- a/netwerk/protocol/data/nsDataHandler.cpp +++ b/netwerk/protocol/data/nsDataHandler.cpp @@ -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; } diff --git a/netwerk/protocol/device/nsDeviceProtocolHandler.cpp b/netwerk/protocol/device/nsDeviceProtocolHandler.cpp index 577692bd7c0f..51cfe9033d6d 100644 --- a/netwerk/protocol/device/nsDeviceProtocolHandler.cpp +++ b/netwerk/protocol/device/nsDeviceProtocolHandler.cpp @@ -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); } diff --git a/netwerk/protocol/file/nsFileProtocolHandler.cpp b/netwerk/protocol/file/nsFileProtocolHandler.cpp index 2c417a6a4e5f..c8b9ac0e0fa8 100644 --- a/netwerk/protocol/file/nsFileProtocolHandler.cpp +++ b/netwerk/protocol/file/nsFileProtocolHandler.cpp @@ -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; } diff --git a/netwerk/protocol/ftp/nsFtpProtocolHandler.cpp b/netwerk/protocol/ftp/nsFtpProtocolHandler.cpp index bd1f94ee8451..f540650d2cf4 100644 --- a/netwerk/protocol/ftp/nsFtpProtocolHandler.cpp +++ b/netwerk/protocol/ftp/nsFtpProtocolHandler.cpp @@ -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 @@ -234,7 +234,13 @@ nsFtpProtocolHandler::NewProxiedChannel2(nsIURI* uri, nsIProxyInfo* proxyInfo, 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 rv; } diff --git a/netwerk/protocol/http/nsHttpHandler.cpp b/netwerk/protocol/http/nsHttpHandler.cpp index 1ef14cdf1bc7..af343ca84617 100644 --- a/netwerk/protocol/http/nsHttpHandler.cpp +++ b/netwerk/protocol/http/nsHttpHandler.cpp @@ -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 diff --git a/netwerk/protocol/res/nsResProtocolHandler.cpp b/netwerk/protocol/res/nsResProtocolHandler.cpp index 1f6cf39dbd44..8111deea320d 100644 --- a/netwerk/protocol/res/nsResProtocolHandler.cpp +++ b/netwerk/protocol/res/nsResProtocolHandler.cpp @@ -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 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); diff --git a/netwerk/protocol/rtsp/RtspHandler.cpp b/netwerk/protocol/rtsp/RtspHandler.cpp index 885cb64d4bf1..f633f1ce85d3 100644 --- a/netwerk/protocol/rtsp/RtspHandler.cpp +++ b/netwerk/protocol/rtsp/RtspHandler.cpp @@ -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; } diff --git a/netwerk/protocol/viewsource/nsViewSourceHandler.cpp b/netwerk/protocol/viewsource/nsViewSourceHandler.cpp index 979aea3510cb..261ee2465e51 100644 --- a/netwerk/protocol/viewsource/nsViewSourceHandler.cpp +++ b/netwerk/protocol/viewsource/nsViewSourceHandler.cpp @@ -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(channel); return NS_OK; } diff --git a/netwerk/protocol/wyciwyg/nsWyciwygProtocolHandler.cpp b/netwerk/protocol/wyciwyg/nsWyciwygProtocolHandler.cpp index 30cfd2127d22..3e9b66af47c3 100644 --- a/netwerk/protocol/wyciwyg/nsWyciwygProtocolHandler.cpp +++ b/netwerk/protocol/wyciwyg/nsWyciwygProtocolHandler.cpp @@ -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; }