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 "components/url_fixer/url_fixer.h" | 5 #include "components/url_fixer/url_fixer.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #if defined(OS_POSIX) | 12 #if defined(OS_POSIX) |
13 #include "base/path_service.h" | 13 #include "base/path_service.h" |
14 #endif | 14 #endif |
15 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
16 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
| 17 #include "components/url_formatter/url_formatter.h" |
17 #include "net/base/escape.h" | 18 #include "net/base/escape.h" |
18 #include "net/base/filename_util.h" | 19 #include "net/base/filename_util.h" |
19 #include "net/base/net_util.h" | |
20 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" | 20 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
21 #include "url/third_party/mozilla/url_parse.h" | 21 #include "url/third_party/mozilla/url_parse.h" |
22 #include "url/url_file.h" | 22 #include "url/url_file.h" |
23 #include "url/url_util.h" | 23 #include "url/url_util.h" |
24 | 24 |
25 const char* url_fixer::home_directory_override = NULL; | 25 const char* url_fixer::home_directory_override = NULL; |
26 | 26 |
27 namespace { | 27 namespace { |
28 | 28 |
29 // Hardcode these constants to avoid dependences on //chrome and //content. | 29 // Hardcode these constants to avoid dependences on //chrome and //content. |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 #elif defined(OS_POSIX) | 173 #elif defined(OS_POSIX) |
174 base::FilePath input_path(text); | 174 base::FilePath input_path(text); |
175 PrepareStringForFileOps(input_path, &filename); | 175 PrepareStringForFileOps(input_path, &filename); |
176 if (filename.length() > 0 && filename[0] == '~') | 176 if (filename.length() > 0 && filename[0] == '~') |
177 filename = FixupHomedir(filename); | 177 filename = FixupHomedir(filename); |
178 #endif | 178 #endif |
179 | 179 |
180 // Here, we know the input looks like a file. | 180 // Here, we know the input looks like a file. |
181 GURL file_url = net::FilePathToFileURL(base::FilePath(filename)); | 181 GURL file_url = net::FilePathToFileURL(base::FilePath(filename)); |
182 if (file_url.is_valid()) { | 182 if (file_url.is_valid()) { |
183 return base::UTF16ToUTF8(net::FormatUrl(file_url, | 183 return base::UTF16ToUTF8(url_formatter::FormatUrl( |
184 std::string(), | 184 file_url, std::string(), url_formatter::kFormatUrlOmitUsernamePassword, |
185 net::kFormatUrlOmitUsernamePassword, | 185 net::UnescapeRule::NORMAL, nullptr, nullptr, nullptr)); |
186 net::UnescapeRule::NORMAL, | |
187 NULL, | |
188 NULL, | |
189 NULL)); | |
190 } | 186 } |
191 | 187 |
192 // Invalid file URL, just return the input. | 188 // Invalid file URL, just return the input. |
193 return text; | 189 return text; |
194 } | 190 } |
195 | 191 |
196 // Checks |domain| to see if a valid TLD is already present. If not, appends | 192 // Checks |domain| to see if a valid TLD is already present. If not, appends |
197 // |desired_tld| to the domain, and prepends "www." unless it's already present. | 193 // |desired_tld| to the domain, and prepends "www." unless it's already present. |
198 void AddDesiredTLD(const std::string& desired_tld, std::string* domain) { | 194 void AddDesiredTLD(const std::string& desired_tld, std::string* domain) { |
199 if (desired_tld.empty() || domain->empty()) | 195 if (desired_tld.empty() || domain->empty()) |
(...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
630 is_file = false; | 626 is_file = false; |
631 } | 627 } |
632 | 628 |
633 // Put back the current directory if we saved it. | 629 // Put back the current directory if we saved it. |
634 if (!base_dir.empty()) | 630 if (!base_dir.empty()) |
635 base::SetCurrentDirectory(old_cur_directory); | 631 base::SetCurrentDirectory(old_cur_directory); |
636 | 632 |
637 if (is_file) { | 633 if (is_file) { |
638 GURL file_url = net::FilePathToFileURL(full_path); | 634 GURL file_url = net::FilePathToFileURL(full_path); |
639 if (file_url.is_valid()) | 635 if (file_url.is_valid()) |
640 return GURL( | 636 return GURL(base::UTF16ToUTF8(url_formatter::FormatUrl( |
641 base::UTF16ToUTF8(net::FormatUrl(file_url, | 637 file_url, std::string(), |
642 std::string(), | 638 url_formatter::kFormatUrlOmitUsernamePassword, |
643 net::kFormatUrlOmitUsernamePassword, | 639 net::UnescapeRule::NORMAL, nullptr, nullptr, nullptr))); |
644 net::UnescapeRule::NORMAL, | |
645 NULL, | |
646 NULL, | |
647 NULL))); | |
648 // Invalid files fall through to regular processing. | 640 // Invalid files fall through to regular processing. |
649 } | 641 } |
650 | 642 |
651 // Fall back on regular fixup for this input. | 643 // Fall back on regular fixup for this input. |
652 #if defined(OS_WIN) | 644 #if defined(OS_WIN) |
653 std::string text_utf8 = base::WideToUTF8(text.value()); | 645 std::string text_utf8 = base::WideToUTF8(text.value()); |
654 #elif defined(OS_POSIX) | 646 #elif defined(OS_POSIX) |
655 std::string text_utf8 = text.value(); | 647 std::string text_utf8 = text.value(); |
656 #endif | 648 #endif |
657 return FixupURL(text_utf8, std::string()); | 649 return FixupURL(text_utf8, std::string()); |
(...skipping 11 matching lines...) Expand all Loading... |
669 part->reset(); | 661 part->reset(); |
670 } | 662 } |
671 } | 663 } |
672 | 664 |
673 bool url_fixer::IsEquivalentScheme(const std::string& scheme1, | 665 bool url_fixer::IsEquivalentScheme(const std::string& scheme1, |
674 const std::string& scheme2) { | 666 const std::string& scheme2) { |
675 return scheme1 == scheme2 || | 667 return scheme1 == scheme2 || |
676 (scheme1 == url::kAboutScheme && scheme2 == kChromeUIScheme) || | 668 (scheme1 == url::kAboutScheme && scheme2 == kChromeUIScheme) || |
677 (scheme1 == kChromeUIScheme && scheme2 == url::kAboutScheme); | 669 (scheme1 == kChromeUIScheme && scheme2 == url::kAboutScheme); |
678 } | 670 } |
OLD | NEW |