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