| 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 567 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 578 // The rules are different here than for regular fixup, since we need to handle | 578 // The rules are different here than for regular fixup, since we need to handle |
| 579 // input like "hello.html" and know to look in the current directory. Regular | 579 // input like "hello.html" and know to look in the current directory. Regular |
| 580 // fixup will look for cues that it is actually a file path before trying to | 580 // fixup will look for cues that it is actually a file path before trying to |
| 581 // figure out what file it is. If our logic doesn't work, we will fall back on | 581 // figure out what file it is. If our logic doesn't work, we will fall back on |
| 582 // regular fixup. | 582 // regular fixup. |
| 583 GURL URLFixerUpper::FixupRelativeFile(const base::FilePath& base_dir, | 583 GURL URLFixerUpper::FixupRelativeFile(const base::FilePath& base_dir, |
| 584 const base::FilePath& text) { | 584 const base::FilePath& text) { |
| 585 base::FilePath old_cur_directory; | 585 base::FilePath old_cur_directory; |
| 586 if (!base_dir.empty()) { | 586 if (!base_dir.empty()) { |
| 587 // Save the old current directory before we move to the new one. | 587 // Save the old current directory before we move to the new one. |
| 588 file_util::GetCurrentDirectory(&old_cur_directory); | 588 base::GetCurrentDirectory(&old_cur_directory); |
| 589 file_util::SetCurrentDirectory(base_dir); | 589 base::SetCurrentDirectory(base_dir); |
| 590 } | 590 } |
| 591 | 591 |
| 592 // Allow funny input with extra whitespace and the wrong kind of slashes. | 592 // Allow funny input with extra whitespace and the wrong kind of slashes. |
| 593 base::FilePath::StringType trimmed; | 593 base::FilePath::StringType trimmed; |
| 594 PrepareStringForFileOps(text, &trimmed); | 594 PrepareStringForFileOps(text, &trimmed); |
| 595 | 595 |
| 596 bool is_file = true; | 596 bool is_file = true; |
| 597 // Avoid recognizing definite non-file URLs as file paths. | 597 // Avoid recognizing definite non-file URLs as file paths. |
| 598 GURL gurl(trimmed); | 598 GURL gurl(trimmed); |
| 599 if (gurl.is_valid() && gurl.IsStandard()) | 599 if (gurl.is_valid() && gurl.IsStandard()) |
| (...skipping 12 matching lines...) Expand all Loading... |
| 612 trimmed, | 612 trimmed, |
| 613 net::UnescapeRule::SPACES | net::UnescapeRule::URL_SPECIAL_CHARS); | 613 net::UnescapeRule::SPACES | net::UnescapeRule::URL_SPECIAL_CHARS); |
| 614 #endif | 614 #endif |
| 615 | 615 |
| 616 if (!ValidPathForFile(unescaped, &full_path)) | 616 if (!ValidPathForFile(unescaped, &full_path)) |
| 617 is_file = false; | 617 is_file = false; |
| 618 } | 618 } |
| 619 | 619 |
| 620 // Put back the current directory if we saved it. | 620 // Put back the current directory if we saved it. |
| 621 if (!base_dir.empty()) | 621 if (!base_dir.empty()) |
| 622 file_util::SetCurrentDirectory(old_cur_directory); | 622 base::SetCurrentDirectory(old_cur_directory); |
| 623 | 623 |
| 624 if (is_file) { | 624 if (is_file) { |
| 625 GURL file_url = net::FilePathToFileURL(full_path); | 625 GURL file_url = net::FilePathToFileURL(full_path); |
| 626 if (file_url.is_valid()) | 626 if (file_url.is_valid()) |
| 627 return GURL(base::UTF16ToUTF8(net::FormatUrl(file_url, std::string(), | 627 return GURL(base::UTF16ToUTF8(net::FormatUrl(file_url, std::string(), |
| 628 net::kFormatUrlOmitUsernamePassword, net::UnescapeRule::NORMAL, NULL, | 628 net::kFormatUrlOmitUsernamePassword, net::UnescapeRule::NORMAL, NULL, |
| 629 NULL, NULL))); | 629 NULL, NULL))); |
| 630 // Invalid files fall through to regular processing. | 630 // Invalid files fall through to regular processing. |
| 631 } | 631 } |
| 632 | 632 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 644 | 644 |
| 645 if (part->is_valid()) { | 645 if (part->is_valid()) { |
| 646 // Offset the location of this component. | 646 // Offset the location of this component. |
| 647 part->begin += offset; | 647 part->begin += offset; |
| 648 | 648 |
| 649 // This part might not have existed in the original text. | 649 // This part might not have existed in the original text. |
| 650 if (part->begin < 0) | 650 if (part->begin < 0) |
| 651 part->reset(); | 651 part->reset(); |
| 652 } | 652 } |
| 653 } | 653 } |
| OLD | NEW |