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/scoped_ptr.h"
10 #include "net/base/net_export.h"
11 #include "net/proxy/proxy_resolver.h"
15 // Implementation of ProxyResolver that uses V8 to evaluate PAC scripts.
16 class NET_EXPORT_PRIVATE ProxyResolverV8
: public ProxyResolver
{
18 // Interface for the javascript bindings.
19 class NET_EXPORT_PRIVATE JSBindings
{
21 enum ResolveDnsOperation
{
30 // Handler for "dnsResolve()", "dnsResolveEx()", "myIpAddress()",
31 // "myIpAddressEx()". Returns true on success and fills |*output| with the
32 // result. If |*terminate| is set to true, then the script execution will
33 // be aborted. Note that termination may not happen right away.
34 virtual bool ResolveDns(const std::string
& host
,
35 ResolveDnsOperation op
,
39 // Handler for "alert(message)"
40 virtual void Alert(const base::string16
& message
) = 0;
42 // Handler for when an error is encountered. |line_number| may be -1
43 // if a line number is not applicable to this error.
44 virtual void OnError(int line_number
, const base::string16
& error
) = 0;
47 virtual ~JSBindings() {}
50 // Constructs a ProxyResolverV8.
53 ~ProxyResolverV8() override
;
55 JSBindings
* js_bindings() const { return js_bindings_
; }
56 void set_js_bindings(JSBindings
* js_bindings
) { js_bindings_
= js_bindings
; }
58 // ProxyResolver implementation:
59 int GetProxyForURL(const GURL
& url
,
61 const CompletionCallback
& /*callback*/,
62 RequestHandle
* /*request*/,
63 const BoundNetLog
& net_log
) override
;
64 void CancelRequest(RequestHandle request
) override
;
65 LoadState
GetLoadState(RequestHandle request
) const override
;
66 void CancelSetPacScript() override
;
67 int SetPacScript(const scoped_refptr
<ProxyResolverScriptData
>& script_data
,
68 const CompletionCallback
& /*callback*/) override
;
70 // Get total/ued heap memory usage of all v8 instances used by the proxy
72 static size_t GetTotalHeapSize();
73 static size_t GetUsedHeapSize();
76 // Context holds the Javascript state for the most recently loaded PAC
77 // script. It corresponds with the data from the last call to
81 scoped_ptr
<Context
> context_
;
83 JSBindings
* js_bindings_
;
85 DISALLOW_COPY_AND_ASSIGN(ProxyResolverV8
);
90 #endif // NET_PROXY_PROXY_RESOLVER_V8_H_