From 99d901bc9ab7e8e6107ecdf0938056a068e94839 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sun, 29 Sep 2013 15:06:29 +0800 Subject: [PATCH] Switch to use the ProxyResolverV8, fixes atom/atom#894. --- browser/atom_browser_main_parts.cc | 10 ++++++++ browser/atom_browser_main_parts.h | 1 + .../net/atom_url_request_context_getter.cc | 25 ++++++++++++++----- vendor/brightray | 2 +- 4 files changed, 31 insertions(+), 7 deletions(-) diff --git a/browser/atom_browser_main_parts.cc b/browser/atom_browser_main_parts.cc index aaec24bea7..1427d7e407 100644 --- a/browser/atom_browser_main_parts.cc +++ b/browser/atom_browser_main_parts.cc @@ -10,6 +10,7 @@ #include "browser/atom_browser_context.h" #include "browser/browser.h" #include "common/node_bindings.h" +#include "net/proxy/proxy_resolver_v8.h" #include "vendor/node/src/node.h" #include "vendor/node/src/node_internals.h" @@ -87,4 +88,13 @@ void AtomBrowserMainParts::PreMainMessageLoopRun() { #endif } +int AtomBrowserMainParts::PreCreateThreads() { +#if defined(OS_WIN) + net::ProxyResolverV8::CreateIsolate(); +#else + net::ProxyResolverV8::RememberDefaultIsolate(); +#endif + return 0; +} + } // namespace atom diff --git a/browser/atom_browser_main_parts.h b/browser/atom_browser_main_parts.h index 3b7ac1071a..a7fd180932 100644 --- a/browser/atom_browser_main_parts.h +++ b/browser/atom_browser_main_parts.h @@ -30,6 +30,7 @@ class AtomBrowserMainParts : public brightray::BrowserMainParts { // Implementations of content::BrowserMainParts. virtual void PostEarlyInitialization() OVERRIDE; virtual void PreMainMessageLoopRun() OVERRIDE; + virtual int PreCreateThreads() OVERRIDE; #if defined(OS_MACOSX) virtual void PreMainMessageLoopStart() OVERRIDE; virtual void PostDestroyThreads() OVERRIDE; diff --git a/browser/net/atom_url_request_context_getter.cc b/browser/net/atom_url_request_context_getter.cc index 0472905527..92a3d9efac 100644 --- a/browser/net/atom_url_request_context_getter.cc +++ b/browser/net/atom_url_request_context_getter.cc @@ -15,7 +15,11 @@ #include "net/http/http_auth_handler_factory.h" #include "net/http/http_cache.h" #include "net/http/http_server_properties_impl.h" +#include "net/proxy/dhcp_proxy_script_fetcher_factory.h" +#include "net/proxy/proxy_config_service.h" +#include "net/proxy/proxy_script_fetcher_impl.h" #include "net/proxy/proxy_service.h" +#include "net/proxy/proxy_service_v8.h" #include "net/ssl/default_server_bound_cert_store.h" #include "net/ssl/server_bound_cert_service.h" #include "net/ssl/ssl_config_service_defaults.h" @@ -43,7 +47,12 @@ AtomURLRequestContextGetter::AtomURLRequestContextGetter( network_delegate_(network_delegate.Pass()) { // Must first be created on the UI thread. DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); + std::swap(protocol_handlers_, *protocol_handlers); + + // We must create the proxy config service on the UI loop on Linux because it + // must synchronously run on the glib message loop. This will be passed to + // the URLRequestContextStorage on the IO thread in GetURLRequestContext(). proxy_config_service_.reset( net::ProxyService::CreateSystemProxyConfigService( io_loop_->message_loop_proxy(), @@ -77,12 +86,6 @@ net::URLRequestContext* AtomURLRequestContextGetter::GetURLRequestContext() { net::HostResolver::CreateDefaultResolver(NULL)); storage_->set_cert_verifier(net::CertVerifier::CreateDefault()); - // TODO(jam): use v8 if possible, look at chrome code. - storage_->set_proxy_service( - net::ProxyService::CreateUsingSystemProxyResolver( - proxy_config_service_.release(), - 0, - NULL)); storage_->set_ssl_config_service(new net::SSLConfigServiceDefaults); storage_->set_http_auth_handler_factory( net::HttpAuthHandlerFactory::CreateDefault(host_resolver.get())); @@ -119,6 +122,16 @@ net::URLRequestContext* AtomURLRequestContextGetter::GetURLRequestContext() { network_session_params.host_resolver = url_request_context_->host_resolver(); + net::DhcpProxyScriptFetcherFactory dhcp_factory; + storage_->set_proxy_service( + net::CreateProxyServiceUsingV8ProxyResolver( + proxy_config_service_.release(), + new net::ProxyScriptFetcherImpl(url_request_context_.get()), + dhcp_factory.Create(url_request_context_.get()), + url_request_context_->host_resolver(), + NULL, + url_request_context_->network_delegate())); + net::HttpCache* main_cache = new net::HttpCache( network_session_params, main_backend); storage_->set_http_transaction_factory(main_cache); diff --git a/vendor/brightray b/vendor/brightray index 3cb2782cff..b207f0e5be 160000 --- a/vendor/brightray +++ b/vendor/brightray @@ -1 +1 @@ -Subproject commit 3cb2782cff77081df2788c68948163dea53530d5 +Subproject commit b207f0e5bed9c06142879abdd6749ac954eff8b8