Home | History | Annotate | Download | only in net
      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 
     49   ProxyConfig config_type() const { return config_type_; }
     50 
     51   std::string http_proxy() const { return http_proxy_; }
     52   int http_proxy_port() const { return http_proxy_port_; }
     53 
     54   std::string ssl_proxy() const { return ssl_proxy_; }
     55   int ssl_proxy_port() const { return ssl_proxy_port_; }
     56 
     57   std::string ftp_proxy() const { return ftp_proxy_; }
     58   int ftp_proxy_port() const { return ftp_proxy_port_; }
     59 
     60   std::string gopher_proxy() const { return gopher_proxy_; }
     61   int gopher_proxy_port() const { return gopher_proxy_port_; }
     62 
     63   std::string socks_host() const { return socks_host_; }
     64   int socks_port() const { return socks_port_; }
     65   SOCKSVersion socks_version() const { return socks_version_; }
     66 
     67   std::vector<std::string> proxy_bypass_list() const {
     68     return proxy_bypass_list_;
     69   }
     70 
     71   const std::string autoconfig_url() const {
     72     return autoconfig_url_;
     73   }
     74 
     75   // Converts a FirefoxProxySettings object to a net::ProxyConfig.
     76   // On success returns true and fills |config| with the result.
     77   bool ToProxyConfig(net::ProxyConfig* config);
     78 
     79  protected:
     80   // Gets the settings from the passed prefs.js file and returns true if
     81   // successful.
     82   // Protected for tests.
     83   static bool GetSettingsFromFile(const base::FilePath& pref_file,
     84                                   FirefoxProxySettings* settings);
     85 
     86  private:
     87   ProxyConfig config_type_;
     88 
     89   std::string http_proxy_;
     90   int http_proxy_port_;
     91 
     92   std::string ssl_proxy_;
     93   int ssl_proxy_port_;
     94 
     95   std::string ftp_proxy_;
     96   int ftp_proxy_port_;
     97 
     98   std::string gopher_proxy_;
     99   int gopher_proxy_port_;
    100 
    101   std::string socks_host_;
    102   int socks_port_;
    103   SOCKSVersion socks_version_;
    104 
    105   std::vector<std::string> proxy_bypass_list_;
    106 
    107   std::string autoconfig_url_;
    108 
    109   DISALLOW_COPY_AND_ASSIGN(FirefoxProxySettings);
    110 };
    111 
    112 #endif  // CHROME_BROWSER_NET_FIREFOX_PROXY_SETTINGS_H_
    113