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 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
418 } | 418 } |
419 if (!found_scheme) { | 419 if (!found_scheme) { |
420 // Couldn't determine the scheme, so just pick one. | 420 // Couldn't determine the scheme, so just pick one. |
421 parts->scheme.reset(); | 421 parts->scheme.reset(); |
422 scheme.assign(StartsWithASCII(*text, "ftp.", false) ? | 422 scheme.assign(StartsWithASCII(*text, "ftp.", false) ? |
423 content::kFtpScheme : content::kHttpScheme); | 423 content::kFtpScheme : content::kHttpScheme); |
424 } | 424 } |
425 } | 425 } |
426 | 426 |
427 // Proceed with about and chrome schemes, but not file or nonstandard schemes. | 427 // Proceed with about and chrome schemes, but not file or nonstandard schemes. |
428 if ((scheme != chrome::kAboutScheme) && (scheme != chrome::kChromeUIScheme) && | 428 if ((scheme != chrome::kAboutScheme) && |
429 ((scheme == content::kFileScheme) || !url_util::IsStandard(scheme.c_str(), | 429 (scheme != content::kChromeUIScheme) && |
430 url_parse::Component(0, static_cast<int>(scheme.length()))))) | 430 ((scheme == content::kFileScheme) || |
| 431 !url_util::IsStandard( |
| 432 scheme.c_str(), |
| 433 url_parse::Component(0, static_cast<int>(scheme.length()))))) |
431 return scheme; | 434 return scheme; |
432 | 435 |
433 if (scheme == content::kFileSystemScheme) { | 436 if (scheme == content::kFileSystemScheme) { |
434 // Have the GURL parser do the heavy lifting for us. | 437 // Have the GURL parser do the heavy lifting for us. |
435 url_parse::ParseFileSystemURL(text->data(), | 438 url_parse::ParseFileSystemURL(text->data(), |
436 static_cast<int>(text->length()), parts); | 439 static_cast<int>(text->length()), parts); |
437 return scheme; | 440 return scheme; |
438 } | 441 } |
439 | 442 |
440 if (parts->scheme.is_valid()) { | 443 if (parts->scheme.is_valid()) { |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
522 | 525 |
523 // We handle the filesystem scheme separately. | 526 // We handle the filesystem scheme separately. |
524 if (scheme == content::kFileSystemScheme) { | 527 if (scheme == content::kFileSystemScheme) { |
525 if (parts.inner_parsed() && parts.inner_parsed()->scheme.is_valid()) | 528 if (parts.inner_parsed() && parts.inner_parsed()->scheme.is_valid()) |
526 return GURL(text); | 529 return GURL(text); |
527 return GURL(); | 530 return GURL(); |
528 } | 531 } |
529 | 532 |
530 // Parse and rebuild about: and chrome: URLs, except about:blank. | 533 // Parse and rebuild about: and chrome: URLs, except about:blank. |
531 bool chrome_url = !LowerCaseEqualsASCII(trimmed, content::kAboutBlankURL) && | 534 bool chrome_url = !LowerCaseEqualsASCII(trimmed, content::kAboutBlankURL) && |
532 ((scheme == chrome::kAboutScheme) || (scheme == chrome::kChromeUIScheme)); | 535 ((scheme == chrome::kAboutScheme) || |
| 536 (scheme == content::kChromeUIScheme)); |
533 | 537 |
534 // For some schemes whose layouts we understand, we rebuild it. | 538 // For some schemes whose layouts we understand, we rebuild it. |
535 if (chrome_url || url_util::IsStandard(scheme.c_str(), | 539 if (chrome_url || url_util::IsStandard(scheme.c_str(), |
536 url_parse::Component(0, static_cast<int>(scheme.length())))) { | 540 url_parse::Component(0, static_cast<int>(scheme.length())))) { |
537 // Replace the about: scheme with the chrome: scheme. | 541 // Replace the about: scheme with the chrome: scheme. |
538 std::string url(chrome_url ? chrome::kChromeUIScheme : scheme); | 542 std::string url(chrome_url ? content::kChromeUIScheme : scheme); |
539 url.append(content::kStandardSchemeSeparator); | 543 url.append(content::kStandardSchemeSeparator); |
540 | 544 |
541 // We need to check whether the |username| is valid because it is our | 545 // We need to check whether the |username| is valid because it is our |
542 // responsibility to append the '@' to delineate the user information from | 546 // responsibility to append the '@' to delineate the user information from |
543 // the host portion of the URL. | 547 // the host portion of the URL. |
544 if (parts.username.is_valid()) { | 548 if (parts.username.is_valid()) { |
545 FixupUsername(trimmed, parts.username, &url); | 549 FixupUsername(trimmed, parts.username, &url); |
546 FixupPassword(trimmed, parts.password, &url); | 550 FixupPassword(trimmed, parts.password, &url); |
547 url.append("@"); | 551 url.append("@"); |
548 } | 552 } |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
637 | 641 |
638 if (part->is_valid()) { | 642 if (part->is_valid()) { |
639 // Offset the location of this component. | 643 // Offset the location of this component. |
640 part->begin += offset; | 644 part->begin += offset; |
641 | 645 |
642 // This part might not have existed in the original text. | 646 // This part might not have existed in the original text. |
643 if (part->begin < 0) | 647 if (part->begin < 0) |
644 part->reset(); | 648 part->reset(); |
645 } | 649 } |
646 } | 650 } |
OLD | NEW |