| 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 418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 429 if (semicolon != 0 && semicolon != std::string::npos) { | 429 if (semicolon != 0 && semicolon != std::string::npos) { |
| 430 (*text)[semicolon] = ':'; | 430 (*text)[semicolon] = ':'; |
| 431 if (GetValidScheme(*text, &parts->scheme, &scheme)) | 431 if (GetValidScheme(*text, &parts->scheme, &scheme)) |
| 432 found_scheme = true; | 432 found_scheme = true; |
| 433 else | 433 else |
| 434 (*text)[semicolon] = ';'; | 434 (*text)[semicolon] = ';'; |
| 435 } | 435 } |
| 436 if (!found_scheme) { | 436 if (!found_scheme) { |
| 437 // Couldn't determine the scheme, so just pick one. | 437 // Couldn't determine the scheme, so just pick one. |
| 438 parts->scheme.reset(); | 438 parts->scheme.reset(); |
| 439 scheme = base::StartsWithASCII(*text, "ftp.", false) ? url::kFtpScheme | 439 scheme = base::StartsWith(*text, "ftp.", |
| 440 : url::kHttpScheme; | 440 base::CompareCase::INSENSITIVE_ASCII) ? |
| 441 url::kFtpScheme : url::kHttpScheme; |
| 441 } | 442 } |
| 442 } | 443 } |
| 443 | 444 |
| 444 // Proceed with about and chrome schemes, but not file or nonstandard schemes. | 445 // Proceed with about and chrome schemes, but not file or nonstandard schemes. |
| 445 if ((scheme != url::kAboutScheme) && (scheme != kChromeUIScheme) && | 446 if ((scheme != url::kAboutScheme) && (scheme != kChromeUIScheme) && |
| 446 ((scheme == url::kFileScheme) || | 447 ((scheme == url::kFileScheme) || |
| 447 !url::IsStandard( | 448 !url::IsStandard( |
| 448 scheme.c_str(), | 449 scheme.c_str(), |
| 449 url::Component(0, static_cast<int>(scheme.length()))))) { | 450 url::Component(0, static_cast<int>(scheme.length()))))) { |
| 450 return scheme; | 451 return scheme; |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 521 | 522 |
| 522 // Segment the URL. | 523 // Segment the URL. |
| 523 url::Parsed parts; | 524 url::Parsed parts; |
| 524 std::string scheme(SegmentURLInternal(&trimmed, &parts)); | 525 std::string scheme(SegmentURLInternal(&trimmed, &parts)); |
| 525 | 526 |
| 526 // For view-source: URLs, we strip "view-source:", do fixup, and stick it back | 527 // For view-source: URLs, we strip "view-source:", do fixup, and stick it back |
| 527 // on. This allows us to handle things like "view-source:google.com". | 528 // on. This allows us to handle things like "view-source:google.com". |
| 528 if (scheme == kViewSourceScheme) { | 529 if (scheme == kViewSourceScheme) { |
| 529 // Reject "view-source:view-source:..." to avoid deep recursion. | 530 // Reject "view-source:view-source:..." to avoid deep recursion. |
| 530 std::string view_source(kViewSourceScheme + std::string(":")); | 531 std::string view_source(kViewSourceScheme + std::string(":")); |
| 531 if (!base::StartsWithASCII(text, view_source + view_source, false)) { | 532 if (!base::StartsWith(text, view_source + view_source, |
| 533 base::CompareCase::INSENSITIVE_ASCII)) { |
| 532 return GURL(kViewSourceScheme + std::string(":") + | 534 return GURL(kViewSourceScheme + std::string(":") + |
| 533 FixupURL(trimmed.substr(scheme.length() + 1), desired_tld) | 535 FixupURL(trimmed.substr(scheme.length() + 1), desired_tld) |
| 534 .possibly_invalid_spec()); | 536 .possibly_invalid_spec()); |
| 535 } | 537 } |
| 536 } | 538 } |
| 537 | 539 |
| 538 // We handle the file scheme separately. | 540 // We handle the file scheme separately. |
| 539 if (scheme == url::kFileScheme) | 541 if (scheme == url::kFileScheme) |
| 540 return GURL(parts.scheme.is_valid() ? text : FixupPath(text)); | 542 return GURL(parts.scheme.is_valid() ? text : FixupPath(text)); |
| 541 | 543 |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 670 part->reset(); | 672 part->reset(); |
| 671 } | 673 } |
| 672 } | 674 } |
| 673 | 675 |
| 674 bool url_fixer::IsEquivalentScheme(const std::string& scheme1, | 676 bool url_fixer::IsEquivalentScheme(const std::string& scheme1, |
| 675 const std::string& scheme2) { | 677 const std::string& scheme2) { |
| 676 return scheme1 == scheme2 || | 678 return scheme1 == scheme2 || |
| 677 (scheme1 == url::kAboutScheme && scheme2 == kChromeUIScheme) || | 679 (scheme1 == url::kAboutScheme && scheme2 == kChromeUIScheme) || |
| 678 (scheme1 == kChromeUIScheme && scheme2 == url::kAboutScheme); | 680 (scheme1 == kChromeUIScheme && scheme2 == url::kAboutScheme); |
| 679 } | 681 } |
| OLD | NEW |