OLD | NEW |
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 1225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1236 } | 1236 } |
1237 | 1237 |
1238 string16 StripWWW(const string16& text) { | 1238 string16 StripWWW(const string16& text) { |
1239 const string16 www(ASCIIToUTF16("www.")); | 1239 const string16 www(ASCIIToUTF16("www.")); |
1240 return StartsWith(text, www, true) ? text.substr(www.length()) : text; | 1240 return StartsWith(text, www, true) ? text.substr(www.length()) : text; |
1241 } | 1241 } |
1242 | 1242 |
1243 string16 GetSuggestedFilename(const GURL& url, | 1243 string16 GetSuggestedFilename(const GURL& url, |
1244 const std::string& content_disposition, | 1244 const std::string& content_disposition, |
1245 const std::string& referrer_charset, | 1245 const std::string& referrer_charset, |
| 1246 const std::string& suggested_name, |
1246 const string16& default_name) { | 1247 const string16& default_name) { |
1247 // TODO: this function to be updated to match the httpbis recommendations. | 1248 // TODO: this function to be updated to match the httpbis recommendations. |
1248 // Talk to abarth for the latest news. | 1249 // Talk to abarth for the latest news. |
1249 | 1250 |
1250 // We don't translate this fallback string, "download". If localization is | 1251 // We don't translate this fallback string, "download". If localization is |
1251 // needed, the caller should provide localized fallback default_name. | 1252 // needed, the caller should provide localized fallback default_name. |
1252 static const char* kFinalFallbackName = "download"; | 1253 static const char* kFinalFallbackName = "download"; |
1253 | 1254 |
1254 // about: and data: URLs don't have file names, but esp. data: URLs may | 1255 std::string filename; |
1255 // contain parts that look like ones (i.e., contain a slash). | |
1256 // Therefore we don't attempt to divine a file name out of them. | |
1257 if (url.SchemeIs("about") || url.SchemeIs("data")) { | |
1258 return default_name.empty() ? ASCIIToUTF16(kFinalFallbackName) | |
1259 : default_name; | |
1260 } | |
1261 | 1256 |
1262 std::string filename = GetFileNameFromCD(content_disposition, | 1257 // Try to extract from content-disposition first. |
1263 referrer_charset); | 1258 if (!content_disposition.empty()) |
| 1259 filename = GetFileNameFromCD(content_disposition, referrer_charset); |
| 1260 |
| 1261 // Then try to use suggested name. |
| 1262 if (filename.empty() && !suggested_name.empty()) |
| 1263 filename = suggested_name; |
1264 | 1264 |
1265 if (!filename.empty()) { | 1265 if (!filename.empty()) { |
1266 // Replace any path information the server may have sent, by changing | 1266 // Replace any path information the server may have sent, by changing |
1267 // path separators with underscores. | 1267 // path separators with underscores. |
1268 ReplaceSubstringsAfterOffset(&filename, 0, "/", "_"); | 1268 ReplaceSubstringsAfterOffset(&filename, 0, "/", "_"); |
1269 ReplaceSubstringsAfterOffset(&filename, 0, "\\", "_"); | 1269 ReplaceSubstringsAfterOffset(&filename, 0, "\\", "_"); |
1270 | 1270 |
1271 // Next, remove "." from the beginning and end of the file name to avoid | 1271 // Next, remove "." from the beginning and end of the file name to avoid |
1272 // tricks with hidden files, "..", and "." | 1272 // tricks with hidden files, "..", and "." |
1273 TrimString(filename, ".", &filename); | 1273 TrimString(filename, ".", &filename); |
1274 } | 1274 } |
| 1275 |
1275 if (filename.empty()) { | 1276 if (filename.empty()) { |
| 1277 // about: and data: URLs don't have file names, but esp. data: URLs may |
| 1278 // contain parts that look like ones (i.e., contain a slash). |
| 1279 // Therefore we don't attempt to divine a file name out of them. |
| 1280 if (url.SchemeIs("about") || url.SchemeIs("data")) { |
| 1281 return default_name.empty() ? ASCIIToUTF16(kFinalFallbackName) |
| 1282 : default_name; |
| 1283 } |
| 1284 |
1276 if (url.is_valid()) { | 1285 if (url.is_valid()) { |
1277 const std::string unescaped_url_filename = UnescapeURLComponent( | 1286 const std::string unescaped_url_filename = UnescapeURLComponent( |
1278 url.ExtractFileName(), | 1287 url.ExtractFileName(), |
1279 UnescapeRule::SPACES | UnescapeRule::URL_SPECIAL_CHARS); | 1288 UnescapeRule::SPACES | UnescapeRule::URL_SPECIAL_CHARS); |
1280 | 1289 |
1281 // The URL's path should be escaped UTF-8, but may not be. | 1290 // The URL's path should be escaped UTF-8, but may not be. |
1282 std::string decoded_filename = unescaped_url_filename; | 1291 std::string decoded_filename = unescaped_url_filename; |
1283 if (!IsStringASCII(decoded_filename)) { | 1292 if (!IsStringASCII(decoded_filename)) { |
1284 bool ignore; | 1293 bool ignore; |
1285 // TODO(jshin): this is probably not robust enough. To be sure, we | 1294 // TODO(jshin): this is probably not robust enough. To be sure, we |
(...skipping 938 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2224 | 2233 |
2225 NetworkInterface::NetworkInterface(const std::string& name, | 2234 NetworkInterface::NetworkInterface(const std::string& name, |
2226 const IPAddressNumber& address) | 2235 const IPAddressNumber& address) |
2227 : name(name), address(address) { | 2236 : name(name), address(address) { |
2228 } | 2237 } |
2229 | 2238 |
2230 NetworkInterface::~NetworkInterface() { | 2239 NetworkInterface::~NetworkInterface() { |
2231 } | 2240 } |
2232 | 2241 |
2233 } // namespace net | 2242 } // namespace net |
OLD | NEW |