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