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/extensions/extension_proxy_api.h" | 5 #include "chrome/browser/extensions/extension_proxy_api.h" |
| 6 | 6 |
| 7 #include "base/string_util.h" | 7 #include "base/string_util.h" |
| 8 #include "base/stringprintf.h" | 8 #include "base/stringprintf.h" |
| 9 #include "base/values.h" | 9 #include "base/values.h" |
| 10 #include "chrome/browser/prefs/proxy_prefs.h" | 10 #include "chrome/browser/prefs/proxy_prefs.h" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 42 "ftp", | 42 "ftp", |
| 43 "socks" }; | 43 "socks" }; |
| 44 | 44 |
| 45 } // namespace | 45 } // namespace |
| 46 | 46 |
| 47 COMPILE_ASSERT(SCHEME_MAX == SCHEME_SOCKS, SCHEME_MAX_must_equal_SCHEME_SOCKS); | 47 COMPILE_ASSERT(SCHEME_MAX == SCHEME_SOCKS, SCHEME_MAX_must_equal_SCHEME_SOCKS); |
| 48 COMPILE_ASSERT(arraysize(field_name) == SCHEME_MAX + 1, | 48 COMPILE_ASSERT(arraysize(field_name) == SCHEME_MAX + 1, |
| 49 field_name_array_is_wrong_size); | 49 field_name_array_is_wrong_size); |
| 50 COMPILE_ASSERT(arraysize(scheme_name) == SCHEME_MAX + 1, | 50 COMPILE_ASSERT(arraysize(scheme_name) == SCHEME_MAX + 1, |
| 51 scheme_name_array_is_wrong_size); | 51 scheme_name_array_is_wrong_size); |
| 52 COMPILE_ASSERT(SCHEME_ALL == 0, singleProxy_must_be_first_option); | |
| 52 | 53 |
| 53 void ProxySettingsFunction::ApplyPreference(const char* pref_path, | 54 void ProxySettingsFunction::ApplyPreference(const char* pref_path, |
| 54 Value* pref_value, | 55 Value* pref_value, |
| 55 bool incognito) { | 56 bool incognito) { |
| 56 profile()->GetExtensionService()->extension_prefs()-> | 57 profile()->GetExtensionService()->extension_prefs()-> |
| 57 SetExtensionControlledPref(extension_id(), pref_path, incognito, | 58 SetExtensionControlledPref(extension_id(), pref_path, incognito, |
| 58 pref_value); | 59 pref_value); |
| 59 } | 60 } |
| 60 | 61 |
| 61 void ProxySettingsFunction::RemovePreference(const char* pref_path, | 62 void ProxySettingsFunction::RemovePreference(const char* pref_path, |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 167 // singleProxy that will supersede per-URL proxies, but it's worth it to keep | 168 // singleProxy that will supersede per-URL proxies, but it's worth it to keep |
| 168 // the code simple and extensible. | 169 // the code simple and extensible. |
| 169 for (size_t i = 0; i <= SCHEME_MAX; ++i) { | 170 for (size_t i = 0; i <= SCHEME_MAX; ++i) { |
| 170 has_proxy[i] = proxy_rules->GetDictionary(field_name[i], &proxy_dict[i]); | 171 has_proxy[i] = proxy_rules->GetDictionary(field_name[i], &proxy_dict[i]); |
| 171 if (has_proxy[i]) { | 172 if (has_proxy[i]) { |
| 172 if (!GetProxyServer(proxy_dict[i], &proxy_server[i])) | 173 if (!GetProxyServer(proxy_dict[i], &proxy_server[i])) |
| 173 return false; | 174 return false; |
| 174 } | 175 } |
| 175 } | 176 } |
| 176 | 177 |
| 177 // A single proxy supersedes individual HTTP, HTTPS, and FTP proxies. | 178 // Handle case that only singleProxy is specified. |
| 178 if (has_proxy[SCHEME_ALL]) { | 179 if (has_proxy[SCHEME_ALL]) { |
| 179 proxy_server[SCHEME_HTTP] = proxy_server[SCHEME_ALL]; | 180 for (size_t i = 1; i <= SCHEME_MAX; ++i) { |
| 180 proxy_server[SCHEME_HTTPS] = proxy_server[SCHEME_ALL]; | 181 if (has_proxy[i]) { |
| 181 proxy_server[SCHEME_FTP] = proxy_server[SCHEME_ALL]; | 182 LOG(ERROR) << "Proxy rule for " << field_name[SCHEME_ALL] << " and " |
| 182 has_proxy[SCHEME_HTTP] = true; | 183 << field_name[i] << " cannot be set at the same time."; |
| 183 has_proxy[SCHEME_HTTPS] = true; | 184 return false; |
| 184 has_proxy[SCHEME_FTP] = true; | 185 } |
| 185 has_proxy[SCHEME_ALL] = false; | 186 } |
| 187 if (!proxy_server[SCHEME_ALL].scheme.empty()) | |
| 188 LOG(WARNING) << "Ignoring scheme attribute from proxy server."; | |
| 189 // Build the proxy preference string. | |
| 190 std::string proxy_pref; | |
| 191 proxy_pref.append(proxy_server[SCHEME_ALL].host); | |
| 192 if (proxy_server[SCHEME_ALL].port != ProxyServer::INVALID_PORT) { | |
| 193 proxy_pref.append(":"); | |
|
eroman
2011/02/08 01:11:07
It is not generally safe to form host:port pairs s
| |
| 194 proxy_pref.append(base::StringPrintf("%d", | |
| 195 proxy_server[SCHEME_ALL].port)); | |
| 196 } | |
| 197 *out = proxy_pref; | |
| 198 return true; | |
| 186 } | 199 } |
| 187 | 200 |
| 188 // TODO(pamg): Ensure that if a value is empty, that means "don't use a proxy | 201 // Handle case the anything but singleProxy is specified. |
| 189 // for this scheme". | |
| 190 | 202 |
| 191 // Build the proxy preference string. | 203 // Build the proxy preference string. |
| 192 std::string proxy_pref; | 204 std::string proxy_pref; |
| 193 for (size_t i = 0; i <= SCHEME_MAX; ++i) { | 205 for (size_t i = 1; i <= SCHEME_MAX; ++i) { |
| 194 if (has_proxy[i]) { | 206 if (has_proxy[i]) { |
| 195 // http=foopy:4010;ftp=socks://foopy2:80 | 207 // http=foopy:4010;ftp=socks://foopy2:80 |
| 196 if (!proxy_pref.empty()) | 208 if (!proxy_pref.empty()) |
| 197 proxy_pref.append(";"); | 209 proxy_pref.append(";"); |
| 198 proxy_pref.append(scheme_name[i]); | 210 proxy_pref.append(scheme_name[i]); |
| 199 proxy_pref.append("="); | 211 proxy_pref.append("="); |
| 200 proxy_pref.append(proxy_server[i].scheme); | 212 proxy_pref.append(proxy_server[i].scheme); |
| 201 proxy_pref.append("://"); | 213 proxy_pref.append("://"); |
| 202 proxy_pref.append(proxy_server[i].host); | 214 proxy_pref.append(proxy_server[i].host); |
| 203 if (proxy_server[i].port != ProxyServer::INVALID_PORT) { | 215 if (proxy_server[i].port != ProxyServer::INVALID_PORT) { |
| 204 proxy_pref.append(":"); | 216 proxy_pref.append(":"); |
| 205 proxy_pref.append(base::StringPrintf("%d", proxy_server[i].port)); | 217 proxy_pref.append(base::StringPrintf("%d", proxy_server[i].port)); |
| 206 } | 218 } |
| 207 } | 219 } |
| 208 } | 220 } |
| 209 | 221 |
| 210 *out = proxy_pref; | 222 *out = proxy_pref; |
| 211 return true; | 223 return true; |
| 212 } | 224 } |
| 213 | 225 |
| 214 bool RemoveCustomProxySettingsFunction::RunImpl() { | 226 bool RemoveCustomProxySettingsFunction::RunImpl() { |
| 215 bool incognito = false; | 227 bool incognito = false; |
| 216 args_->GetBoolean(0, &incognito); | 228 args_->GetBoolean(0, &incognito); |
| 217 | 229 |
| 218 RemovePreference(prefs::kProxy, incognito); | 230 RemovePreference(prefs::kProxy, incognito); |
| 219 return true; | 231 return true; |
| 220 } | 232 } |
| OLD | NEW |