OLD | NEW |
---|---|
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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
50 | 50 |
51 if (path == kProxyPacUrl) { | 51 if (path == kProxyPacUrl) { |
52 std::string val; | 52 std::string val; |
53 if (in_value->GetAsString(&val)) { | 53 if (in_value->GetAsString(&val)) { |
54 GURL url(val); | 54 GURL url(val); |
55 config_service->UISetProxyConfigToPACScript(url); | 55 config_service->UISetProxyConfigToPACScript(url); |
56 } | 56 } |
57 } else if (path == kProxySingleHttp) { | 57 } else if (path == kProxySingleHttp) { |
58 std::string val; | 58 std::string val; |
59 if (in_value->GetAsString(&val)) { | 59 if (in_value->GetAsString(&val)) { |
60 std::string uri = val; | 60 config_service->UISetProxyConfigToSingleProxy(CreateProxyServerFromHost( |
61 AppendPortIfValid(kProxySingleHttpPort, &uri); | 61 val, config.single_proxy, net::ProxyServer::SCHEME_HTTP)); |
xiyuan
2011/04/04 21:24:20
You need AppendPortIfValid to get cached user inpu
dtu
2011/04/04 22:48:57
This was true previously, when this function was c
xiyuan
2011/04/04 23:31:18
It would be great that the backend proxy service w
dtu
2011/04/05 00:04:11
I have tried it and it works =)
xiyuan
2011/04/05 16:32:49
Cool. Thanks for trying this out.
Then we don't n
dtu
2011/04/05 18:48:49
Huh, I thought I had already done that. Done now.
| |
62 config_service->UISetProxyConfigToSingleProxy( | |
63 net::ProxyServer::FromURI(uri, net::ProxyServer::SCHEME_HTTP)); | |
64 } | 62 } |
65 } else if (path == kProxySingleHttpPort) { | 63 } else if (path == kProxySingleHttpPort) { |
66 std::string val; | 64 int val; |
67 if (in_value->GetAsString(&val)) { | 65 if (in_value->GetAsInteger(&val)) { |
68 std::string uri; | 66 config_service->UISetProxyConfigToSingleProxy(CreateProxyServerFromPort( |
69 FormServerUriIfValid(kProxySingleHttp, val, &uri); | 67 val, config.single_proxy, net::ProxyServer::SCHEME_HTTP)); |
xiyuan
2011/04/04 21:24:20
similar, you need FormServerUriIfValid.
We might
dtu
2011/04/04 22:48:57
See above.
| |
70 config_service->UISetProxyConfigToSingleProxy( | |
71 net::ProxyServer::FromURI(uri, net::ProxyServer::SCHEME_HTTP)); | |
72 } | 68 } |
73 } else if (path == kProxyHttpUrl) { | 69 } else if (path == kProxyHttpUrl) { |
74 std::string val; | 70 std::string val; |
75 if (in_value->GetAsString(&val)) { | 71 if (in_value->GetAsString(&val)) { |
76 std::string uri = val; | |
77 AppendPortIfValid(kProxyHttpPort, &uri); | |
78 config_service->UISetProxyConfigToProxyPerScheme("http", | 72 config_service->UISetProxyConfigToProxyPerScheme("http", |
79 net::ProxyServer::FromURI(uri, net::ProxyServer::SCHEME_HTTP)); | 73 CreateProxyServerFromHost( |
74 val, config.http_proxy, net::ProxyServer::SCHEME_HTTP)); | |
80 } | 75 } |
81 } else if (path == kProxyHttpPort) { | 76 } else if (path == kProxyHttpPort) { |
82 std::string val; | 77 int val; |
83 if (in_value->GetAsString(&val)) { | 78 if (in_value->GetAsInteger(&val)) { |
84 std::string uri; | |
85 FormServerUriIfValid(kProxyHttpUrl, val, &uri); | |
86 config_service->UISetProxyConfigToProxyPerScheme("http", | 79 config_service->UISetProxyConfigToProxyPerScheme("http", |
87 net::ProxyServer::FromURI(uri, net::ProxyServer::SCHEME_HTTP)); | 80 CreateProxyServerFromPort( |
81 val, config.http_proxy, net::ProxyServer::SCHEME_HTTP)); | |
88 } | 82 } |
89 } else if (path == kProxyHttpsUrl) { | 83 } else if (path == kProxyHttpsUrl) { |
90 std::string val; | 84 std::string val; |
91 if (in_value->GetAsString(&val)) { | 85 if (in_value->GetAsString(&val)) { |
92 std::string uri = val; | |
93 AppendPortIfValid(kProxyHttpsPort, &uri); | |
94 config_service->UISetProxyConfigToProxyPerScheme("https", | 86 config_service->UISetProxyConfigToProxyPerScheme("https", |
95 net::ProxyServer::FromURI(uri, net::ProxyServer::SCHEME_HTTP)); | 87 CreateProxyServerFromHost( |
88 val, config.https_proxy, net::ProxyServer::SCHEME_HTTPS)); | |
96 } | 89 } |
97 } else if (path == kProxyHttpsPort) { | 90 } else if (path == kProxyHttpsPort) { |
98 std::string val; | 91 int val; |
99 if (in_value->GetAsString(&val)) { | 92 if (in_value->GetAsInteger(&val)) { |
100 std::string uri; | |
101 FormServerUriIfValid(kProxyHttpsUrl, val, &uri); | |
102 config_service->UISetProxyConfigToProxyPerScheme("https", | 93 config_service->UISetProxyConfigToProxyPerScheme("https", |
103 net::ProxyServer::FromURI(uri, net::ProxyServer::SCHEME_HTTP)); | 94 CreateProxyServerFromPort( |
95 val, config.https_proxy, net::ProxyServer::SCHEME_HTTPS)); | |
104 } | 96 } |
105 } else if (path == kProxyType) { | 97 } else if (path == kProxyType) { |
106 int val; | 98 int val; |
107 if (in_value->GetAsInteger(&val)) { | 99 if (in_value->GetAsInteger(&val)) { |
108 if (val == 3) { | 100 if (val == 3) { |
109 if (config.automatic_proxy.pac_url.is_valid()) | 101 if (config.automatic_proxy.pac_url.is_valid()) |
110 config_service->UISetProxyConfigToPACScript( | 102 config_service->UISetProxyConfigToPACScript( |
111 config.automatic_proxy.pac_url); | 103 config.automatic_proxy.pac_url); |
112 else | 104 else |
113 config_service->UISetProxyConfigToAutoDetect(); | 105 config_service->UISetProxyConfigToAutoDetect(); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
152 if (val) | 144 if (val) |
153 config_service->UISetProxyConfigToSingleProxy( | 145 config_service->UISetProxyConfigToSingleProxy( |
154 config.single_proxy.server); | 146 config.single_proxy.server); |
155 else | 147 else |
156 config_service->UISetProxyConfigToProxyPerScheme("http", | 148 config_service->UISetProxyConfigToProxyPerScheme("http", |
157 config.http_proxy.server); | 149 config.http_proxy.server); |
158 } | 150 } |
159 } else if (path == kProxyFtpUrl) { | 151 } else if (path == kProxyFtpUrl) { |
160 std::string val; | 152 std::string val; |
161 if (in_value->GetAsString(&val)) { | 153 if (in_value->GetAsString(&val)) { |
162 std::string uri = val; | |
163 AppendPortIfValid(kProxyFtpPort, &uri); | |
164 config_service->UISetProxyConfigToProxyPerScheme("ftp", | 154 config_service->UISetProxyConfigToProxyPerScheme("ftp", |
165 net::ProxyServer::FromURI(uri, net::ProxyServer::SCHEME_HTTP)); | 155 CreateProxyServerFromHost( |
156 val, config.ftp_proxy, net::ProxyServer::SCHEME_HTTP)); | |
166 } | 157 } |
167 } else if (path == kProxyFtpPort) { | 158 } else if (path == kProxyFtpPort) { |
168 std::string val; | 159 int val; |
169 if (in_value->GetAsString(&val)) { | 160 if (in_value->GetAsInteger(&val)) { |
170 std::string uri; | |
171 FormServerUriIfValid(kProxyFtpUrl, val, &uri); | |
172 config_service->UISetProxyConfigToProxyPerScheme("ftp", | 161 config_service->UISetProxyConfigToProxyPerScheme("ftp", |
173 net::ProxyServer::FromURI(uri, net::ProxyServer::SCHEME_HTTP)); | 162 CreateProxyServerFromPort( |
163 val, config.ftp_proxy, net::ProxyServer::SCHEME_HTTP)); | |
174 } | 164 } |
175 } else if (path == kProxySocks) { | 165 } else if (path == kProxySocks) { |
176 std::string val; | 166 std::string val; |
177 if (in_value->GetAsString(&val)) { | 167 if (in_value->GetAsString(&val)) { |
178 std::string uri = val; | |
179 AppendPortIfValid(kProxySocksPort, &uri); | |
180 config_service->UISetProxyConfigToProxyPerScheme("socks", | 168 config_service->UISetProxyConfigToProxyPerScheme("socks", |
181 net::ProxyServer::FromURI(uri, | 169 CreateProxyServerFromHost(val, config.socks_proxy, |
182 StartsWithASCII(uri, "socks4://", false) ? | 170 StartsWithASCII(val, "socks5://", false) ? |
183 net::ProxyServer::SCHEME_SOCKS4 : | 171 net::ProxyServer::SCHEME_SOCKS5 : |
184 net::ProxyServer::SCHEME_SOCKS5)); | 172 net::ProxyServer::SCHEME_SOCKS4)); |
185 } | 173 } |
186 } else if (path == kProxySocksPort) { | 174 } else if (path == kProxySocksPort) { |
187 std::string val; | 175 int val; |
188 if (in_value->GetAsString(&val)) { | 176 if (in_value->GetAsInteger(&val)) { |
189 std::string uri; | 177 std::string host = config.socks_proxy.server.host_port_pair().host(); |
190 FormServerUriIfValid(kProxySocks, val, &uri); | |
191 config_service->UISetProxyConfigToProxyPerScheme("socks", | 178 config_service->UISetProxyConfigToProxyPerScheme("socks", |
192 net::ProxyServer::FromURI(uri, | 179 CreateProxyServerFromPort(val, config.socks_proxy, |
193 StartsWithASCII(uri, "socks4://", false) ? | 180 StartsWithASCII(host, "socks5://", false) ? |
194 net::ProxyServer::SCHEME_SOCKS4 : | 181 net::ProxyServer::SCHEME_SOCKS5 : |
195 net::ProxyServer::SCHEME_SOCKS5)); | 182 net::ProxyServer::SCHEME_SOCKS4)); |
196 } | 183 } |
197 } else if (path == kProxyIgnoreList) { | 184 } else if (path == kProxyIgnoreList) { |
198 net::ProxyBypassRules bypass_rules; | 185 net::ProxyBypassRules bypass_rules; |
199 if (in_value->GetType() == Value::TYPE_LIST) { | 186 if (in_value->GetType() == Value::TYPE_LIST) { |
200 const ListValue* list_value = static_cast<const ListValue*>(in_value); | 187 const ListValue* list_value = static_cast<const ListValue*>(in_value); |
201 for (size_t x = 0; x < list_value->GetSize(); x++) { | 188 for (size_t x = 0; x < list_value->GetSize(); x++) { |
202 std::string val; | 189 std::string val; |
203 if (list_value->GetString(x, &val)) { | 190 if (list_value->GetString(x, &val)) { |
204 bypass_rules.AddRuleFromString(val); | 191 bypass_rules.AddRuleFromString(val); |
205 } | 192 } |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
287 return ::StartsWithASCII(path, "cros.session.proxy", true); | 274 return ::StartsWithASCII(path, "cros.session.proxy", true); |
288 } | 275 } |
289 | 276 |
290 //----------------- ProxyCrosSettingsProvider: private methods ----------------- | 277 //----------------- ProxyCrosSettingsProvider: private methods ----------------- |
291 | 278 |
292 chromeos::ProxyConfigServiceImpl* | 279 chromeos::ProxyConfigServiceImpl* |
293 ProxyCrosSettingsProvider::GetConfigService() const { | 280 ProxyCrosSettingsProvider::GetConfigService() const { |
294 return g_browser_process->chromeos_proxy_config_service_impl(); | 281 return g_browser_process->chromeos_proxy_config_service_impl(); |
295 } | 282 } |
296 | 283 |
297 void ProxyCrosSettingsProvider::AppendPortIfValid( | 284 net::ProxyServer ProxyCrosSettingsProvider::CreateProxyServerFromHost( |
298 const char* port_cache_key, | 285 const std::string& host, |
299 std::string* server_uri) { | 286 const ProxyConfigServiceImpl::ProxyConfig::ManualProxy& proxy, |
300 std::string port; | 287 net::ProxyServer::Scheme scheme) const { |
301 if (!server_uri->empty() && cache_.GetString(port_cache_key, &port) && | 288 uint16 port = proxy.server.host_port_pair().port(); |
302 !port.empty()) { | 289 if (!port) |
303 *server_uri += ":" + port; | 290 port = net::ProxyServer::GetDefaultPortForScheme(scheme); |
304 } | 291 net::HostPortPair host_port_pair(host, port); |
292 return net::ProxyServer(scheme, host_port_pair); | |
305 } | 293 } |
306 | 294 |
307 void ProxyCrosSettingsProvider::FormServerUriIfValid( | 295 net::ProxyServer ProxyCrosSettingsProvider::CreateProxyServerFromPort( |
308 const char* host_cache_key, | 296 uint16 port, |
309 const std::string& port_num, std::string* server_uri) { | 297 const ProxyConfigServiceImpl::ProxyConfig::ManualProxy& proxy, |
310 if (cache_.GetString(host_cache_key, server_uri) && !server_uri->empty() && | 298 net::ProxyServer::Scheme scheme) const { |
311 !port_num.empty()) | 299 std::string host = proxy.server.host_port_pair().host(); |
312 *server_uri += ":" + port_num; | 300 net::HostPortPair host_port_pair(host, port); |
301 return net::ProxyServer(scheme, host_port_pair); | |
313 } | 302 } |
314 | 303 |
315 Value* ProxyCrosSettingsProvider::CreateServerHostValue( | 304 Value* ProxyCrosSettingsProvider::CreateServerHostValue( |
316 const ProxyConfigServiceImpl::ProxyConfig::ManualProxy& proxy) const { | 305 const ProxyConfigServiceImpl::ProxyConfig::ManualProxy& proxy) const { |
317 return proxy.server.is_valid() ? | 306 return proxy.server.is_valid() ? |
318 Value::CreateStringValue(proxy.server.host_port_pair().host()) : | 307 Value::CreateStringValue(proxy.server.host_port_pair().host()) : |
319 NULL; | 308 NULL; |
320 } | 309 } |
321 | 310 |
322 Value* ProxyCrosSettingsProvider::CreateServerPortValue( | 311 Value* ProxyCrosSettingsProvider::CreateServerPortValue( |
323 const ProxyConfigServiceImpl::ProxyConfig::ManualProxy& proxy) const { | 312 const ProxyConfigServiceImpl::ProxyConfig::ManualProxy& proxy) const { |
324 return proxy.server.is_valid() ? | 313 return proxy.server.is_valid() ? |
325 Value::CreateIntegerValue(proxy.server.host_port_pair().port()) : | 314 Value::CreateIntegerValue(proxy.server.host_port_pair().port()) : |
326 NULL; | 315 NULL; |
327 } | 316 } |
328 | 317 |
329 void ProxyCrosSettingsProvider::SetCache(const std::string& key, | 318 void ProxyCrosSettingsProvider::SetCache(const std::string& key, |
330 const Value* value) { | 319 const Value* value) { |
331 cache_.Set(key, value->DeepCopy()); | 320 cache_.Set(key, value->DeepCopy()); |
332 } | 321 } |
333 | 322 |
334 } // namespace chromeos | 323 } // namespace chromeos |
OLD | NEW |