| 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 "chrome/common/net/url_fixer_upper.h" | 5 #include "chrome/common/net/url_fixer_upper.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #if defined(OS_POSIX) | 9 #if defined(OS_POSIX) |
| 10 #include "base/environment.h" | 10 #include "base/environment.h" |
| (...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 422 } | 422 } |
| 423 if (!found_scheme) { | 423 if (!found_scheme) { |
| 424 // Couldn't determine the scheme, so just pick one. | 424 // Couldn't determine the scheme, so just pick one. |
| 425 parts->scheme.reset(); | 425 parts->scheme.reset(); |
| 426 scheme = StartsWithASCII(*text, "ftp.", false) ? | 426 scheme = StartsWithASCII(*text, "ftp.", false) ? |
| 427 url::kFtpScheme : url::kHttpScheme; | 427 url::kFtpScheme : url::kHttpScheme; |
| 428 } | 428 } |
| 429 } | 429 } |
| 430 | 430 |
| 431 // Proceed with about and chrome schemes, but not file or nonstandard schemes. | 431 // Proceed with about and chrome schemes, but not file or nonstandard schemes. |
| 432 if ((scheme != content::kAboutScheme) && | 432 if ((scheme != url::kAboutScheme) && (scheme != content::kChromeUIScheme) && |
| 433 (scheme != content::kChromeUIScheme) && | |
| 434 ((scheme == url::kFileScheme) || | 433 ((scheme == url::kFileScheme) || |
| 435 !url::IsStandard(scheme.c_str(), | 434 !url::IsStandard( |
| 436 url::Component(0, | 435 scheme.c_str(), |
| 437 static_cast<int>(scheme.length()))))) { | 436 url::Component(0, static_cast<int>(scheme.length()))))) { |
| 438 return scheme; | 437 return scheme; |
| 439 } | 438 } |
| 440 | 439 |
| 441 if (scheme == url::kFileSystemScheme) { | 440 if (scheme == url::kFileSystemScheme) { |
| 442 // Have the GURL parser do the heavy lifting for us. | 441 // Have the GURL parser do the heavy lifting for us. |
| 443 url::ParseFileSystemURL(text->data(), static_cast<int>(text->length()), | 442 url::ParseFileSystemURL(text->data(), static_cast<int>(text->length()), |
| 444 parts); | 443 parts); |
| 445 return scheme; | 444 return scheme; |
| 446 } | 445 } |
| 447 | 446 |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 528 return GURL(parts.scheme.is_valid() ? text : FixupPath(text)); | 527 return GURL(parts.scheme.is_valid() ? text : FixupPath(text)); |
| 529 | 528 |
| 530 // We handle the filesystem scheme separately. | 529 // We handle the filesystem scheme separately. |
| 531 if (scheme == url::kFileSystemScheme) { | 530 if (scheme == url::kFileSystemScheme) { |
| 532 if (parts.inner_parsed() && parts.inner_parsed()->scheme.is_valid()) | 531 if (parts.inner_parsed() && parts.inner_parsed()->scheme.is_valid()) |
| 533 return GURL(text); | 532 return GURL(text); |
| 534 return GURL(); | 533 return GURL(); |
| 535 } | 534 } |
| 536 | 535 |
| 537 // Parse and rebuild about: and chrome: URLs, except about:blank. | 536 // Parse and rebuild about: and chrome: URLs, except about:blank. |
| 538 bool chrome_url = !LowerCaseEqualsASCII(trimmed, content::kAboutBlankURL) && | 537 bool chrome_url = |
| 539 ((scheme == content::kAboutScheme) || | 538 !LowerCaseEqualsASCII(trimmed, url::kAboutBlankURL) && |
| 540 (scheme == content::kChromeUIScheme)); | 539 ((scheme == url::kAboutScheme) || (scheme == content::kChromeUIScheme)); |
| 541 | 540 |
| 542 // For some schemes whose layouts we understand, we rebuild it. | 541 // For some schemes whose layouts we understand, we rebuild it. |
| 543 if (chrome_url || | 542 if (chrome_url || |
| 544 url::IsStandard(scheme.c_str(), | 543 url::IsStandard(scheme.c_str(), |
| 545 url::Component(0, static_cast<int>(scheme.length())))) { | 544 url::Component(0, static_cast<int>(scheme.length())))) { |
| 546 // Replace the about: scheme with the chrome: scheme. | 545 // Replace the about: scheme with the chrome: scheme. |
| 547 std::string url(chrome_url ? content::kChromeUIScheme : scheme); | 546 std::string url(chrome_url ? content::kChromeUIScheme : scheme); |
| 548 url.append(url::kStandardSchemeSeparator); | 547 url.append(url::kStandardSchemeSeparator); |
| 549 | 548 |
| 550 // We need to check whether the |username| is valid because it is our | 549 // We need to check whether the |username| is valid because it is our |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 646 | 645 |
| 647 if (part->is_valid()) { | 646 if (part->is_valid()) { |
| 648 // Offset the location of this component. | 647 // Offset the location of this component. |
| 649 part->begin += offset; | 648 part->begin += offset; |
| 650 | 649 |
| 651 // This part might not have existed in the original text. | 650 // This part might not have existed in the original text. |
| 652 if (part->begin < 0) | 651 if (part->begin < 0) |
| 653 part->reset(); | 652 part->reset(); |
| 654 } | 653 } |
| 655 } | 654 } |
| OLD | NEW |