[email protected] | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
[email protected] | 943c808 | 2009-02-23 19:10:45 | [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 | |
| 5 | #ifndef NET_PROXY_PROXY_RESOLVER_V8_H_ |
| 6 | #define NET_PROXY_PROXY_RESOLVER_V8_H_ |
| 7 | |
[email protected] | c4c1b48 | 2011-07-22 17:24:26 | [diff] [blame] | 8 | #include "base/compiler_specific.h" |
sammc | d2284e5 | 2015-05-27 03:14:46 | [diff] [blame^] | 9 | #include "base/memory/ref_counted.h" |
[email protected] | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame] | 10 | #include "base/memory/scoped_ptr.h" |
sammc | d2284e5 | 2015-05-27 03:14:46 | [diff] [blame^] | 11 | #include "base/strings/string16.h" |
[email protected] | 172da1b | 2011-08-12 15:52:26 | [diff] [blame] | 12 | #include "net/base/net_export.h" |
sammc | d2284e5 | 2015-05-27 03:14:46 | [diff] [blame^] | 13 | |
| 14 | class GURL; |
[email protected] | 943c808 | 2009-02-23 19:10:45 | [diff] [blame] | 15 | |
| 16 | namespace net { |
sammc | d2284e5 | 2015-05-27 03:14:46 | [diff] [blame^] | 17 | class ProxyInfo; |
| 18 | class ProxyResolverScriptData; |
[email protected] | 943c808 | 2009-02-23 19:10:45 | [diff] [blame] | 19 | |
sammc | d2284e5 | 2015-05-27 03:14:46 | [diff] [blame^] | 20 | // A synchronous ProxyResolver-like that uses V8 to evaluate PAC scripts. |
| 21 | class NET_EXPORT_PRIVATE ProxyResolverV8 { |
[email protected] | 943c808 | 2009-02-23 19:10:45 | [diff] [blame] | 22 | public: |
[email protected] | 501e2d4 | 2013-01-30 22:30:49 | [diff] [blame] | 23 | // Interface for the javascript bindings. |
| 24 | class NET_EXPORT_PRIVATE JSBindings { |
| 25 | public: |
| 26 | enum ResolveDnsOperation { |
| 27 | DNS_RESOLVE, |
| 28 | DNS_RESOLVE_EX, |
| 29 | MY_IP_ADDRESS, |
| 30 | MY_IP_ADDRESS_EX, |
[email protected] | 501e2d4 | 2013-01-30 22:30:49 | [diff] [blame] | 31 | }; |
| 32 | |
| 33 | JSBindings() {} |
| 34 | |
[email protected] | 501e2d4 | 2013-01-30 22:30:49 | [diff] [blame] | 35 | // Handler for "dnsResolve()", "dnsResolveEx()", "myIpAddress()", |
| 36 | // "myIpAddressEx()". Returns true on success and fills |*output| with the |
[email protected] | 8cdc881 | 2013-02-21 05:29:49 | [diff] [blame] | 37 | // result. If |*terminate| is set to true, then the script execution will |
| 38 | // be aborted. Note that termination may not happen right away. |
[email protected] | 501e2d4 | 2013-01-30 22:30:49 | [diff] [blame] | 39 | virtual bool ResolveDns(const std::string& host, |
| 40 | ResolveDnsOperation op, |
[email protected] | 8cdc881 | 2013-02-21 05:29:49 | [diff] [blame] | 41 | std::string* output, |
| 42 | bool* terminate) = 0; |
[email protected] | 501e2d4 | 2013-01-30 22:30:49 | [diff] [blame] | 43 | |
| 44 | // Handler for "alert(message)" |
[email protected] | 42cba2fb | 2013-03-29 19:58:57 | [diff] [blame] | 45 | virtual void Alert(const base::string16& message) = 0; |
[email protected] | 501e2d4 | 2013-01-30 22:30:49 | [diff] [blame] | 46 | |
| 47 | // Handler for when an error is encountered. |line_number| may be -1 |
| 48 | // if a line number is not applicable to this error. |
[email protected] | 42cba2fb | 2013-03-29 19:58:57 | [diff] [blame] | 49 | virtual void OnError(int line_number, const base::string16& error) = 0; |
[email protected] | 8c49a50 | 2013-02-01 03:54:11 | [diff] [blame] | 50 | |
| 51 | protected: |
| 52 | virtual ~JSBindings() {} |
[email protected] | 501e2d4 | 2013-01-30 22:30:49 | [diff] [blame] | 53 | }; |
| 54 | |
| 55 | // Constructs a ProxyResolverV8. |
sammc | d2284e5 | 2015-05-27 03:14:46 | [diff] [blame^] | 56 | static int Create(const scoped_refptr<ProxyResolverScriptData>& script_data, |
| 57 | JSBindings* bindings, |
| 58 | scoped_ptr<ProxyResolverV8>* resolver); |
[email protected] | 50d7d728 | 2009-03-02 21:45:18 | [diff] [blame] | 59 | |
sammc | d2284e5 | 2015-05-27 03:14:46 | [diff] [blame^] | 60 | ~ProxyResolverV8(); |
[email protected] | 943c808 | 2009-02-23 19:10:45 | [diff] [blame] | 61 | |
sammc | d2284e5 | 2015-05-27 03:14:46 | [diff] [blame^] | 62 | int GetProxyForURL(const GURL& url, ProxyInfo* results, JSBindings* bindings); |
[email protected] | 943c808 | 2009-02-23 19:10:45 | [diff] [blame] | 63 | |
[email protected] | 8f09c54f | 2013-03-05 11:06:55 | [diff] [blame] | 64 | // Get total/ued heap memory usage of all v8 instances used by the proxy |
| 65 | // resolver. |
| 66 | static size_t GetTotalHeapSize(); |
| 67 | static size_t GetUsedHeapSize(); |
| 68 | |
[email protected] | 943c808 | 2009-02-23 19:10:45 | [diff] [blame] | 69 | private: |
sammc | d2284e5 | 2015-05-27 03:14:46 | [diff] [blame^] | 70 | // Context holds the Javascript state for the PAC script. |
[email protected] | 943c808 | 2009-02-23 19:10:45 | [diff] [blame] | 71 | class Context; |
[email protected] | 501e2d4 | 2013-01-30 22:30:49 | [diff] [blame] | 72 | |
sammc | d2284e5 | 2015-05-27 03:14:46 | [diff] [blame^] | 73 | explicit ProxyResolverV8(scoped_ptr<Context> context); |
[email protected] | 943c808 | 2009-02-23 19:10:45 | [diff] [blame] | 74 | |
sammc | d2284e5 | 2015-05-27 03:14:46 | [diff] [blame^] | 75 | scoped_ptr<Context> context_; |
[email protected] | 50d7d728 | 2009-03-02 21:45:18 | [diff] [blame] | 76 | |
[email protected] | 943c808 | 2009-02-23 19:10:45 | [diff] [blame] | 77 | DISALLOW_COPY_AND_ASSIGN(ProxyResolverV8); |
| 78 | }; |
| 79 | |
[email protected] | 943c808 | 2009-02-23 19:10:45 | [diff] [blame] | 80 | } // namespace net |
| 81 | |
| 82 | #endif // NET_PROXY_PROXY_RESOLVER_V8_H_ |