proxy_resolver_js_bindings.h revision fc93418c483ce474a1f4888b50f92574a1b81be3
1// Copyright (c) 2010 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.
4
5#ifndef NET_PROXY_PROXY_RESOLVER_JS_BINDINGS_H_
6#define NET_PROXY_PROXY_RESOLVER_JS_BINDINGS_H_
7#pragma once
8
9#include <string>
10
11
12namespace net {
13
14class HostResolver;
15class NetLog;
16
17// Interface for the javascript bindings.
18class ProxyResolverJSBindings {
19 public:
20  ProxyResolverJSBindings() {}// : current_request_context_(NULL) {}
21
22  virtual ~ProxyResolverJSBindings() {}
23
24  // Handler for "alert(message)"
25  virtual void Alert(const std::wstring& message) = 0;
26
27  // Handler for "myIpAddress()". Returns true on success and fills
28  // |*first_ip_address| with the result.
29  virtual bool MyIpAddress(std::string* first_ip_address) = 0;
30
31  // Handler for "myIpAddressEx()". Returns true on success and fills
32  // |*ip_address_list| with the result.
33  //
34  // This is a Microsoft extension to PAC for IPv6, see:
35  // http://blogs.msdn.com/b/wndp/archive/2006/07/13/ipv6-pac-extensions-v0-9.aspx
36
37  virtual bool MyIpAddressEx(std::string* ip_address_list) = 0;
38
39  // Handler for "dnsResolve(host)". Returns true on success and fills
40  // |*first_ip_address| with the result.
41  virtual bool DnsResolve(const std::string& host,
42                          std::string* first_ip_address) = 0;
43
44  // Handler for "dnsResolveEx(host)". Returns true on success and fills
45  // |*ip_address_list| with the result.
46  //
47  // This is a Microsoft extension to PAC for IPv6, see:
48  // http://blogs.msdn.com/b/wndp/archive/2006/07/13/ipv6-pac-extensions-v0-9.aspx
49  virtual bool DnsResolveEx(const std::string& host,
50                            std::string* ip_address_list) = 0;
51
52  // Handler for when an error is encountered. |line_number| may be -1
53  // if a line number is not applicable to this error.
54  virtual void OnError(int line_number, const std::wstring& error) = 0;
55
56  // Creates a default javascript bindings implementation that will:
57  //   - Send script error messages to both VLOG(1) and the NetLog.
58  //   - Send script alert()s to both VLOG(1) and the NetLog.
59  //   - Use the provided host resolver to service dnsResolve().
60  //
61  // Note that |host_resolver| will be used in sync mode mode.
62  static ProxyResolverJSBindings* CreateDefault();
63
64 private:
65};
66
67}  // namespace net
68
69#endif  // NET_PROXY_PROXY_RESOLVER_JS_BINDINGS_H_
70