OLD | NEW |
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 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 // Both |name| and |raw_bytes| are escaped internally. | 236 // Both |name| and |raw_bytes| are escaped internally. |
237 NET_EXPORT std::string GetDirectoryListingEntry(const string16& name, | 237 NET_EXPORT std::string GetDirectoryListingEntry(const string16& name, |
238 const std::string& raw_bytes, | 238 const std::string& raw_bytes, |
239 bool is_dir, int64 size, | 239 bool is_dir, int64 size, |
240 base::Time modified); | 240 base::Time modified); |
241 | 241 |
242 // If text starts with "www." it is removed, otherwise text is returned | 242 // If text starts with "www." it is removed, otherwise text is returned |
243 // unmodified. | 243 // unmodified. |
244 NET_EXPORT string16 StripWWW(const string16& text); | 244 NET_EXPORT string16 StripWWW(const string16& text); |
245 | 245 |
246 // Gets the filename in the following order: | 246 // Generates a filename using the first successful method from the following (in |
247 // 1) the raw Content-Disposition header (as read from the network). | 247 // order): |
248 // |referrer_charset| is used as one of charsets to interpret a raw 8bit | 248 // |
249 // string in C-D header (after interpreting as UTF-8 fails). | 249 // 1) The raw Content-Disposition header in |content_disposition| (as read from |
250 // See the comment for GetFilenameFromCD for more details. | 250 // the network. |referrer_charset| is used as described in the comment for |
251 // 2) the suggested name | 251 // GetFileNameFromCD(). |
252 // 3) the last path component name or hostname from |url| | 252 // 2) |suggested_name| if specified. |suggested_name| is assumed to be in |
253 // 4) the given |default_name| | 253 // UTF-8. |
254 // 5) the hard-coded name "download", as the last resort | 254 // 3) The filename extracted from the |url|. |referrer_charset| will be used to |
| 255 // interpret the URL if there are non-ascii characters. |
| 256 // 4) |default_name|. If non-empty, |default_name| is assumed to be a filename |
| 257 // and shouldn't contain a path. |default_name| is not subject to validation |
| 258 // or sanitization, and therefore shouldn't be a user supplied string. |
| 259 // 5) The hostname portion from the |url| |
| 260 // |
| 261 // Then, leading and trailing '.'s will be removed. On Windows, trailing spaces |
| 262 // are also removed. The string "download" is the final fallback if no filename |
| 263 // is found or the filename is empty. |
| 264 // |
| 265 // Any illegal characters in the filename will be replaced by '-'. If the |
| 266 // filename doesn't contain an extension, and a |mime_type| is specified, the |
| 267 // preferred extension for the |mime_type| will be appended to the filename. |
| 268 // The resulting filename is then checked against a list of reserved names on |
| 269 // Windows. If the name is reserved, an underscore will be prepended to the |
| 270 // filename. |
| 271 // |
| 272 // Note: |mime_type| should only be specified if this function is called from a |
| 273 // thread that allows IO. |
255 NET_EXPORT string16 GetSuggestedFilename(const GURL& url, | 274 NET_EXPORT string16 GetSuggestedFilename(const GURL& url, |
256 const std::string& content_disposition, | 275 const std::string& content_disposition, |
257 const std::string& referrer_charset, | 276 const std::string& referrer_charset, |
258 const std::string& suggested_name, | 277 const std::string& suggested_name, |
| 278 const std::string& mime_type, |
259 const string16& default_name); | 279 const string16& default_name); |
260 | 280 |
261 // Generate a filename based on a HTTP request. | 281 // Similar to GetSuggestedFilename(), but returns a FilePath. |
262 // | |
263 // The |url|, |content_disposition|, |referrer_charset|, |suggested_name|, and | |
264 // |default_name| parameters will be used with GetSuggestedFilename() to | |
265 // generate a filename. The resulting filename will be passed in along with the | |
266 // |mime_type| to GenerateSafeFileName() to generate the returned filename. | |
267 NET_EXPORT FilePath GenerateFileName(const GURL& url, | 282 NET_EXPORT FilePath GenerateFileName(const GURL& url, |
268 const std::string& content_disposition, | 283 const std::string& content_disposition, |
269 const std::string& referrer_charset, | 284 const std::string& referrer_charset, |
270 const std::string& suggested_name, | 285 const std::string& suggested_name, |
271 const std::string& mime_type, | 286 const std::string& mime_type, |
272 const string16& default_name); | 287 const string16& default_name); |
273 | 288 |
274 // Ensures that the filename and extension is safe to use in the filesystem. | 289 // Ensures that the filename and extension is safe to use in the filesystem. |
275 // | 290 // |
276 // Assumes that |file_path| already contains a valid path or file name. On | 291 // Assumes that |file_path| already contains a valid path or file name. On |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
490 | 505 |
491 // Returns list of network interfaces except loopback interface. If an | 506 // Returns list of network interfaces except loopback interface. If an |
492 // interface has more than one address, a separate entry is added to | 507 // interface has more than one address, a separate entry is added to |
493 // the list for each address. | 508 // the list for each address. |
494 // Can be called only on a thread that allows IO. | 509 // Can be called only on a thread that allows IO. |
495 NET_EXPORT bool GetNetworkList(NetworkInterfaceList* networks); | 510 NET_EXPORT bool GetNetworkList(NetworkInterfaceList* networks); |
496 | 511 |
497 } // namespace net | 512 } // namespace net |
498 | 513 |
499 #endif // NET_BASE_NET_UTIL_H_ | 514 #endif // NET_BASE_NET_UTIL_H_ |
OLD | NEW |