blob: 2b391c4df69f989e44f5614670843bea59b578c9 [file] [log] [blame]
[email protected]3b63f8f42011-03-28 01:54:151// Copyright (c) 2011 The Chromium Authors. All rights reserved.
[email protected]943c8082009-02-23 19:10:452// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Lily Houghton582d4622018-01-22 22:43:405#ifndef NET_PROXY_RESOLUTION_PROXY_RESOLVER_V8_H_
6#define NET_PROXY_RESOLUTION_PROXY_RESOLVER_V8_H_
[email protected]943c8082009-02-23 19:10:457
Avi Drissman13fc8932015-12-20 04:40:468#include <stddef.h>
9
danakj8a98ca22016-04-16 02:47:3610#include <memory>
11
[email protected]c4c1b482011-07-22 17:24:2612#include "base/compiler_specific.h"
Avi Drissman13fc8932015-12-20 04:40:4613#include "base/macros.h"
sammcd2284e52015-05-27 03:14:4614#include "base/memory/ref_counted.h"
sammcd2284e52015-05-27 03:14:4615#include "base/strings/string16.h"
[email protected]172da1b2011-08-12 15:52:2616#include "net/base/net_export.h"
sammcd2284e52015-05-27 03:14:4617
18class GURL;
[email protected]943c8082009-02-23 19:10:4519
20namespace net {
sammcd2284e52015-05-27 03:14:4621class ProxyInfo;
22class ProxyResolverScriptData;
[email protected]943c8082009-02-23 19:10:4523
sammcd2284e52015-05-27 03:14:4624// A synchronous ProxyResolver-like that uses V8 to evaluate PAC scripts.
25class NET_EXPORT_PRIVATE ProxyResolverV8 {
[email protected]943c8082009-02-23 19:10:4526 public:
[email protected]501e2d42013-01-30 22:30:4927 // 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]501e2d42013-01-30 22:30:4935 };
36
37 JSBindings() {}
38
[email protected]501e2d42013-01-30 22:30:4939 // Handler for "dnsResolve()", "dnsResolveEx()", "myIpAddress()",
40 // "myIpAddressEx()". Returns true on success and fills |*output| with the
[email protected]8cdc8812013-02-21 05:29:4941 // 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]501e2d42013-01-30 22:30:4943 virtual bool ResolveDns(const std::string& host,
44 ResolveDnsOperation op,
[email protected]8cdc8812013-02-21 05:29:4945 std::string* output,
46 bool* terminate) = 0;
[email protected]501e2d42013-01-30 22:30:4947
48 // Handler for "alert(message)"
[email protected]42cba2fb2013-03-29 19:58:5749 virtual void Alert(const base::string16& message) = 0;
[email protected]501e2d42013-01-30 22:30:4950
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]42cba2fb2013-03-29 19:58:5753 virtual void OnError(int line_number, const base::string16& error) = 0;
[email protected]8c49a502013-02-01 03:54:1154
55 protected:
56 virtual ~JSBindings() {}
[email protected]501e2d42013-01-30 22:30:4957 };
58
59 // Constructs a ProxyResolverV8.
sammcd2284e52015-05-27 03:14:4660 static int Create(const scoped_refptr<ProxyResolverScriptData>& script_data,
61 JSBindings* bindings,
danakj8a98ca22016-04-16 02:47:3662 std::unique_ptr<ProxyResolverV8>* resolver);
[email protected]50d7d7282009-03-02 21:45:1863
sammcd2284e52015-05-27 03:14:4664 ~ProxyResolverV8();
[email protected]943c8082009-02-23 19:10:4565
sammcd2284e52015-05-27 03:14:4666 int GetProxyForURL(const GURL& url, ProxyInfo* results, JSBindings* bindings);
[email protected]943c8082009-02-23 19:10:4567
scottmg5bf34202017-01-26 05:49:0268 // Get total/used heap memory usage of all v8 instances used by the proxy
[email protected]8f09c54f2013-03-05 11:06:5569 // resolver.
70 static size_t GetTotalHeapSize();
71 static size_t GetUsedHeapSize();
72
[email protected]943c8082009-02-23 19:10:4573 private:
sammcd2284e52015-05-27 03:14:4674 // Context holds the Javascript state for the PAC script.
[email protected]943c8082009-02-23 19:10:4575 class Context;
[email protected]501e2d42013-01-30 22:30:4976
danakj8a98ca22016-04-16 02:47:3677 explicit ProxyResolverV8(std::unique_ptr<Context> context);
[email protected]943c8082009-02-23 19:10:4578
danakj8a98ca22016-04-16 02:47:3679 std::unique_ptr<Context> context_;
[email protected]50d7d7282009-03-02 21:45:1880
[email protected]943c8082009-02-23 19:10:4581 DISALLOW_COPY_AND_ASSIGN(ProxyResolverV8);
82};
83
[email protected]943c8082009-02-23 19:10:4584} // namespace net
85
Lily Houghton582d4622018-01-22 22:43:4086#endif // NET_PROXY_RESOLUTION_PROXY_RESOLVER_V8_H_