[email protected] | 82a3767 | 2011-05-03 12:02:41 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
[email protected] | 90ae1fb | 2009-08-02 21:07:12 | [diff] [blame] | 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] | 32b76ef | 2010-07-26 23:08:24 | [diff] [blame] | 7 | #pragma once |
[email protected] | 90ae1fb | 2009-08-02 21:07:12 | [diff] [blame] | 8 | |
9 | #include <string> | ||||
10 | |||||
[email protected] | 51e413c | 2010-06-23 00:15:58 | [diff] [blame] | 11 | #include "base/string16.h" |
[email protected] | f4ffb7a | 2011-05-19 21:23:00 | [diff] [blame] | 12 | #include "net/base/net_api.h" |
[email protected] | 51e413c | 2010-06-23 00:15:58 | [diff] [blame] | 13 | |
[email protected] | 90ae1fb | 2009-08-02 21:07:12 | [diff] [blame] | 14 | namespace net { |
15 | |||||
16 | class HostResolver; | ||||
[email protected] | 72b4a77 | 2010-07-14 01:29:30 | [diff] [blame] | 17 | class NetLog; |
[email protected] | 82a3767 | 2011-05-03 12:02:41 | [diff] [blame] | 18 | class ProxyResolverErrorObserver; |
[email protected] | 59872eb | 2010-06-22 18:56:12 | [diff] [blame] | 19 | struct ProxyResolverRequestContext; |
[email protected] | 90ae1fb | 2009-08-02 21:07:12 | [diff] [blame] | 20 | |
21 | // Interface for the javascript bindings. | ||||
[email protected] | f4ffb7a | 2011-05-19 21:23:00 | [diff] [blame] | 22 | class NET_TEST ProxyResolverJSBindings { |
[email protected] | 90ae1fb | 2009-08-02 21:07:12 | [diff] [blame] | 23 | public: |
[email protected] | 59872eb | 2010-06-22 18:56:12 | [diff] [blame] | 24 | ProxyResolverJSBindings() : current_request_context_(NULL) {} |
25 | |||||
[email protected] | 90ae1fb | 2009-08-02 21:07:12 | [diff] [blame] | 26 | virtual ~ProxyResolverJSBindings() {} |
27 | |||||
28 | // Handler for "alert(message)" | ||||
[email protected] | 51e413c | 2010-06-23 00:15:58 | [diff] [blame] | 29 | virtual void Alert(const string16& message) = 0; |
[email protected] | 90ae1fb | 2009-08-02 21:07:12 | [diff] [blame] | 30 | |
[email protected] | 51e413c | 2010-06-23 00:15:58 | [diff] [blame] | 31 | // Handler for "myIpAddress()". Returns true on success and fills |
32 | // |*first_ip_address| with the result. | ||||
33 | virtual bool MyIpAddress(std::string* first_ip_address) = 0; | ||||
[email protected] | 90ae1fb | 2009-08-02 21:07:12 | [diff] [blame] | 34 | |
[email protected] | 51e413c | 2010-06-23 00:15:58 | [diff] [blame] | 35 | // Handler for "myIpAddressEx()". Returns true on success and fills |
36 | // |*ip_address_list| with the result. | ||||
[email protected] | 21f20c89 | 2009-10-26 23:51:28 | [diff] [blame] | 37 | // |
38 | // This is a Microsoft extension to PAC for IPv6, see: | ||||
[email protected] | a37b8bb | 2010-08-26 23:31:00 | [diff] [blame] | 39 | // http://blogs.msdn.com/b/wndp/archive/2006/07/13/ipv6-pac-extensions-v0-9.aspx |
40 | |||||
[email protected] | 51e413c | 2010-06-23 00:15:58 | [diff] [blame] | 41 | virtual bool MyIpAddressEx(std::string* ip_address_list) = 0; |
[email protected] | 21f20c89 | 2009-10-26 23:51:28 | [diff] [blame] | 42 | |
[email protected] | 51e413c | 2010-06-23 00:15:58 | [diff] [blame] | 43 | // Handler for "dnsResolve(host)". Returns true on success and fills |
44 | // |*first_ip_address| with the result. | ||||
45 | virtual bool DnsResolve(const std::string& host, | ||||
46 | std::string* first_ip_address) = 0; | ||||
[email protected] | 90ae1fb | 2009-08-02 21:07:12 | [diff] [blame] | 47 | |
[email protected] | 51e413c | 2010-06-23 00:15:58 | [diff] [blame] | 48 | // Handler for "dnsResolveEx(host)". Returns true on success and fills |
49 | // |*ip_address_list| with the result. | ||||
[email protected] | 21f20c89 | 2009-10-26 23:51:28 | [diff] [blame] | 50 | // |
51 | // This is a Microsoft extension to PAC for IPv6, see: | ||||
[email protected] | a37b8bb | 2010-08-26 23:31:00 | [diff] [blame] | 52 | // http://blogs.msdn.com/b/wndp/archive/2006/07/13/ipv6-pac-extensions-v0-9.aspx |
[email protected] | 51e413c | 2010-06-23 00:15:58 | [diff] [blame] | 53 | virtual bool DnsResolveEx(const std::string& host, |
54 | std::string* ip_address_list) = 0; | ||||
[email protected] | 21f20c89 | 2009-10-26 23:51:28 | [diff] [blame] | 55 | |
[email protected] | 90ae1fb | 2009-08-02 21:07:12 | [diff] [blame] | 56 | // Handler for when an error is encountered. |line_number| may be -1 |
57 | // if a line number is not applicable to this error. | ||||
[email protected] | 51e413c | 2010-06-23 00:15:58 | [diff] [blame] | 58 | virtual void OnError(int line_number, const string16& error) = 0; |
[email protected] | 90ae1fb | 2009-08-02 21:07:12 | [diff] [blame] | 59 | |
[email protected] | 61b84d5 | 2010-07-09 03:32:00 | [diff] [blame] | 60 | // Called before the thread running the proxy resolver is stopped. |
61 | virtual void Shutdown() = 0; | ||||
62 | |||||
[email protected] | 90ae1fb | 2009-08-02 21:07:12 | [diff] [blame] | 63 | // Creates a default javascript bindings implementation that will: |
[email protected] | b30a3f5 | 2010-10-16 01:05:46 | [diff] [blame] | 64 | // - Send script error messages to both VLOG(1) and the NetLog. |
65 | // - Send script alert()s to both VLOG(1) and the NetLog. | ||||
[email protected] | 90ae1fb | 2009-08-02 21:07:12 | [diff] [blame] | 66 | // - Use the provided host resolver to service dnsResolve(). |
67 | // | ||||
[email protected] | 1ca2b45 | 2010-04-17 00:07:04 | [diff] [blame] | 68 | // Note that |host_resolver| will be used in sync mode mode. |
[email protected] | 82a3767 | 2011-05-03 12:02:41 | [diff] [blame] | 69 | // Takes ownership of |error_observer| which might be NULL. |
70 | static ProxyResolverJSBindings* CreateDefault( | ||||
71 | HostResolver* host_resolver, | ||||
72 | NetLog* net_log, | ||||
73 | ProxyResolverErrorObserver* error_observer); | ||||
[email protected] | 59872eb | 2010-06-22 18:56:12 | [diff] [blame] | 74 | |
75 | // Sets details about the currently executing FindProxyForURL() request. | ||||
76 | void set_current_request_context( | ||||
77 | ProxyResolverRequestContext* current_request_context) { | ||||
78 | current_request_context_ = current_request_context; | ||||
79 | } | ||||
80 | |||||
81 | // Retrieves details about the currently executing FindProxyForURL() request. | ||||
82 | ProxyResolverRequestContext* current_request_context() { | ||||
83 | return current_request_context_; | ||||
84 | } | ||||
85 | |||||
86 | private: | ||||
87 | ProxyResolverRequestContext* current_request_context_; | ||||
[email protected] | 90ae1fb | 2009-08-02 21:07:12 | [diff] [blame] | 88 | }; |
89 | |||||
90 | } // namespace net | ||||
91 | |||||
[email protected] | 59872eb | 2010-06-22 18:56:12 | [diff] [blame] | 92 | #endif // NET_PROXY_PROXY_RESOLVER_JS_BINDINGS_H_ |