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

Side by Side Diff: net/base/filename_util.cc

Issue 2481923002: [WIP] make GURL::path() return a StringPiece (Closed)
Patch Set: thanks asan Created 4 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
« no previous file with comments | « ios/web/webui/crw_web_ui_manager_unittest.mm ('k') | net/base/mac/url_conversions.mm » ('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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "net/base/filename_util.h" 5 #include "net/base/filename_util.h"
6 6
7 #include "base/files/file_path.h" 7 #include "base/files/file_path.h"
8 #include "base/files/file_util.h" 8 #include "base/files/file_util.h"
9 #include "base/path_service.h" 9 #include "base/path_service.h"
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 if (!url.is_valid()) 66 if (!url.is_valid())
67 return false; 67 return false;
68 68
69 #if defined(OS_WIN) 69 #if defined(OS_WIN)
70 std::string path; 70 std::string path;
71 std::string host = url.host(); 71 std::string host = url.host();
72 if (host.empty()) { 72 if (host.empty()) {
73 // URL contains no host, the path is the filename. In this case, the path 73 // URL contains no host, the path is the filename. In this case, the path
74 // will probably be preceeded with a slash, as in "/C:/foo.txt", so we 74 // will probably be preceeded with a slash, as in "/C:/foo.txt", so we
75 // trim out that here. 75 // trim out that here.
76 path = url.path(); 76 path = url.path().as_string();
77 size_t first_non_slash = path.find_first_not_of("/\\"); 77 size_t first_non_slash = path.find_first_not_of("/\\");
78 if (first_non_slash != std::string::npos && first_non_slash > 0) 78 if (first_non_slash != std::string::npos && first_non_slash > 0)
79 path.erase(0, first_non_slash); 79 path.erase(0, first_non_slash);
80 } else { 80 } else {
81 // URL contains a host: this means it's UNC. We keep the preceeding slash 81 // URL contains a host: this means it's UNC. We keep the preceeding slash
82 // on the path. 82 // on the path.
83 path = "\\\\"; 83 path = "\\\\";
84 path.append(host); 84 path.append(host);
85 path.append(url.path()); 85 path.append(url.path().as_string());
86 } 86 }
87 std::replace(path.begin(), path.end(), '/', '\\'); 87 std::replace(path.begin(), path.end(), '/', '\\');
88 #else // defined(OS_WIN) 88 #else // defined(OS_WIN)
89 // Firefox seems to ignore the "host" of a file url if there is one. That is, 89 // Firefox seems to ignore the "host" of a file url if there is one. That is,
90 // file://foo/bar.txt maps to /bar.txt. 90 // file://foo/bar.txt maps to /bar.txt.
91 // TODO(dhg): This should probably take into account UNCs which could 91 // TODO(dhg): This should probably take into account UNCs which could
92 // include a hostname other than localhost or blank 92 // include a hostname other than localhost or blank
93 std::string path = url.path(); 93 std::string path = url.path().as_string();
94 #endif // !defined(OS_WIN) 94 #endif // !defined(OS_WIN)
95 95
96 if (path.empty()) 96 if (path.empty())
97 return false; 97 return false;
98 98
99 // GURL stores strings as percent-encoded 8-bit, this will undo if possible. 99 // GURL stores strings as percent-encoded 8-bit, this will undo if possible.
100 path = UnescapeURLComponent( 100 path = UnescapeURLComponent(
101 path, UnescapeRule::SPACES | 101 path, UnescapeRule::SPACES |
102 UnescapeRule::URL_SPECIAL_CHARS_EXCEPT_PATH_SEPARATORS); 102 UnescapeRule::URL_SPECIAL_CHARS_EXCEPT_PATH_SEPARATORS);
103 103
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 189
190 for (size_t i = 0; i < arraysize(magic_names); ++i) { 190 for (size_t i = 0; i < arraysize(magic_names); ++i) {
191 if (filename_lower == magic_names[i]) 191 if (filename_lower == magic_names[i])
192 return true; 192 return true;
193 } 193 }
194 194
195 return false; 195 return false;
196 } 196 }
197 197
198 } // namespace net 198 } // namespace net
OLDNEW
« no previous file with comments | « ios/web/webui/crw_web_ui_manager_unittest.mm ('k') | net/base/mac/url_conversions.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698