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#include "base/string16.h"
12
13namespace net {
14
15class HostResolver;
16class NetLog;
17struct ProxyResolverRequestContext;
18
19// Interface for the javascript bindings.
20class ProxyResolverJSBindings {
21 public:
22  ProxyResolverJSBindings() : current_request_context_(NULL) {}
23
24  virtual ~ProxyResolverJSBindings() {}
25
26  // Handler for "alert(message)"
27  virtual void Alert(const string16& message) = 0;
28
29  // Handler for "myIpAddress()". Returns true on success and fills
30  // |*first_ip_address| with the result.
31  virtual bool MyIpAddress(std::string* first_ip_address) = 0;
32
33  // Handler for "myIpAddressEx()". Returns true on success and fills
34  // |*ip_address_list| with the result.
35  //
36  // This is a Microsoft extension to PAC for IPv6, see:
37  // http://blogs.msdn.com/b/wndp/archive/2006/07/13/ipv6-pac-extensions-v0-9.aspx
38
39  virtual bool MyIpAddressEx(std::string* ip_address_list) = 0;
40
41  // Handler for "dnsResolve(host)". Returns true on success and fills
42  // |*first_ip_address| with the result.
43  virtual bool DnsResolve(const std::string& host,
44                          std::string* first_ip_address) = 0;
45
46  // Handler for "dnsResolveEx(host)". Returns true on success and fills
47  // |*ip_address_list| with the result.
48  //
49  // This is a Microsoft extension to PAC for IPv6, see:
50  // http://blogs.msdn.com/b/wndp/archive/2006/07/13/ipv6-pac-extensions-v0-9.aspx
51  virtual bool DnsResolveEx(const std::string& host,
52                            std::string* ip_address_list) = 0;
53
54  // Handler for when an error is encountered. |line_number| may be -1
55  // if a line number is not applicable to this error.
56  virtual void OnError(int line_number, const string16& error) = 0;
57
58  // Called before the thread running the proxy resolver is stopped.
59  virtual void Shutdown() = 0;
60
61  // Creates a default javascript bindings implementation that will:
62  //   - Send script error messages to both VLOG(1) and the NetLog.
63  //   - Send script alert()s to both VLOG(1) and the NetLog.
64  //   - Use the provided host resolver to service dnsResolve().
65  //
66  // Note that |host_resolver| will be used in sync mode mode.
67  static ProxyResolverJSBindings* CreateDefault(HostResolver* host_resolver,
68                                                NetLog* net_log);
69
70  // Sets details about the currently executing FindProxyForURL() request.
71  void set_current_request_context(
72      ProxyResolverRequestContext* current_request_context) {
73    current_request_context_ = current_request_context;
74  }
75
76  // Retrieves details about the currently executing FindProxyForURL() request.
77  ProxyResolverRequestContext* current_request_context() {
78    return current_request_context_;
79  }
80
81 private:
82  ProxyResolverRequestContext* current_request_context_;
83};
84
85}  // namespace net
86
87#endif  // NET_PROXY_PROXY_RESOLVER_JS_BINDINGS_H_
88