OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/browser/download/save_package.h" | 5 #include "content/browser/download/save_package.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 1244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1255 // Normally we want to base the filename on the page title, or if it doesn't | 1255 // Normally we want to base the filename on the page title, or if it doesn't |
1256 // exist, on the URL. It's not easy to tell if the page has no title, because | 1256 // exist, on the URL. It's not easy to tell if the page has no title, because |
1257 // if the page has no title, WebContents::GetTitle() will return the page's | 1257 // if the page has no title, WebContents::GetTitle() will return the page's |
1258 // URL (adjusted for display purposes). Therefore, we convert the "title" | 1258 // URL (adjusted for display purposes). Therefore, we convert the "title" |
1259 // back to a URL, and if it matches the original page URL, we know the page | 1259 // back to a URL, and if it matches the original page URL, we know the page |
1260 // had no title (or had a title equal to its URL, which is fine to treat | 1260 // had no title (or had a title equal to its URL, which is fine to treat |
1261 // similarly). | 1261 // similarly). |
1262 if (title == url_formatter::FormatUrl(page_url)) { | 1262 if (title == url_formatter::FormatUrl(page_url)) { |
1263 std::string url_path; | 1263 std::string url_path; |
1264 if (!page_url.SchemeIs(url::kDataScheme)) { | 1264 if (!page_url.SchemeIs(url::kDataScheme)) { |
1265 std::vector<std::string> url_parts = base::SplitString( | 1265 name_with_proper_ext = net::GenerateFileName( |
1266 page_url.path(), "/", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); | 1266 page_url, std::string(), std::string(), std::string(), |
1267 if (!url_parts.empty()) { | 1267 contents_mime_type, std::string()); |
1268 for (int i = static_cast<int>(url_parts.size()) - 1; i >= 0; --i) { | 1268 |
1269 url_path = url_parts[i]; | 1269 // If host is used as file name, try to decode punycode. |
1270 if (!url_path.empty()) | 1270 if (name_with_proper_ext.AsUTF8Unsafe() == page_url.host()) { |
asanka
2017/01/10 19:42:46
Darn. This should really go in //net/base, but //n
| |
1271 break; | 1271 name_with_proper_ext = base::FilePath::FromUTF16Unsafe( |
1272 } | 1272 url_formatter::IDNToUnicode(page_url.host())); |
1273 } | 1273 } |
1274 if (url_path.empty()) | |
1275 url_path = page_url.host(); | |
1276 } else { | 1274 } else { |
1277 url_path = "dataurl"; | 1275 name_with_proper_ext = |
1276 base::FilePath::FromUTF8Unsafe(std::string("dataurl")); | |
1278 } | 1277 } |
1279 name_with_proper_ext = base::FilePath::FromUTF8Unsafe(url_path); | |
1280 } | 1278 } |
1281 | 1279 |
1282 // Ask user for getting final saving name. | 1280 // Ask user for getting final saving name. |
1283 name_with_proper_ext = EnsureMimeExtension(name_with_proper_ext, | 1281 name_with_proper_ext = EnsureMimeExtension(name_with_proper_ext, |
1284 contents_mime_type); | 1282 contents_mime_type); |
1285 // Adjust extension for complete types. | 1283 // Adjust extension for complete types. |
1286 if (can_save_as_complete) | 1284 if (can_save_as_complete) |
1287 name_with_proper_ext = EnsureHtmlExtension(name_with_proper_ext); | 1285 name_with_proper_ext = EnsureHtmlExtension(name_with_proper_ext); |
1288 | 1286 |
1289 base::FilePath::StringType file_name = name_with_proper_ext.value(); | 1287 base::FilePath::StringType file_name = name_with_proper_ext.value(); |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1483 } | 1481 } |
1484 | 1482 |
1485 void SavePackage::FinalizeDownloadEntry() { | 1483 void SavePackage::FinalizeDownloadEntry() { |
1486 DCHECK(download_); | 1484 DCHECK(download_); |
1487 | 1485 |
1488 download_manager_->OnSavePackageSuccessfullyFinished(download_); | 1486 download_manager_->OnSavePackageSuccessfullyFinished(download_); |
1489 RemoveObservers(); | 1487 RemoveObservers(); |
1490 } | 1488 } |
1491 | 1489 |
1492 } // namespace content | 1490 } // namespace content |
OLD | NEW |