| 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 "chrome/browser/download/chrome_download_manager_delegate.h" | 5 #include "chrome/browser/download/chrome_download_manager_delegate.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 return drive_download_handler->GetTargetPath(download); | 102 return drive_download_handler->GetTargetPath(download); |
| 103 #endif | 103 #endif |
| 104 // The caller wants to open the download or show it in a file browser. The | 104 // The caller wants to open the download or show it in a file browser. The |
| 105 // download could be in one of three states: | 105 // download could be in one of three states: |
| 106 // - Complete: The path we want is GetTargetFilePath(). | 106 // - Complete: The path we want is GetTargetFilePath(). |
| 107 // - Not complete, but there's an intermediate file: GetFullPath() will be | 107 // - Not complete, but there's an intermediate file: GetFullPath() will be |
| 108 // non-empty and is the location of the intermediate file. Since no target | 108 // non-empty and is the location of the intermediate file. Since no target |
| 109 // file exits yet, use GetFullPath(). This should only happen during | 109 // file exits yet, use GetFullPath(). This should only happen during |
| 110 // ShowDownloadInShell(). | 110 // ShowDownloadInShell(). |
| 111 // - Not Complete, and there's no intermediate file: GetFullPath() will be | 111 // - Not Complete, and there's no intermediate file: GetFullPath() will be |
| 112 // empty. This shouldn't happen since CanShowInFolder() returns false and | 112 // empty. |
| 113 // this function shouldn't have been called. | |
| 114 if (download->IsComplete()) { | 113 if (download->IsComplete()) { |
| 115 DCHECK(!download->GetTargetFilePath().empty()); | 114 DCHECK(!download->GetTargetFilePath().empty()); |
| 116 return download->GetTargetFilePath(); | 115 return download->GetTargetFilePath(); |
| 117 } | 116 } |
| 118 | 117 |
| 119 DCHECK(!download->GetFullPath().empty()); | |
| 120 return download->GetFullPath(); | 118 return download->GetFullPath(); |
| 121 } | 119 } |
| 122 | 120 |
| 123 // Callback invoked by DownloadProtectionService::CheckClientDownload. | 121 // Callback invoked by DownloadProtectionService::CheckClientDownload. |
| 124 // |is_content_check_supported| is true if the SB service supports scanning the | 122 // |is_content_check_supported| is true if the SB service supports scanning the |
| 125 // download for malicious content. | 123 // download for malicious content. |
| 126 // |callback| is invoked with a danger type determined as follows: | 124 // |callback| is invoked with a danger type determined as follows: |
| 127 // | 125 // |
| 128 // Danger type is (in order of preference): | 126 // Danger type is (in order of preference): |
| 129 // * DANGEROUS_URL, if the URL is a known malware site. | 127 // * DANGEROUS_URL, if the URL is a known malware site. |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 return DownloadId(this, next_download_id_++); | 184 return DownloadId(this, next_download_id_++); |
| 187 | 185 |
| 188 return BrowserContext::GetDownloadManager(profile_->GetOriginalProfile())-> | 186 return BrowserContext::GetDownloadManager(profile_->GetOriginalProfile())-> |
| 189 GetDelegate()->GetNextId(); | 187 GetDelegate()->GetNextId(); |
| 190 } | 188 } |
| 191 | 189 |
| 192 bool ChromeDownloadManagerDelegate::DetermineDownloadTarget( | 190 bool ChromeDownloadManagerDelegate::DetermineDownloadTarget( |
| 193 DownloadItem* download, | 191 DownloadItem* download, |
| 194 const content::DownloadTargetCallback& callback) { | 192 const content::DownloadTargetCallback& callback) { |
| 195 DownloadTargetDeterminer::Start(download, | 193 DownloadTargetDeterminer::Start(download, |
| 194 GetPlatformDownloadPath(profile_, download), |
| 196 download_prefs_.get(), | 195 download_prefs_.get(), |
| 197 last_download_path_, | 196 last_download_path_, |
| 198 this, | 197 this, |
| 199 callback); | 198 callback); |
| 200 return true; | 199 return true; |
| 201 } | 200 } |
| 202 | 201 |
| 203 bool ChromeDownloadManagerDelegate::ShouldOpenFileBasedOnExtension( | 202 bool ChromeDownloadManagerDelegate::ShouldOpenFileBasedOnExtension( |
| 204 const base::FilePath& path) { | 203 const base::FilePath& path) { |
| 205 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 204 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 365 can_save_as_complete, | 364 can_save_as_complete, |
| 366 download_prefs_.get(), | 365 download_prefs_.get(), |
| 367 callback); | 366 callback); |
| 368 #endif | 367 #endif |
| 369 } | 368 } |
| 370 | 369 |
| 371 void ChromeDownloadManagerDelegate::OpenDownload(DownloadItem* download) { | 370 void ChromeDownloadManagerDelegate::OpenDownload(DownloadItem* download) { |
| 372 DCHECK(download->IsComplete()); | 371 DCHECK(download->IsComplete()); |
| 373 if (!download->CanOpenDownload()) | 372 if (!download->CanOpenDownload()) |
| 374 return; | 373 return; |
| 375 platform_util::OpenItem(GetPlatformDownloadPath(profile_, download)); | 374 base::FilePath platform_path(GetPlatformDownloadPath(profile_, download)); |
| 375 DCHECK(!platform_path.empty()); |
| 376 platform_util::OpenItem(platform_path); |
| 376 } | 377 } |
| 377 | 378 |
| 378 void ChromeDownloadManagerDelegate::ShowDownloadInShell( | 379 void ChromeDownloadManagerDelegate::ShowDownloadInShell( |
| 379 DownloadItem* download) { | 380 DownloadItem* download) { |
| 380 if (!download->CanShowInFolder()) | 381 if (!download->CanShowInFolder()) |
| 381 return; | 382 return; |
| 382 platform_util::ShowItemInFolder(GetPlatformDownloadPath(profile_, download)); | 383 base::FilePath platform_path(GetPlatformDownloadPath(profile_, download)); |
| 384 DCHECK(!platform_path.empty()); |
| 385 platform_util::ShowItemInFolder(platform_path); |
| 383 } | 386 } |
| 384 | 387 |
| 385 void ChromeDownloadManagerDelegate::CheckForFileExistence( | 388 void ChromeDownloadManagerDelegate::CheckForFileExistence( |
| 386 DownloadItem* download, | 389 DownloadItem* download, |
| 387 const content::CheckForFileExistenceCallback& callback) { | 390 const content::CheckForFileExistenceCallback& callback) { |
| 388 #if defined(OS_CHROMEOS) | 391 #if defined(OS_CHROMEOS) |
| 389 drive::DownloadHandler* drive_download_handler = | 392 drive::DownloadHandler* drive_download_handler = |
| 390 drive::DownloadHandler::GetForProfile(profile_); | 393 drive::DownloadHandler::GetForProfile(profile_); |
| 391 if (drive_download_handler && | 394 if (drive_download_handler && |
| 392 drive_download_handler->IsDriveDownload(download)) { | 395 drive_download_handler->IsDriveDownload(download)) { |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 570 registrar_.Remove(this, | 573 registrar_.Remove(this, |
| 571 chrome::NOTIFICATION_CRX_INSTALLER_DONE, | 574 chrome::NOTIFICATION_CRX_INSTALLER_DONE, |
| 572 source); | 575 source); |
| 573 | 576 |
| 574 scoped_refptr<extensions::CrxInstaller> installer = | 577 scoped_refptr<extensions::CrxInstaller> installer = |
| 575 content::Source<extensions::CrxInstaller>(source).ptr(); | 578 content::Source<extensions::CrxInstaller>(source).ptr(); |
| 576 content::DownloadOpenDelayedCallback callback = crx_installers_[installer]; | 579 content::DownloadOpenDelayedCallback callback = crx_installers_[installer]; |
| 577 crx_installers_.erase(installer.get()); | 580 crx_installers_.erase(installer.get()); |
| 578 callback.Run(installer->did_handle_successfully()); | 581 callback.Run(installer->did_handle_successfully()); |
| 579 } | 582 } |
| OLD | NEW |