Bug 1283319 - Add origin attributes to nsHttpConnectionInfo's hash key. r=mayhemer

--HG--
extra : rebase_source : a3f95ed223d6658e78daba0268407b7be0b7e16f
This commit is contained in:
Jonathan Hao 2016-08-04 01:17:00 -04:00
Родитель 9278a3992a
Коммит bc22b048bf
9 изменённых файлов: 69 добавлений и 23 удалений

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

@ -40,7 +40,7 @@ AltSvcMapping::ProcessHeader(const nsCString &buf, const nsCString &originScheme
const nsCString &originHost, int32_t originPort,
const nsACString &username, bool privateBrowsing,
nsIInterfaceRequestor *callbacks, nsProxyInfo *proxyInfo,
uint32_t caps)
uint32_t caps, const NeckoOriginAttributes &originAttributes)
{
MOZ_ASSERT(NS_IsMainThread());
LOG(("AltSvcMapping::ProcessHeader: %s\n", buf.get()));
@ -135,7 +135,8 @@ AltSvcMapping::ProcessHeader(const nsCString &buf, const nsCString &originScheme
// as that would have happened if we had accepted the parameters.
gHttpHandler->ConnMgr()->ClearHostMapping(originHost, originPort);
} else {
gHttpHandler->UpdateAltServiceMapping(mapping, proxyInfo, callbacks, caps);
gHttpHandler->UpdateAltServiceMapping(mapping, proxyInfo, callbacks, caps,
originAttributes);
}
}
}
@ -237,11 +238,13 @@ AltSvcMapping::RouteEquals(AltSvcMapping *map)
void
AltSvcMapping::GetConnectionInfo(nsHttpConnectionInfo **outCI,
nsProxyInfo *pi)
nsProxyInfo *pi,
const NeckoOriginAttributes &originAttributes)
{
RefPtr<nsHttpConnectionInfo> ci =
new nsHttpConnectionInfo(mOriginHost, mOriginPort, mNPNToken,
mUsername, pi, mAlternateHost, mAlternatePort);
mUsername, pi, originAttributes,
mAlternateHost, mAlternatePort);
ci->SetInsecureScheme(!mHttps);
ci->SetPrivate(mPrivate);
ci.forget(outCI);
@ -391,7 +394,8 @@ private:
void
AltSvcCache::UpdateAltServiceMapping(AltSvcMapping *map, nsProxyInfo *pi,
nsIInterfaceRequestor *aCallbacks,
uint32_t caps)
uint32_t caps,
const NeckoOriginAttributes &originAttributes)
{
MOZ_ASSERT(NS_IsMainThread());
AltSvcMapping *existing = mHash.GetWeak(map->mHashKey);
@ -429,7 +433,7 @@ AltSvcCache::UpdateAltServiceMapping(AltSvcMapping *map, nsProxyInfo *pi,
mHash.Put(map->mHashKey, map);
RefPtr<nsHttpConnectionInfo> ci;
map->GetConnectionInfo(getter_AddRefs(ci), pi);
map->GetConnectionInfo(getter_AddRefs(ci), pi, originAttributes);
caps |= ci->GetAnonymous() ? NS_HTTP_LOAD_ANONYMOUS : 0;
nsCOMPtr<nsIInterfaceRequestor> callbacks = new AltSvcOverride(aCallbacks);

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

@ -26,6 +26,7 @@ https://tools.ietf.org/html/draft-ietf-httpbis-alt-svc-06
#include "nsString.h"
#include "nsIInterfaceRequestor.h"
#include "nsISpeculativeConnect.h"
#include "mozilla/BasePrincipal.h"
namespace mozilla { namespace net {
@ -53,7 +54,7 @@ public:
const nsCString &originHost, int32_t originPort,
const nsACString &username, bool privateBrowsing,
nsIInterfaceRequestor *callbacks, nsProxyInfo *proxyInfo,
uint32_t caps);
uint32_t caps, const NeckoOriginAttributes &originAttributes);
const nsCString &AlternateHost() const { return mAlternateHost; }
const nsCString &OriginHost() const { return mOriginHost; }
@ -69,7 +70,8 @@ public:
bool RouteEquals(AltSvcMapping *map);
bool HTTPS() { return mHttps; }
void GetConnectionInfo(nsHttpConnectionInfo **outCI, nsProxyInfo *pi);
void GetConnectionInfo(nsHttpConnectionInfo **outCI, nsProxyInfo *pi,
const NeckoOriginAttributes &originAttributes);
int32_t TTL();
private:
@ -120,7 +122,8 @@ class AltSvcCache
{
public:
void UpdateAltServiceMapping(AltSvcMapping *map, nsProxyInfo *pi,
nsIInterfaceRequestor *, uint32_t caps); // main thread
nsIInterfaceRequestor *, uint32_t caps,
const NeckoOriginAttributes &originAttributes); // main thread
AltSvcMapping *GetAltServiceMapping(const nsACString &scheme,
const nsACString &host,
int32_t port, bool pb);

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

@ -2069,7 +2069,7 @@ UpdateAltSvcEvent(const nsCString &header,
AltSvcMapping::ProcessHeader(mHeader, originScheme, originHost, originPort,
mCI->GetUsername(), mCI->GetPrivate(), mCallbacks,
mCI->ProxyInfo(), 0);
mCI->ProxyInfo(), 0, mCI->GetOriginAttributes());
return NS_OK;
}

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

@ -1815,9 +1815,13 @@ nsHttpChannel::ProcessAltService()
proxyInfo = do_QueryInterface(mProxyInfo);
}
NeckoOriginAttributes originAttributes;
NS_GetOriginAttributes(this, originAttributes);
AltSvcMapping::ProcessHeader(altSvc, scheme, originHost, originPort,
mUsername, mPrivateBrowsing, callbacks, proxyInfo,
mCaps & NS_HTTP_DISALLOW_SPDY);
mCaps & NS_HTTP_DISALLOW_SPDY,
originAttributes);
}
nsresult
@ -5719,6 +5723,9 @@ nsHttpChannel::BeginConnect()
SetDoNotTrack();
NeckoOriginAttributes originAttributes;
NS_GetOriginAttributes(this, originAttributes);
RefPtr<AltSvcMapping> mapping;
if (mAllowAltSvc && // per channel
(scheme.Equals(NS_LITERAL_CSTRING("http")) ||
@ -5761,12 +5768,14 @@ nsHttpChannel::BeginConnect()
}
LOG(("nsHttpChannel %p Using connection info from altsvc mapping", this));
mapping->GetConnectionInfo(getter_AddRefs(mConnectionInfo), proxyInfo);
mapping->GetConnectionInfo(getter_AddRefs(mConnectionInfo), proxyInfo, originAttributes);
Telemetry::Accumulate(Telemetry::HTTP_TRANSACTION_USE_ALTSVC, true);
Telemetry::Accumulate(Telemetry::HTTP_TRANSACTION_USE_ALTSVC_OE, !isHttps);
} else {
LOG(("nsHttpChannel %p Using default connection info", this));
mConnectionInfo = new nsHttpConnectionInfo(host, port, EmptyCString(), mUsername, proxyInfo, isHttps);
mConnectionInfo = new nsHttpConnectionInfo(host, port, EmptyCString(), mUsername, proxyInfo,
originAttributes, isHttps);
Telemetry::Accumulate(Telemetry::HTTP_TRANSACTION_USE_ALTSVC, false);
}

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

