diff options
author | jianli@chromium.org <jianli@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-18 22:55:09 +0000 |
---|---|---|
committer | jianli@chromium.org <jianli@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-18 22:55:09 +0000 |
commit | cc099a3a5e644bfff00db13b9a97b43267118080 (patch) | |
tree | a0acac0bff6b206bab061fd6480cf9b11ebca4df /net/base/net_util.cc | |
parent | 58753dcfeb72a64d32443217e6afc7fa73d2e34b (diff) | |
download | chromium_src-cc099a3a5e644bfff00db13b9a97b43267118080.zip chromium_src-cc099a3a5e644bfff00db13b9a97b43267118080.tar.gz chromium_src-cc099a3a5e644bfff00db13b9a97b43267118080.tar.bz2 |
Fix bug 79905: Drag and drop of "DownloadURL" type ignores specified filename for data URLs.
BUG=79905
TEST=Manual test and unittest added for net::GetSuggestedFilename
Review URL: http://codereview.chromium.org/7005011
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@85831 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/base/net_util.cc')
-rw-r--r-- | net/base/net_util.cc | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/net/base/net_util.cc b/net/base/net_util.cc index 2e77acf..31d7497 100644 --- a/net/base/net_util.cc +++ b/net/base/net_util.cc @@ -1248,6 +1248,7 @@ string16 StripWWW(const string16& text) { string16 GetSuggestedFilename(const GURL& url, const std::string& content_disposition, const std::string& referrer_charset, + const std::string& suggested_name, const string16& default_name) { // TODO: this function to be updated to match the httpbis recommendations. // Talk to abarth for the latest news. @@ -1256,16 +1257,15 @@ string16 GetSuggestedFilename(const GURL& url, // needed, the caller should provide localized fallback default_name. static const char* kFinalFallbackName = "download"; - // about: and data: URLs don't have file names, but esp. data: URLs may - // contain parts that look like ones (i.e., contain a slash). - // Therefore we don't attempt to divine a file name out of them. - if (url.SchemeIs("about") || url.SchemeIs("data")) { - return default_name.empty() ? ASCIIToUTF16(kFinalFallbackName) - : default_name; - } + std::string filename; + + // Try to extract from content-disposition first. + if (!content_disposition.empty()) + filename = GetFileNameFromCD(content_disposition, referrer_charset); - std::string filename = GetFileNameFromCD(content_disposition, - referrer_charset); + // Then try to use suggested name. + if (filename.empty() && !suggested_name.empty()) + filename = suggested_name; if (!filename.empty()) { // Replace any path information the server may have sent, by changing @@ -1277,7 +1277,16 @@ string16 GetSuggestedFilename(const GURL& url, // tricks with hidden files, "..", and "." TrimString(filename, ".", &filename); } + if (filename.empty()) { + // about: and data: URLs don't have file names, but esp. data: URLs may + // contain parts that look like ones (i.e., contain a slash). + // Therefore we don't attempt to divine a file name out of them. + if (url.SchemeIs("about") || url.SchemeIs("data")) { + return default_name.empty() ? ASCIIToUTF16(kFinalFallbackName) + : default_name; + } + if (url.is_valid()) { const std::string unescaped_url_filename = UnescapeURLComponent( url.ExtractFileName(), |