1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef NET_PROXY_PROXY_RESOLVER_V8_H_
6 #define NET_PROXY_PROXY_RESOLVER_V8_H_
8 #include "base/compiler_specific.h"
9 #include "base/memory/ref_counted.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/strings/string16.h"
12 #include "net/base/net_export.h"
18 class ProxyResolverScriptData
;
20 // A synchronous ProxyResolver-like that uses V8 to evaluate PAC scripts.
21 class NET_EXPORT_PRIVATE ProxyResolverV8
{
23 // Interface for the javascript bindings.
24 class NET_EXPORT_PRIVATE JSBindings
{
26 enum ResolveDnsOperation
{
35 // Handler for "dnsResolve()", "dnsResolveEx()", "myIpAddress()",
36 // "myIpAddressEx()". Returns true on success and fills |*output| with the
37 // result. If |*terminate| is set to true, then the script execution will
38 // be aborted. Note that termination may not happen right away.
39 virtual bool ResolveDns(const std::string
& host
,
40 ResolveDnsOperation op
,
44 // Handler for "alert(message)"
45 virtual void Alert(const base::string16
& message
) = 0;
47 // Handler for when an error is encountered. |line_number| may be -1
48 // if a line number is not applicable to this error.
49 virtual void OnError(int line_number
, const base::string16
& error
) = 0;
52 virtual ~JSBindings() {}
55 // Constructs a ProxyResolverV8.
56 static int Create(const scoped_refptr
<ProxyResolverScriptData
>& script_data
,
58 scoped_ptr
<ProxyResolverV8
>* resolver
);
62 int GetProxyForURL(const GURL
& url
, ProxyInfo
* results
, JSBindings
* bindings
);
64 // Get total/ued heap memory usage of all v8 instances used by the proxy
66 static size_t GetTotalHeapSize();
67 static size_t GetUsedHeapSize();
70 // Context holds the Javascript state for the PAC script.
73 explicit ProxyResolverV8(scoped_ptr
<Context
> context
);
75 scoped_ptr
<Context
> context_
;
77 DISALLOW_COPY_AND_ASSIGN(ProxyResolverV8
);
82 #endif // NET_PROXY_PROXY_RESOLVER_V8_H_