blob: 98746ac0279c26e72d6779fce7d84ffc9488a9ab [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
5#ifndef NET_PROXY_PROXY_RESOLVER_V8_H_
6#define NET_PROXY_PROXY_RESOLVER_V8_H_
7
[email protected]c4c1b482011-07-22 17:24:268#include "base/compiler_specific.h"
sammcd2284e52015-05-27 03:14:469#include "base/memory/ref_counted.h"
[email protected]3b63f8f42011-03-28 01:54:1510#include "base/memory/scoped_ptr.h"
sammcd2284e52015-05-27 03:14:4611#include "base/strings/string16.h"
[email protected]172da1b2011-08-12 15:52:2612#include "net/base/net_export.h"
sammcd2284e52015-05-27 03:14:4613
14class GURL;
[email protected]943c8082009-02-23 19:10:4515
16namespace net {
sammcd2284e52015-05-27 03:14:4617class ProxyInfo;
18class ProxyResolverScriptData;
[email protected]943c8082009-02-23 19:10:4519
sammcd2284e52015-05-27 03:14:4620// A synchronous ProxyResolver-like that uses V8 to evaluate PAC scripts.
21class NET_EXPORT_PRIVATE ProxyResolverV8 {
[email protected]943c8082009-02-23 19:10:4522 public:
[email protected]501e2d42013-01-30 22:30:4923 // 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]501e2d42013-01-30 22:30:4931 };
32
33 JSBindings() {}
34
[email protected]501e2d42013-01-30 22:30:4935 // Handler for "dnsResolve()", "dnsResolveEx()", "myIpAddress()",
36 // "myIpAddressEx()". Returns true on success and fills |*output| with the
[email protected]8cdc8812013-02-21 05:29:4937 // 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]501e2d42013-01-30 22:30:4939 virtual bool ResolveDns(const std::string& host,
40 ResolveDnsOperation op,
[email protected]8cdc8812013-02-21 05:29:4941 std::string* output,
42 bool* terminate) = 0;
[email protected]501e2d42013-01-30 22:30:4943
44 // Handler for "alert(message)"
[email protected]42cba2fb2013-03-29 19:58:5745 virtual void Alert(const base::string16& message) = 0;
[email protected]501e2d42013-01-30 22:30:4946
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]42cba2fb2013-03-29 19:58:5749 virtual void OnError(int line_number, const base::string16& error) = 0;
[email protected]8c49a502013-02-01 03:54:1150
51 protected:
52 virtual ~JSBindings() {}
[email protected]501e2d42013-01-30 22:30:4953 };
54
55 // Constructs a ProxyResolverV8.
sammcd2284e52015-05-27 03:14:4656 static int Create(const scoped_refptr<ProxyResolverScriptData>& script_data,
57 JSBindings* bindings,
58 scoped_ptr<ProxyResolverV8>* resolver);
[email protected]50d7d7282009-03-02 21:45:1859
sammcd2284e52015-05-27 03:14:4660 ~ProxyResolverV8();
[email protected]943c8082009-02-23 19:10:4561
sammcd2284e52015-05-27 03:14:4662 int GetProxyForURL(const GURL& url, ProxyInfo* results, JSBindings* bindings);
[email protected]943c8082009-02-23 19:10:4563
[email protected]8f09c54f2013-03-05 11:06:5564 // 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]943c8082009-02-23 19:10:4569 private:
sammcd2284e52015-05-27 03:14:4670 // Context holds the Javascript state for the PAC script.
[email protected]943c8082009-02-23 19:10:4571 class Context;
[email protected]501e2d42013-01-30 22:30:4972
sammcd2284e52015-05-27 03:14:4673 explicit ProxyResolverV8(scoped_ptr<Context> context);
[email protected]943c8082009-02-23 19:10:4574
sammcd2284e52015-05-27 03:14:4675 scoped_ptr<Context> context_;
[email protected]50d7d7282009-03-02 21:45:1876
[email protected]943c8082009-02-23 19:10:4577 DISALLOW_COPY_AND_ASSIGN(ProxyResolverV8);
78};
79
[email protected]943c8082009-02-23 19:10:4580} // namespace net
81
82#endif // NET_PROXY_PROXY_RESOLVER_V8_H_