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

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

Issue 8552002: net: Move UnescapeRule into the net namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 1 month 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 FilePath input_path(text); 166 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);
170 #endif 170 #endif
171 171
172 // Here, we know the input looks like a file. 172 // Here, we know the input looks like a file.
173 GURL file_url = net::FilePathToFileURL(FilePath(filename)); 173 GURL file_url = net::FilePathToFileURL(FilePath(filename));
174 if (file_url.is_valid()) { 174 if (file_url.is_valid()) {
175 return UTF16ToUTF8(net::FormatUrl(file_url, std::string(), 175 return UTF16ToUTF8(net::FormatUrl(file_url, std::string(),
176 net::kFormatUrlOmitUsernamePassword, UnescapeRule::NORMAL, NULL, 176 net::kFormatUrlOmitUsernamePassword, net::UnescapeRule::NORMAL, NULL,
177 NULL, NULL)); 177 NULL, NULL));
178 } 178 }
179 179
180 // Invalid file URL, just return the input. 180 // Invalid file URL, just return the input.
181 return text; 181 return text;
182 } 182 }
183 183
184 // Checks |domain| to see if a valid TLD is already present. If not, appends 184 // Checks |domain| to see if a valid TLD is already present. If not, appends
185 // |desired_tld| to the domain, and prepends "www." unless it's already present. 185 // |desired_tld| to the domain, and prepends "www." unless it's already present.
186 static void AddDesiredTLD(const std::string& desired_tld, 186 static void AddDesiredTLD(const std::string& desired_tld,
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after
543 if (gurl.is_valid() && gurl.IsStandard()) 543 if (gurl.is_valid() && gurl.IsStandard())
544 is_file = false; 544 is_file = false;
545 FilePath full_path; 545 FilePath full_path;
546 if (is_file && !ValidPathForFile(trimmed, &full_path)) { 546 if (is_file && !ValidPathForFile(trimmed, &full_path)) {
547 // Not a path as entered, try unescaping it in case the user has 547 // Not a path as entered, try unescaping it in case the user has
548 // escaped things. We need to go through 8-bit since the escaped values 548 // escaped things. We need to go through 8-bit since the escaped values
549 // only represent 8-bit values. 549 // only represent 8-bit values.
550 #if defined(OS_WIN) 550 #if defined(OS_WIN)
551 std::wstring unescaped = UTF8ToWide(net::UnescapeURLComponent( 551 std::wstring unescaped = UTF8ToWide(net::UnescapeURLComponent(
552 WideToUTF8(trimmed), 552 WideToUTF8(trimmed),
553 UnescapeRule::SPACES | UnescapeRule::URL_SPECIAL_CHARS)); 553 net::UnescapeRule::SPACES | net::UnescapeRule::URL_SPECIAL_CHARS));
554 #elif defined(OS_POSIX) 554 #elif defined(OS_POSIX)
555 std::string unescaped = net::UnescapeURLComponent( 555 std::string unescaped = net::UnescapeURLComponent(
556 trimmed, 556 trimmed,
557 UnescapeRule::SPACES | UnescapeRule::URL_SPECIAL_CHARS); 557 net::UnescapeRule::SPACES | net::UnescapeRule::URL_SPECIAL_CHARS);
558 #endif 558 #endif
559 559
560 if (!ValidPathForFile(unescaped, &full_path)) 560 if (!ValidPathForFile(unescaped, &full_path))
561 is_file = false; 561 is_file = false;
562 } 562 }
563 563
564 // Put back the current directory if we saved it. 564 // Put back the current directory if we saved it.
565 if (!base_dir.empty()) 565 if (!base_dir.empty())
566 file_util::SetCurrentDirectory(old_cur_directory); 566 file_util::SetCurrentDirectory(old_cur_directory);
567 567
568 if (is_file) { 568 if (is_file) {
569 GURL file_url = net::FilePathToFileURL(full_path); 569 GURL file_url = net::FilePathToFileURL(full_path);
570 if (file_url.is_valid()) 570 if (file_url.is_valid())
571 return GURL(UTF16ToUTF8(net::FormatUrl(file_url, std::string(), 571 return GURL(UTF16ToUTF8(net::FormatUrl(file_url, std::string(),
572 net::kFormatUrlOmitUsernamePassword, UnescapeRule::NORMAL, NULL, 572 net::kFormatUrlOmitUsernamePassword, net::UnescapeRule::NORMAL, NULL,
573 NULL, NULL))); 573 NULL, NULL)));
574 // Invalid files fall through to regular processing. 574 // Invalid files fall through to regular processing.
575 } 575 }
576 576
577 // Fall back on regular fixup for this input. 577 // Fall back on regular fixup for this input.
578 #if defined(OS_WIN) 578 #if defined(OS_WIN)
579 std::string text_utf8 = WideToUTF8(text.value()); 579 std::string text_utf8 = WideToUTF8(text.value());
580 #elif defined(OS_POSIX) 580 #elif defined(OS_POSIX)
581 std::string text_utf8 = text.value(); 581 std::string text_utf8 = text.value();
582 #endif 582 #endif
(...skipping 14 matching lines...) Expand all
597 597
598 if (part->is_valid()) { 598 if (part->is_valid()) {
599 // Offset the location of this component. 599 // Offset the location of this component.
600 part->begin += offset; 600 part->begin += offset;
601 601
602 // This part might not have existed in the original text. 602 // This part might not have existed in the original text.
603 if (part->begin < 0) 603 if (part->begin < 0)
604 part->reset(); 604 part->reset();
605 } 605 }
606 } 606 }
OLDNEW
« no previous file with comments | « chrome/browser/net/browser_url_util.cc ('k') | chrome/browser/policy/device_management_service_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698