@ -51,10 +51,11 @@ nsHttpConnectionInfo::nsHttpConnectionInfo(const nsACString &originHost,
const nsACString &npnToken,
const nsACString &username,
nsProxyInfo *proxyInfo,
const NeckoOriginAttributes &originAttributes,
bool endToEndSSL)
: mRoutedPort(443)
{
Init(originHost, originPort, npnToken, username, proxyInfo, endToEndSSL);
Init(originHost, originPort, npnToken, username, proxyInfo, originAttributes, endToEndSSL);
}
nsHttpConnectionInfo::nsHttpConnectionInfo(const nsACString &originHost,
@ -62,6 +63,7 @@ nsHttpConnectionInfo::nsHttpConnectionInfo(const nsACString &originHost,
const nsACString &npnToken,
const nsACString &username,
nsProxyInfo *proxyInfo,
const NeckoOriginAttributes &originAttributes,
const nsACString &routedHost,
int32_t routedPort)
@ -72,7 +74,7 @@ nsHttpConnectionInfo::nsHttpConnectionInfo(const nsACString &originHost,
if (!originHost.Equals(routedHost) || (originPort != routedPort)) {
mRoutedHost = routedHost;
}
Init(originHost, originPort, npnToken, username, proxyInfo, true);
Init(originHost, originPort, npnToken, username, proxyInfo, originAttributes, true);
}
void
@ -80,6 +82,7 @@ nsHttpConnectionInfo::Init(const nsACString &host, int32_t port,
const nsACString &npnToken,
const nsACString &username,
nsProxyInfo* proxyInfo,
const NeckoOriginAttributes &originAttributes,
bool e2eSSL)
{
LOG(("Init nsHttpConnectionInfo @%p\n", this));
@ -89,6 +92,7 @@ nsHttpConnectionInfo::Init(const nsACString &host, int32_t port,
mEndToEndSSL = e2eSSL;
mUsingConnect = false;
mNPNToken = npnToken;
mOriginAttributes = originAttributes;
mUsingHttpsProxy = (proxyInfo && proxyInfo->IsHTTPS());
mUsingHttpProxy = mUsingHttpsProxy || (proxyInfo && proxyInfo->IsHTTP());
@ -218,6 +222,10 @@ void nsHttpConnectionInfo::BuildHashKey()
mHashKey.Append(mNPNToken);
mHashKey.AppendLiteral("}");
}
nsAutoCString originAttributes;
mOriginAttributes.CreateSuffix(originAttributes);
mHashKey.Append(originAttributes);
}
void
@ -233,11 +241,12 @@ nsHttpConnectionInfo::Clone() const
{
nsHttpConnectionInfo *clone;
if (mRoutedHost.IsEmpty()) {
clone = new nsHttpConnectionInfo(mOrigin, mOriginPort, mNPNToken, mUsername, mProxyInfo, mEndToEndSSL);
clone = new nsHttpConnectionInfo(mOrigin, mOriginPort, mNPNToken, mUsername, mProxyInfo,
mOriginAttributes, mEndToEndSSL);
} else {
MOZ_ASSERT(mEndToEndSSL);
clone = new nsHttpConnectionInfo(mOrigin, mOriginPort, mNPNToken, mUsername, mProxyInfo,
mRoutedHost, mRoutedPort);
mOriginAttributes, mRoutedHost, mRoutedPort);
}
if (!mNetworkInterfaceId.IsEmpty()) {
@ -264,7 +273,8 @@ nsHttpConnectionInfo::CloneAsDirectRoute(nsHttpConnectionInfo **outCI)
RefPtr<nsHttpConnectionInfo> clone =
new nsHttpConnectionInfo(mOrigin, mOriginPort,
EmptyCString(), mUsername, mProxyInfo, mEndToEndSSL);
EmptyCString(), mUsername, mProxyInfo,
mOriginAttributes, mEndToEndSSL);
// Make sure the anonymous, insecure-scheme, and private flags are transferred
clone->SetAnonymous(GetAnonymous());
clone->SetPrivate(GetPrivate());
@ -289,7 +299,8 @@ nsHttpConnectionInfo::CreateWildCard(nsHttpConnectionInfo **outParam)
RefPtr<nsHttpConnectionInfo> clone;
clone = new nsHttpConnectionInfo(NS_LITERAL_CSTRING("*"), 0,
mNPNToken, mUsername, mProxyInfo, true);
mNPNToken, mUsername, mProxyInfo,
mOriginAttributes, true);
// Make sure the anonymous and private flags are transferred!
clone->SetAnonymous(GetAnonymous());
clone->SetPrivate(GetPrivate());

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

