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

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: Comments Created 9 years, 5 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
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 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 // 173 //
174 // TODO(jungshik): revisit this issue. At the moment, the only caller 174 // TODO(jungshik): revisit this issue. At the moment, the only caller is
175 // net_util::GetSuggestedFilename and it calls ReplaceIllegalCharacters. The 175 // net::GenerateFilename and it calls ReplaceIllegalCharacters. The other
176 // other caller is a unit test. Need to figure out expose this function only to 176 // caller is a unit test. Need to figure out expose this function only to
177 // net_util_unittest. 177 // net_util_unittest.
rvargas (doing something else) 2011/07/26 00:10:57 You can remove this TODO because that's basically
asanka 2011/07/28 20:04:38 Done.
178 //
179 NET_TEST std::string GetFileNameFromCD(const std::string& header, 178 NET_TEST std::string GetFileNameFromCD(const std::string& header,
180 const std::string& referrer_charset); 179 const std::string& referrer_charset);
181 180
182 // Converts the given host name to unicode characters. This can be called for 181 // 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 182 // 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. 183 // return the ASCII source so it is still usable.
185 // 184 //
186 // The input should be the canonicalized ASCII host name from GURL. This 185 // The input should be the canonicalized ASCII host name from GURL. This
187 // function does NOT accept UTF-8! 186 // function does NOT accept UTF-8!
188 // 187 //
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 // Both |name| and |raw_bytes| are escaped internally. 238 // Both |name| and |raw_bytes| are escaped internally.
240 NET_API std::string GetDirectoryListingEntry(const string16& name, 239 NET_API std::string GetDirectoryListingEntry(const string16& name,
241 const std::string& raw_bytes, 240 const std::string& raw_bytes,
242 bool is_dir, int64 size, 241 bool is_dir, int64 size,
243 base::Time modified); 242 base::Time modified);
244 243
245 // If text starts with "www." it is removed, otherwise text is returned 244 // If text starts with "www." it is removed, otherwise text is returned
246 // unmodified. 245 // unmodified.
247 NET_API string16 StripWWW(const string16& text); 246 NET_API string16 StripWWW(const string16& text);
248 247
249 // Gets the filename in the following order: 248 // Generates a filename using the first successful method from the following (in
250 // 1) the raw Content-Disposition header (as read from the network). 249 // order):
251 // |referrer_charset| is used as one of charsets to interpret a raw 8bit 250 //
252 // string in C-D header (after interpreting as UTF-8 fails). 251 // 1) The raw Content-Disposition header in |content_disposition| (as read from
253 // See the comment for GetFilenameFromCD for more details. 252 // the network. |referrer_charset| is used as described in the comment for
254 // 2) the suggested name 253 // GetFileNameFromCD().
255 // 3) the last path component name or hostname from |url| 254 // 2) |suggested_name| if specified. |suggested_name| is assumed to be in
256 // 4) the given |default_name| 255 // UTF-8.
257 // 5) the hard-coded name "download", as the last resort 256 // 3) The filename extracted from the |url|. |referrer_charset| will be used to
257 // interpret the URL if there are non-ascii characters.
258 // 4) |default_name|. If non-empty, |default_name| is assumed to be a filename
259 // and shouldn't contain a path.
260 // 5) The hostname portion from the |url|
261 // 6) The string "download"
262 //
263 // For each method, except 4), leading and trailing '.'s will be removed. On
264 // OS_WIN, trailing spaces are also removed.
rvargas (doing something else) 2011/07/26 22:25:41 nit: I think that we use "Windows" when describing
asanka 2011/07/28 20:04:38 Done.
265 //
266 // Once the filename is determined, any illegal characters will be replaced by
267 // '-'. If the filename doesn't contain an extension, and a |mime_type| is
268 // specified, the preferred extension for the |mime_type| will be appended to
269 // the filename. The resulting filename is then checked against a list of
270 // reserved names on OS_WIN. If the name is reserved, an underscore will be
271 // prepended to the filename.
272 //
273 // Note: |mime_type| should only be specified if this function is called from a
274 // thread that allows IO.
258 NET_API string16 GetSuggestedFilename(const GURL& url, 275 NET_API string16 GetSuggestedFilename(const GURL& url,
259 const std::string& content_disposition, 276 const std::string& content_disposition,
260 const std::string& referrer_charset, 277 const std::string& referrer_charset,
261 const std::string& suggested_name, 278 const std::string& suggested_name,
279 const std::string& mime_type,
262 const string16& default_name); 280 const string16& default_name);
263 281
282 // Similar to GetSuggestedFilename(), but returns a FilePath.
rvargas (doing something else) 2011/07/26 22:25:41 It looks like long term we should have just one me
asanka 2011/07/28 20:04:38 Perhaps the correct solution is to move the encodi
rvargas (doing something else) 2011/07/29 01:34:53 Yeah, I saw the WebUrlLoader case... The helper ca
283 NET_API FilePath GenerateFileName(const GURL& url,
284 const std::string& content_disposition,
285 const std::string& referrer_charset,
286 const std::string& suggested_name,
287 const std::string& mime_type,
288 const string16& default_name);
289
290 // Ensure that the filename and extension is safe to use in the filesystem.
rvargas (doing something else) 2011/07/26 22:25:41 nit: Ensures
asanka 2011/07/28 20:04:38 Done.
291 //
292 // Assumes that |file_path| already contains a valid path or file name. On
293 // Windows if the extension causes the file to have an unsafe interaction with
294 // the shell (see net_util::IsShellIntegratedExtension()), then it will be
295 // replaced by the string 'download'. If |file_path| doesn't contain an
296 // extension and |mime_type| is non-empty, the preferred extension for
297 // |mime_type| will be used as the extension.
298 //
299 // On Windows, the filename will be checked against a set of reserved names, and
300 // if so, an underscore will be prepended to the name.
301 //
302 // |file_name| can either be just the file name or it can be a full path to a
303 // file.
304 //
305 // Note: |mime_type| should only be non-empty if this function is called from a
306 // thread that allows IO.
307 NET_API void GenerateSafeFileName(const std::string& mime_type,
308 FilePath* file_path);
309
264 // Checks the given port against a list of ports which are restricted by 310 // 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. 311 // default. Returns true if the port is allowed, false if it is restricted.
266 bool IsPortAllowedByDefault(int port); 312 bool IsPortAllowedByDefault(int port);
267 313
268 // Checks the given port against a list of ports which are restricted by the 314 // 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 315 // FTP protocol. Returns true if the port is allowed, false if it is
270 // restricted. 316 // restricted.
271 bool IsPortAllowedByFtp(int port); 317 bool IsPortAllowedByFtp(int port);
272 318
273 // Check if banned |port| has been overriden by an entry in 319 // Check if banned |port| has been overriden by an entry in
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
459 505
460 // Returns list of network interfaces except loopback interface. If an 506 // Returns list of network interfaces except loopback interface. If an
461 // 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
462 // the list for each address. 508 // the list for each address.
463 // Can be called only on a thread that allows IO. 509 // Can be called only on a thread that allows IO.
464 NET_API bool GetNetworkList(NetworkInterfaceList* networks); 510 NET_API bool GetNetworkList(NetworkInterfaceList* networks);
465 511
466 } // namespace net 512 } // namespace net
467 513
468 #endif // NET_BASE_NET_UTIL_H_ 514 #endif // NET_BASE_NET_UTIL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698