OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef NET_PROXY_PROXY_RESOLVER_V8_H_ | 5 #ifndef NET_PROXY_PROXY_RESOLVER_V8_H_ |
6 #define NET_PROXY_PROXY_RESOLVER_V8_H_ | 6 #define NET_PROXY_PROXY_RESOLVER_V8_H_ |
7 | 7 |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "net/base/net_export.h" | 10 #include "net/base/net_export.h" |
11 #include "net/proxy/proxy_resolver.h" | 11 #include "net/proxy/proxy_resolver.h" |
12 | 12 |
13 namespace net { | 13 namespace net { |
14 | 14 |
15 class ProxyResolverJSBindings; | |
16 | |
17 // Implementation of ProxyResolver that uses V8 to evaluate PAC scripts. | 15 // Implementation of ProxyResolver that uses V8 to evaluate PAC scripts. |
18 // | 16 // |
19 // ---------------------------------------------------------------------------- | 17 // ---------------------------------------------------------------------------- |
20 // !!! Important note on threading model: | 18 // !!! Important note on threading model: |
21 // ---------------------------------------------------------------------------- | 19 // ---------------------------------------------------------------------------- |
22 // There can be only one instance of V8 running at a time. To enforce this | 20 // There can be only one instance of V8 running at a time. To enforce this |
23 // constraint, ProxyResolverV8 holds a v8::Locker during execution. Therefore | 21 // constraint, ProxyResolverV8 holds a v8::Locker during execution. Therefore |
24 // it is OK to run multiple instances of ProxyResolverV8 on different threads, | 22 // it is OK to run multiple instances of ProxyResolverV8 on different threads, |
25 // since only one will be running inside V8 at a time. | 23 // since only one will be running inside V8 at a time. |
26 // | 24 // |
27 // It is important that *ALL* instances of V8 in the process be using | 25 // It is important that *ALL* instances of V8 in the process be using |
28 // v8::Locker. If not there can be race conditions between the non-locked V8 | 26 // v8::Locker. If not there can be race conditions between the non-locked V8 |
29 // instances and the locked V8 instances used by ProxyResolverV8 (assuming they | 27 // instances and the locked V8 instances used by ProxyResolverV8 (assuming they |
30 // run on different threads). | 28 // run on different threads). |
31 // | 29 // |
32 // This is the case with the V8 instance used by chromium's renderer -- it runs | 30 // This is the case with the V8 instance used by chromium's renderer -- it runs |
33 // on a different thread from ProxyResolver (renderer thread vs PAC thread), | 31 // on a different thread from ProxyResolver (renderer thread vs PAC thread), |
34 // and does not use locking since it expects to be alone. | 32 // and does not use locking since it expects to be alone. |
35 class NET_EXPORT_PRIVATE ProxyResolverV8 : public ProxyResolver { | 33 class NET_EXPORT_PRIVATE ProxyResolverV8 : public ProxyResolver { |
36 public: | 34 public: |
37 // Constructs a ProxyResolverV8 with custom bindings. ProxyResolverV8 takes | 35 // Interface for the javascript bindings. |
38 // ownership of |custom_js_bindings| and deletes it when ProxyResolverV8 | 36 class NET_EXPORT_PRIVATE JSBindings { |
39 // is destroyed. | 37 public: |
40 explicit ProxyResolverV8(ProxyResolverJSBindings* custom_js_bindings); | 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 "alert(message)" | |
51 virtual void Alert(const string16& message) = 0; | |
52 | |
53 // Handler for "dnsResolve()", "dnsResolveEx()", "myIpAddress()", | |
54 // "myIpAddressEx()". Returns true on success and fills |*output| with the | |
55 // result. | |
56 virtual bool ResolveDns(const std::string& host, | |
57 ResolveDnsOperation op, | |
58 std::string* output) = 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(); | |
41 | 67 |
42 virtual ~ProxyResolverV8(); | 68 virtual ~ProxyResolverV8(); |
43 | 69 |
44 ProxyResolverJSBindings* js_bindings() const { return js_bindings_.get(); } | 70 JSBindings* js_bindings() const { return js_bindings_; } |
71 void set_js_bindings(JSBindings* js_bindings) { js_bindings_ = js_bindings; } | |
45 | 72 |
46 // ProxyResolver implementation: | 73 // ProxyResolver implementation: |
47 virtual int GetProxyForURL(const GURL& url, | 74 virtual int GetProxyForURL(const GURL& url, |
48 ProxyInfo* results, | 75 ProxyInfo* results, |
49 const net::CompletionCallback& /*callback*/, | 76 const net::CompletionCallback& /*callback*/, |
50 RequestHandle* /*request*/, | 77 RequestHandle* /*request*/, |
51 const BoundNetLog& net_log) OVERRIDE; | 78 const BoundNetLog& net_log) OVERRIDE; |
52 virtual void CancelRequest(RequestHandle request) OVERRIDE; | 79 virtual void CancelRequest(RequestHandle request) OVERRIDE; |
53 virtual LoadState GetLoadState(RequestHandle request) const OVERRIDE; | 80 virtual LoadState GetLoadState(RequestHandle request) const OVERRIDE; |
54 virtual LoadState GetLoadStateThreadSafe( | |
55 RequestHandle request) const OVERRIDE; | |
56 virtual void CancelSetPacScript() OVERRIDE; | 81 virtual void CancelSetPacScript() OVERRIDE; |
57 virtual void PurgeMemory() OVERRIDE; | 82 virtual void PurgeMemory() OVERRIDE; |
58 virtual void Shutdown() OVERRIDE; | |
59 virtual int SetPacScript( | 83 virtual int SetPacScript( |
60 const scoped_refptr<ProxyResolverScriptData>& script_data, | 84 const scoped_refptr<ProxyResolverScriptData>& script_data, |
61 const net::CompletionCallback& /*callback*/) OVERRIDE; | 85 const net::CompletionCallback& /*callback*/) OVERRIDE; |
62 | 86 |
63 private: | 87 private: |
64 // Context holds the Javascript state for the most recently loaded PAC | 88 // Context holds the Javascript state for the most recently loaded PAC |
65 // script. It corresponds with the data from the last call to | 89 // script. It corresponds with the data from the last call to |
66 // SetPacScript(). | 90 // SetPacScript(). |
67 class Context; | 91 class Context; |
92 friend class Context; | |
mmenke
2013/01/18 19:59:40
I believe inner classes don't have to be friends t
eroman
2013/01/23 03:26:02
Done.
| |
93 | |
68 scoped_ptr<Context> context_; | 94 scoped_ptr<Context> context_; |
69 | 95 |
70 scoped_ptr<ProxyResolverJSBindings> js_bindings_; | 96 JSBindings* js_bindings_; |
71 | 97 |
72 DISALLOW_COPY_AND_ASSIGN(ProxyResolverV8); | 98 DISALLOW_COPY_AND_ASSIGN(ProxyResolverV8); |
73 }; | 99 }; |
74 | 100 |
75 } // namespace net | 101 } // namespace net |
76 | 102 |
77 #endif // NET_PROXY_PROXY_RESOLVER_V8_H_ | 103 #endif // NET_PROXY_PROXY_RESOLVER_V8_H_ |
OLD | NEW |