| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/chromeos/ui_proxy_config.h" | 5 #include "chrome/browser/chromeos/ui_proxy_config.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/values.h" | 8 #include "base/values.h" |
| 9 #include "components/proxy_config/proxy_config_dictionary.h" | 9 #include "components/proxy_config/proxy_config_dictionary.h" |
| 10 #include "net/proxy/proxy_config.h" | 10 #include "net/proxy/proxy_config.h" |
| 11 #include "url/url_constants.h" |
| 12 |
| 13 namespace { |
| 14 const char kSocksScheme[] = "socks"; |
| 15 } |
| 11 | 16 |
| 12 namespace chromeos { | 17 namespace chromeos { |
| 13 | 18 |
| 14 UIProxyConfig::UIProxyConfig() | 19 UIProxyConfig::UIProxyConfig() |
| 15 : mode(MODE_DIRECT), | 20 : mode(MODE_DIRECT), |
| 16 state(ProxyPrefs::CONFIG_UNSET), | 21 state(ProxyPrefs::CONFIG_UNSET), |
| 17 user_modifiable(true) { | 22 user_modifiable(true) { |
| 18 } | 23 } |
| 19 | 24 |
| 20 UIProxyConfig::~UIProxyConfig() { | 25 UIProxyConfig::~UIProxyConfig() { |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 } | 118 } |
| 114 case MODE_SINGLE_PROXY: { | 119 case MODE_SINGLE_PROXY: { |
| 115 std::string spec; | 120 std::string spec; |
| 116 if (single_proxy.server.is_valid()) | 121 if (single_proxy.server.is_valid()) |
| 117 spec = single_proxy.server.ToURI(); | 122 spec = single_proxy.server.ToURI(); |
| 118 return ProxyConfigDictionary::CreateFixedServers( | 123 return ProxyConfigDictionary::CreateFixedServers( |
| 119 spec, bypass_rules.ToString()); | 124 spec, bypass_rules.ToString()); |
| 120 } | 125 } |
| 121 case MODE_PROXY_PER_SCHEME: { | 126 case MODE_PROXY_PER_SCHEME: { |
| 122 std::string spec; | 127 std::string spec; |
| 123 EncodeAndAppendProxyServer("http", http_proxy.server, &spec); | 128 ProxyConfigDictionary::EncodeAndAppendProxyServer( |
| 124 EncodeAndAppendProxyServer("https", https_proxy.server, &spec); | 129 url::kHttpScheme, http_proxy.server, &spec); |
| 125 EncodeAndAppendProxyServer("ftp", ftp_proxy.server, &spec); | 130 ProxyConfigDictionary::EncodeAndAppendProxyServer( |
| 126 EncodeAndAppendProxyServer("socks", socks_proxy.server, &spec); | 131 url::kHttpsScheme, https_proxy.server, &spec); |
| 132 ProxyConfigDictionary::EncodeAndAppendProxyServer( |
| 133 url::kFtpScheme, ftp_proxy.server, &spec); |
| 134 ProxyConfigDictionary::EncodeAndAppendProxyServer( |
| 135 kSocksScheme, socks_proxy.server, &spec); |
| 127 return ProxyConfigDictionary::CreateFixedServers( | 136 return ProxyConfigDictionary::CreateFixedServers( |
| 128 spec, bypass_rules.ToString()); | 137 spec, bypass_rules.ToString()); |
| 129 } | 138 } |
| 130 default: | 139 default: |
| 131 break; | 140 break; |
| 132 } | 141 } |
| 133 NOTREACHED() << "Unrecognized proxy config mode for preference"; | 142 NOTREACHED() << "Unrecognized proxy config mode for preference"; |
| 134 return NULL; | 143 return NULL; |
| 135 } | 144 } |
| 136 | 145 |
| 137 UIProxyConfig::ManualProxy* UIProxyConfig::MapSchemeToProxy( | 146 UIProxyConfig::ManualProxy* UIProxyConfig::MapSchemeToProxy( |
| 138 const std::string& scheme) { | 147 const std::string& scheme) { |
| 139 if (scheme == "http") | 148 if (scheme == url::kHttpScheme) |
| 140 return &http_proxy; | 149 return &http_proxy; |
| 141 if (scheme == "https") | 150 if (scheme == url::kHttpsScheme) |
| 142 return &https_proxy; | 151 return &https_proxy; |
| 143 if (scheme == "ftp") | 152 if (scheme == url::kFtpScheme) |
| 144 return &ftp_proxy; | 153 return &ftp_proxy; |
| 145 if (scheme == "socks") | 154 if (scheme == kSocksScheme) |
| 146 return &socks_proxy; | 155 return &socks_proxy; |
| 147 NOTREACHED() << "Invalid scheme: " << scheme; | 156 NOTREACHED() << "Invalid scheme: " << scheme; |
| 148 return NULL; | 157 return NULL; |
| 149 } | 158 } |
| 150 | 159 |
| 151 // static | |
| 152 void UIProxyConfig::EncodeAndAppendProxyServer(const std::string& url_scheme, | |
| 153 const net::ProxyServer& server, | |
| 154 std::string* spec) { | |
| 155 if (!server.is_valid()) | |
| 156 return; | |
| 157 | |
| 158 if (!spec->empty()) | |
| 159 *spec += ';'; | |
| 160 | |
| 161 if (!url_scheme.empty()) { | |
| 162 *spec += url_scheme; | |
| 163 *spec += "="; | |
| 164 } | |
| 165 *spec += server.ToURI(); | |
| 166 } | |
| 167 | |
| 168 } // namespace chromeos | 160 } // namespace chromeos |
| OLD | NEW |