| 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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 UTF8ComponentToWideComponent(text_utf8, parts_utf8.query); | 68 UTF8ComponentToWideComponent(text_utf8, parts_utf8.query); |
| 69 parts->ref = | 69 parts->ref = |
| 70 UTF8ComponentToWideComponent(text_utf8, parts_utf8.ref); | 70 UTF8ComponentToWideComponent(text_utf8, parts_utf8.ref); |
| 71 } | 71 } |
| 72 | 72 |
| 73 } // namespace | 73 } // namespace |
| 74 | 74 |
| 75 // does some basic fixes for input that we want to test for file-ness | 75 // does some basic fixes for input that we want to test for file-ness |
| 76 static void PrepareStringForFileOps(const FilePath& text, | 76 static void PrepareStringForFileOps(const FilePath& text, |
| 77 FilePath::StringType* output) { | 77 FilePath::StringType* output) { |
| 78 #if defined(OS_WIN) |
| 78 TrimWhitespace(text.value(), TRIM_ALL, output); | 79 TrimWhitespace(text.value(), TRIM_ALL, output); |
| 79 #if defined(OS_WIN) | |
| 80 replace(output->begin(), output->end(), '/', '\\'); | 80 replace(output->begin(), output->end(), '/', '\\'); |
| 81 #else |
| 82 TrimWhitespaceUTF8(text.value(), TRIM_ALL, output); |
| 81 #endif | 83 #endif |
| 82 } | 84 } |
| 83 | 85 |
| 84 // Tries to create a full path from |text|. If the result is valid and the | 86 // Tries to create a full path from |text|. If the result is valid and the |
| 85 // file exists, returns true and sets |full_path| to the result. Otherwise, | 87 // file exists, returns true and sets |full_path| to the result. Otherwise, |
| 86 // returns false and leaves |full_path| unchanged. | 88 // returns false and leaves |full_path| unchanged. |
| 87 static bool ValidPathForFile(const FilePath::StringType& text, | 89 static bool ValidPathForFile(const FilePath::StringType& text, |
| 88 FilePath* full_path) { | 90 FilePath* full_path) { |
| 89 FilePath file_path(text); | 91 FilePath file_path(text); |
| 90 if (!file_util::AbsolutePath(&file_path)) | 92 if (!file_util::AbsolutePath(&file_path)) |
| (...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 423 OffsetComponent(offset, &parts->path); | 425 OffsetComponent(offset, &parts->path); |
| 424 OffsetComponent(offset, &parts->query); | 426 OffsetComponent(offset, &parts->query); |
| 425 OffsetComponent(offset, &parts->ref); | 427 OffsetComponent(offset, &parts->ref); |
| 426 | 428 |
| 427 return scheme; | 429 return scheme; |
| 428 } | 430 } |
| 429 | 431 |
| 430 string URLFixerUpper::FixupURL(const string& text, | 432 string URLFixerUpper::FixupURL(const string& text, |
| 431 const string& desired_tld) { | 433 const string& desired_tld) { |
| 432 string trimmed; | 434 string trimmed; |
| 433 TrimWhitespace(text, TRIM_ALL, &trimmed); | 435 TrimWhitespaceUTF8(text, TRIM_ALL, &trimmed); |
| 434 if (trimmed.empty()) | 436 if (trimmed.empty()) |
| 435 return string(); // Nothing here. | 437 return string(); // Nothing here. |
| 436 | 438 |
| 437 // Segment the URL. | 439 // Segment the URL. |
| 438 url_parse::Parsed parts; | 440 url_parse::Parsed parts; |
| 439 string scheme(SegmentURL(trimmed, &parts)); | 441 string scheme(SegmentURL(trimmed, &parts)); |
| 440 | 442 |
| 441 // We handle the file scheme separately. | 443 // We handle the file scheme separately. |
| 442 if (scheme == "file") | 444 if (scheme == "file") |
| 443 return (parts.scheme.is_valid() ? text : FixupPath(text)); | 445 return (parts.scheme.is_valid() ? text : FixupPath(text)); |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 547 } | 549 } |
| 548 wstring URLFixerUpper::FixupURL(const wstring& text, | 550 wstring URLFixerUpper::FixupURL(const wstring& text, |
| 549 const wstring& desired_tld) { | 551 const wstring& desired_tld) { |
| 550 return UTF8ToWide(FixupURL(WideToUTF8(text), WideToUTF8(desired_tld))); | 552 return UTF8ToWide(FixupURL(WideToUTF8(text), WideToUTF8(desired_tld))); |
| 551 } | 553 } |
| 552 wstring URLFixerUpper::FixupRelativeFile(const wstring& base_dir, | 554 wstring URLFixerUpper::FixupRelativeFile(const wstring& base_dir, |
| 553 const wstring& text) { | 555 const wstring& text) { |
| 554 return UTF8ToWide(FixupRelativeFile(FilePath::FromWStringHack(base_dir), | 556 return UTF8ToWide(FixupRelativeFile(FilePath::FromWStringHack(base_dir), |
| 555 FilePath::FromWStringHack(text))); | 557 FilePath::FromWStringHack(text))); |
| 556 } | 558 } |
| OLD | NEW |