@ -12,6 +12,7 @@
#include "nsCOMPtr.h"
#include "nsStringFwd.h"
#include "mozilla/Logging.h"
#include "mozilla/BasePrincipal.h"
#include "ARefBase.h"
//-----------------------------------------------------------------------------
@ -39,6 +40,7 @@ public:
const nsACString &npnToken,
const nsACString &username,
nsProxyInfo *proxyInfo,
const NeckoOriginAttributes &originAttributes,
bool endToEndSSL = false);
// this version must use TLS and you may supply separate
@ -49,6 +51,7 @@ public:
const nsACString &npnToken,
const nsACString &username,
nsProxyInfo *proxyInfo,
const NeckoOriginAttributes &originAttributes,
const nsACString &routedHost,
int32_t routedPort);
@ -120,6 +123,8 @@ public:
const nsCString &GetNPNToken() { return mNPNToken; }
const nsCString &GetUsername() { return mUsername; }
const NeckoOriginAttributes &GetOriginAttributes() { return mOriginAttributes; }
// Returns true for any kind of proxy (http, socks, https, etc..)
bool UsingProxy();
@ -147,6 +152,7 @@ private:
const nsACString &npnToken,
const nsACString &username,
nsProxyInfo* proxyInfo,
const NeckoOriginAttributes &originAttributes,
bool EndToEndSSL);
void SetOriginServer(const nsACString &host, int32_t port);
@ -164,6 +170,7 @@ private:
bool mEndToEndSSL;
bool mUsingConnect; // if will use CONNECT with http proxy
nsCString mNPNToken;
NeckoOriginAttributes mOriginAttributes;
// for RefPtr
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(nsHttpConnectionInfo)

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

