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 "app/gfx/text_elider.h" | |
10 #include "base/file_util.h" | 9 #include "base/file_util.h" |
11 #include "base/logging.h" | 10 #include "base/logging.h" |
12 #include "base/string_util.h" | 11 #include "base/string_util.h" |
13 #include "chrome/common/url_constants.h" | 12 #include "chrome/common/url_constants.h" |
14 #include "googleurl/src/gurl.h" | 13 #include "googleurl/src/gurl.h" |
15 #include "googleurl/src/url_file.h" | 14 #include "googleurl/src/url_file.h" |
16 #include "googleurl/src/url_parse.h" | 15 #include "googleurl/src/url_parse.h" |
17 #include "googleurl/src/url_util.h" | 16 #include "googleurl/src/url_util.h" |
18 #include "net/base/escape.h" | 17 #include "net/base/escape.h" |
19 #include "net/base/net_util.h" | 18 #include "net/base/net_util.h" |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 if (filename.length() > 1 && filename[1] == '|') | 114 if (filename.length() > 1 && filename[1] == '|') |
116 filename[1] = ':'; | 115 filename[1] = ':'; |
117 #elif defined(OS_POSIX) | 116 #elif defined(OS_POSIX) |
118 FilePath input_path(text); | 117 FilePath input_path(text); |
119 PrepareStringForFileOps(input_path, &filename); | 118 PrepareStringForFileOps(input_path, &filename); |
120 #endif | 119 #endif |
121 | 120 |
122 // Here, we know the input looks like a file. | 121 // Here, we know the input looks like a file. |
123 GURL file_url = net::FilePathToFileURL(FilePath(filename)); | 122 GURL file_url = net::FilePathToFileURL(FilePath(filename)); |
124 if (file_url.is_valid()) { | 123 if (file_url.is_valid()) { |
125 return WideToUTF8(gfx::GetCleanStringFromUrl(file_url, std::wstring(), | 124 return WideToUTF8(net::FormatUrl(file_url, std::wstring())); |
126 NULL, NULL)); | |
127 } | 125 } |
128 | 126 |
129 // Invalid file URL, just return the input. | 127 // Invalid file URL, just return the input. |
130 return text; | 128 return text; |
131 } | 129 } |
132 | 130 |
133 // Checks |domain| to see if a valid TLD is already present. If not, appends | 131 // Checks |domain| to see if a valid TLD is already present. If not, appends |
134 // |desired_tld| to the domain, and prepends "www." unless it's already present. | 132 // |desired_tld| to the domain, and prepends "www." unless it's already present. |
135 // Then modifies |fixed_up_url| to reflect the changes. | 133 // Then modifies |fixed_up_url| to reflect the changes. |
136 static void AddDesiredTLD(const string& desired_tld, | 134 static void AddDesiredTLD(const string& desired_tld, |
(...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
515 } | 513 } |
516 | 514 |
517 // Put back the current directory if we saved it. | 515 // Put back the current directory if we saved it. |
518 if (!base_dir.empty()) { | 516 if (!base_dir.empty()) { |
519 file_util::SetCurrentDirectory(old_cur_directory); | 517 file_util::SetCurrentDirectory(old_cur_directory); |
520 } | 518 } |
521 | 519 |
522 if (is_file) { | 520 if (is_file) { |
523 GURL file_url = net::FilePathToFileURL(full_path); | 521 GURL file_url = net::FilePathToFileURL(full_path); |
524 if (file_url.is_valid()) | 522 if (file_url.is_valid()) |
525 return WideToUTF8(gfx::GetCleanStringFromUrl(file_url, std::wstring(), | 523 return WideToUTF8(net::FormatUrl(file_url, std::wstring())); |
526 NULL, NULL)); | |
527 // Invalid files fall through to regular processing. | 524 // Invalid files fall through to regular processing. |
528 } | 525 } |
529 | 526 |
530 // Fall back on regular fixup for this input. | 527 // Fall back on regular fixup for this input. |
531 #if defined(OS_WIN) | 528 #if defined(OS_WIN) |
532 string text_utf8 = WideToUTF8(text.value()); | 529 string text_utf8 = WideToUTF8(text.value()); |
533 #elif defined(OS_POSIX) | 530 #elif defined(OS_POSIX) |
534 string text_utf8 = text.value(); | 531 string text_utf8 = text.value(); |
535 #endif | 532 #endif |
536 return FixupURL(text_utf8, ""); | 533 return FixupURL(text_utf8, ""); |
(...skipping 10 matching lines...) Expand all Loading... |
547 } | 544 } |
548 wstring URLFixerUpper::FixupURL(const wstring& text, | 545 wstring URLFixerUpper::FixupURL(const wstring& text, |
549 const wstring& desired_tld) { | 546 const wstring& desired_tld) { |
550 return UTF8ToWide(FixupURL(WideToUTF8(text), WideToUTF8(desired_tld))); | 547 return UTF8ToWide(FixupURL(WideToUTF8(text), WideToUTF8(desired_tld))); |
551 } | 548 } |
552 wstring URLFixerUpper::FixupRelativeFile(const wstring& base_dir, | 549 wstring URLFixerUpper::FixupRelativeFile(const wstring& base_dir, |
553 const wstring& text) { | 550 const wstring& text) { |
554 return UTF8ToWide(FixupRelativeFile(FilePath::FromWStringHack(base_dir), | 551 return UTF8ToWide(FixupRelativeFile(FilePath::FromWStringHack(base_dir), |
555 FilePath::FromWStringHack(text))); | 552 FilePath::FromWStringHack(text))); |
556 } | 553 } |
OLD | NEW |