blob: da55956b7c1b23578b5ac0abcbfb333ba2b3e8f7 [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"
Eric Orthfa19a832019-02-13 20:04:5017#include "net/proxy_resolution/proxy_resolve_dns_operation.h"
sammcd2284e52015-05-27 03:14:4618
19class GURL;
[email protected]943c8082009-02-23 19:10:4520
21namespace net {
sammcd2284e52015-05-27 03:14:4622class ProxyInfo;
Lily Houghton99597862018-03-07 16:40:4223class PacFileData;
[email protected]943c8082009-02-23 19:10:4524
sammcd2284e52015-05-27 03:14:4625// A synchronous ProxyResolver-like that uses V8 to evaluate PAC scripts.
26class NET_EXPORT_PRIVATE ProxyResolverV8 {
[email protected]943c8082009-02-23 19:10:4527 public:
[email protected]501e2d42013-01-30 22:30:4928 // Interface for the javascript bindings.
29 class NET_EXPORT_PRIVATE JSBindings {
30 public:
[email protected]501e2d42013-01-30 22:30:4931 JSBindings() {}
32
[email protected]501e2d42013-01-30 22:30:4933 // Handler for "dnsResolve()", "dnsResolveEx()", "myIpAddress()",
34 // "myIpAddressEx()". Returns true on success and fills |*output| with the
[email protected]8cdc8812013-02-21 05:29:4935 // 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]501e2d42013-01-30 22:30:4937 virtual bool ResolveDns(const std::string& host,
Eric Orthfa19a832019-02-13 20:04:5038 ProxyResolveDnsOperation op,
[email protected]8cdc8812013-02-21 05:29:4939 std::string* output,
40 bool* terminate) = 0;
[email protected]501e2d42013-01-30 22:30:4941
42 // Handler for "alert(message)"
[email protected]42cba2fb2013-03-29 19:58:5743 virtual void Alert(const base::string16& message) = 0;
[email protected]501e2d42013-01-30 22:30:4944
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]42cba2fb2013-03-29 19:58:5747 virtual void OnError(int line_number, const base::string16& error) = 0;
[email protected]8c49a502013-02-01 03:54:1148
49 protected:
50 virtual ~JSBindings() {}
[email protected]501e2d42013-01-30 22:30:4951 };
52
53 // Constructs a ProxyResolverV8.
Lily Houghton99597862018-03-07 16:40:4254 static int Create(const scoped_refptr<PacFileData>& script_data,
sammcd2284e52015-05-27 03:14:4655 JSBindings* bindings,
danakj8a98ca22016-04-16 02:47:3656 std::unique_ptr<ProxyResolverV8>* resolver);
[email protected]50d7d7282009-03-02 21:45:1857
sammcd2284e52015-05-27 03:14:4658 ~ProxyResolverV8();
[email protected]943c8082009-02-23 19:10:4559
sammcd2284e52015-05-27 03:14:4660 int GetProxyForURL(const GURL& url, ProxyInfo* results, JSBindings* bindings);
[email protected]943c8082009-02-23 19:10:4561
scottmg5bf34202017-01-26 05:49:0262 // Get total/used heap memory usage of all v8 instances used by the proxy
[email protected]8f09c54f2013-03-05 11:06:5563 // resolver.
64 static size_t GetTotalHeapSize();
65 static size_t GetUsedHeapSize();
66
[email protected]943c8082009-02-23 19:10:4567 private:
sammcd2284e52015-05-27 03:14:4668 // Context holds the Javascript state for the PAC script.
[email protected]943c8082009-02-23 19:10:4569 class Context;
[email protected]501e2d42013-01-30 22:30:4970
danakj8a98ca22016-04-16 02:47:3671 explicit ProxyResolverV8(std::unique_ptr<Context> context);
[email protected]943c8082009-02-23 19:10:4572
danakj8a98ca22016-04-16 02:47:3673 std::unique_ptr<Context> context_;
[email protected]50d7d7282009-03-02 21:45:1874
[email protected]943c8082009-02-23 19:10:4575 DISALLOW_COPY_AND_ASSIGN(ProxyResolverV8);
76};
77
[email protected]943c8082009-02-23 19:10:4578} // namespace net
79
Lily Houghton582d4622018-01-22 22:43:4080#endif // NET_PROXY_RESOLUTION_PROXY_RESOLVER_V8_H_