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 #include "components/url_fixer/url_fixer.h" | 5 #include "components/url_fixer/url_fixer.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
336 size_t port_start = scheme_component.end() + 1; | 336 size_t port_start = scheme_component.end() + 1; |
337 size_t port_end = port_start; | 337 size_t port_end = port_start; |
338 while ((port_end < original_text.length()) && | 338 while ((port_end < original_text.length()) && |
339 !url::IsAuthorityTerminator(original_text[port_end])) | 339 !url::IsAuthorityTerminator(original_text[port_end])) |
340 ++port_end; | 340 ++port_end; |
341 if (port_end == port_start) | 341 if (port_end == port_start) |
342 return false; | 342 return false; |
343 | 343 |
344 // Scan the range to see if it is entirely digits. | 344 // Scan the range to see if it is entirely digits. |
345 for (size_t i = port_start; i < port_end; ++i) { | 345 for (size_t i = port_start; i < port_end; ++i) { |
346 if (!IsAsciiDigit(original_text[i])) | 346 if (!base::IsAsciiDigit(original_text[i])) |
347 return false; | 347 return false; |
348 } | 348 } |
349 | 349 |
350 return true; | 350 return true; |
351 } | 351 } |
352 | 352 |
353 // Try to extract a valid scheme from the beginning of |text|. | 353 // Try to extract a valid scheme from the beginning of |text|. |
354 // If successful, set |scheme_component| to the text range where the scheme | 354 // If successful, set |scheme_component| to the text range where the scheme |
355 // was located, and fill |canon_scheme| with its canonicalized form. | 355 // was located, and fill |canon_scheme| with its canonicalized form. |
356 // Otherwise, return false and leave the outputs in an indeterminate state. | 356 // Otherwise, return false and leave the outputs in an indeterminate state. |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
460 if (parts->scheme.is_valid()) { | 460 if (parts->scheme.is_valid()) { |
461 // Have the GURL parser do the heavy lifting for us. | 461 // Have the GURL parser do the heavy lifting for us. |
462 url::ParseStandardURL( | 462 url::ParseStandardURL( |
463 text->data(), static_cast<int>(text->length()), parts); | 463 text->data(), static_cast<int>(text->length()), parts); |
464 return scheme; | 464 return scheme; |
465 } | 465 } |
466 | 466 |
467 // We need to add a scheme in order for ParseStandardURL to be happy. | 467 // We need to add a scheme in order for ParseStandardURL to be happy. |
468 // Find the first non-whitespace character. | 468 // Find the first non-whitespace character. |
469 std::string::iterator first_nonwhite = text->begin(); | 469 std::string::iterator first_nonwhite = text->begin(); |
470 while ((first_nonwhite != text->end()) && IsWhitespace(*first_nonwhite)) | 470 while ((first_nonwhite != text->end()) && |
| 471 base::IsUnicodeWhitespace(*first_nonwhite)) |
471 ++first_nonwhite; | 472 ++first_nonwhite; |
472 | 473 |
473 // Construct the text to parse by inserting the scheme. | 474 // Construct the text to parse by inserting the scheme. |
474 std::string inserted_text(scheme); | 475 std::string inserted_text(scheme); |
475 inserted_text.append(url::kStandardSchemeSeparator); | 476 inserted_text.append(url::kStandardSchemeSeparator); |
476 std::string text_to_parse(text->begin(), first_nonwhite); | 477 std::string text_to_parse(text->begin(), first_nonwhite); |
477 text_to_parse.append(inserted_text); | 478 text_to_parse.append(inserted_text); |
478 text_to_parse.append(first_nonwhite, text->end()); | 479 text_to_parse.append(first_nonwhite, text->end()); |
479 | 480 |
480 // Have the GURL parser do the heavy lifting for us. | 481 // Have the GURL parser do the heavy lifting for us. |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
669 part->reset(); | 670 part->reset(); |
670 } | 671 } |
671 } | 672 } |
672 | 673 |
673 bool url_fixer::IsEquivalentScheme(const std::string& scheme1, | 674 bool url_fixer::IsEquivalentScheme(const std::string& scheme1, |
674 const std::string& scheme2) { | 675 const std::string& scheme2) { |
675 return scheme1 == scheme2 || | 676 return scheme1 == scheme2 || |
676 (scheme1 == url::kAboutScheme && scheme2 == kChromeUIScheme) || | 677 (scheme1 == url::kAboutScheme && scheme2 == kChromeUIScheme) || |
677 (scheme1 == kChromeUIScheme && scheme2 == url::kAboutScheme); | 678 (scheme1 == kChromeUIScheme && scheme2 == url::kAboutScheme); |
678 } | 679 } |
OLD | NEW |