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/browser/net/url_fixer_upper.h" | 5 #include "chrome/browser/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 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
427 } | 427 } |
428 | 428 |
429 // We need to add a scheme in order for ParseStandardURL to be happy. | 429 // We need to add a scheme in order for ParseStandardURL to be happy. |
430 // Find the first non-whitespace character. | 430 // Find the first non-whitespace character. |
431 std::string::const_iterator first_nonwhite = text.begin(); | 431 std::string::const_iterator first_nonwhite = text.begin(); |
432 while ((first_nonwhite != text.end()) && IsWhitespace(*first_nonwhite)) | 432 while ((first_nonwhite != text.end()) && IsWhitespace(*first_nonwhite)) |
433 ++first_nonwhite; | 433 ++first_nonwhite; |
434 | 434 |
435 // Construct the text to parse by inserting the scheme. | 435 // Construct the text to parse by inserting the scheme. |
436 std::string inserted_text(scheme); | 436 std::string inserted_text(scheme); |
437 inserted_text.append(chrome::kStandardSchemeSeparator); | 437 inserted_text.append(content::kStandardSchemeSeparator); |
438 std::string text_to_parse(text.begin(), first_nonwhite); | 438 std::string text_to_parse(text.begin(), first_nonwhite); |
439 text_to_parse.append(inserted_text); | 439 text_to_parse.append(inserted_text); |
440 text_to_parse.append(first_nonwhite, text.end()); | 440 text_to_parse.append(first_nonwhite, text.end()); |
441 | 441 |
442 // Have the GURL parser do the heavy lifting for us. | 442 // Have the GURL parser do the heavy lifting for us. |
443 url_parse::ParseStandardURL(text_to_parse.data(), | 443 url_parse::ParseStandardURL(text_to_parse.data(), |
444 static_cast<int>(text_to_parse.length()), | 444 static_cast<int>(text_to_parse.length()), |
445 parts); | 445 parts); |
446 | 446 |
447 // Offset the results of the parse to match the original text. | 447 // Offset the results of the parse to match the original text. |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
494 | 494 |
495 // Parse and rebuild about: and chrome: URLs, except about:blank. | 495 // Parse and rebuild about: and chrome: URLs, except about:blank. |
496 bool chrome_url = !LowerCaseEqualsASCII(trimmed, chrome::kAboutBlankURL) && | 496 bool chrome_url = !LowerCaseEqualsASCII(trimmed, chrome::kAboutBlankURL) && |
497 ((scheme == chrome::kAboutScheme) || (scheme == chrome::kChromeUIScheme)); | 497 ((scheme == chrome::kAboutScheme) || (scheme == chrome::kChromeUIScheme)); |
498 | 498 |
499 // For some schemes whose layouts we understand, we rebuild it. | 499 // For some schemes whose layouts we understand, we rebuild it. |
500 if (chrome_url || url_util::IsStandard(scheme.c_str(), | 500 if (chrome_url || url_util::IsStandard(scheme.c_str(), |
501 url_parse::Component(0, static_cast<int>(scheme.length())))) { | 501 url_parse::Component(0, static_cast<int>(scheme.length())))) { |
502 // Replace the about: scheme with the chrome: scheme. | 502 // Replace the about: scheme with the chrome: scheme. |
503 std::string url(chrome_url ? chrome::kChromeUIScheme : scheme); | 503 std::string url(chrome_url ? chrome::kChromeUIScheme : scheme); |
504 url.append(chrome::kStandardSchemeSeparator); | 504 url.append(content::kStandardSchemeSeparator); |
505 | 505 |
506 // We need to check whether the |username| is valid because it is our | 506 // We need to check whether the |username| is valid because it is our |
507 // responsibility to append the '@' to delineate the user information from | 507 // responsibility to append the '@' to delineate the user information from |
508 // the host portion of the URL. | 508 // the host portion of the URL. |
509 if (parts.username.is_valid()) { | 509 if (parts.username.is_valid()) { |
510 FixupUsername(trimmed, parts.username, &url); | 510 FixupUsername(trimmed, parts.username, &url); |
511 FixupPassword(trimmed, parts.password, &url); | 511 FixupPassword(trimmed, parts.password, &url); |
512 url.append("@"); | 512 url.append("@"); |
513 } | 513 } |
514 | 514 |
515 FixupHost(trimmed, parts.host, parts.scheme.is_valid(), desired_tld, &url); | 515 FixupHost(trimmed, parts.host, parts.scheme.is_valid(), desired_tld, &url); |
516 if (chrome_url && !parts.host.is_valid()) | 516 if (chrome_url && !parts.host.is_valid()) |
517 url.append(chrome::kChromeUIDefaultHost); | 517 url.append(chrome::kChromeUIDefaultHost); |
518 FixupPort(trimmed, parts.port, &url); | 518 FixupPort(trimmed, parts.port, &url); |
519 FixupPath(trimmed, parts.path, &url); | 519 FixupPath(trimmed, parts.path, &url); |
520 FixupQuery(trimmed, parts.query, &url); | 520 FixupQuery(trimmed, parts.query, &url); |
521 FixupRef(trimmed, parts.ref, &url); | 521 FixupRef(trimmed, parts.ref, &url); |
522 | 522 |
523 return GURL(url); | 523 return GURL(url); |
524 } | 524 } |
525 | 525 |
526 // In the worst-case, we insert a scheme if the URL lacks one. | 526 // In the worst-case, we insert a scheme if the URL lacks one. |
527 if (!parts.scheme.is_valid()) { | 527 if (!parts.scheme.is_valid()) { |
528 std::string fixed_scheme(scheme); | 528 std::string fixed_scheme(scheme); |
529 fixed_scheme.append(chrome::kStandardSchemeSeparator); | 529 fixed_scheme.append(content::kStandardSchemeSeparator); |
530 trimmed.insert(0, fixed_scheme); | 530 trimmed.insert(0, fixed_scheme); |
531 } | 531 } |
532 | 532 |
533 return GURL(trimmed); | 533 return GURL(trimmed); |
534 } | 534 } |
535 | 535 |
536 // The rules are different here than for regular fixup, since we need to handle | 536 // The rules are different here than for regular fixup, since we need to handle |
537 // input like "hello.html" and know to look in the current directory. Regular | 537 // input like "hello.html" and know to look in the current directory. Regular |
538 // fixup will look for cues that it is actually a file path before trying to | 538 // fixup will look for cues that it is actually a file path before trying to |
539 // figure out what file it is. If our logic doesn't work, we will fall back on | 539 // figure out what file it is. If our logic doesn't work, we will fall back on |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
611 | 611 |
612 if (part->is_valid()) { | 612 if (part->is_valid()) { |
613 // Offset the location of this component. | 613 // Offset the location of this component. |
614 part->begin += offset; | 614 part->begin += offset; |
615 | 615 |
616 // This part might not have existed in the original text. | 616 // This part might not have existed in the original text. |
617 if (part->begin < 0) | 617 if (part->begin < 0) |
618 part->reset(); | 618 part->reset(); |
619 } | 619 } |
620 } | 620 } |
OLD | NEW |