OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "base/logging.h" | 5 #include "base/logging.h" |
6 #include "url/url_canon.h" | 6 #include "url/url_canon.h" |
7 #include "url/url_canon_internal.h" | 7 #include "url/url_canon_internal.h" |
8 | 8 |
9 namespace url { | 9 namespace url { |
10 | 10 |
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
302 } | 302 } |
303 | 303 |
304 // No unescaping necessary, we can safely pass the input to ICU. This | 304 // No unescaping necessary, we can safely pass the input to ICU. This |
305 // function will only get called if we either have escaped or non-ascii | 305 // function will only get called if we either have escaped or non-ascii |
306 // input, so it's safe to just use ICU now. Even if the input is ASCII, | 306 // input, so it's safe to just use ICU now. Even if the input is ASCII, |
307 // this function will do the right thing (just slower than we could). | 307 // this function will do the right thing (just slower than we could). |
308 return DoIDNHost(host, host_len, output); | 308 return DoIDNHost(host, host_len, output); |
309 } | 309 } |
310 | 310 |
311 template<typename CHAR, typename UCHAR> | 311 template<typename CHAR, typename UCHAR> |
312 bool DoHostSubstring(const CHAR* spec, | |
313 const Component& host, | |
314 CanonOutput* output) { | |
315 bool has_non_ascii, has_escaped; | |
316 ScanHostname<CHAR, UCHAR>(spec, host, &has_non_ascii, &has_escaped); | |
317 | |
318 bool success; | |
319 if (!has_non_ascii && !has_escaped) { | |
320 success = DoSimpleHost(&spec[host.begin], host.len, | |
321 output, &has_non_ascii); | |
322 DCHECK(!has_non_ascii); | |
323 } else { | |
324 success = DoComplexHost(&spec[host.begin], host.len, | |
325 has_non_ascii, has_escaped, output); | |
326 } | |
327 return success; | |
Peter Kasting
2016/10/22 05:04:20
Nit: Slightly simpler:
if (has_non_ascii || has
brettw
2016/10/24 21:45:24
Done.
| |
328 } | |
329 | |
330 template<typename CHAR, typename UCHAR> | |
312 void DoHost(const CHAR* spec, | 331 void DoHost(const CHAR* spec, |
313 const Component& host, | 332 const Component& host, |
314 CanonOutput* output, | 333 CanonOutput* output, |
315 CanonHostInfo* host_info) { | 334 CanonHostInfo* host_info) { |
316 if (host.len <= 0) { | 335 if (host.len <= 0) { |
317 // Empty hosts don't need anything. | 336 // Empty hosts don't need anything. |
318 host_info->family = CanonHostInfo::NEUTRAL; | 337 host_info->family = CanonHostInfo::NEUTRAL; |
319 host_info->out_host = Component(); | 338 host_info->out_host = Component(); |
320 return; | 339 return; |
321 } | 340 } |
322 | 341 |
323 bool has_non_ascii, has_escaped; | |
324 ScanHostname<CHAR, UCHAR>(spec, host, &has_non_ascii, &has_escaped); | |
325 | |
326 // Keep track of output's initial length, so we can rewind later. | 342 // Keep track of output's initial length, so we can rewind later. |
327 const int output_begin = output->length(); | 343 const int output_begin = output->length(); |
328 | 344 |
329 bool success; | 345 if (!DoHostSubstring<CHAR, UCHAR>(spec, host, output)) { |
Peter Kasting
2016/10/22 05:04:20
Nit: Reverse conditional and arms, so "else" does
brettw
2016/10/24 21:45:24
Done.
| |
330 if (!has_non_ascii && !has_escaped) { | |
331 success = DoSimpleHost(&spec[host.begin], host.len, | |
332 output, &has_non_ascii); | |
333 DCHECK(!has_non_ascii); | |
334 } else { | |
335 success = DoComplexHost(&spec[host.begin], host.len, | |
336 has_non_ascii, has_escaped, output); | |
337 } | |
338 | |
339 if (!success) { | |
340 // Canonicalization failed. Set BROKEN to notify the caller. | 346 // Canonicalization failed. Set BROKEN to notify the caller. |
341 host_info->family = CanonHostInfo::BROKEN; | 347 host_info->family = CanonHostInfo::BROKEN; |
342 } else { | 348 } else { |
343 // After all the other canonicalization, check if we ended up with an IP | 349 // After all the other canonicalization, check if we ended up with an IP |
344 // address. IP addresses are small, so writing into this temporary buffer | 350 // address. IP addresses are small, so writing into this temporary buffer |
345 // should not cause an allocation. | 351 // should not cause an allocation. |
346 RawCanonOutput<64> canon_ip; | 352 RawCanonOutput<64> canon_ip; |
347 CanonicalizeIPAddress(output->data(), | 353 CanonicalizeIPAddress(output->data(), |
348 MakeRange(output_begin, output->length()), | 354 MakeRange(output_begin, output->length()), |
349 &canon_ip, host_info); | 355 &canon_ip, host_info); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
389 DoHost<char, unsigned char>(spec, host, output, host_info); | 395 DoHost<char, unsigned char>(spec, host, output, host_info); |
390 } | 396 } |
391 | 397 |
392 void CanonicalizeHostVerbose(const base::char16* spec, | 398 void CanonicalizeHostVerbose(const base::char16* spec, |
393 const Component& host, | 399 const Component& host, |
394 CanonOutput* output, | 400 CanonOutput* output, |
395 CanonHostInfo* host_info) { | 401 CanonHostInfo* host_info) { |
396 DoHost<base::char16, base::char16>(spec, host, output, host_info); | 402 DoHost<base::char16, base::char16>(spec, host, output, host_info); |
397 } | 403 } |
398 | 404 |
405 bool CanonicalizeHostSubstring(const char* spec, | |
406 const Component& host, | |
407 CanonOutput* output) { | |
408 return DoHostSubstring<char, unsigned char>(spec, host, output); | |
409 } | |
410 | |
411 bool CanonicalizeHostSubstring(const base::char16* spec, | |
412 const Component& host, | |
413 CanonOutput* output) { | |
414 return DoHostSubstring<base::char16, base::char16>(spec, host, output); | |
415 } | |
416 | |
399 } // namespace url | 417 } // namespace url |
OLD | NEW |