diff options
-rw-r--r-- | chrome/browser/debugger/debugger_shell.cc | 11 | ||||
-rw-r--r-- | chrome/browser/net/chrome_url_request_context.cc | 30 | ||||
-rw-r--r-- | chrome/common/chrome_switches.cc | 6 | ||||
-rw-r--r-- | chrome/common/chrome_switches.h | 1 | ||||
-rw-r--r-- | net/proxy/proxy_service.cc | 33 | ||||
-rw-r--r-- | net/proxy/proxy_service.h | 21 |
6 files changed, 93 insertions, 9 deletions
diff --git a/chrome/browser/debugger/debugger_shell.cc b/chrome/browser/debugger/debugger_shell.cc index ec7d6c4..7b1af30 100644 --- a/chrome/browser/debugger/debugger_shell.cc +++ b/chrome/browser/debugger/debugger_shell.cc @@ -35,6 +35,7 @@ DebuggerShell::~DebuggerShell() { io_->Stop(); io_ = NULL; + v8::Locker locked; v8::HandleScope scope; SubshellFunction("exit", 0, NULL); v8::V8::RemoveMessageListeners(&DelegateMessageListener); @@ -46,6 +47,7 @@ DebuggerShell::~DebuggerShell() { void DebuggerShell::Start() { io_->Start(this); + v8::Locker locked; v8::HandleScope scope; v8_this_ = v8::Persistent<v8::External>::New(v8::External::New(this)); @@ -215,6 +217,7 @@ void DebuggerShell::MessageListener(v8::Handle<v8::Message> message) { } void DebuggerShell::Debug(TabContents* tab) { + v8::Locker locked; v8::HandleScope outer; v8::Context::Scope scope(v8_context_); @@ -228,6 +231,7 @@ void DebuggerShell::Debug(TabContents* tab) { } void DebuggerShell::DebugMessage(const std::wstring& msg) { + v8::Locker locked; v8::HandleScope scope; if (msg.length()) { @@ -247,11 +251,13 @@ void DebuggerShell::DebugMessage(const std::wstring& msg) { } void DebuggerShell::OnDebugAttach() { + v8::Locker locked; v8::HandleScope scope; SubshellFunction("on_attach", 0, NULL); } void DebuggerShell::OnDebugDisconnect() { + v8::Locker locked; v8::HandleScope scope; SubshellFunction("on_disconnect", 0, NULL); } @@ -323,6 +329,7 @@ void DebuggerShell::PrintPrompt() { if (!shell_.IsEmpty()) { if (!debugger_ready_) return; + v8::Locker locked; v8::HandleScope outer; v8::Handle<v8::Value> result = CompileAndRun("shell_.prompt()"); if (!result.IsEmpty() && !result->IsUndefined()) { @@ -334,6 +341,7 @@ void DebuggerShell::PrintPrompt() { } void DebuggerShell::ProcessCommand(const std::wstring& data) { + v8::Locker locked; v8::HandleScope outer; v8::Context::Scope scope(v8_context_); if (!shell_.IsEmpty() && data.substr(0, 7) != L"source(") { @@ -375,6 +383,7 @@ void DebuggerShell::LoadUserConfig() { } void DebuggerShell::DidConnect() { + v8::Locker locked; v8::HandleScope outer; v8::Context::Scope scope(v8_context_); @@ -384,6 +393,7 @@ void DebuggerShell::DidConnect() { } void DebuggerShell::DidDisconnect() { + v8::Locker locked; v8::HandleScope outer; SubshellFunction("exit", 0, NULL); } @@ -398,6 +408,7 @@ v8::Handle<v8::Value> DebuggerShell::CompileAndRun( v8::Handle<v8::Value> DebuggerShell::CompileAndRun( const std::wstring& wstr, const std::string& filename) { + v8::Locker locked; v8::Context::Scope scope(v8_context_); v8::Handle<v8::String> scriptname; if (filename.length() > 0) { diff --git a/chrome/browser/net/chrome_url_request_context.cc b/chrome/browser/net/chrome_url_request_context.cc index 748c497..351107a 100644 --- a/chrome/browser/net/chrome_url_request_context.cc +++ b/chrome/browser/net/chrome_url_request_context.cc @@ -21,12 +21,12 @@ #include "net/proxy/proxy_service.h" #include "webkit/glue/webkit_glue.h" -// Sets up proxy info if it was specified, otherwise returns NULL. The -// returned pointer MUST be deleted by the caller if non-NULL. -static net::ProxyInfo* CreateProxyInfo() { +// Sets up proxy info if overrides were specified on the command line. +// Otherwise returns NULL (meaning we should use the system defaults). +// The caller is responsible for deleting returned pointer. +static net::ProxyInfo* CreateProxyInfo(const CommandLine& command_line) { net::ProxyInfo* proxy_info = NULL; - const CommandLine& command_line = *CommandLine::ForCurrentProcess(); if (command_line.HasSwitch(switches::kProxyServer)) { proxy_info = new net::ProxyInfo(); const std::wstring& proxy_server = @@ -37,6 +37,24 @@ static net::ProxyInfo* CreateProxyInfo() { return proxy_info; } +// Create a proxy service according to the options on command line. +static net::ProxyService* CreateProxyService(URLRequestContext* context, + const CommandLine& command_line) { + scoped_ptr<net::ProxyInfo> proxy_info(CreateProxyInfo(command_line)); + + bool use_v8 = command_line.HasSwitch(switches::kV8ProxyResolver); + if (use_v8 && command_line.HasSwitch(switches::kSingleProcess)) { + // See the note about V8 multithreading in net/proxy/proxy_resolver_v8.h + // to understand why we have this limitation. + LOG(ERROR) << "Cannot use V8 Proxy resolver in single process mode."; + use_v8 = false; // Fallback to non-v8 implementation. + } + + return use_v8 ? + net::ProxyService::CreateUsingV8Resolver(proxy_info.get(), context) : + net::ProxyService::Create(proxy_info.get()); +} + // static ChromeURLRequestContext* ChromeURLRequestContext::CreateOriginal( Profile* profile, const FilePath& cookie_store_path, @@ -44,8 +62,8 @@ ChromeURLRequestContext* ChromeURLRequestContext::CreateOriginal( DCHECK(!profile->IsOffTheRecord()); ChromeURLRequestContext* context = new ChromeURLRequestContext(profile); - scoped_ptr<net::ProxyInfo> proxy_info(CreateProxyInfo()); - context->proxy_service_ = net::ProxyService::Create(proxy_info.get()); + context->proxy_service_ = CreateProxyService( + context, *CommandLine::ForCurrentProcess()); net::HttpCache* cache = new net::HttpCache(context->proxy_service_, diff --git a/chrome/common/chrome_switches.cc b/chrome/common/chrome_switches.cc index c4b4512..53c7910 100644 --- a/chrome/common/chrome_switches.cc +++ b/chrome/common/chrome_switches.cc @@ -235,6 +235,12 @@ const wchar_t kMakeDefaultBrowser[] = L"make-default-browser"; // affects HTTP and HTTPS requests. const wchar_t kProxyServer[] = L"proxy-server"; +// Enable alternate proxy autoconfig implementation, which downloads PAC +// scripts internally and executes them using V8 (as opposed to fetching +// and executing using WinHTTP). This cannot be used in conjunction with +// --single-process. +const wchar_t kV8ProxyResolver[] = L"v8-proxy-resolver"; + // Chrome will support prefetching of DNS information. Until this becomes // the default, we'll provide a command line switch. extern const wchar_t kDnsLogDetails[] = L"dns-log-details"; diff --git a/chrome/common/chrome_switches.h b/chrome/common/chrome_switches.h index cce31ad..93841cd 100644 --- a/chrome/common/chrome_switches.h +++ b/chrome/common/chrome_switches.h @@ -78,6 +78,7 @@ extern const wchar_t kShowIcons[]; extern const wchar_t kMakeDefaultBrowser[]; extern const wchar_t kProxyServer[]; +extern const wchar_t kV8ProxyResolver[]; extern const wchar_t kDebugPrint[]; extern const wchar_t kDnsLogDetails[]; diff --git a/net/proxy/proxy_service.cc b/net/proxy/proxy_service.cc index 14b60f6..443a46b 100644 --- a/net/proxy/proxy_service.cc +++ b/net/proxy/proxy_service.cc @@ -21,6 +21,7 @@ #include "net/proxy/proxy_resolver_mac.h" #endif #include "net/proxy/proxy_resolver.h" +#include "net/proxy/proxy_resolver_v8.h" using base::TimeDelta; using base::TimeTicks; @@ -214,6 +215,38 @@ ProxyService* ProxyService::Create(const ProxyInfo* pi) { } // static +ProxyService* ProxyService::CreateUsingV8Resolver( + const ProxyInfo* pi, URLRequestContext* url_request_context) { + if (pi) { + // The ProxyResolver is set to NULL, since it should never be called + // (because the configuration will never require PAC). + return new ProxyService(new ProxyConfigServiceFixed(*pi), NULL); + } + + // Choose the system configuration service appropriate for each platform. + ProxyConfigService* config_service; +#if defined(OS_WIN) + config_service = new ProxyConfigServiceWin(); +#elif defined(OS_MACOSX) + config_service = new ProxyConfigServiceMac(); +#else + // TODO(port): implement ProxyConfigServiceLinux. + // See: http://code.google.com/p/chromium/issues/detail?id=8143 + return CreateNull(); +#endif + + // Create a ProxyService that uses V8 to evaluate PAC scripts. + ProxyService* proxy_service = new ProxyService( + config_service, new ProxyResolverV8()); + + // Configure PAC script downloads to be issued using |url_request_context|. + proxy_service->SetProxyScriptFetcher( + ProxyScriptFetcher::Create(url_request_context)); + + return proxy_service; +} + +// static ProxyService* ProxyService::CreateNull() { // The ProxyResolver is set to NULL, since it should never be called // (because the configuration will never require PAC). diff --git a/net/proxy/proxy_service.h b/net/proxy/proxy_service.h index 21b0e07..cb1fc91 100644 --- a/net/proxy/proxy_service.h +++ b/net/proxy/proxy_service.h @@ -17,6 +17,7 @@ #include "net/proxy/proxy_info.h" class GURL; +class URLRequestContext; namespace net { @@ -80,17 +81,31 @@ class ProxyService { // Call this method with a non-null |pac_request| to cancel the PAC request. void CancelPacRequest(PacRequest* pac_request); - // Set the ProxyScriptFetcher dependency. This is needed if the ProxyResolver + // Sets the ProxyScriptFetcher dependency. This is needed if the ProxyResolver // is of type ProxyResolverWithoutFetch. ProxyService takes ownership of // |proxy_script_fetcher|. void SetProxyScriptFetcher(ProxyScriptFetcher* proxy_script_fetcher); - // Create a proxy service using the specified settings. If |pi| is NULL then + // Creates a proxy service using the specified settings. If |pi| is NULL then // the system's default proxy settings will be used (on Windows this will // use IE's settings). static ProxyService* Create(const ProxyInfo* pi); - // Create a proxy service that always fails to fetch the proxy configuration, + // Creates a proxy service using the specified settings. If |pi| is NULL then + // the system's default proxy settings will be used. This is basically the + // same as Create(const ProxyInfo*), however under the hood it uses a + // different implementation (V8). |url_request_context| is the URL request + // context that will be used if a PAC script needs to be fetched. + // ########################################################################## + // # See the warnings in net/proxy/proxy_resolver_v8.h describing the + // # multi-threading model. In order for this to be safe to use, *ALL* the + // # other V8's running in the process must use v8::Locker. + // ########################################################################## + static ProxyService* CreateUsingV8Resolver( + const ProxyInfo* pi, + URLRequestContext* url_request_context); + + // Creates a proxy service that always fails to fetch the proxy configuration, // so it falls back to direct connect. static ProxyService* CreateNull(); |