| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef NET_PROXY_PROXY_RESOLVER_V8_H_ | 5 #ifndef NET_PROXY_PROXY_RESOLVER_V8_H_ |
| 6 #define NET_PROXY_PROXY_RESOLVER_V8_H_ | 6 #define NET_PROXY_PROXY_RESOLVER_V8_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/scoped_ptr.h" | 10 #include "base/scoped_ptr.h" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 // and does not use locking since it expects to be alone. | 36 // and does not use locking since it expects to be alone. |
| 37 class ProxyResolverV8 : public ProxyResolver { | 37 class ProxyResolverV8 : public ProxyResolver { |
| 38 public: | 38 public: |
| 39 class JSBindings; | 39 class JSBindings; |
| 40 | 40 |
| 41 // Constructs a ProxyResolverV8 with custom bindings. ProxyResolverV8 takes | 41 // Constructs a ProxyResolverV8 with custom bindings. ProxyResolverV8 takes |
| 42 // ownership of |custom_js_bindings| and deletes it when ProxyResolverV8 | 42 // ownership of |custom_js_bindings| and deletes it when ProxyResolverV8 |
| 43 // is destroyed. | 43 // is destroyed. |
| 44 explicit ProxyResolverV8(JSBindings* custom_js_bindings); | 44 explicit ProxyResolverV8(JSBindings* custom_js_bindings); |
| 45 | 45 |
| 46 ~ProxyResolverV8(); | 46 virtual ~ProxyResolverV8(); |
| 47 | 47 |
| 48 // ProxyResolver implementation: | 48 // ProxyResolver implementation: |
| 49 virtual int GetProxyForURL(const GURL& query_url, | 49 virtual int GetProxyForURL(const GURL& url, |
| 50 const GURL& /*pac_url*/, | 50 ProxyInfo* results, |
| 51 ProxyInfo* results); | 51 CompletionCallback* /*callback*/, |
| 52 virtual void SetPacScript(const std::string& bytes); | 52 RequestHandle* /*request*/); |
| 53 virtual void CancelRequest(RequestHandle request); |
| 53 | 54 |
| 54 JSBindings* js_bindings() const { return js_bindings_.get(); } | 55 JSBindings* js_bindings() const { return js_bindings_.get(); } |
| 55 | 56 |
| 56 // Creates a default javascript bindings implementation that will: | 57 // Creates a default javascript bindings implementation that will: |
| 57 // - Send script error messages to LOG(INFO) | 58 // - Send script error messages to LOG(INFO) |
| 58 // - Send script alert()s to LOG(INFO) | 59 // - Send script alert()s to LOG(INFO) |
| 59 // - Use the provided host resolver to service dnsResolve(). | 60 // - Use the provided host resolver to service dnsResolve(). |
| 60 // | 61 // |
| 61 // For clients that need more control (for example, sending the script output | 62 // For clients that need more control (for example, sending the script output |
| 62 // to a UI widget), use the ProxyResolverV8(JSBindings*) and specify your | 63 // to a UI widget), use the ProxyResolverV8(JSBindings*) and specify your |
| 63 // own bindings. | 64 // own bindings. |
| 64 // | 65 // |
| 65 // |host_resolver| will be used in async mode on |host_resolver_loop|. If | 66 // |host_resolver| will be used in async mode on |host_resolver_loop|. If |
| 66 // |host_resolver_loop| is NULL, then |host_resolver| will be used in sync | 67 // |host_resolver_loop| is NULL, then |host_resolver| will be used in sync |
| 67 // mode on the PAC thread. | 68 // mode on the PAC thread. |
| 68 static JSBindings* CreateDefaultBindings(HostResolver* host_resolver, | 69 static JSBindings* CreateDefaultBindings(HostResolver* host_resolver, |
| 69 MessageLoop* host_resolver_loop); | 70 MessageLoop* host_resolver_loop); |
| 70 | 71 |
| 71 private: | 72 private: |
| 72 // Context holds the Javascript state for the most recently loaded PAC | 73 // Context holds the Javascript state for the most recently loaded PAC |
| 73 // script. It corresponds with the data from the last call to | 74 // script. It corresponds with the data from the last call to |
| 74 // SetPacScript(). | 75 // SetPacScriptByDataInternal(). |
| 75 class Context; | 76 class Context; |
| 77 |
| 78 // ProxyResolver implementation: |
| 79 virtual void SetPacScriptByDataInternal(const std::string& bytes); |
| 80 |
| 76 scoped_ptr<Context> context_; | 81 scoped_ptr<Context> context_; |
| 77 | 82 |
| 78 scoped_ptr<JSBindings> js_bindings_; | 83 scoped_ptr<JSBindings> js_bindings_; |
| 79 | 84 |
| 80 DISALLOW_COPY_AND_ASSIGN(ProxyResolverV8); | 85 DISALLOW_COPY_AND_ASSIGN(ProxyResolverV8); |
| 81 }; | 86 }; |
| 82 | 87 |
| 83 // Interface for the javascript bindings. | 88 // Interface for the javascript bindings. |
| 84 class ProxyResolverV8::JSBindings { | 89 class ProxyResolverV8::JSBindings { |
| 85 public: | 90 public: |
| 86 virtual ~JSBindings() {} | 91 virtual ~JSBindings() {} |
| 87 | 92 |
| 88 // Handler for "alert(message)" | 93 // Handler for "alert(message)" |
| 89 virtual void Alert(const std::string& message) = 0; | 94 virtual void Alert(const std::string& message) = 0; |
| 90 | 95 |
| 91 // Handler for "myIpAddress()". Returns empty string on failure. | 96 // Handler for "myIpAddress()". Returns empty string on failure. |
| 92 virtual std::string MyIpAddress() = 0; | 97 virtual std::string MyIpAddress() = 0; |
| 93 | 98 |
| 94 // Handler for "dnsResolve(host)". Returns empty string on failure. | 99 // Handler for "dnsResolve(host)". Returns empty string on failure. |
| 95 virtual std::string DnsResolve(const std::string& host) = 0; | 100 virtual std::string DnsResolve(const std::string& host) = 0; |
| 96 | 101 |
| 97 // Handler for when an error is encountered. |line_number| may be -1 | 102 // Handler for when an error is encountered. |line_number| may be -1 |
| 98 // if a line number is not applicable to this error. | 103 // if a line number is not applicable to this error. |
| 99 virtual void OnError(int line_number, const std::string& error) = 0; | 104 virtual void OnError(int line_number, const std::string& error) = 0; |
| 100 }; | 105 }; |
| 101 | 106 |
| 102 } // namespace net | 107 } // namespace net |
| 103 | 108 |
| 104 #endif // NET_PROXY_PROXY_RESOLVER_V8_H_ | 109 #endif // NET_PROXY_PROXY_RESOLVER_V8_H_ |
| OLD | NEW |