From 04539e3a79c31d626c18820a373efd8a0707c04d Mon Sep 17 00:00:00 2001 From: Kai Koehne Date: Tue, 30 Jun 2015 15:28:46 +0200 Subject: Use v8 backend for proxy resolution Use the v8 proxy resolution backend instead of the native one in the multi-process case. This fixes a particular issue on windows where the winhttp one will attempt to find proxy servers for every single request: https://crbug.com/40797 . Chrome uses the v8 backend too. Resort to the native backend though if started with --single-process. This is because the Chromium renderer and the V8 ProxyResolver can't run in the same process. See also proxy_resolver_v8.h: // It is important that *ALL* instances of V8 in the process be using // v8::Locker. If not there can be race conditions between the non-locked V8 // instances and the locked V8 instances used by ProxyResolverV8 (assuming they // run on different threads). // // This is the case with the V8 instance used by chromium's renderer -- it runs // on a different thread from ProxyResolver (renderer thread vs PAC thread), // and does not use locking since it expects to be alone. Task-number: QTBUG-44763 Change-Id: I7b48cb9d0f3c41fdddffc9eb9f51d83442d80622 Reviewed-by: Joerg Bornemann --- src/core/qtwebengine.gypi | 1 + src/core/url_request_context_getter_qt.cpp | 31 ++++++++++++++++++++++++++++-- src/core/url_request_context_getter_qt.h | 2 ++ 3 files changed, 32 insertions(+), 2 deletions(-) (limited to 'src/core') diff --git a/src/core/qtwebengine.gypi b/src/core/qtwebengine.gypi index 4b627a626..cca2bd73f 100644 --- a/src/core/qtwebengine.gypi +++ b/src/core/qtwebengine.gypi @@ -23,6 +23,7 @@ '<(chromium_src_dir)/media/media.gyp:media', '<(chromium_src_dir)/net/net.gyp:net', '<(chromium_src_dir)/net/net.gyp:net_resources', + '<(chromium_src_dir)/net/net.gyp:net_with_v8', '<(chromium_src_dir)/skia/skia.gyp:skia', '<(chromium_src_dir)/third_party/WebKit/Source/web/web.gyp:blink_web', '<(chromium_src_dir)/ui/base/ui_base.gyp:ui_base', diff --git a/src/core/url_request_context_getter_qt.cpp b/src/core/url_request_context_getter_qt.cpp index 4f893175a..10923e4cb 100644 --- a/src/core/url_request_context_getter_qt.cpp +++ b/src/core/url_request_context_getter_qt.cpp @@ -36,12 +36,14 @@ #include "url_request_context_getter_qt.h" +#include "base/command_line.h" #include "base/strings/string_util.h" #include "base/threading/worker_pool.h" #include "base/threading/sequenced_worker_pool.h" #include "content/public/browser/browser_thread.h" #include "content/public/browser/cookie_crypto_delegate.h" #include "content/public/browser/cookie_store_factory.h" +#include "content/public/common/content_switches.h" #include "net/base/cache_type.h" #include "net/cert/cert_verifier.h" #include "net/dns/host_resolver.h" @@ -50,7 +52,11 @@ #include "net/http/http_cache.h" #include "net/http/http_network_session.h" #include "net/http/http_server_properties_impl.h" +#include "net/proxy/dhcp_proxy_script_fetcher_factory.h" +#include "net/proxy/proxy_script_fetcher_impl.h" #include "net/proxy/proxy_service.h" +#include "net/proxy/proxy_service_v8.h" +#include "net/proxy/proxy_resolver_v8.h" #include "net/ssl/channel_id_service.h" #include "net/ssl/default_channel_id_store.h" #include "net/ssl/ssl_config_service_defaults.h" @@ -149,11 +155,32 @@ void URLRequestContextGetterQt::generateStorage() base::WorkerPool::GetTaskRunner(true))); m_storage->set_cert_verifier(net::CertVerifier::CreateDefault()); - m_storage->set_proxy_service(net::ProxyService::CreateUsingSystemProxyResolver(proxyConfigService, 0, NULL)); + + scoped_ptr host_resolver(net::HostResolver::CreateDefaultResolver(NULL)); + + // The System Proxy Resolver has issues on Windows with unconfigured network cards, + // which is why we want to use the v8 one. However, V8ProxyResolver doesn't work reliably with + // --single-process (See also the warnings in net/proxy/proxy_resolver_v8.h). + base::CommandLine& command_line = *base::CommandLine::ForCurrentProcess(); + if (command_line.HasSwitch(switches::kSingleProcess)) { + m_storage->set_proxy_service( + net::ProxyService::CreateUsingSystemProxyResolver(proxyConfigService, 0, NULL)); + } else { + if (!m_dhcpProxyScriptFetcherFactory) + m_dhcpProxyScriptFetcherFactory.reset(new net::DhcpProxyScriptFetcherFactory); + + net::ProxyResolverV8::EnsureIsolateCreated(); + m_storage->set_proxy_service(net::CreateProxyServiceUsingV8ProxyResolver( + proxyConfigService, + new net::ProxyScriptFetcherImpl(m_urlRequestContext.get()), + m_dhcpProxyScriptFetcherFactory->Create(m_urlRequestContext.get()), + host_resolver.get(), + NULL /* NetLog */, + m_networkDelegate.get())); + } m_storage->set_ssl_config_service(new net::SSLConfigServiceDefaults); m_storage->set_transport_security_state(new net::TransportSecurityState()); - scoped_ptr host_resolver(net::HostResolver::CreateDefaultResolver(NULL)); m_storage->set_http_auth_handler_factory(net::HttpAuthHandlerFactory::CreateDefault(host_resolver.get())); m_storage->set_http_server_properties(scoped_ptr(new net::HttpServerPropertiesImpl)); diff --git a/src/core/url_request_context_getter_qt.h b/src/core/url_request_context_getter_qt.h index d08836714..38cfd7957 100644 --- a/src/core/url_request_context_getter_qt.h +++ b/src/core/url_request_context_getter_qt.h @@ -47,6 +47,7 @@ #include "content/public/common/url_constants.h" #include "net/url_request/url_request_context_storage.h" #include "net/url_request/url_request_job_factory_impl.h" +#include "net/proxy/dhcp_proxy_script_fetcher_factory.h" #include "qglobal.h" #include @@ -95,6 +96,7 @@ private: scoped_ptr m_networkDelegate; scoped_ptr m_storage; scoped_ptr m_jobFactory; + scoped_ptr m_dhcpProxyScriptFetcherFactory; }; } // namespace QtWebEngineCore -- cgit v1.2.3