summaryrefslogtreecommitdiffstats
path: root/net/proxy/proxy_resolver_v8.h
diff options
context:
space:
mode:
authorericroman@google.com <ericroman@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-02 21:45:18 +0000
committerericroman@google.com <ericroman@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-02 21:45:18 +0000
commit50d7d7283db42b531a9df9c6f5a34b8526d4d5b0 (patch)
tree6d29abd0b0a82a658a9a526e37279a26a636142e /net/proxy/proxy_resolver_v8.h
parente97cdd5e81a3f8c3bd735ab1e7d264c36c2c3870 (diff)
downloadchromium_src-50d7d7283db42b531a9df9c6f5a34b8526d4d5b0.zip
chromium_src-50d7d7283db42b531a9df9c6f5a34b8526d4d5b0.tar.gz
chromium_src-50d7d7283db42b531a9df9c6f5a34b8526d4d5b0.tar.bz2
Add js bindings layer for ProxyResolverV8 {"alert()", "dnsResolve()", "myIpAddress" <-- [partial]}.
Also adds a utility function to net_util for turning a addrinfo into an IP address string. BUG=2764 Review URL: http://codereview.chromium.org/31009 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@10730 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/proxy/proxy_resolver_v8.h')
-rw-r--r--net/proxy/proxy_resolver_v8.h42
1 files changed, 42 insertions, 0 deletions
diff --git a/net/proxy/proxy_resolver_v8.h b/net/proxy/proxy_resolver_v8.h
index 312b557..ec765fb 100644
--- a/net/proxy/proxy_resolver_v8.h
+++ b/net/proxy/proxy_resolver_v8.h
@@ -32,7 +32,26 @@ namespace net {
// and does not use locking since it expects to be alone.
class ProxyResolverV8 : public ProxyResolver {
public:
+ // Constructs a ProxyResolverV8 with default javascript bindings.
+ //
+ // The default javascript bindings will:
+ // - Send script error messages to LOG(INFO)
+ // - Send script alert()s to LOG(INFO)
+ // - Use the default host mapper to service dnsResolve(), synchronously
+ // on the V8 thread.
+ //
+ // For clients that need more control (for example, sending the script output
+ // to a UI widget), use the ProxyResolverV8(JSBindings*) and specify your
+ // own bindings.
ProxyResolverV8();
+
+ class JSBindings;
+
+ // Constructs a ProxyResolverV8 with custom bindings. ProxyResolverV8 takes
+ // ownership of |custom_js_bindings| and deletes it when ProxyResolverV8
+ // is destroyed.
+ explicit ProxyResolverV8(JSBindings* custom_js_bindings);
+
~ProxyResolverV8();
// ProxyResolver implementation:
@@ -41,6 +60,8 @@ class ProxyResolverV8 : public ProxyResolver {
ProxyInfo* results);
virtual void SetPacScript(const std::string& bytes);
+ JSBindings* js_bindings() const { return js_bindings_.get(); }
+
private:
// Context holds the Javascript state for the most recently loaded PAC
// script. It corresponds with the data from the last call to
@@ -48,9 +69,30 @@ class ProxyResolverV8 : public ProxyResolver {
class Context;
scoped_ptr<Context> context_;
+ scoped_ptr<JSBindings> js_bindings_;
+
DISALLOW_COPY_AND_ASSIGN(ProxyResolverV8);
};
+// Interface for the javascript bindings.
+class ProxyResolverV8::JSBindings {
+ public:
+ virtual ~JSBindings() {}
+
+ // Handler for "alert(message)"
+ virtual void Alert(const std::string& message) = 0;
+
+ // Handler for "myIpAddress()". Returns empty string on failure.
+ virtual std::string MyIpAddress() = 0;
+
+ // Handler for "dnsResolve(host)". Returns empty string on failure.
+ virtual std::string DnsResolve(const std::string& host) = 0;
+
+ // Handler for when an error is encountered. |line_number| may be -1
+ // if a line number is not applicable to this error.
+ virtual void OnError(int line_number, const std::string& error) = 0;
+};
+
} // namespace net
#endif // NET_PROXY_PROXY_RESOLVER_V8_H_