blob: a310460144768f7ad5e2b71b04143f6281ffb300 [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"
[email protected]3b63f8f42011-03-28 01:54:159#include "base/memory/scoped_ptr.h"
[email protected]172da1b2011-08-12 15:52:2610#include "net/base/net_export.h"
[email protected]7dc52f22009-03-02 22:37:1811#include "net/proxy/proxy_resolver.h"
[email protected]943c8082009-02-23 19:10:4512
13namespace net {
14
15// Implementation of ProxyResolver that uses V8 to evaluate PAC scripts.
16//
17// ----------------------------------------------------------------------------
18// !!! Important note on threading model:
19// ----------------------------------------------------------------------------
20// There can be only one instance of V8 running at a time. To enforce this
21// constraint, ProxyResolverV8 holds a v8::Locker during execution. Therefore
22// it is OK to run multiple instances of ProxyResolverV8 on different threads,
23// since only one will be running inside V8 at a time.
24//
25// It is important that *ALL* instances of V8 in the process be using
[email protected]49639fa2011-12-20 23:22:4126// v8::Locker. If not there can be race conditions between the non-locked V8
[email protected]943c8082009-02-23 19:10:4527// instances and the locked V8 instances used by ProxyResolverV8 (assuming they
28// run on different threads).
29//
30// This is the case with the V8 instance used by chromium's renderer -- it runs
31// on a different thread from ProxyResolver (renderer thread vs PAC thread),
32// and does not use locking since it expects to be alone.
[email protected]172da1b2011-08-12 15:52:2633class NET_EXPORT_PRIVATE ProxyResolverV8 : public ProxyResolver {
[email protected]943c8082009-02-23 19:10:4534 public:
[email protected]501e2d42013-01-30 22:30:4935 // Interface for the javascript bindings.
36 class NET_EXPORT_PRIVATE JSBindings {
37 public:
38 enum ResolveDnsOperation {
39 DNS_RESOLVE,
40 DNS_RESOLVE_EX,
41 MY_IP_ADDRESS,
42 MY_IP_ADDRESS_EX,
43 NUM_DNS_OPERATIONS,
44 };
45
46 JSBindings() {}
47
48 virtual ~JSBindings() {}
49
50 // Handler for "dnsResolve()", "dnsResolveEx()", "myIpAddress()",
51 // "myIpAddressEx()". Returns true on success and fills |*output| with the
52 // result.
53 virtual bool ResolveDns(const std::string& host,
54 ResolveDnsOperation op,
55 std::string* output) = 0;
56
57 // Handler for "alert(message)"
58 virtual void Alert(const string16& message) = 0;
59
60 // Handler for when an error is encountered. |line_number| may be -1
61 // if a line number is not applicable to this error.
62 virtual void OnError(int line_number, const string16& error) = 0;
63 };
64
65 // Constructs a ProxyResolverV8.
66 ProxyResolverV8();
[email protected]50d7d7282009-03-02 21:45:1867
[email protected]775fd9e2009-07-26 21:12:2068 virtual ~ProxyResolverV8();
[email protected]943c8082009-02-23 19:10:4569
[email protected]501e2d42013-01-30 22:30:4970 JSBindings* js_bindings() const { return js_bindings_; }
71 void set_js_bindings(JSBindings* js_bindings) { js_bindings_ = js_bindings; }
[email protected]7aefb152011-01-21 23:46:4972
[email protected]943c8082009-02-23 19:10:4573 // ProxyResolver implementation:
[email protected]775fd9e2009-07-26 21:12:2074 virtual int GetProxyForURL(const GURL& url,
75 ProxyInfo* results,
[email protected]235786812011-12-20 02:15:3176 const net::CompletionCallback& /*callback*/,
[email protected]52ae80c2009-09-10 21:27:0077 RequestHandle* /*request*/,
[email protected]c4c1b482011-07-22 17:24:2678 const BoundNetLog& net_log) OVERRIDE;
79 virtual void CancelRequest(RequestHandle request) OVERRIDE;
[email protected]f2c971f2011-11-08 00:33:1780 virtual LoadState GetLoadState(RequestHandle request) const OVERRIDE;
[email protected]c4c1b482011-07-22 17:24:2681 virtual void CancelSetPacScript() OVERRIDE;
82 virtual void PurgeMemory() OVERRIDE;
[email protected]24476402010-07-20 20:55:1783 virtual int SetPacScript(
84 const scoped_refptr<ProxyResolverScriptData>& script_data,
[email protected]235786812011-12-20 02:15:3185 const net::CompletionCallback& /*callback*/) OVERRIDE;
[email protected]943c8082009-02-23 19:10:4586
87 private:
88 // Context holds the Javascript state for the most recently loaded PAC
89 // script. It corresponds with the data from the last call to
[email protected]620f5712009-08-04 22:43:1290 // SetPacScript().
[email protected]943c8082009-02-23 19:10:4591 class Context;
[email protected]501e2d42013-01-30 22:30:4992
[email protected]943c8082009-02-23 19:10:4593 scoped_ptr<Context> context_;
94
[email protected]501e2d42013-01-30 22:30:4995 JSBindings* js_bindings_;
[email protected]50d7d7282009-03-02 21:45:1896
[email protected]943c8082009-02-23 19:10:4597 DISALLOW_COPY_AND_ASSIGN(ProxyResolverV8);
98};
99
[email protected]943c8082009-02-23 19:10:45100} // namespace net
101
102#endif // NET_PROXY_PROXY_RESOLVER_V8_H_