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 |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 return true; | 105 return true; |
106 | 106 |
107 // TODO(battre): Handle UTF-8 URLs (http://crbug.com/72692). | 107 // TODO(battre): Handle UTF-8 URLs (http://crbug.com/72692). |
108 base::string16 pac_url16; | 108 base::string16 pac_url16; |
109 if (pac_dict->HasKey(keys::kProxyConfigPacScriptUrl) && | 109 if (pac_dict->HasKey(keys::kProxyConfigPacScriptUrl) && |
110 !pac_dict->GetString(keys::kProxyConfigPacScriptUrl, &pac_url16)) { | 110 !pac_dict->GetString(keys::kProxyConfigPacScriptUrl, &pac_url16)) { |
111 LOG(ERROR) << "'pacScript.url' could not be parsed."; | 111 LOG(ERROR) << "'pacScript.url' could not be parsed."; |
112 *bad_message = true; | 112 *bad_message = true; |
113 return false; | 113 return false; |
114 } | 114 } |
115 if (!IsStringASCII(pac_url16)) { | 115 if (!base::IsStringASCII(pac_url16)) { |
116 *error = "'pacScript.url' supports only ASCII URLs " | 116 *error = "'pacScript.url' supports only ASCII URLs " |
117 "(encode URLs in Punycode format)."; | 117 "(encode URLs in Punycode format)."; |
118 return false; | 118 return false; |
119 } | 119 } |
120 *out = base::UTF16ToASCII(pac_url16); | 120 *out = base::UTF16ToASCII(pac_url16); |
121 return true; | 121 return true; |
122 } | 122 } |
123 | 123 |
124 bool GetPacDataFromExtensionPref(const base::DictionaryValue* proxy_config, | 124 bool GetPacDataFromExtensionPref(const base::DictionaryValue* proxy_config, |
125 std::string* out, | 125 std::string* out, |
126 std::string* error, | 126 std::string* error, |
127 bool* bad_message) { | 127 bool* bad_message) { |
128 const base::DictionaryValue* pac_dict = NULL; | 128 const base::DictionaryValue* pac_dict = NULL; |
129 proxy_config->GetDictionary(keys::kProxyConfigPacScript, &pac_dict); | 129 proxy_config->GetDictionary(keys::kProxyConfigPacScript, &pac_dict); |
130 if (!pac_dict) | 130 if (!pac_dict) |
131 return true; | 131 return true; |
132 | 132 |
133 base::string16 pac_data16; | 133 base::string16 pac_data16; |
134 if (pac_dict->HasKey(keys::kProxyConfigPacScriptData) && | 134 if (pac_dict->HasKey(keys::kProxyConfigPacScriptData) && |
135 !pac_dict->GetString(keys::kProxyConfigPacScriptData, &pac_data16)) { | 135 !pac_dict->GetString(keys::kProxyConfigPacScriptData, &pac_data16)) { |
136 LOG(ERROR) << "'pacScript.data' could not be parsed."; | 136 LOG(ERROR) << "'pacScript.data' could not be parsed."; |
137 *bad_message = true; | 137 *bad_message = true; |
138 return false; | 138 return false; |
139 } | 139 } |
140 if (!IsStringASCII(pac_data16)) { | 140 if (!base::IsStringASCII(pac_data16)) { |
141 *error = "'pacScript.data' supports only ASCII code" | 141 *error = "'pacScript.data' supports only ASCII code" |
142 "(encode URLs in Punycode format)."; | 142 "(encode URLs in Punycode format)."; |
143 return false; | 143 return false; |
144 } | 144 } |
145 *out = base::UTF16ToASCII(pac_data16); | 145 *out = base::UTF16ToASCII(pac_data16); |
146 return true; | 146 return true; |
147 } | 147 } |
148 | 148 |
149 bool GetProxyServer(const base::DictionaryValue* proxy_server, | 149 bool GetProxyServer(const base::DictionaryValue* proxy_server, |
150 net::ProxyServer::Scheme default_scheme, | 150 net::ProxyServer::Scheme default_scheme, |
(...skipping 11 matching lines...) Expand all Loading... |
162 if (scheme == net::ProxyServer::SCHEME_INVALID) | 162 if (scheme == net::ProxyServer::SCHEME_INVALID) |
163 scheme = default_scheme; | 163 scheme = default_scheme; |
164 | 164 |
165 // TODO(battre): handle UTF-8 in hostnames (http://crbug.com/72692). | 165 // TODO(battre): handle UTF-8 in hostnames (http://crbug.com/72692). |
166 base::string16 host16; | 166 base::string16 host16; |
167 if (!proxy_server->GetString(keys::kProxyConfigRuleHost, &host16)) { | 167 if (!proxy_server->GetString(keys::kProxyConfigRuleHost, &host16)) { |
168 LOG(ERROR) << "Could not parse a 'rules.*.host' entry."; | 168 LOG(ERROR) << "Could not parse a 'rules.*.host' entry."; |
169 *bad_message = true; | 169 *bad_message = true; |
170 return false; | 170 return false; |
171 } | 171 } |
172 if (!IsStringASCII(host16)) { | 172 if (!base::IsStringASCII(host16)) { |
173 *error = ErrorUtils::FormatErrorMessage( | 173 *error = ErrorUtils::FormatErrorMessage( |
174 "Invalid 'rules.???.host' entry '*'. 'host' field supports only ASCII " | 174 "Invalid 'rules.???.host' entry '*'. 'host' field supports only ASCII " |
175 "URLs (encode URLs in Punycode format).", | 175 "URLs (encode URLs in Punycode format).", |
176 base::UTF16ToUTF8(host16)); | 176 base::UTF16ToUTF8(host16)); |
177 return false; | 177 return false; |
178 } | 178 } |
179 std::string host = base::UTF16ToASCII(host16); | 179 std::string host = base::UTF16ToASCII(host16); |
180 | 180 |
181 int port; // optional. | 181 int port; // optional. |
182 if (!proxy_server->GetInteger(keys::kProxyConfigRulePort, &port)) | 182 if (!proxy_server->GetInteger(keys::kProxyConfigRulePort, &port)) |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 if (!result.empty()) | 265 if (!result.empty()) |
266 result.append(joiner); | 266 result.append(joiner); |
267 | 267 |
268 // TODO(battre): handle UTF-8 (http://crbug.com/72692). | 268 // TODO(battre): handle UTF-8 (http://crbug.com/72692). |
269 base::string16 entry; | 269 base::string16 entry; |
270 if (!list->GetString(i, &entry)) { | 270 if (!list->GetString(i, &entry)) { |
271 LOG(ERROR) << "'rules.bypassList' could not be parsed."; | 271 LOG(ERROR) << "'rules.bypassList' could not be parsed."; |
272 *bad_message = true; | 272 *bad_message = true; |
273 return false; | 273 return false; |
274 } | 274 } |
275 if (!IsStringASCII(entry)) { | 275 if (!base::IsStringASCII(entry)) { |
276 *error = "'rules.bypassList' supports only ASCII URLs " | 276 *error = "'rules.bypassList' supports only ASCII URLs " |
277 "(encode URLs in Punycode format)."; | 277 "(encode URLs in Punycode format)."; |
278 return false; | 278 return false; |
279 } | 279 } |
280 result.append(base::UTF16ToASCII(entry)); | 280 result.append(base::UTF16ToASCII(entry)); |
281 } | 281 } |
282 *out = result; | 282 *out = result; |
283 return true; | 283 return true; |
284 } | 284 } |
285 | 285 |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
491 const std::string& delims) { | 491 const std::string& delims) { |
492 base::ListValue* out = new base::ListValue; | 492 base::ListValue* out = new base::ListValue; |
493 base::StringTokenizer entries(in, delims); | 493 base::StringTokenizer entries(in, delims); |
494 while (entries.GetNext()) | 494 while (entries.GetNext()) |
495 out->Append(new base::StringValue(entries.token())); | 495 out->Append(new base::StringValue(entries.token())); |
496 return out; | 496 return out; |
497 } | 497 } |
498 | 498 |
499 } // namespace proxy_api_helpers | 499 } // namespace proxy_api_helpers |
500 } // namespace extensions | 500 } // namespace extensions |
OLD | NEW |