| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 #elif defined(OS_POSIX) | 163 #elif defined(OS_POSIX) |
| 164 FilePath input_path(text); | 164 FilePath input_path(text); |
| 165 PrepareStringForFileOps(input_path, &filename); | 165 PrepareStringForFileOps(input_path, &filename); |
| 166 if (filename.length() > 0 && filename[0] == '~') | 166 if (filename.length() > 0 && filename[0] == '~') |
| 167 filename = FixupHomedir(filename); | 167 filename = FixupHomedir(filename); |
| 168 #endif | 168 #endif |
| 169 | 169 |
| 170 // Here, we know the input looks like a file. | 170 // Here, we know the input looks like a file. |
| 171 GURL file_url = net::FilePathToFileURL(FilePath(filename)); | 171 GURL file_url = net::FilePathToFileURL(FilePath(filename)); |
| 172 if (file_url.is_valid()) { | 172 if (file_url.is_valid()) { |
| 173 return WideToUTF8(net::FormatUrl(file_url, std::wstring(), true, | 173 return WideToUTF8(net::FormatUrl(file_url, std::wstring(), |
| 174 UnescapeRule::NORMAL, NULL, NULL, NULL)); | 174 net::kFormatUrlOmitUsernamePassword, UnescapeRule::NORMAL, NULL, |
| 175 NULL, NULL)); |
| 175 } | 176 } |
| 176 | 177 |
| 177 // Invalid file URL, just return the input. | 178 // Invalid file URL, just return the input. |
| 178 return text; | 179 return text; |
| 179 } | 180 } |
| 180 | 181 |
| 181 // Checks |domain| to see if a valid TLD is already present. If not, appends | 182 // Checks |domain| to see if a valid TLD is already present. If not, appends |
| 182 // |desired_tld| to the domain, and prepends "www." unless it's already present. | 183 // |desired_tld| to the domain, and prepends "www." unless it's already present. |
| 183 static void AddDesiredTLD(const std::string& desired_tld, | 184 static void AddDesiredTLD(const std::string& desired_tld, |
| 184 std::string* domain) { | 185 std::string* domain) { |
| (...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 550 | 551 |
| 551 // Put back the current directory if we saved it. | 552 // Put back the current directory if we saved it. |
| 552 if (!base_dir.empty()) { | 553 if (!base_dir.empty()) { |
| 553 file_util::SetCurrentDirectory(old_cur_directory); | 554 file_util::SetCurrentDirectory(old_cur_directory); |
| 554 } | 555 } |
| 555 | 556 |
| 556 if (is_file) { | 557 if (is_file) { |
| 557 GURL file_url = net::FilePathToFileURL(full_path); | 558 GURL file_url = net::FilePathToFileURL(full_path); |
| 558 if (file_url.is_valid()) | 559 if (file_url.is_valid()) |
| 559 return WideToUTF8(net::FormatUrl(file_url, std::wstring(), | 560 return WideToUTF8(net::FormatUrl(file_url, std::wstring(), |
| 560 true, UnescapeRule::NORMAL, NULL, NULL, NULL)); | 561 net::kFormatUrlOmitUsernamePassword, UnescapeRule::NORMAL, NULL, |
| 562 NULL, NULL)); |
| 561 // Invalid files fall through to regular processing. | 563 // Invalid files fall through to regular processing. |
| 562 } | 564 } |
| 563 | 565 |
| 564 // Fall back on regular fixup for this input. | 566 // Fall back on regular fixup for this input. |
| 565 #if defined(OS_WIN) | 567 #if defined(OS_WIN) |
| 566 std::string text_utf8 = WideToUTF8(text.value()); | 568 std::string text_utf8 = WideToUTF8(text.value()); |
| 567 #elif defined(OS_POSIX) | 569 #elif defined(OS_POSIX) |
| 568 std::string text_utf8 = text.value(); | 570 std::string text_utf8 = text.value(); |
| 569 #endif | 571 #endif |
| 570 return FixupURL(text_utf8, ""); | 572 return FixupURL(text_utf8, ""); |
| 571 } | 573 } |
| 572 | 574 |
| 573 // Deprecated functions. To be removed when all callers are updated. | 575 // Deprecated functions. To be removed when all callers are updated. |
| 574 std::wstring URLFixerUpper::SegmentURL(const std::wstring& text, | 576 std::wstring URLFixerUpper::SegmentURL(const std::wstring& text, |
| 575 url_parse::Parsed* parts) { | 577 url_parse::Parsed* parts) { |
| 576 std::string text_utf8 = WideToUTF8(text); | 578 std::string text_utf8 = WideToUTF8(text); |
| 577 url_parse::Parsed parts_utf8; | 579 url_parse::Parsed parts_utf8; |
| 578 std::string scheme_utf8 = SegmentURL(text_utf8, &parts_utf8); | 580 std::string scheme_utf8 = SegmentURL(text_utf8, &parts_utf8); |
| 579 UTF8PartsToWideParts(text_utf8, parts_utf8, parts); | 581 UTF8PartsToWideParts(text_utf8, parts_utf8, parts); |
| 580 return UTF8ToWide(scheme_utf8); | 582 return UTF8ToWide(scheme_utf8); |
| 581 } | 583 } |
| 582 std::wstring URLFixerUpper::FixupRelativeFile(const std::wstring& base_dir, | 584 std::wstring URLFixerUpper::FixupRelativeFile(const std::wstring& base_dir, |
| 583 const std::wstring& text) { | 585 const std::wstring& text) { |
| 584 return UTF8ToWide(FixupRelativeFile(FilePath::FromWStringHack(base_dir), | 586 return UTF8ToWide(FixupRelativeFile(FilePath::FromWStringHack(base_dir), |
| 585 FilePath::FromWStringHack(text))); | 587 FilePath::FromWStringHack(text))); |
| 586 } | 588 } |
| OLD | NEW |