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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/base/net_util.h ('k') | net/base/net_util_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include "net/base/net_util.h" 5 #include "net/base/net_util.h"
6 6
7 #include <unicode/regex.h> 7 #include <unicode/regex.h>
8 #include <unicode/ucnv.h> 8 #include <unicode/ucnv.h>
9 #include <unicode/uidna.h> 9 #include <unicode/uidna.h>
10 #include <unicode/ulocdata.h> 10 #include <unicode/ulocdata.h>
(...skipping 1230 matching lines...) Expand 10 before | Expand all | Expand 10 after
1241 } 1241 }
1242 1242
1243 string16 StripWWW(const string16& text) { 1243 string16 StripWWW(const string16& text) {
1244 const string16 www(ASCIIToUTF16("www.")); 1244 const string16 www(ASCIIToUTF16("www."));
1245 return StartsWith(text, www, true) ? text.substr(www.length()) : text; 1245 return StartsWith(text, www, true) ? text.substr(www.length()) : text;
1246 } 1246 }
1247 1247
1248 string16 GetSuggestedFilename(const GURL& url, 1248 string16 GetSuggestedFilename(const GURL& url,
1249 const std::string& content_disposition, 1249 const std::string& content_disposition,
1250 const std::string& referrer_charset, 1250 const std::string& referrer_charset,
1251 const std::string& suggested_name,
1251 const string16& default_name) { 1252 const string16& default_name) {
1252 // TODO: this function to be updated to match the httpbis recommendations. 1253 // TODO: this function to be updated to match the httpbis recommendations.
1253 // Talk to abarth for the latest news. 1254 // Talk to abarth for the latest news.
1254 1255
1255 // We don't translate this fallback string, "download". If localization is 1256 // We don't translate this fallback string, "download". If localization is
1256 // needed, the caller should provide localized fallback default_name. 1257 // needed, the caller should provide localized fallback default_name.
1257 static const char* kFinalFallbackName = "download"; 1258 static const char* kFinalFallbackName = "download";
1258 1259
1259 // about: and data: URLs don't have file names, but esp. data: URLs may 1260 std::string filename;
1260 // contain parts that look like ones (i.e., contain a slash).
1261 // Therefore we don't attempt to divine a file name out of them.
1262 if (url.SchemeIs("about") || url.SchemeIs("data")) {
1263 return default_name.empty() ? ASCIIToUTF16(kFinalFallbackName)
1264 : default_name;
1265 }
1266 1261
1267 std::string filename = GetFileNameFromCD(content_disposition, 1262 // Try to extract from content-disposition first.
1268 referrer_charset); 1263 if (!content_disposition.empty())
1264 filename = GetFileNameFromCD(content_disposition, referrer_charset);
1265
1266 // Then try to use suggested name.
1267 if (filename.empty() && !suggested_name.empty())
1268 filename = suggested_name;
1269 1269
1270 if (!filename.empty()) { 1270 if (!filename.empty()) {
1271 // Replace any path information the server may have sent, by changing 1271 // Replace any path information the server may have sent, by changing
1272 // path separators with underscores. 1272 // path separators with underscores.
1273 ReplaceSubstringsAfterOffset(&filename, 0, "/", "_"); 1273 ReplaceSubstringsAfterOffset(&filename, 0, "/", "_");
1274 ReplaceSubstringsAfterOffset(&filename, 0, "\\", "_"); 1274 ReplaceSubstringsAfterOffset(&filename, 0, "\\", "_");
1275 1275
1276 // Next, remove "." from the beginning and end of the file name to avoid 1276 // Next, remove "." from the beginning and end of the file name to avoid
1277 // tricks with hidden files, "..", and "." 1277 // tricks with hidden files, "..", and "."
1278 TrimString(filename, ".", &filename); 1278 TrimString(filename, ".", &filename);
1279 } 1279 }
1280
1280 if (filename.empty()) { 1281 if (filename.empty()) {
1282 // about: and data: URLs don't have file names, but esp. data: URLs may
1283 // contain parts that look like ones (i.e., contain a slash).
1284 // Therefore we don't attempt to divine a file name out of them.
1285 if (url.SchemeIs("about") || url.SchemeIs("data")) {
1286 return default_name.empty() ? ASCIIToUTF16(kFinalFallbackName)
1287 : default_name;
1288 }
1289
1281 if (url.is_valid()) { 1290 if (url.is_valid()) {
1282 const std::string unescaped_url_filename = UnescapeURLComponent( 1291 const std::string unescaped_url_filename = UnescapeURLComponent(
1283 url.ExtractFileName(), 1292 url.ExtractFileName(),
1284 UnescapeRule::SPACES | UnescapeRule::URL_SPECIAL_CHARS); 1293 UnescapeRule::SPACES | UnescapeRule::URL_SPECIAL_CHARS);
1285 1294
1286 // The URL's path should be escaped UTF-8, but may not be. 1295 // The URL's path should be escaped UTF-8, but may not be.
1287 std::string decoded_filename = unescaped_url_filename; 1296 std::string decoded_filename = unescaped_url_filename;
1288 if (!IsStringASCII(decoded_filename)) { 1297 if (!IsStringASCII(decoded_filename)) {
1289 bool ignore; 1298 bool ignore;
1290 // TODO(jshin): this is probably not robust enough. To be sure, we 1299 // TODO(jshin): this is probably not robust enough. To be sure, we
(...skipping 938 matching lines...) Expand 10 before | Expand all | Expand 10 after
2229 2238
2230 NetworkInterface::NetworkInterface(const std::string& name, 2239 NetworkInterface::NetworkInterface(const std::string& name,
2231 const IPAddressNumber& address) 2240 const IPAddressNumber& address)
2232 : name(name), address(address) { 2241 : name(name), address(address) {
2233 } 2242 }
2234 2243
2235 NetworkInterface::~NetworkInterface() { 2244 NetworkInterface::~NetworkInterface() {
2236 } 2245 }
2237 2246
2238 } // namespace net 2247 } // namespace net
OLDNEW
« 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