blob: d2a53d1c60d4b6a42a31ade28d0b837bb10b12ff [file] [log] [blame]
[email protected]82a37672011-05-03 12:02:411// Copyright (c) 2011 The Chromium Authors. All rights reserved.
[email protected]90ae1fb2009-08-02 21:07:122// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]59872eb2010-06-22 18:56:125#ifndef NET_PROXY_PROXY_RESOLVER_JS_BINDINGS_H_
6#define NET_PROXY_PROXY_RESOLVER_JS_BINDINGS_H_
[email protected]32b76ef2010-07-26 23:08:247#pragma once
[email protected]90ae1fb2009-08-02 21:07:128
9#include <string>
10
[email protected]51e413c2010-06-23 00:15:5811#include "base/string16.h"
[email protected]f4ffb7a2011-05-19 21:23:0012#include "net/base/net_api.h"
[email protected]51e413c2010-06-23 00:15:5813
[email protected]90ae1fb2009-08-02 21:07:1214namespace net {
15
16class HostResolver;
[email protected]72b4a772010-07-14 01:29:3017class NetLog;
[email protected]82a37672011-05-03 12:02:4118class ProxyResolverErrorObserver;
[email protected]59872eb2010-06-22 18:56:1219struct ProxyResolverRequestContext;
[email protected]90ae1fb2009-08-02 21:07:1220
21// Interface for the javascript bindings.
[email protected]f4ffb7a2011-05-19 21:23:0022class NET_TEST ProxyResolverJSBindings {
[email protected]90ae1fb2009-08-02 21:07:1223 public:
[email protected]59872eb2010-06-22 18:56:1224 ProxyResolverJSBindings() : current_request_context_(NULL) {}
25
[email protected]90ae1fb2009-08-02 21:07:1226 virtual ~ProxyResolverJSBindings() {}
27
28 // Handler for "alert(message)"
[email protected]51e413c2010-06-23 00:15:5829 virtual void Alert(const string16& message) = 0;
[email protected]90ae1fb2009-08-02 21:07:1230
[email protected]51e413c2010-06-23 00:15:5831 // Handler for "myIpAddress()". Returns true on success and fills
32 // |*first_ip_address| with the result.
33 virtual bool MyIpAddress(std::string* first_ip_address) = 0;
[email protected]90ae1fb2009-08-02 21:07:1234
[email protected]51e413c2010-06-23 00:15:5835 // Handler for "myIpAddressEx()". Returns true on success and fills
36 // |*ip_address_list| with the result.
[email protected]21f20c892009-10-26 23:51:2837 //
38 // This is a Microsoft extension to PAC for IPv6, see:
[email protected]a37b8bb2010-08-26 23:31:0039 // http://blogs.msdn.com/b/wndp/archive/2006/07/13/ipv6-pac-extensions-v0-9.aspx
40
[email protected]51e413c2010-06-23 00:15:5841 virtual bool MyIpAddressEx(std::string* ip_address_list) = 0;
[email protected]21f20c892009-10-26 23:51:2842
[email protected]51e413c2010-06-23 00:15:5843 // Handler for "dnsResolve(host)". Returns true on success and fills
44 // |*first_ip_address| with the result.
45 virtual bool DnsResolve(const std::string& host,
46 std::string* first_ip_address) = 0;
[email protected]90ae1fb2009-08-02 21:07:1247
[email protected]51e413c2010-06-23 00:15:5848 // Handler for "dnsResolveEx(host)". Returns true on success and fills
49 // |*ip_address_list| with the result.
[email protected]21f20c892009-10-26 23:51:2850 //
51 // This is a Microsoft extension to PAC for IPv6, see:
[email protected]a37b8bb2010-08-26 23:31:0052 // http://blogs.msdn.com/b/wndp/archive/2006/07/13/ipv6-pac-extensions-v0-9.aspx
[email protected]51e413c2010-06-23 00:15:5853 virtual bool DnsResolveEx(const std::string& host,
54 std::string* ip_address_list) = 0;
[email protected]21f20c892009-10-26 23:51:2855
[email protected]90ae1fb2009-08-02 21:07:1256 // Handler for when an error is encountered. |line_number| may be -1
57 // if a line number is not applicable to this error.
[email protected]51e413c2010-06-23 00:15:5858 virtual void OnError(int line_number, const string16& error) = 0;
[email protected]90ae1fb2009-08-02 21:07:1259
[email protected]61b84d52010-07-09 03:32:0060 // Called before the thread running the proxy resolver is stopped.
61 virtual void Shutdown() = 0;
62
[email protected]90ae1fb2009-08-02 21:07:1263 // Creates a default javascript bindings implementation that will:
[email protected]b30a3f52010-10-16 01:05:4664 // - Send script error messages to both VLOG(1) and the NetLog.
65 // - Send script alert()s to both VLOG(1) and the NetLog.
[email protected]90ae1fb2009-08-02 21:07:1266 // - Use the provided host resolver to service dnsResolve().
67 //
[email protected]1ca2b452010-04-17 00:07:0468 // Note that |host_resolver| will be used in sync mode mode.
[email protected]82a37672011-05-03 12:02:4169 // Takes ownership of |error_observer| which might be NULL.
70 static ProxyResolverJSBindings* CreateDefault(
71 HostResolver* host_resolver,
72 NetLog* net_log,
73 ProxyResolverErrorObserver* error_observer);
[email protected]59872eb2010-06-22 18:56:1274
75 // Sets details about the currently executing FindProxyForURL() request.
76 void set_current_request_context(
77 ProxyResolverRequestContext* current_request_context) {
78 current_request_context_ = current_request_context;
79 }
80
81 // Retrieves details about the currently executing FindProxyForURL() request.
82 ProxyResolverRequestContext* current_request_context() {
83 return current_request_context_;
84 }
85
86 private:
87 ProxyResolverRequestContext* current_request_context_;
[email protected]90ae1fb2009-08-02 21:07:1288};
89
90} // namespace net
91
[email protected]59872eb2010-06-22 18:56:1292#endif // NET_PROXY_PROXY_RESOLVER_JS_BINDINGS_H_