Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(184)

Side by Side Diff: chrome/browser/net/url_fixer_upper.cc

Issue 12314090: Add utf_string_conversions to base namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/memory_details_win.cc ('k') | chrome/browser/net/url_fixer_upper_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "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 #if defined(OS_POSIX) 9 #if defined(OS_POSIX)
10 #include "base/environment.h" 10 #include "base/environment.h"
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 // Tries to create a file: URL from |text| if it looks like a filename, even if 149 // Tries to create a file: URL from |text| if it looks like a filename, even if
150 // it doesn't resolve as a valid path or to an existing file. Returns a 150 // it doesn't resolve as a valid path or to an existing file. Returns a
151 // (possibly invalid) file: URL in |fixed_up_url| for input beginning 151 // (possibly invalid) file: URL in |fixed_up_url| for input beginning
152 // with a drive specifier or "\\". Returns the unchanged input in other cases 152 // with a drive specifier or "\\". Returns the unchanged input in other cases
153 // (including file: URLs: these don't look like filenames). 153 // (including file: URLs: these don't look like filenames).
154 static std::string FixupPath(const std::string& text) { 154 static std::string FixupPath(const std::string& text) {
155 DCHECK(!text.empty()); 155 DCHECK(!text.empty());
156 156
157 base::FilePath::StringType filename; 157 base::FilePath::StringType filename;
158 #if defined(OS_WIN) 158 #if defined(OS_WIN)
159 base::FilePath input_path(UTF8ToWide(text)); 159 base::FilePath input_path(base::UTF8ToWide(text));
160 PrepareStringForFileOps(input_path, &filename); 160 PrepareStringForFileOps(input_path, &filename);
161 161
162 // Fixup Windows-style drive letters, where "C:" gets rewritten to "C|". 162 // Fixup Windows-style drive letters, where "C:" gets rewritten to "C|".
163 if (filename.length() > 1 && filename[1] == '|') 163 if (filename.length() > 1 && filename[1] == '|')
164 filename[1] = ':'; 164 filename[1] = ':';
165 #elif defined(OS_POSIX) 165 #elif defined(OS_POSIX)
166 base::FilePath input_path(text); 166 base::FilePath input_path(text);
167 PrepareStringForFileOps(input_path, &filename); 167 PrepareStringForFileOps(input_path, &filename);
168 if (filename.length() > 0 && filename[0] == '~') 168 if (filename.length() > 0 && filename[0] == '~')
169 filename = FixupHomedir(filename); 169 filename = FixupHomedir(filename);
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after
556 // Avoid recognizing definite non-file URLs as file paths. 556 // Avoid recognizing definite non-file URLs as file paths.
557 GURL gurl(trimmed); 557 GURL gurl(trimmed);
558 if (gurl.is_valid() && gurl.IsStandard()) 558 if (gurl.is_valid() && gurl.IsStandard())
559 is_file = false; 559 is_file = false;
560 base::FilePath full_path; 560 base::FilePath full_path;
561 if (is_file && !ValidPathForFile(trimmed, &full_path)) { 561 if (is_file && !ValidPathForFile(trimmed, &full_path)) {
562 // Not a path as entered, try unescaping it in case the user has 562 // Not a path as entered, try unescaping it in case the user has
563 // escaped things. We need to go through 8-bit since the escaped values 563 // escaped things. We need to go through 8-bit since the escaped values
564 // only represent 8-bit values. 564 // only represent 8-bit values.
565 #if defined(OS_WIN) 565 #if defined(OS_WIN)
566 std::wstring unescaped = UTF8ToWide(net::UnescapeURLComponent( 566 std::wstring unescaped = base::UTF8ToWide(net::UnescapeURLComponent(
567 WideToUTF8(trimmed), 567 base::WideToUTF8(trimmed),
568 net::UnescapeRule::SPACES | net::UnescapeRule::URL_SPECIAL_CHARS)); 568 net::UnescapeRule::SPACES | net::UnescapeRule::URL_SPECIAL_CHARS));
569 #elif defined(OS_POSIX) 569 #elif defined(OS_POSIX)
570 std::string unescaped = net::UnescapeURLComponent( 570 std::string unescaped = net::UnescapeURLComponent(
571 trimmed, 571 trimmed,
572 net::UnescapeRule::SPACES | net::UnescapeRule::URL_SPECIAL_CHARS); 572 net::UnescapeRule::SPACES | net::UnescapeRule::URL_SPECIAL_CHARS);
573 #endif 573 #endif
574 574
575 if (!ValidPathForFile(unescaped, &full_path)) 575 if (!ValidPathForFile(unescaped, &full_path))
576 is_file = false; 576 is_file = false;
577 } 577 }
578 578
579 // Put back the current directory if we saved it. 579 // Put back the current directory if we saved it.
580 if (!base_dir.empty()) 580 if (!base_dir.empty())
581 file_util::SetCurrentDirectory(old_cur_directory); 581 file_util::SetCurrentDirectory(old_cur_directory);
582 582
583 if (is_file) { 583 if (is_file) {
584 GURL file_url = net::FilePathToFileURL(full_path); 584 GURL file_url = net::FilePathToFileURL(full_path);
585 if (file_url.is_valid()) 585 if (file_url.is_valid())
586 return GURL(UTF16ToUTF8(net::FormatUrl(file_url, std::string(), 586 return GURL(UTF16ToUTF8(net::FormatUrl(file_url, std::string(),
587 net::kFormatUrlOmitUsernamePassword, net::UnescapeRule::NORMAL, NULL, 587 net::kFormatUrlOmitUsernamePassword, net::UnescapeRule::NORMAL, NULL,
588 NULL, NULL))); 588 NULL, NULL)));
589 // Invalid files fall through to regular processing. 589 // Invalid files fall through to regular processing.
590 } 590 }
591 591
592 // Fall back on regular fixup for this input. 592 // Fall back on regular fixup for this input.
593 #if defined(OS_WIN) 593 #if defined(OS_WIN)
594 std::string text_utf8 = WideToUTF8(text.value()); 594 std::string text_utf8 = base::WideToUTF8(text.value());
595 #elif defined(OS_POSIX) 595 #elif defined(OS_POSIX)
596 std::string text_utf8 = text.value(); 596 std::string text_utf8 = text.value();
597 #endif 597 #endif
598 return FixupURL(text_utf8, std::string()); 598 return FixupURL(text_utf8, std::string());
599 } 599 }
600 600
601 string16 URLFixerUpper::SegmentURL(const string16& text, 601 string16 URLFixerUpper::SegmentURL(const string16& text,
602 url_parse::Parsed* parts) { 602 url_parse::Parsed* parts) {
603 std::string text_utf8 = UTF16ToUTF8(text); 603 std::string text_utf8 = UTF16ToUTF8(text);
604 url_parse::Parsed parts_utf8; 604 url_parse::Parsed parts_utf8;
605 std::string scheme_utf8 = SegmentURL(text_utf8, &parts_utf8); 605 std::string scheme_utf8 = SegmentURL(text_utf8, &parts_utf8);
606 UTF8PartsToUTF16Parts(text_utf8, parts_utf8, parts); 606 UTF8PartsToUTF16Parts(text_utf8, parts_utf8, parts);
607 return UTF8ToUTF16(scheme_utf8); 607 return UTF8ToUTF16(scheme_utf8);
608 } 608 }
609 609
610 void URLFixerUpper::OffsetComponent(int offset, url_parse::Component* part) { 610 void URLFixerUpper::OffsetComponent(int offset, url_parse::Component* part) {
611 DCHECK(part); 611 DCHECK(part);
612 612
613 if (part->is_valid()) { 613 if (part->is_valid()) {
614 // Offset the location of this component. 614 // Offset the location of this component.
615 part->begin += offset; 615 part->begin += offset;
616 616
617 // This part might not have existed in the original text. 617 // This part might not have existed in the original text.
618 if (part->begin < 0) 618 if (part->begin < 0)
619 part->reset(); 619 part->reset();
620 } 620 }
621 } 621 }
OLDNEW
« no previous file with comments | « chrome/browser/memory_details_win.cc ('k') | chrome/browser/net/url_fixer_upper_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698