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