| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this |
| 2 // source code is governed by a BSD-style license that can be found in the | 2 // source code is governed by a BSD-style license that can be found in the |
| 3 // LICENSE file. | 3 // LICENSE file. |
| 4 | 4 |
| 5 #include "net/proxy/proxy_resolver_v8.h" | 5 #include "net/proxy/proxy_resolver_v8.h" |
| 6 | 6 |
| 7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/waitable_event.h" | 10 #include "base/waitable_event.h" |
| (...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 337 | 337 |
| 338 JSBindings* js_bindings_; | 338 JSBindings* js_bindings_; |
| 339 v8::Persistent<v8::External> v8_this_; | 339 v8::Persistent<v8::External> v8_this_; |
| 340 v8::Persistent<v8::Context> v8_context_; | 340 v8::Persistent<v8::Context> v8_context_; |
| 341 }; | 341 }; |
| 342 | 342 |
| 343 // ProxyResolverV8 ------------------------------------------------------------ | 343 // ProxyResolverV8 ------------------------------------------------------------ |
| 344 | 344 |
| 345 ProxyResolverV8::ProxyResolverV8( | 345 ProxyResolverV8::ProxyResolverV8( |
| 346 ProxyResolverV8::JSBindings* custom_js_bindings) | 346 ProxyResolverV8::JSBindings* custom_js_bindings) |
| 347 : ProxyResolver(false), js_bindings_(custom_js_bindings) { | 347 : ProxyResolver(true /*expects_pac_bytes*/), |
| 348 js_bindings_(custom_js_bindings) { |
| 348 } | 349 } |
| 349 | 350 |
| 350 ProxyResolverV8::~ProxyResolverV8() {} | 351 ProxyResolverV8::~ProxyResolverV8() {} |
| 351 | 352 |
| 352 int ProxyResolverV8::GetProxyForURL(const GURL& query_url, | 353 int ProxyResolverV8::GetProxyForURL(const GURL& query_url, |
| 353 const GURL& /*pac_url*/, | 354 ProxyInfo* results, |
| 354 ProxyInfo* results) { | 355 CompletionCallback* /*callback*/, |
| 355 // If the V8 instance has not been initialized (either because SetPacScript() | 356 RequestHandle* /*request*/) { |
| 356 // wasn't called yet, or because it was called with empty string). | 357 // If the V8 instance has not been initialized (either because |
| 358 // SetPacScriptByData() wasn't called yet, or because it was called with |
| 359 // empty string). |
| 357 if (!context_.get()) | 360 if (!context_.get()) |
| 358 return ERR_FAILED; | 361 return ERR_FAILED; |
| 359 | 362 |
| 360 // Otherwise call into V8. | 363 // Otherwise call into V8. |
| 361 return context_->ResolveProxy(query_url, results); | 364 return context_->ResolveProxy(query_url, results); |
| 362 } | 365 } |
| 363 | 366 |
| 364 void ProxyResolverV8::SetPacScript(const std::string& data) { | 367 void ProxyResolverV8::CancelRequest(RequestHandle request) { |
| 365 context_.reset(); | 368 // This is a synchronous ProxyResolver; no possibility for async requests. |
| 366 if (!data.empty()) | 369 NOTREACHED(); |
| 367 context_.reset(new Context(js_bindings_.get(), data)); | |
| 368 } | 370 } |
| 369 | 371 |
| 370 // static | 372 // static |
| 371 ProxyResolverV8::JSBindings* ProxyResolverV8::CreateDefaultBindings( | 373 ProxyResolverV8::JSBindings* ProxyResolverV8::CreateDefaultBindings( |
| 372 HostResolver* host_resolver, MessageLoop* host_resolver_loop) { | 374 HostResolver* host_resolver, MessageLoop* host_resolver_loop) { |
| 373 return new DefaultJSBindings(host_resolver, host_resolver_loop); | 375 return new DefaultJSBindings(host_resolver, host_resolver_loop); |
| 374 } | 376 } |
| 375 | 377 |
| 378 void ProxyResolverV8::SetPacScriptByDataInternal(const std::string& data) { |
| 379 context_.reset(); |
| 380 if (!data.empty()) |
| 381 context_.reset(new Context(js_bindings_.get(), data)); |
| 382 } |
| 383 |
| 376 } // namespace net | 384 } // namespace net |
| OLD | NEW |