summaryrefslogtreecommitdiffstats
path: root/chrome/browser/net/firefox_proxy_settings.h
blob: 94dfe56b1b6ae35859e36d51fe561c0d7d670138 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_NET_FIREFOX_PROXY_SETTINGS_H_
#define CHROME_BROWSER_NET_FIREFOX_PROXY_SETTINGS_H_

#include <string>
#include <vector>

#include "base/basictypes.h"

namespace base {
class FilePath;
}

namespace net {
class ProxyConfig;
}

class FirefoxProxySettings {
 public:
  enum ProxyConfig {
    NO_PROXY = 0,    // No proxy are used.
    AUTO_DETECT,     // Automatically detected.
    SYSTEM,          // Using system proxy settings.
    AUTO_FROM_URL,   // Automatically configured from a URL.
    MANUAL           // User specified settings.
  };

  enum SOCKSVersion {
    UNKNONW = 0,
    V4,
    V5
  };

  FirefoxProxySettings();
  ~FirefoxProxySettings();

  // Sets |settings| to the proxy settings for the current installed version of
  // Firefox and returns true if successful.
  // Returns false if Firefox is not installed or if the settings could not be
  // retrieved.
  static bool GetSettings(FirefoxProxySettings* settings);

  // Resets all the states of this FirefoxProxySettings to no proxy.
  void Reset();

  ProxyConfig config_type() const { return config_type_; }

  std::string http_proxy() const { return http_proxy_; }
  int http_proxy_port() const { return http_proxy_port_; }

  std::string ssl_proxy() const { return ssl_proxy_; }
  int ssl_proxy_port() const { return ssl_proxy_port_; }

  std::string ftp_proxy() const { return ftp_proxy_; }
  int ftp_proxy_port() const { return ftp_proxy_port_; }

  std::string gopher_proxy() const { return gopher_proxy_; }
  int gopher_proxy_port() const { return gopher_proxy_port_; }

  std::string socks_host() const { return socks_host_; }
  int socks_port() const { return socks_port_; }
  SOCKSVersion socks_version() const { return socks_version_; }

  std::vector<std::string> proxy_bypass_list() const {
    return proxy_bypass_list_;
  }

  const std::string& autoconfig_url() const { return autoconfig_url_; }

  // Converts a FirefoxProxySettings object to a net::ProxyConfig.
  // On success returns true and fills |config| with the result.
  bool ToProxyConfig(net::ProxyConfig* config);

 protected:
  // Gets the settings from the passed prefs.js file and returns true if
  // successful.
  // Protected for tests.
  static bool GetSettingsFromFile(const base::FilePath& pref_file,
                                  FirefoxProxySettings* settings);

 private:
  ProxyConfig config_type_;

  std::string http_proxy_;
  int http_proxy_port_;

  std::string ssl_proxy_;
  int ssl_proxy_port_;

  std::string ftp_proxy_;
  int ftp_proxy_port_;

  std::string gopher_proxy_;
  int gopher_proxy_port_;

  std::string socks_host_;
  int socks_port_;
  SOCKSVersion socks_version_;

  std::vector<std::string> proxy_bypass_list_;

  std::string autoconfig_url_;

  DISALLOW_COPY_AND_ASSIGN(FirefoxProxySettings);
};

#endif  // CHROME_BROWSER_NET_FIREFOX_PROXY_SETTINGS_H_