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 99 matching lines...) Loading... |
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 (!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 = 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 (!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 = 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, |
151 net::ProxyServer* out, | 151 net::ProxyServer* out, |
152 std::string* error, | 152 std::string* error, |
153 bool* bad_message) { | 153 bool* bad_message) { |
154 std::string scheme_string; // optional. | 154 std::string scheme_string; // optional. |
155 | 155 |
(...skipping 13 matching lines...) Loading... |
169 *bad_message = true; | 169 *bad_message = true; |
170 return false; | 170 return false; |
171 } | 171 } |
172 if (!IsStringASCII(host16)) { | 172 if (!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 = 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)) |
183 port = net::ProxyServer::GetDefaultPortForScheme(scheme); | 183 port = net::ProxyServer::GetDefaultPortForScheme(scheme); |
184 | 184 |
185 *out = net::ProxyServer(scheme, net::HostPortPair(host, port)); | 185 *out = net::ProxyServer(scheme, net::HostPortPair(host, port)); |
186 | 186 |
187 return true; | 187 return true; |
188 } | 188 } |
189 | 189 |
(...skipping 80 matching lines...) Loading... |
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 (!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(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 |
286 bool GetBypassListFromExtensionPref(const base::DictionaryValue* proxy_config, | 286 bool GetBypassListFromExtensionPref(const base::DictionaryValue* proxy_config, |
287 std::string* out, | 287 std::string* out, |
288 std::string* error, | 288 std::string* error, |
289 bool* bad_message) { | 289 bool* bad_message) { |
290 const base::DictionaryValue* proxy_rules = NULL; | 290 const base::DictionaryValue* proxy_rules = NULL; |
(...skipping 200 matching lines...) 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 |