From bd0875ed222d58f51816ebb08e6203ef94053276 Mon Sep 17 00:00:00 2001 From: "eroman@chromium.org" Date: Fri, 25 Mar 2011 05:13:35 +0000 Subject: Make sure the system request context specifies a user agent. BUG=76833 TEST=open about:net-internals. Change your proxy settings to use an http:// URL for PAC. Check that the request headers sent contains a User-Agent line. Review URL: http://codereview.chromium.org/6732048 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@79371 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome/browser/io_thread.cc | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/chrome/browser/io_thread.cc b/chrome/browser/io_thread.cc index 6ddad22..f73a5f2 100644 --- a/chrome/browser/io_thread.cc +++ b/chrome/browser/io_thread.cc @@ -50,9 +50,21 @@ #include "net/ocsp/nss_ocsp.h" #endif // defined(USE_NSS) #include "net/proxy/proxy_script_fetcher_impl.h" +#include "webkit/glue/webkit_glue.h" namespace { +// Custom URLRequestContext used by requests which aren't associated with a +// particular profile. We need to use a subclass of URLRequestContext in order +// to provide the correct User-Agent. +class URLRequestContextWithUserAgent : public net::URLRequestContext { + public: + virtual const std::string& GetUserAgent( + const GURL& url) const OVERRIDE { + return webkit_glue::GetUserAgent(url); + } +}; + net::HostResolver* CreateGlobalHostResolver(net::NetLog* net_log) { const CommandLine& command_line = *CommandLine::ForCurrentProcess(); @@ -186,7 +198,8 @@ class LoggingNetworkChangeObserver scoped_refptr ConstructProxyScriptFetcherContext(IOThread::Globals* globals, net::NetLog* net_log) { - scoped_refptr context(new net::URLRequestContext); + scoped_refptr context( + new URLRequestContextWithUserAgent); context->set_net_log(net_log); context->set_host_resolver(globals->host_resolver.get()); context->set_cert_verifier(globals->cert_verifier.get()); @@ -205,7 +218,8 @@ ConstructProxyScriptFetcherContext(IOThread::Globals* globals, scoped_refptr ConstructSystemRequestContext(IOThread::Globals* globals, net::NetLog* net_log) { - scoped_refptr context(new net::URLRequestContext); + scoped_refptr context( + new URLRequestContextWithUserAgent); context->set_net_log(net_log); context->set_host_resolver(globals->host_resolver.get()); context->set_cert_verifier(globals->cert_verifier.get()); -- cgit v1.1