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