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

Side by Side Diff: net/base/net_util.h

Issue 7300005: Move filename determination to net_util (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: " Created 9 years, 4 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 | « content/browser/download/save_package.cc ('k') | net/base/net_util.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) 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 #ifndef NET_BASE_NET_UTIL_H_ 5 #ifndef NET_BASE_NET_UTIL_H_
6 #define NET_BASE_NET_UTIL_H_ 6 #define NET_BASE_NET_UTIL_H_
7 #pragma once 7 #pragma once
8 8
9 #include "build/build_config.h" 9 #include "build/build_config.h"
10 10
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 // 163 //
164 // When a param value is ASCII, but is not in format #2 or format #4 above, 164 // When a param value is ASCII, but is not in format #2 or format #4 above,
165 // it is returned as it is unless it's pretty close to two supported 165 // it is returned as it is unless it's pretty close to two supported
166 // formats but not well-formed. In that case, an empty string is returned. 166 // formats but not well-formed. In that case, an empty string is returned.
167 // 167 //
168 // In any case, a caller must check for the empty return value and resort to 168 // In any case, a caller must check for the empty return value and resort to
169 // another means to get a filename (e.g. url). 169 // another means to get a filename (e.g. url).
170 // 170 //
171 // This function does not do any escaping and callers are responsible for 171 // This function does not do any escaping and callers are responsible for
172 // escaping 'unsafe' characters (e.g. (back)slash, colon) as they see fit. 172 // escaping 'unsafe' characters (e.g. (back)slash, colon) as they see fit.
173 //
174 // TODO(jungshik): revisit this issue. At the moment, the only caller
175 // net_util::GetSuggestedFilename and it calls ReplaceIllegalCharacters. The
176 // other caller is a unit test. Need to figure out expose this function only to
177 // net_util_unittest.
178 //
179 NET_TEST std::string GetFileNameFromCD(const std::string& header, 173 NET_TEST std::string GetFileNameFromCD(const std::string& header,
180 const std::string& referrer_charset); 174 const std::string& referrer_charset);
181 175
182 // Converts the given host name to unicode characters. This can be called for 176 // Converts the given host name to unicode characters. This can be called for
183 // any host name, if the input is not IDN or is invalid in some way, we'll just 177 // any host name, if the input is not IDN or is invalid in some way, we'll just
184 // return the ASCII source so it is still usable. 178 // return the ASCII source so it is still usable.
185 // 179 //
186 // The input should be the canonicalized ASCII host name from GURL. This 180 // The input should be the canonicalized ASCII host name from GURL. This
187 // function does NOT accept UTF-8! 181 // function does NOT accept UTF-8!
188 // 182 //
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 // 2) the suggested name 248 // 2) the suggested name
255 // 3) the last path component name or hostname from |url| 249 // 3) the last path component name or hostname from |url|
256 // 4) the given |default_name| 250 // 4) the given |default_name|
257 // 5) the hard-coded name "download", as the last resort 251 // 5) the hard-coded name "download", as the last resort
258 NET_API string16 GetSuggestedFilename(const GURL& url, 252 NET_API string16 GetSuggestedFilename(const GURL& url,
259 const std::string& content_disposition, 253 const std::string& content_disposition,
260 const std::string& referrer_charset, 254 const std::string& referrer_charset,
261 const std::string& suggested_name, 255 const std::string& suggested_name,
262 const string16& default_name); 256 const string16& default_name);
263 257
258 // Generate a filename based on a HTTP request.
259 //
260 // The |url|, |content_disposition|, |referrer_charset|, |suggested_name|, and
261 // |default_name| parameters will be used with GetSuggestedFilename() to
262 // generate a filename. The resulting filename will be passed in along with the
263 // |mime_type| to GenerateSafeFileName() to generate the returned filename.
264 NET_API FilePath GenerateFileName(const GURL& url,
265 const std::string& content_disposition,
266 const std::string& referrer_charset,
267 const std::string& suggested_name,
268 const std::string& mime_type,
269 const string16& default_name);
270
271 // Ensures that the filename and extension is safe to use in the filesystem.
272 //
273 // Assumes that |file_path| already contains a valid path or file name. On
274 // Windows if the extension causes the file to have an unsafe interaction with
275 // the shell (see net_util::IsShellIntegratedExtension()), then it will be
276 // replaced by the string 'download'. If |file_path| doesn't contain an
277 // extension and |mime_type| is non-empty, the preferred extension for
278 // |mime_type| will be used as the extension.
279 //
280 // On Windows, the filename will be checked against a set of reserved names, and
281 // if so, an underscore will be prepended to the name.
282 //
283 // |file_name| can either be just the file name or it can be a full path to a
284 // file.
285 //
286 // Note: |mime_type| should only be non-empty if this function is called from a
287 // thread that allows IO.
288 NET_API void GenerateSafeFileName(const std::string& mime_type,
289 FilePath* file_path);
290
264 // Checks the given port against a list of ports which are restricted by 291 // Checks the given port against a list of ports which are restricted by
265 // default. Returns true if the port is allowed, false if it is restricted. 292 // default. Returns true if the port is allowed, false if it is restricted.
266 bool IsPortAllowedByDefault(int port); 293 bool IsPortAllowedByDefault(int port);
267 294
268 // Checks the given port against a list of ports which are restricted by the 295 // Checks the given port against a list of ports which are restricted by the
269 // FTP protocol. Returns true if the port is allowed, false if it is 296 // FTP protocol. Returns true if the port is allowed, false if it is
270 // restricted. 297 // restricted.
271 bool IsPortAllowedByFtp(int port); 298 bool IsPortAllowedByFtp(int port);
272 299
273 // Check if banned |port| has been overriden by an entry in 300 // Check if banned |port| has been overriden by an entry in
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
459 486
460 // Returns list of network interfaces except loopback interface. If an 487 // Returns list of network interfaces except loopback interface. If an
461 // interface has more than one address, a separate entry is added to 488 // interface has more than one address, a separate entry is added to
462 // the list for each address. 489 // the list for each address.
463 // Can be called only on a thread that allows IO. 490 // Can be called only on a thread that allows IO.
464 NET_API bool GetNetworkList(NetworkInterfaceList* networks); 491 NET_API bool GetNetworkList(NetworkInterfaceList* networks);
465 492
466 } // namespace net 493 } // namespace net
467 494
468 #endif // NET_BASE_NET_UTIL_H_ 495 #endif // NET_BASE_NET_UTIL_H_
OLDNEW
« no previous file with comments | « content/browser/download/save_package.cc ('k') | net/base/net_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698