| 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/chrome_download_manager_delegate.h" | 5 #include "chrome/browser/download/chrome_download_manager_delegate.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 #include "chrome/browser/prefs/pref_member.h" | 25 #include "chrome/browser/prefs/pref_member.h" |
| 26 #include "chrome/browser/prefs/pref_service.h" | 26 #include "chrome/browser/prefs/pref_service.h" |
| 27 #include "chrome/browser/profiles/profile.h" | 27 #include "chrome/browser/profiles/profile.h" |
| 28 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 28 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
| 29 #include "chrome/browser/ui/browser.h" | 29 #include "chrome/browser/ui/browser.h" |
| 30 #include "chrome/browser/ui/browser_list.h" | 30 #include "chrome/browser/ui/browser_list.h" |
| 31 #include "chrome/common/chrome_paths.h" | 31 #include "chrome/common/chrome_paths.h" |
| 32 #include "chrome/common/extensions/user_script.h" | 32 #include "chrome/common/extensions/user_script.h" |
| 33 #include "chrome/common/pref_names.h" | 33 #include "chrome/common/pref_names.h" |
| 34 #include "content/browser/download/download_status_updater.h" | 34 #include "content/browser/download/download_status_updater.h" |
| 35 #include "content/browser/tab_contents/tab_contents.h" | |
| 36 #include "content/public/browser/download_file.h" | 35 #include "content/public/browser/download_file.h" |
| 37 #include "content/public/browser/download_item.h" | 36 #include "content/public/browser/download_item.h" |
| 38 #include "content/public/browser/download_manager.h" | 37 #include "content/public/browser/download_manager.h" |
| 39 #include "content/public/browser/notification_source.h" | 38 #include "content/public/browser/notification_source.h" |
| 39 #include "content/public/browser/web_contents.h" |
| 40 #include "grit/generated_resources.h" | 40 #include "grit/generated_resources.h" |
| 41 #include "ui/base/l10n/l10n_util.h" | 41 #include "ui/base/l10n/l10n_util.h" |
| 42 | 42 |
| 43 using content::BrowserThread; | 43 using content::BrowserThread; |
| 44 using content::DownloadFile; | 44 using content::DownloadFile; |
| 45 using content::DownloadItem; | 45 using content::DownloadItem; |
| 46 using content::DownloadManager; | 46 using content::DownloadManager; |
| 47 using content::WebContents; | 47 using content::WebContents; |
| 48 using safe_browsing::DownloadProtectionService; | 48 using safe_browsing::DownloadProtectionService; |
| 49 | 49 |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 this, | 118 this, |
| 119 download->GetId())); | 119 download->GetId())); |
| 120 return false; | 120 return false; |
| 121 } | 121 } |
| 122 #endif | 122 #endif |
| 123 CheckDownloadUrlDone(download_id, DownloadProtectionService::SAFE); | 123 CheckDownloadUrlDone(download_id, DownloadProtectionService::SAFE); |
| 124 return false; | 124 return false; |
| 125 } | 125 } |
| 126 | 126 |
| 127 void ChromeDownloadManagerDelegate::ChooseDownloadPath( | 127 void ChromeDownloadManagerDelegate::ChooseDownloadPath( |
| 128 TabContents* tab_contents, | 128 WebContents* web_contents, |
| 129 const FilePath& suggested_path, | 129 const FilePath& suggested_path, |
| 130 void* data) { | 130 void* data) { |
| 131 // Deletes itself. | 131 // Deletes itself. |
| 132 new DownloadFilePicker( | 132 new DownloadFilePicker( |
| 133 download_manager_, tab_contents, suggested_path, data); | 133 download_manager_, web_contents, suggested_path, data); |
| 134 } | 134 } |
| 135 | 135 |
| 136 bool ChromeDownloadManagerDelegate::OverrideIntermediatePath( | 136 bool ChromeDownloadManagerDelegate::OverrideIntermediatePath( |
| 137 DownloadItem* item, | 137 DownloadItem* item, |
| 138 FilePath* intermediate_path) { | 138 FilePath* intermediate_path) { |
| 139 if (item->GetDangerType() != DownloadStateInfo::NOT_DANGEROUS) { | 139 if (item->GetDangerType() != DownloadStateInfo::NOT_DANGEROUS) { |
| 140 if (item->PromptUserForSaveLocation()) { | 140 if (item->PromptUserForSaveLocation()) { |
| 141 // When we prompt the user, we overwrite the FullPath with what the user | 141 // When we prompt the user, we overwrite the FullPath with what the user |
| 142 // wanted to use. Construct a file path using the previously determined | 142 // wanted to use. Construct a file path using the previously determined |
| 143 // intermediate filename and the new path. | 143 // intermediate filename and the new path. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 154 } | 154 } |
| 155 | 155 |
| 156 // The download is a safe download. We need to rename it to its intermediate | 156 // The download is a safe download. We need to rename it to its intermediate |
| 157 // '.crdownload' path. The final name after user confirmation will be set | 157 // '.crdownload' path. The final name after user confirmation will be set |
| 158 // from DownloadItem::OnDownloadCompleting. | 158 // from DownloadItem::OnDownloadCompleting. |
| 159 *intermediate_path = download_util::GetCrDownloadPath(item->GetFullPath()); | 159 *intermediate_path = download_util::GetCrDownloadPath(item->GetFullPath()); |
| 160 return true; | 160 return true; |
| 161 } | 161 } |
| 162 | 162 |
| 163 WebContents* ChromeDownloadManagerDelegate:: | 163 WebContents* ChromeDownloadManagerDelegate:: |
| 164 GetAlternativeTabContentsToNotifyForDownload() { | 164 GetAlternativeWebContentsToNotifyForDownload() { |
| 165 // Start the download in the last active browser. This is not ideal but better | 165 // Start the download in the last active browser. This is not ideal but better |
| 166 // than fully hiding the download from the user. | 166 // than fully hiding the download from the user. |
| 167 Browser* last_active = BrowserList::GetLastActiveWithProfile(profile_); | 167 Browser* last_active = BrowserList::GetLastActiveWithProfile(profile_); |
| 168 return last_active ? last_active->GetSelectedWebContents() : NULL; | 168 return last_active ? last_active->GetSelectedWebContents() : NULL; |
| 169 } | 169 } |
| 170 | 170 |
| 171 | 171 |
| 172 bool ChromeDownloadManagerDelegate::ShouldOpenFileBasedOnExtension( | 172 bool ChromeDownloadManagerDelegate::ShouldOpenFileBasedOnExtension( |
| 173 const FilePath& path) { | 173 const FilePath& path) { |
| 174 FilePath::StringType extension = path.Extension(); | 174 FilePath::StringType extension = path.Extension(); |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 DownloadItem* item) { | 269 DownloadItem* item) { |
| 270 download_history_->RemoveEntry(item); | 270 download_history_->RemoveEntry(item); |
| 271 } | 271 } |
| 272 | 272 |
| 273 void ChromeDownloadManagerDelegate::RemoveItemsFromPersistentStoreBetween( | 273 void ChromeDownloadManagerDelegate::RemoveItemsFromPersistentStoreBetween( |
| 274 base::Time remove_begin, | 274 base::Time remove_begin, |
| 275 base::Time remove_end) { | 275 base::Time remove_end) { |
| 276 download_history_->RemoveEntriesBetween(remove_begin, remove_end); | 276 download_history_->RemoveEntriesBetween(remove_begin, remove_end); |
| 277 } | 277 } |
| 278 | 278 |
| 279 void ChromeDownloadManagerDelegate::GetSaveDir(TabContents* tab_contents, | 279 void ChromeDownloadManagerDelegate::GetSaveDir(WebContents* web_contents, |
| 280 FilePath* website_save_dir, | 280 FilePath* website_save_dir, |
| 281 FilePath* download_save_dir) { | 281 FilePath* download_save_dir) { |
| 282 Profile* profile = | 282 Profile* profile = |
| 283 Profile::FromBrowserContext(tab_contents->GetBrowserContext()); | 283 Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
| 284 PrefService* prefs = profile->GetPrefs(); | 284 PrefService* prefs = profile->GetPrefs(); |
| 285 | 285 |
| 286 // Check whether the preference has the preferred directory for saving file. | 286 // Check whether the preference has the preferred directory for saving file. |
| 287 // If not, initialize it with default directory. | 287 // If not, initialize it with default directory. |
| 288 if (!prefs->FindPreference(prefs::kSaveFileDefaultDirectory)) { | 288 if (!prefs->FindPreference(prefs::kSaveFileDefaultDirectory)) { |
| 289 DCHECK(prefs->FindPreference(prefs::kDownloadDefaultDirectory)); | 289 DCHECK(prefs->FindPreference(prefs::kDownloadDefaultDirectory)); |
| 290 FilePath default_save_path = prefs->GetFilePath( | 290 FilePath default_save_path = prefs->GetFilePath( |
| 291 prefs::kDownloadDefaultDirectory); | 291 prefs::kDownloadDefaultDirectory); |
| 292 prefs->RegisterFilePathPref(prefs::kSaveFileDefaultDirectory, | 292 prefs->RegisterFilePathPref(prefs::kSaveFileDefaultDirectory, |
| 293 default_save_path, | 293 default_save_path, |
| (...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 619 int32 download_id, int64 db_handle) { | 619 int32 download_id, int64 db_handle) { |
| 620 // It's not immediately obvious, but HistoryBackend::CreateDownload() can | 620 // It's not immediately obvious, but HistoryBackend::CreateDownload() can |
| 621 // call this function with an invalid |db_handle|. For instance, this can | 621 // call this function with an invalid |db_handle|. For instance, this can |
| 622 // happen when the history database is offline. We cannot have multiple | 622 // happen when the history database is offline. We cannot have multiple |
| 623 // DownloadItems with the same invalid db_handle, so we need to assign a | 623 // DownloadItems with the same invalid db_handle, so we need to assign a |
| 624 // unique |db_handle| here. | 624 // unique |db_handle| here. |
| 625 if (db_handle == DownloadItem::kUninitializedHandle) | 625 if (db_handle == DownloadItem::kUninitializedHandle) |
| 626 db_handle = download_history_->GetNextFakeDbHandle(); | 626 db_handle = download_history_->GetNextFakeDbHandle(); |
| 627 download_manager_->OnItemAddedToPersistentStore(download_id, db_handle); | 627 download_manager_->OnItemAddedToPersistentStore(download_id, db_handle); |
| 628 } | 628 } |
| OLD | NEW |