OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
405 scheme.assign(StartsWithASCII(text, "ftp.", false) ? | 405 scheme.assign(StartsWithASCII(text, "ftp.", false) ? |
406 chrome::kFtpScheme : chrome::kHttpScheme); | 406 chrome::kFtpScheme : chrome::kHttpScheme); |
407 } | 407 } |
408 | 408 |
409 // Proceed with about and chrome schemes, but not file or nonstandard schemes. | 409 // Proceed with about and chrome schemes, but not file or nonstandard schemes. |
410 if ((scheme != chrome::kAboutScheme) && (scheme != chrome::kChromeUIScheme) && | 410 if ((scheme != chrome::kAboutScheme) && (scheme != chrome::kChromeUIScheme) && |
411 ((scheme == chrome::kFileScheme) || !url_util::IsStandard(scheme.c_str(), | 411 ((scheme == chrome::kFileScheme) || !url_util::IsStandard(scheme.c_str(), |
412 url_parse::Component(0, static_cast<int>(scheme.length()))))) | 412 url_parse::Component(0, static_cast<int>(scheme.length()))))) |
413 return scheme; | 413 return scheme; |
414 | 414 |
| 415 if (scheme == chrome::kFileSystemScheme) { |
| 416 // Have the GURL parser do the heavy lifting for us. |
| 417 url_parse::ParseFileSystemURL(text.data(), |
| 418 static_cast<int>(text.length()), parts); |
| 419 return scheme; |
| 420 } |
| 421 |
415 if (parts->scheme.is_valid()) { | 422 if (parts->scheme.is_valid()) { |
416 // Have the GURL parser do the heavy lifting for us. | 423 // Have the GURL parser do the heavy lifting for us. |
417 url_parse::ParseStandardURL(text.data(), static_cast<int>(text.length()), | 424 url_parse::ParseStandardURL(text.data(), static_cast<int>(text.length()), |
418 parts); | 425 parts); |
419 return scheme; | 426 return scheme; |
420 } | 427 } |
421 | 428 |
422 // 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. |
423 // Find the first non-whitespace character. | 430 // Find the first non-whitespace character. |
424 std::string::const_iterator first_nonwhite = text.begin(); | 431 std::string::const_iterator first_nonwhite = text.begin(); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
471 return GURL(chrome::kViewSourceScheme + std::string(":") + | 478 return GURL(chrome::kViewSourceScheme + std::string(":") + |
472 FixupURL(trimmed.substr(scheme.length() + 1), | 479 FixupURL(trimmed.substr(scheme.length() + 1), |
473 desired_tld).possibly_invalid_spec()); | 480 desired_tld).possibly_invalid_spec()); |
474 } | 481 } |
475 } | 482 } |
476 | 483 |
477 // We handle the file scheme separately. | 484 // We handle the file scheme separately. |
478 if (scheme == chrome::kFileScheme) | 485 if (scheme == chrome::kFileScheme) |
479 return GURL(parts.scheme.is_valid() ? text : FixupPath(text)); | 486 return GURL(parts.scheme.is_valid() ? text : FixupPath(text)); |
480 | 487 |
| 488 // We handle the filesystem scheme separately. |
| 489 if (scheme == chrome::kFileSystemScheme) { |
| 490 if (parts.inner_parsed() && parts.inner_parsed()->scheme.is_valid()) |
| 491 return GURL(text); |
| 492 return GURL(); |
| 493 } |
| 494 |
481 // Parse and rebuild about: and chrome: URLs, except about:blank. | 495 // Parse and rebuild about: and chrome: URLs, except about:blank. |
482 bool chrome_url = !LowerCaseEqualsASCII(trimmed, chrome::kAboutBlankURL) && | 496 bool chrome_url = !LowerCaseEqualsASCII(trimmed, chrome::kAboutBlankURL) && |
483 ((scheme == chrome::kAboutScheme) || (scheme == chrome::kChromeUIScheme)); | 497 ((scheme == chrome::kAboutScheme) || (scheme == chrome::kChromeUIScheme)); |
484 | 498 |
485 // For some schemes whose layouts we understand, we rebuild it. | 499 // For some schemes whose layouts we understand, we rebuild it. |
486 if (chrome_url || url_util::IsStandard(scheme.c_str(), | 500 if (chrome_url || url_util::IsStandard(scheme.c_str(), |
487 url_parse::Component(0, static_cast<int>(scheme.length())))) { | 501 url_parse::Component(0, static_cast<int>(scheme.length())))) { |
488 // Replace the about: scheme with the chrome: scheme. | 502 // Replace the about: scheme with the chrome: scheme. |
489 std::string url(chrome_url ? chrome::kChromeUIScheme : scheme); | 503 std::string url(chrome_url ? chrome::kChromeUIScheme : scheme); |
490 url.append(chrome::kStandardSchemeSeparator); | 504 url.append(chrome::kStandardSchemeSeparator); |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
597 | 611 |
598 if (part->is_valid()) { | 612 if (part->is_valid()) { |
599 // Offset the location of this component. | 613 // Offset the location of this component. |
600 part->begin += offset; | 614 part->begin += offset; |
601 | 615 |
602 // This part might not have existed in the original text. | 616 // This part might not have existed in the original text. |
603 if (part->begin < 0) | 617 if (part->begin < 0) |
604 part->reset(); | 618 part->reset(); |
605 } | 619 } |
606 } | 620 } |
OLD | NEW |