| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 if (filename.length() > 1 && filename[1] == '|') | 114 if (filename.length() > 1 && filename[1] == '|') |
| 115 filename[1] = ':'; | 115 filename[1] = ':'; |
| 116 #elif defined(OS_POSIX) | 116 #elif defined(OS_POSIX) |
| 117 FilePath input_path(text); | 117 FilePath input_path(text); |
| 118 PrepareStringForFileOps(input_path, &filename); | 118 PrepareStringForFileOps(input_path, &filename); |
| 119 #endif | 119 #endif |
| 120 | 120 |
| 121 // Here, we know the input looks like a file. | 121 // Here, we know the input looks like a file. |
| 122 GURL file_url = net::FilePathToFileURL(FilePath(filename)); | 122 GURL file_url = net::FilePathToFileURL(FilePath(filename)); |
| 123 if (file_url.is_valid()) { | 123 if (file_url.is_valid()) { |
| 124 return WideToUTF8(net::FormatUrl(file_url, std::wstring())); | 124 return WideToUTF8(net::FormatUrl(file_url, std::wstring(), true, |
| 125 UnescapeRule::NORMAL, NULL, NULL)); |
| 125 } | 126 } |
| 126 | 127 |
| 127 // Invalid file URL, just return the input. | 128 // Invalid file URL, just return the input. |
| 128 return text; | 129 return text; |
| 129 } | 130 } |
| 130 | 131 |
| 131 // Checks |domain| to see if a valid TLD is already present. If not, appends | 132 // Checks |domain| to see if a valid TLD is already present. If not, appends |
| 132 // |desired_tld| to the domain, and prepends "www." unless it's already present. | 133 // |desired_tld| to the domain, and prepends "www." unless it's already present. |
| 133 // Then modifies |fixed_up_url| to reflect the changes. | 134 // Then modifies |fixed_up_url| to reflect the changes. |
| 134 static void AddDesiredTLD(const string& desired_tld, | 135 static void AddDesiredTLD(const string& desired_tld, |
| (...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 513 } | 514 } |
| 514 | 515 |
| 515 // Put back the current directory if we saved it. | 516 // Put back the current directory if we saved it. |
| 516 if (!base_dir.empty()) { | 517 if (!base_dir.empty()) { |
| 517 file_util::SetCurrentDirectory(old_cur_directory); | 518 file_util::SetCurrentDirectory(old_cur_directory); |
| 518 } | 519 } |
| 519 | 520 |
| 520 if (is_file) { | 521 if (is_file) { |
| 521 GURL file_url = net::FilePathToFileURL(full_path); | 522 GURL file_url = net::FilePathToFileURL(full_path); |
| 522 if (file_url.is_valid()) | 523 if (file_url.is_valid()) |
| 523 return WideToUTF8(net::FormatUrl(file_url, std::wstring())); | 524 return WideToUTF8(net::FormatUrl(file_url, std::wstring(), |
| 525 true, UnescapeRule::NORMAL, NULL, NULL)); |
| 524 // Invalid files fall through to regular processing. | 526 // Invalid files fall through to regular processing. |
| 525 } | 527 } |
| 526 | 528 |
| 527 // Fall back on regular fixup for this input. | 529 // Fall back on regular fixup for this input. |
| 528 #if defined(OS_WIN) | 530 #if defined(OS_WIN) |
| 529 string text_utf8 = WideToUTF8(text.value()); | 531 string text_utf8 = WideToUTF8(text.value()); |
| 530 #elif defined(OS_POSIX) | 532 #elif defined(OS_POSIX) |
| 531 string text_utf8 = text.value(); | 533 string text_utf8 = text.value(); |
| 532 #endif | 534 #endif |
| 533 return FixupURL(text_utf8, ""); | 535 return FixupURL(text_utf8, ""); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 544 } | 546 } |
| 545 wstring URLFixerUpper::FixupURL(const wstring& text, | 547 wstring URLFixerUpper::FixupURL(const wstring& text, |
| 546 const wstring& desired_tld) { | 548 const wstring& desired_tld) { |
| 547 return UTF8ToWide(FixupURL(WideToUTF8(text), WideToUTF8(desired_tld))); | 549 return UTF8ToWide(FixupURL(WideToUTF8(text), WideToUTF8(desired_tld))); |
| 548 } | 550 } |
| 549 wstring URLFixerUpper::FixupRelativeFile(const wstring& base_dir, | 551 wstring URLFixerUpper::FixupRelativeFile(const wstring& base_dir, |
| 550 const wstring& text) { | 552 const wstring& text) { |
| 551 return UTF8ToWide(FixupRelativeFile(FilePath::FromWStringHack(base_dir), | 553 return UTF8ToWide(FixupRelativeFile(FilePath::FromWStringHack(base_dir), |
| 552 FilePath::FromWStringHack(text))); | 554 FilePath::FromWStringHack(text))); |
| 553 } | 555 } |
| OLD | NEW |