[email protected] | 90ae1fb | 2009-08-02 21:07:12 | [diff] [blame] | 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 | ||||
3 | // found in the LICENSE file. | ||||
4 | |||||
[email protected] | 59872eb | 2010-06-22 18:56:12 | [diff] [blame] | 5 | #ifndef NET_PROXY_PROXY_RESOLVER_JS_BINDINGS_H_ |
6 | #define NET_PROXY_PROXY_RESOLVER_JS_BINDINGS_H_ | ||||
[email protected] | 90ae1fb | 2009-08-02 21:07:12 | [diff] [blame] | 7 | |
8 | #include <string> | ||||
9 | |||||
[email protected] | 51e413c | 2010-06-23 00:15:58 | [diff] [blame^] | 10 | #include "base/string16.h" |
11 | |||||
[email protected] | 90ae1fb | 2009-08-02 21:07:12 | [diff] [blame] | 12 | class MessageLoop; |
13 | |||||
14 | namespace net { | ||||
15 | |||||
16 | class HostResolver; | ||||
[email protected] | 59872eb | 2010-06-22 18:56:12 | [diff] [blame] | 17 | struct ProxyResolverRequestContext; |
[email protected] | 90ae1fb | 2009-08-02 21:07:12 | [diff] [blame] | 18 | |
19 | // Interface for the javascript bindings. | ||||
20 | class ProxyResolverJSBindings { | ||||
21 | public: | ||||
[email protected] | 59872eb | 2010-06-22 18:56:12 | [diff] [blame] | 22 | ProxyResolverJSBindings() : current_request_context_(NULL) {} |
23 | |||||
[email protected] | 90ae1fb | 2009-08-02 21:07:12 | [diff] [blame] | 24 | virtual ~ProxyResolverJSBindings() {} |
25 | |||||
26 | // Handler for "alert(message)" | ||||
[email protected] | 51e413c | 2010-06-23 00:15:58 | [diff] [blame^] | 27 | virtual void Alert(const string16& message) = 0; |
[email protected] | 90ae1fb | 2009-08-02 21:07:12 | [diff] [blame] | 28 | |
[email protected] | 51e413c | 2010-06-23 00:15:58 | [diff] [blame^] | 29 | // Handler for "myIpAddress()". Returns true on success and fills |
30 | // |*first_ip_address| with the result. | ||||
31 | virtual bool MyIpAddress(std::string* first_ip_address) = 0; | ||||
[email protected] | 90ae1fb | 2009-08-02 21:07:12 | [diff] [blame] | 32 | |
[email protected] | 51e413c | 2010-06-23 00:15:58 | [diff] [blame^] | 33 | // Handler for "myIpAddressEx()". Returns true on success and fills |
34 | // |*ip_address_list| with the result. | ||||
[email protected] | 21f20c89 | 2009-10-26 23:51:28 | [diff] [blame] | 35 | // |
36 | // This is a Microsoft extension to PAC for IPv6, see: | ||||
37 | // http://blogs.msdn.com/wndp/articles/IPV6_PAC_Extensions_v0_9.aspx | ||||
[email protected] | 51e413c | 2010-06-23 00:15:58 | [diff] [blame^] | 38 | virtual bool MyIpAddressEx(std::string* ip_address_list) = 0; |
[email protected] | 21f20c89 | 2009-10-26 23:51:28 | [diff] [blame] | 39 | |
[email protected] | 51e413c | 2010-06-23 00:15:58 | [diff] [blame^] | 40 | // Handler for "dnsResolve(host)". Returns true on success and fills |
41 | // |*first_ip_address| with the result. | ||||
42 | virtual bool DnsResolve(const std::string& host, | ||||
43 | std::string* first_ip_address) = 0; | ||||
[email protected] | 90ae1fb | 2009-08-02 21:07:12 | [diff] [blame] | 44 | |
[email protected] | 51e413c | 2010-06-23 00:15:58 | [diff] [blame^] | 45 | // Handler for "dnsResolveEx(host)". Returns true on success and fills |
46 | // |*ip_address_list| with the result. | ||||
[email protected] | 21f20c89 | 2009-10-26 23:51:28 | [diff] [blame] | 47 | // |
48 | // This is a Microsoft extension to PAC for IPv6, see: | ||||
49 | // http://blogs.msdn.com/wndp/articles/IPV6_PAC_Extensions_v0_9.aspx | ||||
[email protected] | 51e413c | 2010-06-23 00:15:58 | [diff] [blame^] | 50 | virtual bool DnsResolveEx(const std::string& host, |
51 | std::string* ip_address_list) = 0; | ||||
[email protected] | 21f20c89 | 2009-10-26 23:51:28 | [diff] [blame] | 52 | |
[email protected] | 90ae1fb | 2009-08-02 21:07:12 | [diff] [blame] | 53 | // Handler for when an error is encountered. |line_number| may be -1 |
54 | // if a line number is not applicable to this error. | ||||
[email protected] | 51e413c | 2010-06-23 00:15:58 | [diff] [blame^] | 55 | virtual void OnError(int line_number, const string16& error) = 0; |
[email protected] | 90ae1fb | 2009-08-02 21:07:12 | [diff] [blame] | 56 | |
57 | // Creates a default javascript bindings implementation that will: | ||||
58 | // - Send script error messages to LOG(INFO) | ||||
59 | // - Send script alert()s to LOG(INFO) | ||||
60 | // - Use the provided host resolver to service dnsResolve(). | ||||
61 | // | ||||
[email protected] | 1ca2b45 | 2010-04-17 00:07:04 | [diff] [blame] | 62 | // Note that |host_resolver| will be used in sync mode mode. |
63 | static ProxyResolverJSBindings* CreateDefault(HostResolver* host_resolver); | ||||
[email protected] | 59872eb | 2010-06-22 18:56:12 | [diff] [blame] | 64 | |
65 | // Sets details about the currently executing FindProxyForURL() request. | ||||
66 | void set_current_request_context( | ||||
67 | ProxyResolverRequestContext* current_request_context) { | ||||
68 | current_request_context_ = current_request_context; | ||||
69 | } | ||||
70 | |||||
71 | // Retrieves details about the currently executing FindProxyForURL() request. | ||||
72 | ProxyResolverRequestContext* current_request_context() { | ||||
73 | return current_request_context_; | ||||
74 | } | ||||
75 | |||||
76 | private: | ||||
77 | ProxyResolverRequestContext* current_request_context_; | ||||
[email protected] | 90ae1fb | 2009-08-02 21:07:12 | [diff] [blame] | 78 | }; |
79 | |||||
80 | } // namespace net | ||||
81 | |||||
[email protected] | 59872eb | 2010-06-22 18:56:12 | [diff] [blame] | 82 | #endif // NET_PROXY_PROXY_RESOLVER_JS_BINDINGS_H_ |