@ -1016,7 +1016,8 @@ nsHttpConnectionMgr::ReportFailedToProcess(nsIURI *uri)
// report the event for all the permutations of anonymous and
// private versions of this host
RefPtr<nsHttpConnectionInfo> ci =
new nsHttpConnectionInfo(host, port, EmptyCString(), username, nullptr, usingSSL);
new nsHttpConnectionInfo(host, port, EmptyCString(), username, nullptr,
NeckoOriginAttributes(), usingSSL);
ci->SetAnonymous(false);
ci->SetPrivate(false);
PipelineFeedbackInfo(ci, RedCorruptedContent, nullptr, 0);

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

@ -60,6 +60,7 @@
#include "mozilla/ipc/URIUtils.h"
#include "mozilla/Telemetry.h"
#include "mozilla/unused.h"
#include "mozilla/BasePrincipal.h"
#if defined(XP_UNIX)
#include <sys/utsname.h>
@ -2279,8 +2280,16 @@ nsHttpHandler::SpeculativeConnectInternal(nsIURI *aURI,
nsAutoCString username;
aURI->GetUsername(username);
NeckoOriginAttributes neckoOriginAttributes;
if (loadContext) {
DocShellOriginAttributes docshellOriginAttributes;
loadContext->GetOriginAttributes(docshellOriginAttributes);
neckoOriginAttributes.InheritFromDocShellToNecko(docshellOriginAttributes);
}
nsHttpConnectionInfo *ci =
new nsHttpConnectionInfo(host, port, EmptyCString(), username, nullptr, usingSSL);
new nsHttpConnectionInfo(host, port, EmptyCString(), username, nullptr,
neckoOriginAttributes, usingSSL);
ci->SetAnonymous(anonymous);
return SpeculativeConnect(ci, aCallbacks);

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

@ -241,9 +241,11 @@ public:
void UpdateAltServiceMapping(AltSvcMapping *map,
nsProxyInfo *proxyInfo,
nsIInterfaceRequestor *callbacks,
uint32_t caps)
uint32_t caps,
const NeckoOriginAttributes &originAttributes)
{
mConnMgr->UpdateAltServiceMapping(map, proxyInfo, callbacks, caps);
mConnMgr->UpdateAltServiceMapping(map, proxyInfo, callbacks, caps,
originAttributes);
}
AltSvcMapping *GetAltServiceMapping(const nsACString &scheme,