| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // Implementation of helper functions for the Chrome Extensions Proxy Settings | 5 // Implementation of helper functions for the Chrome Extensions Proxy Settings |
| 6 // API. | 6 // API. |
| 7 // | 7 // |
| 8 // Throughout this code, we report errors to the user by setting an |error| | 8 // Throughout this code, we report errors to the user by setting an |error| |
| 9 // parameter, if and only if these errors can be cause by invalid input | 9 // parameter, if and only if these errors can be cause by invalid input |
| 10 // from the extension and we cannot expect that the extensions API has | 10 // from the extension and we cannot expect that the extensions API has |
| 11 // caught this error before. In all other cases we are dealing with internal | 11 // caught this error before. In all other cases we are dealing with internal |
| 12 // errors and log to LOG(ERROR). | 12 // errors and log to LOG(ERROR). |
| 13 | 13 |
| 14 #include "chrome/browser/extensions/api/proxy/proxy_api_helpers.h" | 14 #include "chrome/browser/extensions/api/proxy/proxy_api_helpers.h" |
| 15 | 15 |
| 16 #include "base/base64.h" | 16 #include "base/base64.h" |
| 17 #include "base/basictypes.h" | 17 #include "base/basictypes.h" |
| 18 #include "base/string_tokenizer.h" | 18 #include "base/string_tokenizer.h" |
| 19 #include "base/string_util.h" | 19 #include "base/string_util.h" |
| 20 #include "base/utf_string_conversions.h" | 20 #include "base/utf_string_conversions.h" |
| 21 #include "base/values.h" | 21 #include "base/values.h" |
| 22 #include "chrome/browser/extensions/api/proxy/proxy_api_constants.h" | 22 #include "chrome/browser/extensions/api/proxy/proxy_api_constants.h" |
| 23 #include "chrome/browser/prefs/proxy_config_dictionary.h" | 23 #include "chrome/browser/prefs/proxy_config_dictionary.h" |
| 24 #include "chrome/common/extensions/extension_error_utils.h" | 24 #include "extensions/common/error_utils.h" |
| 25 #include "net/base/data_url.h" | 25 #include "net/base/data_url.h" |
| 26 #include "net/proxy/proxy_config.h" | 26 #include "net/proxy/proxy_config.h" |
| 27 | 27 |
| 28 namespace extensions { | 28 namespace extensions { |
| 29 | 29 |
| 30 namespace keys = proxy_api_constants; | 30 namespace keys = proxy_api_constants; |
| 31 | 31 |
| 32 namespace proxy_api_helpers { | 32 namespace proxy_api_helpers { |
| 33 | 33 |
| 34 bool CreateDataURLFromPACScript(const std::string& pac_script, | 34 bool CreateDataURLFromPACScript(const std::string& pac_script, |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 scheme = default_scheme; | 164 scheme = default_scheme; |
| 165 | 165 |
| 166 // TODO(battre): handle UTF-8 in hostnames (http://crbug.com/72692). | 166 // TODO(battre): handle UTF-8 in hostnames (http://crbug.com/72692). |
| 167 string16 host16; | 167 string16 host16; |
| 168 if (!proxy_server->GetString(keys::kProxyConfigRuleHost, &host16)) { | 168 if (!proxy_server->GetString(keys::kProxyConfigRuleHost, &host16)) { |
| 169 LOG(ERROR) << "Could not parse a 'rules.*.host' entry."; | 169 LOG(ERROR) << "Could not parse a 'rules.*.host' entry."; |
| 170 *bad_message = true; | 170 *bad_message = true; |
| 171 return false; | 171 return false; |
| 172 } | 172 } |
| 173 if (!IsStringASCII(host16)) { | 173 if (!IsStringASCII(host16)) { |
| 174 *error = ExtensionErrorUtils::FormatErrorMessage( | 174 *error = ErrorUtils::FormatErrorMessage( |
| 175 "Invalid 'rules.???.host' entry '*'. 'host' field supports only ASCII " | 175 "Invalid 'rules.???.host' entry '*'. 'host' field supports only ASCII " |
| 176 "URLs (encode URLs in Punycode format).", | 176 "URLs (encode URLs in Punycode format).", |
| 177 UTF16ToUTF8(host16)); | 177 UTF16ToUTF8(host16)); |
| 178 return false; | 178 return false; |
| 179 } | 179 } |
| 180 std::string host = UTF16ToASCII(host16); | 180 std::string host = UTF16ToASCII(host16); |
| 181 | 181 |
| 182 int port; // optional. | 182 int port; // optional. |
| 183 if (!proxy_server->GetInteger(keys::kProxyConfigRulePort, &port)) | 183 if (!proxy_server->GetInteger(keys::kProxyConfigRulePort, &port)) |
| 184 port = net::ProxyServer::GetDefaultPortForScheme(scheme); | 184 port = net::ProxyServer::GetDefaultPortForScheme(scheme); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 } | 219 } |
| 220 } | 220 } |
| 221 } | 221 } |
| 222 | 222 |
| 223 COMPILE_ASSERT(keys::SCHEME_ALL == 0, singleProxy_must_be_first_option); | 223 COMPILE_ASSERT(keys::SCHEME_ALL == 0, singleProxy_must_be_first_option); |
| 224 | 224 |
| 225 // Handle case that only singleProxy is specified. | 225 // Handle case that only singleProxy is specified. |
| 226 if (has_proxy[keys::SCHEME_ALL]) { | 226 if (has_proxy[keys::SCHEME_ALL]) { |
| 227 for (size_t i = 1; i <= keys::SCHEME_MAX; ++i) { | 227 for (size_t i = 1; i <= keys::SCHEME_MAX; ++i) { |
| 228 if (has_proxy[i]) { | 228 if (has_proxy[i]) { |
| 229 *error = ExtensionErrorUtils::FormatErrorMessage( | 229 *error = ErrorUtils::FormatErrorMessage( |
| 230 "Proxy rule for * and * cannot be set at the same time.", | 230 "Proxy rule for * and * cannot be set at the same time.", |
| 231 keys::field_name[keys::SCHEME_ALL], keys::field_name[i]); | 231 keys::field_name[keys::SCHEME_ALL], keys::field_name[i]); |
| 232 return false; | 232 return false; |
| 233 } | 233 } |
| 234 } | 234 } |
| 235 *out = proxy_server[keys::SCHEME_ALL].ToURI(); | 235 *out = proxy_server[keys::SCHEME_ALL].ToURI(); |
| 236 return true; | 236 return true; |
| 237 } | 237 } |
| 238 | 238 |
| 239 // Handle case that anything but singleProxy is specified. | 239 // Handle case that anything but singleProxy is specified. |
| (...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 481 const std::string& delims) { | 481 const std::string& delims) { |
| 482 ListValue* out = new ListValue; | 482 ListValue* out = new ListValue; |
| 483 StringTokenizer entries(in, delims); | 483 StringTokenizer entries(in, delims); |
| 484 while (entries.GetNext()) | 484 while (entries.GetNext()) |
| 485 out->Append(Value::CreateStringValue(entries.token())); | 485 out->Append(Value::CreateStringValue(entries.token())); |
| 486 return out; | 486 return out; |
| 487 } | 487 } |
| 488 | 488 |
| 489 } // namespace proxy_api_helpers | 489 } // namespace proxy_api_helpers |
| 490 } // namespace extensions | 490 } // namespace extensions |
| OLD | NEW |