summaryrefslogtreecommitdiffstats
path: root/net/base/net_util.h
diff options
context:
space:
mode:
authorasanka@chromium.org <asanka@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-08-09 18:56:45 +0000
committerasanka@chromium.org <asanka@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-08-09 18:56:45 +0000
commit30219d673a53a373800799d0cb20a679b035280f (patch)
tree222151c750f410c321da0f6d6d5d769e15fadc4e /net/base/net_util.h
parent80426e1b3191e119c9bc92d5daa6c477c715637f (diff)
downloadchromium_src-30219d673a53a373800799d0cb20a679b035280f.zip
chromium_src-30219d673a53a373800799d0cb20a679b035280f.tar.gz
chromium_src-30219d673a53a373800799d0cb20a679b035280f.tar.bz2
Move filename determination logic to net_util so that it's not split between net_util and download_util.
BUG=78085 TEST=net_unittests --gtest_filter=*Generate*FileName Review URL: http://codereview.chromium.org/7300005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@96029 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/base/net_util.h')
-rw-r--r--net/base/net_util.h39
1 files changed, 33 insertions, 6 deletions
diff --git a/net/base/net_util.h b/net/base/net_util.h
index 344a990..ee9fe12 100644
--- a/net/base/net_util.h
+++ b/net/base/net_util.h
@@ -170,12 +170,6 @@ NET_API std::string GetHeaderParamValue(const std::string& header,
//
// This function does not do any escaping and callers are responsible for
// escaping 'unsafe' characters (e.g. (back)slash, colon) as they see fit.
-//
-// TODO(jungshik): revisit this issue. At the moment, the only caller
-// net_util::GetSuggestedFilename and it calls ReplaceIllegalCharacters. The
-// other caller is a unit test. Need to figure out expose this function only to
-// net_util_unittest.
-//
NET_TEST std::string GetFileNameFromCD(const std::string& header,
const std::string& referrer_charset);
@@ -261,6 +255,39 @@ NET_API string16 GetSuggestedFilename(const GURL& url,
const std::string& suggested_name,
const string16& default_name);
+// Generate a filename based on a HTTP request.
+//
+// The |url|, |content_disposition|, |referrer_charset|, |suggested_name|, and
+// |default_name| parameters will be used with GetSuggestedFilename() to
+// generate a filename. The resulting filename will be passed in along with the
+// |mime_type| to GenerateSafeFileName() to generate the returned filename.
+NET_API FilePath GenerateFileName(const GURL& url,
+ const std::string& content_disposition,
+ const std::string& referrer_charset,
+ const std::string& suggested_name,
+ const std::string& mime_type,
+ const string16& default_name);
+
+// Ensures that the filename and extension is safe to use in the filesystem.
+//
+// Assumes that |file_path| already contains a valid path or file name. On
+// Windows if the extension causes the file to have an unsafe interaction with
+// the shell (see net_util::IsShellIntegratedExtension()), then it will be
+// replaced by the string 'download'. If |file_path| doesn't contain an
+// extension and |mime_type| is non-empty, the preferred extension for
+// |mime_type| will be used as the extension.
+//
+// On Windows, the filename will be checked against a set of reserved names, and
+// if so, an underscore will be prepended to the name.
+//
+// |file_name| can either be just the file name or it can be a full path to a
+// file.
+//
+// Note: |mime_type| should only be non-empty if this function is called from a
+// thread that allows IO.
+NET_API void GenerateSafeFileName(const std::string& mime_type,
+ FilePath* file_path);
+
// Checks the given port against a list of ports which are restricted by
// default. Returns true if the port is allowed, false if it is restricted.
bool IsPortAllowedByDefault(int port);