Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1143)

Side by Side Diff: chrome/browser/chromeos/proxy_cros_settings_provider.cc

Issue 6737035: Proxy settings automation hooks and related proxy settings fixes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix outdated header. Created 9 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/proxy_cros_settings_provider.h" 5 #include "chrome/browser/chromeos/proxy_cros_settings_provider.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "chrome/browser/browser_list.h" 9 #include "chrome/browser/browser_list.h"
10 #include "chrome/browser/browser_process.h" 10 #include "chrome/browser/browser_process.h"
11 #include "chrome/common/chrome_switches.h" 11 #include "chrome/common/chrome_switches.h"
(...skipping 18 matching lines...) Expand all
30 //------------------ ProxyCrosSettingsProvider: public methods ----------------- 30 //------------------ ProxyCrosSettingsProvider: public methods -----------------
31 31
32 ProxyCrosSettingsProvider::ProxyCrosSettingsProvider() { } 32 ProxyCrosSettingsProvider::ProxyCrosSettingsProvider() { }
33 33
34 void ProxyCrosSettingsProvider::DoSet(const std::string& path, 34 void ProxyCrosSettingsProvider::DoSet(const std::string& path,
35 Value* in_value) { 35 Value* in_value) {
36 if (!in_value) { 36 if (!in_value) {
37 return; 37 return;
38 } 38 }
39 39
40 // Keep whatever user inputs so that we could use it later.
41 SetCache(path, in_value);
42
43 chromeos::ProxyConfigServiceImpl* config_service = GetConfigService(); 40 chromeos::ProxyConfigServiceImpl* config_service = GetConfigService();
44 // Don't persist settings to device for guest session. 41 // Don't persist settings to device for guest session.
45 config_service->UISetPersistToDevice( 42 config_service->UISetPersistToDevice(
46 !CommandLine::ForCurrentProcess()->HasSwitch(switches::kGuestSession)); 43 !CommandLine::ForCurrentProcess()->HasSwitch(switches::kGuestSession));
47 // Retrieve proxy config. 44 // Retrieve proxy config.
48 chromeos::ProxyConfigServiceImpl::ProxyConfig config; 45 chromeos::ProxyConfigServiceImpl::ProxyConfig config;
49 config_service->UIGetProxyConfig(&config); 46 config_service->UIGetProxyConfig(&config);
50 47
51 if (path == kProxyPacUrl) { 48 if (path == kProxyPacUrl) {
52 std::string val; 49 std::string val;
53 if (in_value->GetAsString(&val)) { 50 if (in_value->GetAsString(&val)) {
54 GURL url(val); 51 GURL url(val);
55 config_service->UISetProxyConfigToPACScript(url); 52 config_service->UISetProxyConfigToPACScript(url);
56 } 53 }
57 } else if (path == kProxySingleHttp) { 54 } else if (path == kProxySingleHttp) {
58 std::string val; 55 std::string val;
59 if (in_value->GetAsString(&val)) { 56 if (in_value->GetAsString(&val)) {
60 std::string uri = val; 57 config_service->UISetProxyConfigToSingleProxy(CreateProxyServerFromHost(
61 AppendPortIfValid(kProxySingleHttpPort, &uri); 58 val, config.single_proxy, net::ProxyServer::SCHEME_HTTP));
62 config_service->UISetProxyConfigToSingleProxy(
63 net::ProxyServer::FromURI(uri, net::ProxyServer::SCHEME_HTTP));
64 } 59 }
65 } else if (path == kProxySingleHttpPort) { 60 } else if (path == kProxySingleHttpPort) {
66 std::string val; 61 int val;
67 if (in_value->GetAsString(&val)) { 62 if (in_value->GetAsInteger(&val)) {
68 std::string uri; 63 config_service->UISetProxyConfigToSingleProxy(CreateProxyServerFromPort(
69 FormServerUriIfValid(kProxySingleHttp, val, &uri); 64 val, config.single_proxy, net::ProxyServer::SCHEME_HTTP));
70 config_service->UISetProxyConfigToSingleProxy(
71 net::ProxyServer::FromURI(uri, net::ProxyServer::SCHEME_HTTP));
72 } 65 }
73 } else if (path == kProxyHttpUrl) { 66 } else if (path == kProxyHttpUrl) {
74 std::string val; 67 std::string val;
75 if (in_value->GetAsString(&val)) { 68 if (in_value->GetAsString(&val)) {
76 std::string uri = val;
77 AppendPortIfValid(kProxyHttpPort, &uri);
78 config_service->UISetProxyConfigToProxyPerScheme("http", 69 config_service->UISetProxyConfigToProxyPerScheme("http",
79 net::ProxyServer::FromURI(uri, net::ProxyServer::SCHEME_HTTP)); 70 CreateProxyServerFromHost(
71 val, config.http_proxy, net::ProxyServer::SCHEME_HTTP));
80 } 72 }
81 } else if (path == kProxyHttpPort) { 73 } else if (path == kProxyHttpPort) {
82 std::string val; 74 int val;
83 if (in_value->GetAsString(&val)) { 75 if (in_value->GetAsInteger(&val)) {
84 std::string uri;
85 FormServerUriIfValid(kProxyHttpUrl, val, &uri);
86 config_service->UISetProxyConfigToProxyPerScheme("http", 76 config_service->UISetProxyConfigToProxyPerScheme("http",
87 net::ProxyServer::FromURI(uri, net::ProxyServer::SCHEME_HTTP)); 77 CreateProxyServerFromPort(
78 val, config.http_proxy, net::ProxyServer::SCHEME_HTTP));
88 } 79 }
89 } else if (path == kProxyHttpsUrl) { 80 } else if (path == kProxyHttpsUrl) {
90 std::string val; 81 std::string val;
91 if (in_value->GetAsString(&val)) { 82 if (in_value->GetAsString(&val)) {
92 std::string uri = val;
93 AppendPortIfValid(kProxyHttpsPort, &uri);
94 config_service->UISetProxyConfigToProxyPerScheme("https", 83 config_service->UISetProxyConfigToProxyPerScheme("https",
95 net::ProxyServer::FromURI(uri, net::ProxyServer::SCHEME_HTTP)); 84 CreateProxyServerFromHost(
85 val, config.https_proxy, net::ProxyServer::SCHEME_HTTPS));
96 } 86 }
97 } else if (path == kProxyHttpsPort) { 87 } else if (path == kProxyHttpsPort) {
98 std::string val; 88 int val;
99 if (in_value->GetAsString(&val)) { 89 if (in_value->GetAsInteger(&val)) {
100 std::string uri;
101 FormServerUriIfValid(kProxyHttpsUrl, val, &uri);
102 config_service->UISetProxyConfigToProxyPerScheme("https", 90 config_service->UISetProxyConfigToProxyPerScheme("https",
103 net::ProxyServer::FromURI(uri, net::ProxyServer::SCHEME_HTTP)); 91 CreateProxyServerFromPort(
92 val, config.https_proxy, net::ProxyServer::SCHEME_HTTPS));
104 } 93 }
105 } else if (path == kProxyType) { 94 } else if (path == kProxyType) {
106 int val; 95 int val;
107 if (in_value->GetAsInteger(&val)) { 96 if (in_value->GetAsInteger(&val)) {
108 if (val == 3) { 97 if (val == 3) {
109 if (config.automatic_proxy.pac_url.is_valid()) 98 if (config.automatic_proxy.pac_url.is_valid())
110 config_service->UISetProxyConfigToPACScript( 99 config_service->UISetProxyConfigToPACScript(
111 config.automatic_proxy.pac_url); 100 config.automatic_proxy.pac_url);
112 else 101 else
113 config_service->UISetProxyConfigToAutoDetect(); 102 config_service->UISetProxyConfigToAutoDetect();
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 if (val) 141 if (val)
153 config_service->UISetProxyConfigToSingleProxy( 142 config_service->UISetProxyConfigToSingleProxy(
154 config.single_proxy.server); 143 config.single_proxy.server);
155 else 144 else
156 config_service->UISetProxyConfigToProxyPerScheme("http", 145 config_service->UISetProxyConfigToProxyPerScheme("http",
157 config.http_proxy.server); 146 config.http_proxy.server);
158 } 147 }
159 } else if (path == kProxyFtpUrl) { 148 } else if (path == kProxyFtpUrl) {
160 std::string val; 149 std::string val;
161 if (in_value->GetAsString(&val)) { 150 if (in_value->GetAsString(&val)) {
162 std::string uri = val;
163 AppendPortIfValid(kProxyFtpPort, &uri);
164 config_service->UISetProxyConfigToProxyPerScheme("ftp", 151 config_service->UISetProxyConfigToProxyPerScheme("ftp",
165 net::ProxyServer::FromURI(uri, net::ProxyServer::SCHEME_HTTP)); 152 CreateProxyServerFromHost(
153 val, config.ftp_proxy, net::ProxyServer::SCHEME_HTTP));
166 } 154 }
167 } else if (path == kProxyFtpPort) { 155 } else if (path == kProxyFtpPort) {
168 std::string val; 156 int val;
169 if (in_value->GetAsString(&val)) { 157 if (in_value->GetAsInteger(&val)) {
170 std::string uri;
171 FormServerUriIfValid(kProxyFtpUrl, val, &uri);
172 config_service->UISetProxyConfigToProxyPerScheme("ftp", 158 config_service->UISetProxyConfigToProxyPerScheme("ftp",
173 net::ProxyServer::FromURI(uri, net::ProxyServer::SCHEME_HTTP)); 159 CreateProxyServerFromPort(
160 val, config.ftp_proxy, net::ProxyServer::SCHEME_HTTP));
174 } 161 }
175 } else if (path == kProxySocks) { 162 } else if (path == kProxySocks) {
176 std::string val; 163 std::string val;
177 if (in_value->GetAsString(&val)) { 164 if (in_value->GetAsString(&val)) {
178 std::string uri = val;
179 AppendPortIfValid(kProxySocksPort, &uri);
180 config_service->UISetProxyConfigToProxyPerScheme("socks", 165 config_service->UISetProxyConfigToProxyPerScheme("socks",
181 net::ProxyServer::FromURI(uri, 166 CreateProxyServerFromHost(val, config.socks_proxy,
182 StartsWithASCII(uri, "socks4://", false) ? 167 StartsWithASCII(val, "socks5://", false) ?
183 net::ProxyServer::SCHEME_SOCKS4 : 168 net::ProxyServer::SCHEME_SOCKS5 :
184 net::ProxyServer::SCHEME_SOCKS5)); 169 net::ProxyServer::SCHEME_SOCKS4));
185 } 170 }
186 } else if (path == kProxySocksPort) { 171 } else if (path == kProxySocksPort) {
187 std::string val; 172 int val;
188 if (in_value->GetAsString(&val)) { 173 if (in_value->GetAsInteger(&val)) {
189 std::string uri; 174 std::string host = config.socks_proxy.server.host_port_pair().host();
190 FormServerUriIfValid(kProxySocks, val, &uri);
191 config_service->UISetProxyConfigToProxyPerScheme("socks", 175 config_service->UISetProxyConfigToProxyPerScheme("socks",
192 net::ProxyServer::FromURI(uri, 176 CreateProxyServerFromPort(val, config.socks_proxy,
193 StartsWithASCII(uri, "socks4://", false) ? 177 StartsWithASCII(host, "socks5://", false) ?
194 net::ProxyServer::SCHEME_SOCKS4 : 178 net::ProxyServer::SCHEME_SOCKS5 :
195 net::ProxyServer::SCHEME_SOCKS5)); 179 net::ProxyServer::SCHEME_SOCKS4));
196 } 180 }
197 } else if (path == kProxyIgnoreList) { 181 } else if (path == kProxyIgnoreList) {
198 net::ProxyBypassRules bypass_rules; 182 net::ProxyBypassRules bypass_rules;
199 if (in_value->GetType() == Value::TYPE_LIST) { 183 if (in_value->GetType() == Value::TYPE_LIST) {
200 const ListValue* list_value = static_cast<const ListValue*>(in_value); 184 const ListValue* list_value = static_cast<const ListValue*>(in_value);
201 for (size_t x = 0; x < list_value->GetSize(); x++) { 185 for (size_t x = 0; x < list_value->GetSize(); x++) {
202 std::string val; 186 std::string val;
203 if (list_value->GetString(x, &val)) { 187 if (list_value->GetString(x, &val)) {
204 bypass_rules.AddRuleFromString(val); 188 bypass_rules.AddRuleFromString(val);
205 } 189 }
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 return ::StartsWithASCII(path, "cros.session.proxy", true); 271 return ::StartsWithASCII(path, "cros.session.proxy", true);
288 } 272 }
289 273
290 //----------------- ProxyCrosSettingsProvider: private methods ----------------- 274 //----------------- ProxyCrosSettingsProvider: private methods -----------------
291 275
292 chromeos::ProxyConfigServiceImpl* 276 chromeos::ProxyConfigServiceImpl*
293 ProxyCrosSettingsProvider::GetConfigService() const { 277 ProxyCrosSettingsProvider::GetConfigService() const {
294 return g_browser_process->chromeos_proxy_config_service_impl(); 278 return g_browser_process->chromeos_proxy_config_service_impl();
295 } 279 }
296 280
297 void ProxyCrosSettingsProvider::AppendPortIfValid( 281 net::ProxyServer ProxyCrosSettingsProvider::CreateProxyServerFromHost(
298 const char* port_cache_key, 282 const std::string& host,
299 std::string* server_uri) { 283 const ProxyConfigServiceImpl::ProxyConfig::ManualProxy& proxy,
300 std::string port; 284 net::ProxyServer::Scheme scheme) const {
301 if (!server_uri->empty() && cache_.GetString(port_cache_key, &port) && 285 uint16 port = proxy.server.host_port_pair().port();
302 !port.empty()) { 286 if (!port)
303 *server_uri += ":" + port; 287 port = net::ProxyServer::GetDefaultPortForScheme(scheme);
304 } 288 net::HostPortPair host_port_pair(host, port);
289 return net::ProxyServer(scheme, host_port_pair);
305 } 290 }
306 291
307 void ProxyCrosSettingsProvider::FormServerUriIfValid( 292 net::ProxyServer ProxyCrosSettingsProvider::CreateProxyServerFromPort(
308 const char* host_cache_key, 293 uint16 port,
309 const std::string& port_num, std::string* server_uri) { 294 const ProxyConfigServiceImpl::ProxyConfig::ManualProxy& proxy,
310 if (cache_.GetString(host_cache_key, server_uri) && !server_uri->empty() && 295 net::ProxyServer::Scheme scheme) const {
311 !port_num.empty()) 296 std::string host = proxy.server.host_port_pair().host();
312 *server_uri += ":" + port_num; 297 net::HostPortPair host_port_pair(host, port);
298 return net::ProxyServer(scheme, host_port_pair);
313 } 299 }
314 300
315 Value* ProxyCrosSettingsProvider::CreateServerHostValue( 301 Value* ProxyCrosSettingsProvider::CreateServerHostValue(
316 const ProxyConfigServiceImpl::ProxyConfig::ManualProxy& proxy) const { 302 const ProxyConfigServiceImpl::ProxyConfig::ManualProxy& proxy) const {
317 return proxy.server.is_valid() ? 303 return proxy.server.is_valid() ?
318 Value::CreateStringValue(proxy.server.host_port_pair().host()) : 304 Value::CreateStringValue(proxy.server.host_port_pair().host()) :
319 NULL; 305 NULL;
320 } 306 }
321 307
322 Value* ProxyCrosSettingsProvider::CreateServerPortValue( 308 Value* ProxyCrosSettingsProvider::CreateServerPortValue(
323 const ProxyConfigServiceImpl::ProxyConfig::ManualProxy& proxy) const { 309 const ProxyConfigServiceImpl::ProxyConfig::ManualProxy& proxy) const {
324 return proxy.server.is_valid() ? 310 return proxy.server.is_valid() ?
325 Value::CreateIntegerValue(proxy.server.host_port_pair().port()) : 311 Value::CreateIntegerValue(proxy.server.host_port_pair().port()) :
326 NULL; 312 NULL;
327 } 313 }
328 314
329 void ProxyCrosSettingsProvider::SetCache(const std::string& key,
330 const Value* value) {
331 cache_.Set(key, value->DeepCopy());
332 }
333
334 } // namespace chromeos 315 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/proxy_cros_settings_provider.h ('k') | chrome/browser/resources/options/chromeos/proxy.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698