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 "chrome/browser/download/download_manager.h" | 5 #include "chrome/browser/download/download_manager.h" |
6 | 6 |
7 #include "base/callback.h" | 7 #include "base/callback.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/i18n/case_conversion.h" | 9 #include "base/i18n/case_conversion.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 15 matching lines...) Expand all Loading... |
26 #include "chrome/browser/download/download_safe_browsing_client.h" | 26 #include "chrome/browser/download/download_safe_browsing_client.h" |
27 #include "chrome/browser/download/download_status_updater.h" | 27 #include "chrome/browser/download/download_status_updater.h" |
28 #include "chrome/browser/download/download_util.h" | 28 #include "chrome/browser/download/download_util.h" |
29 #include "chrome/browser/extensions/extension_service.h" | 29 #include "chrome/browser/extensions/extension_service.h" |
30 #include "chrome/browser/history/download_create_info.h" | 30 #include "chrome/browser/history/download_create_info.h" |
31 #include "chrome/browser/platform_util.h" | 31 #include "chrome/browser/platform_util.h" |
32 #include "chrome/browser/profiles/profile.h" | 32 #include "chrome/browser/profiles/profile.h" |
33 #include "chrome/browser/tab_contents/tab_util.h" | 33 #include "chrome/browser/tab_contents/tab_util.h" |
34 #include "chrome/browser/ui/browser.h" | 34 #include "chrome/browser/ui/browser.h" |
35 #include "chrome/browser/ui/browser_list.h" | 35 #include "chrome/browser/ui/browser_list.h" |
| 36 #include "chrome/browser/ui/download/download_tab_helper.h" |
| 37 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
36 #include "chrome/common/chrome_paths.h" | 38 #include "chrome/common/chrome_paths.h" |
37 #include "content/browser/browser_thread.h" | 39 #include "content/browser/browser_thread.h" |
38 #include "content/browser/renderer_host/render_process_host.h" | 40 #include "content/browser/renderer_host/render_process_host.h" |
39 #include "content/browser/renderer_host/render_view_host.h" | 41 #include "content/browser/renderer_host/render_view_host.h" |
40 #include "content/browser/renderer_host/resource_dispatcher_host.h" | 42 #include "content/browser/renderer_host/resource_dispatcher_host.h" |
41 #include "content/browser/tab_contents/tab_contents.h" | 43 #include "content/browser/tab_contents/tab_contents.h" |
42 #include "content/common/notification_type.h" | 44 #include "content/common/notification_type.h" |
43 #include "googleurl/src/gurl.h" | 45 #include "googleurl/src/gurl.h" |
44 #include "grit/generated_resources.h" | 46 #include "grit/generated_resources.h" |
45 #include "grit/theme_resources.h" | 47 #include "grit/theme_resources.h" |
(...skipping 1016 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1062 | 1064 |
1063 void DownloadManager::ShowDownloadInBrowser( | 1065 void DownloadManager::ShowDownloadInBrowser( |
1064 DownloadProcessHandle* process_handle, DownloadItem* download) { | 1066 DownloadProcessHandle* process_handle, DownloadItem* download) { |
1065 if (!process_handle) | 1067 if (!process_handle) |
1066 return; | 1068 return; |
1067 | 1069 |
1068 // The 'contents' may no longer exist if the user closed the tab before we | 1070 // The 'contents' may no longer exist if the user closed the tab before we |
1069 // get this start completion event. If it does, tell the origin TabContents | 1071 // get this start completion event. If it does, tell the origin TabContents |
1070 // to display its download shelf. | 1072 // to display its download shelf. |
1071 TabContents* contents = process_handle->GetTabContents(); | 1073 TabContents* contents = process_handle->GetTabContents(); |
| 1074 TabContentsWrapper* wrapper = NULL; |
| 1075 if (contents) |
| 1076 wrapper = TabContentsWrapper::GetCurrentWrapperForContents(contents); |
1072 | 1077 |
1073 // If the contents no longer exists, we start the download in the last active | 1078 // If the contents no longer exists, we start the download in the last active |
1074 // browser. This is not ideal but better than fully hiding the download from | 1079 // browser. This is not ideal but better than fully hiding the download from |
1075 // the user. | 1080 // the user. |
1076 if (!contents) { | 1081 if (!wrapper) { |
1077 Browser* last_active = BrowserList::GetLastActive(); | 1082 Browser* last_active = BrowserList::GetLastActive(); |
1078 if (last_active) | 1083 if (last_active) |
1079 contents = last_active->GetSelectedTabContents(); | 1084 wrapper = last_active->GetSelectedTabContentsWrapper(); |
1080 } | 1085 } |
1081 | 1086 |
1082 if (!contents) | 1087 if (!wrapper) |
1083 return; | 1088 return; |
1084 | 1089 |
1085 contents->OnStartDownload(download); | 1090 wrapper->download_tab_helper()->OnStartDownload(download); |
1086 } | 1091 } |
1087 | 1092 |
1088 // Clears the last download path, used to initialize "save as" dialogs. | 1093 // Clears the last download path, used to initialize "save as" dialogs. |
1089 void DownloadManager::ClearLastDownloadPath() { | 1094 void DownloadManager::ClearLastDownloadPath() { |
1090 last_download_path_ = FilePath(); | 1095 last_download_path_ = FilePath(); |
1091 } | 1096 } |
1092 | 1097 |
1093 void DownloadManager::NotifyModelChanged() { | 1098 void DownloadManager::NotifyModelChanged() { |
1094 FOR_EACH_OBSERVER(Observer, observers_, ModelChanged()); | 1099 FOR_EACH_OBSERVER(Observer, observers_, ModelChanged()); |
1095 } | 1100 } |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1170 observed_download_manager_->RemoveObserver(this); | 1175 observed_download_manager_->RemoveObserver(this); |
1171 } | 1176 } |
1172 | 1177 |
1173 void DownloadManager::OtherDownloadManagerObserver::ModelChanged() { | 1178 void DownloadManager::OtherDownloadManagerObserver::ModelChanged() { |
1174 observing_download_manager_->NotifyModelChanged(); | 1179 observing_download_manager_->NotifyModelChanged(); |
1175 } | 1180 } |
1176 | 1181 |
1177 void DownloadManager::OtherDownloadManagerObserver::ManagerGoingDown() { | 1182 void DownloadManager::OtherDownloadManagerObserver::ManagerGoingDown() { |
1178 observed_download_manager_ = NULL; | 1183 observed_download_manager_ = NULL; |
1179 } | 1184 } |
OLD | NEW |