• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2013 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 CHROME_BROWSER_NET_FIREFOX_PROXY_SETTINGS_H_
6 #define CHROME_BROWSER_NET_FIREFOX_PROXY_SETTINGS_H_
7 
8 #include <string>
9 #include <vector>
10 
11 #include "base/basictypes.h"
12 
13 namespace base {
14 class FilePath;
15 }
16 
17 namespace net {
18 class ProxyConfig;
19 }
20 
21 class FirefoxProxySettings {
22  public:
23   enum ProxyConfig {
24     NO_PROXY = 0,    // No proxy are used.
25     AUTO_DETECT,     // Automatically detected.
26     SYSTEM,          // Using system proxy settings.
27     AUTO_FROM_URL,   // Automatically configured from a URL.
28     MANUAL           // User specified settings.
29   };
30 
31   enum SOCKSVersion {
32     UNKNONW = 0,
33     V4,
34     V5
35   };
36 
37   FirefoxProxySettings();
38   ~FirefoxProxySettings();
39 
40   // Sets |settings| to the proxy settings for the current installed version of
41   // Firefox and returns true if successful.
42   // Returns false if Firefox is not installed or if the settings could not be
43   // retrieved.
44   static bool GetSettings(FirefoxProxySettings* settings);
45 
46   // Resets all the states of this FirefoxProxySettings to no proxy.
47   void Reset();
48 
config_type()49   ProxyConfig config_type() const { return config_type_; }
50 
http_proxy()51   std::string http_proxy() const { return http_proxy_; }
http_proxy_port()52   int http_proxy_port() const { return http_proxy_port_; }
53 
ssl_proxy()54   std::string ssl_proxy() const { return ssl_proxy_; }
ssl_proxy_port()55   int ssl_proxy_port() const { return ssl_proxy_port_; }
56 
ftp_proxy()57   std::string ftp_proxy() const { return ftp_proxy_; }
ftp_proxy_port()58   int ftp_proxy_port() const { return ftp_proxy_port_; }
59 
gopher_proxy()60   std::string gopher_proxy() const { return gopher_proxy_; }
gopher_proxy_port()61   int gopher_proxy_port() const { return gopher_proxy_port_; }
62 
socks_host()63   std::string socks_host() const { return socks_host_; }
socks_port()64   int socks_port() const { return socks_port_; }
socks_version()65   SOCKSVersion socks_version() const { return socks_version_; }
66 
proxy_bypass_list()67   std::vector<std::string> proxy_bypass_list() const {
68     return proxy_bypass_list_;
69   }
70 
autoconfig_url()71   const std::string& autoconfig_url() const { return autoconfig_url_; }
72 
73   // Converts a FirefoxProxySettings object to a net::ProxyConfig.
74   // On success returns true and fills |config| with the result.
75   bool ToProxyConfig(net::ProxyConfig* config);
76 
77  protected:
78   // Gets the settings from the passed prefs.js file and returns true if
79   // successful.
80   // Protected for tests.
81   static bool GetSettingsFromFile(const base::FilePath& pref_file,
82                                   FirefoxProxySettings* settings);
83 
84  private:
85   ProxyConfig config_type_;
86 
87   std::string http_proxy_;
88   int http_proxy_port_;
89 
90   std::string ssl_proxy_;
91   int ssl_proxy_port_;
92 
93   std::string ftp_proxy_;
94   int ftp_proxy_port_;
95 
96   std::string gopher_proxy_;
97   int gopher_proxy_port_;
98 
99   std::string socks_host_;
100   int socks_port_;
101   SOCKSVersion socks_version_;
102 
103   std::vector<std::string> proxy_bypass_list_;
104 
105   std::string autoconfig_url_;
106 
107   DISALLOW_COPY_AND_ASSIGN(FirefoxProxySettings);
108 };
109 
110 #endif  // CHROME_BROWSER_NET_FIREFOX_PROXY_SETTINGS_H_
111