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

Unified Diff: net/base/net_util.cc

Issue 7005011: Fix bug 79905: Drag and drop of "DownloadURL" type ignores specified filename for data URLs. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/base/net_util.h ('k') | net/base/net_util_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/base/net_util.cc
===================================================================
--- net/base/net_util.cc (revision 85826)
+++ net/base/net_util.cc (working copy)
@@ -1248,6 +1248,7 @@
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,17 +1257,16 @@
// 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;
- std::string filename = GetFileNameFromCD(content_disposition,
- referrer_charset);
+ // Try to extract from content-disposition first.
+ if (!content_disposition.empty())
+ 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
// path separators with underscores.
@@ -1277,7 +1277,16 @@
// 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(),
« no previous file with comments | « net/base/net_util.h ('k') | net/base/net_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698