Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 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/net/pref_proxy_config_tracker_impl.h" | 5 #include "chrome/browser/net/pref_proxy_config_tracker_impl.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/prefs/pref_registry_simple.h" | 8 #include "base/prefs/pref_registry_simple.h" |
| 9 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
| 10 #include "base/strings/string_util.h" | |
| 10 #include "base/values.h" | 11 #include "base/values.h" |
| 11 #include "chrome/browser/chrome_notification_types.h" | 12 #include "chrome/browser/chrome_notification_types.h" |
| 12 #include "chrome/browser/prefs/proxy_config_dictionary.h" | 13 #include "chrome/browser/prefs/proxy_config_dictionary.h" |
| 13 #include "chrome/common/pref_names.h" | 14 #include "chrome/common/pref_names.h" |
| 14 #include "components/pref_registry/pref_registry_syncable.h" | 15 #include "components/pref_registry/pref_registry_syncable.h" |
| 15 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
| 16 #include "content/public/browser/notification_details.h" | 17 #include "content/public/browser/notification_details.h" |
| 17 #include "content/public/browser/notification_source.h" | 18 #include "content/public/browser/notification_source.h" |
| 19 #include "net/proxy/proxy_list.h" | |
| 20 #include "net/proxy/proxy_server.h" | |
| 18 | 21 |
| 19 using content::BrowserThread; | 22 using content::BrowserThread; |
| 20 | 23 |
| 24 namespace { | |
| 25 | |
| 26 // Determine if |proxy| is of the form "*.googlezip.net". | |
| 27 bool IsGooglezipDataReductionProxy(const net::ProxyServer& proxy) { | |
| 28 return proxy.is_valid() && !proxy.is_direct() && | |
| 29 EndsWith(proxy.host_port_pair().host(), ".googlezip.net", true); | |
| 30 } | |
| 31 | |
| 32 // Removes any Data Reduction Proxies like *.googlezip.net from |proxy_list|. | |
| 33 void RemoveGooglezipDataReductionProxiesFromList(net::ProxyList* proxy_list) { | |
| 34 if (proxy_list->IsEmpty()) | |
| 35 return; | |
| 36 | |
| 37 bool found_googlezip_proxy = false; | |
| 38 for (const net::ProxyServer& proxy : proxy_list->GetAll()) { | |
| 39 if (IsGooglezipDataReductionProxy(proxy)) { | |
| 40 found_googlezip_proxy = true; | |
| 41 break; | |
| 42 } | |
| 43 } | |
| 44 if (!found_googlezip_proxy) | |
| 45 return; | |
| 46 | |
| 47 net::ProxyList replacement_list; | |
| 48 for (const net::ProxyServer& proxy : proxy_list->GetAll()) | |
|
eroman
2015/05/12 03:13:53
can you put curlies around this?
sclittle
2015/05/12 03:30:00
Done.
| |
| 49 if (!IsGooglezipDataReductionProxy(proxy)) | |
| 50 replacement_list.AddProxyServer(proxy); | |
| 51 | |
| 52 if (replacement_list.IsEmpty()) | |
| 53 replacement_list.AddProxyServer(net::ProxyServer::Direct()); | |
| 54 *proxy_list = replacement_list; | |
| 55 } | |
| 56 | |
| 57 // Remove any Data Reduction Proxies like *.googlezip.net from |proxy_rules|. | |
| 58 // This is to prevent a Data Reduction Proxy from being activated in an | |
| 59 // unsupported way, such as from a proxy pref, which could cause Chrome to use | |
| 60 // the Data Reduction Proxy without adding any of the necessary authentication | |
| 61 // headers or applying the Data Reduction Proxy bypass logic. See | |
| 62 // http://crbug.com/476610. | |
| 63 // TODO(sclittle): Add UMA to record how often this method is called, and how | |
| 64 // often it actually removes a *.googlezip.net proxy. This method should be | |
| 65 // removed once it stops actually finding and removing *.googlezip.net proxies | |
| 66 // from the proxy rules. | |
| 67 void RemoveGooglezipDataReductionProxies( | |
| 68 net::ProxyConfig::ProxyRules* proxy_rules) { | |
| 69 RemoveGooglezipDataReductionProxiesFromList(&proxy_rules->fallback_proxies); | |
| 70 RemoveGooglezipDataReductionProxiesFromList(&proxy_rules->proxies_for_ftp); | |
| 71 RemoveGooglezipDataReductionProxiesFromList(&proxy_rules->proxies_for_http); | |
| 72 RemoveGooglezipDataReductionProxiesFromList(&proxy_rules->proxies_for_https); | |
| 73 RemoveGooglezipDataReductionProxiesFromList(&proxy_rules->single_proxies); | |
| 74 } | |
| 75 | |
| 76 } // namespace | |
| 77 | |
| 21 //============================= ChromeProxyConfigService ======================= | 78 //============================= ChromeProxyConfigService ======================= |
| 22 | 79 |
| 23 ChromeProxyConfigService::ChromeProxyConfigService( | 80 ChromeProxyConfigService::ChromeProxyConfigService( |
| 24 net::ProxyConfigService* base_service) | 81 net::ProxyConfigService* base_service) |
| 25 : base_service_(base_service), | 82 : base_service_(base_service), |
| 26 pref_config_state_(ProxyPrefs::CONFIG_UNSET), | 83 pref_config_state_(ProxyPrefs::CONFIG_UNSET), |
| 27 pref_config_read_pending_(true), | 84 pref_config_read_pending_(true), |
| 28 registered_observer_(false) { | 85 registered_observer_(false) { |
| 29 } | 86 } |
| 30 | 87 |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 172 // static | 229 // static |
| 173 net::ProxyConfigService::ConfigAvailability | 230 net::ProxyConfigService::ConfigAvailability |
| 174 PrefProxyConfigTrackerImpl::GetEffectiveProxyConfig( | 231 PrefProxyConfigTrackerImpl::GetEffectiveProxyConfig( |
| 175 ProxyPrefs::ConfigState pref_state, | 232 ProxyPrefs::ConfigState pref_state, |
| 176 const net::ProxyConfig& pref_config, | 233 const net::ProxyConfig& pref_config, |
| 177 net::ProxyConfigService::ConfigAvailability system_availability, | 234 net::ProxyConfigService::ConfigAvailability system_availability, |
| 178 const net::ProxyConfig& system_config, | 235 const net::ProxyConfig& system_config, |
| 179 bool ignore_fallback_config, | 236 bool ignore_fallback_config, |
| 180 ProxyPrefs::ConfigState* effective_config_state, | 237 ProxyPrefs::ConfigState* effective_config_state, |
| 181 net::ProxyConfig* effective_config) { | 238 net::ProxyConfig* effective_config) { |
| 239 net::ProxyConfigService::ConfigAvailability rv; | |
| 182 *effective_config_state = pref_state; | 240 *effective_config_state = pref_state; |
| 183 | 241 |
| 184 if (PrefPrecedes(pref_state)) { | 242 if (PrefPrecedes(pref_state)) { |
| 185 *effective_config = pref_config; | 243 *effective_config = pref_config; |
| 186 return net::ProxyConfigService::CONFIG_VALID; | 244 rv = net::ProxyConfigService::CONFIG_VALID; |
| 187 } | 245 } else if (system_availability == net::ProxyConfigService::CONFIG_UNSET) { |
| 188 | 246 // If there's no system proxy config, fall back to prefs or default. |
| 189 // If there's no system proxy config, fall back to prefs or default. | |
| 190 if (system_availability == net::ProxyConfigService::CONFIG_UNSET) { | |
| 191 if (pref_state == ProxyPrefs::CONFIG_FALLBACK && !ignore_fallback_config) | 247 if (pref_state == ProxyPrefs::CONFIG_FALLBACK && !ignore_fallback_config) |
| 192 *effective_config = pref_config; | 248 *effective_config = pref_config; |
| 193 else | 249 else |
| 194 *effective_config = net::ProxyConfig::CreateDirect(); | 250 *effective_config = net::ProxyConfig::CreateDirect(); |
| 195 return net::ProxyConfigService::CONFIG_VALID; | 251 rv = net::ProxyConfigService::CONFIG_VALID; |
| 252 } else { | |
| 253 *effective_config_state = ProxyPrefs::CONFIG_SYSTEM; | |
| 254 *effective_config = system_config; | |
| 255 rv = system_availability; | |
| 196 } | 256 } |
| 197 | 257 |
| 198 *effective_config_state = ProxyPrefs::CONFIG_SYSTEM; | 258 // Remove any Data Reduction Proxies like *.googlezip.net from the proxy |
| 199 *effective_config = system_config; | 259 // config rules, since specifying a DRP in the proxy rules is not a supported |
| 200 return system_availability; | 260 // means of activating the DRP, and could cause requests to be sent to the DRP |
| 261 // without the appropriate authentication headers and without using any of the | |
| 262 // DRP bypass logic. This prevents the Data Reduction Proxy from being | |
| 263 // improperly activated via the proxy pref. | |
| 264 // TODO(sclittle): This is a temporary hotfix for http://crbug.com/476610, and | |
|
eroman
2015/05/12 03:13:53
not sure what "hotfix" is supposed to mean. In my
sclittle
2015/05/12 03:30:00
Done.
| |
| 265 // should be removed once that bug is fixed and verified. | |
| 266 if (rv == net::ProxyConfigService::CONFIG_VALID) | |
| 267 RemoveGooglezipDataReductionProxies(&effective_config->proxy_rules()); | |
| 268 | |
| 269 return rv; | |
| 201 } | 270 } |
| 202 | 271 |
| 203 // static | 272 // static |
| 204 void PrefProxyConfigTrackerImpl::RegisterPrefs(PrefRegistrySimple* registry) { | 273 void PrefProxyConfigTrackerImpl::RegisterPrefs(PrefRegistrySimple* registry) { |
| 205 base::DictionaryValue* default_settings = | 274 base::DictionaryValue* default_settings = |
| 206 ProxyConfigDictionary::CreateSystem(); | 275 ProxyConfigDictionary::CreateSystem(); |
| 207 registry->RegisterDictionaryPref(prefs::kProxy, default_settings); | 276 registry->RegisterDictionaryPref(prefs::kProxy, default_settings); |
| 208 } | 277 } |
| 209 | 278 |
| 210 // static | 279 // static |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 345 (config_state_ != ProxyPrefs::CONFIG_UNSET && | 414 (config_state_ != ProxyPrefs::CONFIG_UNSET && |
| 346 !pref_config_.Equals(new_config))) { | 415 !pref_config_.Equals(new_config))) { |
| 347 config_state_ = config_state; | 416 config_state_ = config_state; |
| 348 if (config_state_ != ProxyPrefs::CONFIG_UNSET) | 417 if (config_state_ != ProxyPrefs::CONFIG_UNSET) |
| 349 pref_config_ = new_config; | 418 pref_config_ = new_config; |
| 350 update_pending_ = true; | 419 update_pending_ = true; |
| 351 } | 420 } |
| 352 if (update_pending_) | 421 if (update_pending_) |
| 353 OnProxyConfigChanged(config_state, new_config); | 422 OnProxyConfigChanged(config_state, new_config); |
| 354 } | 423 } |
| OLD | NEW |