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 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
11 #include "base/files/file_util.h" | 11 #include "base/files/file_util.h" |
12 #include "base/i18n/file_util_icu.h" | 12 #include "base/i18n/file_util_icu.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "base/message_loop/message_loop.h" | 14 #include "base/message_loop/message_loop.h" |
15 #include "base/stl_util.h" | 15 #include "base/stl_util.h" |
16 #include "base/strings/string_piece.h" | 16 #include "base/strings/string_piece.h" |
17 #include "base/strings/string_split.h" | 17 #include "base/strings/string_split.h" |
18 #include "base/strings/sys_string_conversions.h" | 18 #include "base/strings/sys_string_conversions.h" |
19 #include "base/strings/utf_string_conversions.h" | 19 #include "base/strings/utf_string_conversions.h" |
20 #include "base/threading/thread.h" | 20 #include "base/threading/thread.h" |
| 21 #include "components/url_formatter/url_formatter.h" |
21 #include "content/browser/download/download_item_impl.h" | 22 #include "content/browser/download/download_item_impl.h" |
22 #include "content/browser/download/download_manager_impl.h" | 23 #include "content/browser/download/download_manager_impl.h" |
23 #include "content/browser/download/download_stats.h" | 24 #include "content/browser/download/download_stats.h" |
24 #include "content/browser/download/save_file.h" | 25 #include "content/browser/download/save_file.h" |
25 #include "content/browser/download/save_file_manager.h" | 26 #include "content/browser/download/save_file_manager.h" |
26 #include "content/browser/download/save_item.h" | 27 #include "content/browser/download/save_item.h" |
27 #include "content/browser/loader/resource_dispatcher_host_impl.h" | 28 #include "content/browser/loader/resource_dispatcher_host_impl.h" |
28 #include "content/browser/renderer_host/render_process_host_impl.h" | 29 #include "content/browser/renderer_host/render_process_host_impl.h" |
29 #include "content/browser/renderer_host/render_view_host_delegate.h" | 30 #include "content/browser/renderer_host/render_view_host_delegate.h" |
30 #include "content/browser/renderer_host/render_view_host_impl.h" | 31 #include "content/browser/renderer_host/render_view_host_impl.h" |
(...skipping 1176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1207 | 1208 |
1208 // If the page's title matches its URL, use the URL. Try to use the last path | 1209 // If the page's title matches its URL, use the URL. Try to use the last path |
1209 // component or if there is none, the domain as the file name. | 1210 // component or if there is none, the domain as the file name. |
1210 // Normally we want to base the filename on the page title, or if it doesn't | 1211 // Normally we want to base the filename on the page title, or if it doesn't |
1211 // exist, on the URL. It's not easy to tell if the page has no title, because | 1212 // exist, on the URL. It's not easy to tell if the page has no title, because |
1212 // if the page has no title, WebContents::GetTitle() will return the page's | 1213 // if the page has no title, WebContents::GetTitle() will return the page's |
1213 // URL (adjusted for display purposes). Therefore, we convert the "title" | 1214 // URL (adjusted for display purposes). Therefore, we convert the "title" |
1214 // back to a URL, and if it matches the original page URL, we know the page | 1215 // back to a URL, and if it matches the original page URL, we know the page |
1215 // had no title (or had a title equal to its URL, which is fine to treat | 1216 // had no title (or had a title equal to its URL, which is fine to treat |
1216 // similarly). | 1217 // similarly). |
1217 if (title_ == net::FormatUrl(page_url_, accept_langs)) { | 1218 if (title_ == url_formatter::FormatUrl(page_url_, accept_langs)) { |
1218 std::string url_path; | 1219 std::string url_path; |
1219 if (!page_url_.SchemeIs(url::kDataScheme)) { | 1220 if (!page_url_.SchemeIs(url::kDataScheme)) { |
1220 std::vector<std::string> url_parts; | 1221 std::vector<std::string> url_parts; |
1221 base::SplitString(page_url_.path(), '/', &url_parts); | 1222 base::SplitString(page_url_.path(), '/', &url_parts); |
1222 if (!url_parts.empty()) { | 1223 if (!url_parts.empty()) { |
1223 for (int i = static_cast<int>(url_parts.size()) - 1; i >= 0; --i) { | 1224 for (int i = static_cast<int>(url_parts.size()) - 1; i >= 0; --i) { |
1224 url_path = url_parts[i]; | 1225 url_path = url_parts[i]; |
1225 if (!url_path.empty()) | 1226 if (!url_path.empty()) |
1226 break; | 1227 break; |
1227 } | 1228 } |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1434 | 1435 |
1435 void SavePackage::FinalizeDownloadEntry() { | 1436 void SavePackage::FinalizeDownloadEntry() { |
1436 DCHECK(download_); | 1437 DCHECK(download_); |
1437 DCHECK(download_manager_); | 1438 DCHECK(download_manager_); |
1438 | 1439 |
1439 download_manager_->OnSavePackageSuccessfullyFinished(download_); | 1440 download_manager_->OnSavePackageSuccessfullyFinished(download_); |
1440 StopObservation(); | 1441 StopObservation(); |
1441 } | 1442 } |
1442 | 1443 |
1443 } // namespace content | 1444 } // namespace content |
OLD | NEW |