| 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 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 FilePath::StringType extension = path.Extension(); | 137 FilePath::StringType extension = path.Extension(); |
| 138 if (extension.empty()) | 138 if (extension.empty()) |
| 139 return false; | 139 return false; |
| 140 if (Extension::IsExtension(path)) | 140 if (Extension::IsExtension(path)) |
| 141 return false; | 141 return false; |
| 142 DCHECK(extension[0] == FilePath::kExtensionSeparator); | 142 DCHECK(extension[0] == FilePath::kExtensionSeparator); |
| 143 extension.erase(0, 1); | 143 extension.erase(0, 1); |
| 144 return download_prefs_->IsAutoOpenEnabledForExtension(extension); | 144 return download_prefs_->IsAutoOpenEnabledForExtension(extension); |
| 145 } | 145 } |
| 146 | 146 |
| 147 bool ChromeDownloadManagerDelegate::ShouldOpenDownload(DownloadItem* item) { | 147 bool ChromeDownloadManagerDelegate::ShouldCompleteDownload(DownloadItem* item) { |
| 148 if (!IsExtensionDownload(item)) | 148 return true; |
| 149 return true; | |
| 150 | |
| 151 download_crx_util::OpenChromeExtension(profile_, *item); | |
| 152 return false; | |
| 153 } | 149 } |
| 154 | 150 |
| 155 bool ChromeDownloadManagerDelegate::ShouldCompleteDownload(DownloadItem* item) { | 151 bool ChromeDownloadManagerDelegate::ShouldOpenDownload(DownloadItem* item) { |
| 156 if (!IsExtensionDownload(item)) { | 152 if (!IsExtensionDownload(item)) { |
| 157 #if defined(ENABLE_SAFE_BROWSING) | 153 #if defined(ENABLE_SAFE_BROWSING) |
| 158 // Begin the safe browsing download protection check. | 154 // Begin the safe browsing download protection check. |
| 159 SafeBrowsingService* sb_service = | 155 SafeBrowsingService* sb_service = |
| 160 g_browser_process->safe_browsing_service(); | 156 g_browser_process->safe_browsing_service(); |
| 161 if (sb_service && sb_service->download_protection_service() && | 157 if (sb_service && sb_service->download_protection_service() && |
| 162 profile_->GetPrefs()->GetBoolean(prefs::kSafeBrowsingEnabled)) { | 158 profile_->GetPrefs()->GetBoolean(prefs::kSafeBrowsingEnabled)) { |
| 163 using safe_browsing::DownloadProtectionService; | 159 using safe_browsing::DownloadProtectionService; |
| 164 sb_service->download_protection_service()->CheckClientDownload( | 160 sb_service->download_protection_service()->CheckClientDownload( |
| 165 DownloadProtectionService::DownloadInfo::FromDownloadItem(*item), | 161 DownloadProtectionService::DownloadInfo::FromDownloadItem(*item), |
| 166 base::Bind( | 162 base::Bind( |
| 167 &ChromeDownloadManagerDelegate::CheckClientDownloadDone, | 163 &ChromeDownloadManagerDelegate::CheckClientDownloadDone, |
| 168 this, item->id())); | 164 this, item->id())); |
| 169 // For now, we won't delay the download for this. | 165 // For now, we won't delay the download for this. |
| 170 } | 166 } |
| 171 #else | 167 #else |
| 172 // Assume safe. | 168 // Assume safe. |
| 173 #endif | 169 #endif |
| 174 | 170 |
| 175 return true; | 171 return true; |
| 176 } | 172 } |
| 177 | 173 |
| 178 scoped_refptr<CrxInstaller> crx_installer = | 174 scoped_refptr<CrxInstaller> crx_installer = |
| 179 download_crx_util::OpenChromeExtension(profile_, *item); | 175 download_crx_util::OpenChromeExtension(profile_, *item); |
| 180 | 176 |
| 181 // CRX_INSTALLER_DONE will fire when the install completes. Observe() | 177 // CRX_INSTALLER_DONE will fire when the install completes. Observe() |
| 182 // will call CompleteDelayedDownload() on this item. If this DownloadItem is | 178 // will call DelayedDownloadOpened() on this item. If this DownloadItem is |
| 183 // not around when CRX_INSTALLER_DONE fires, Complete() will not be called. | 179 // not around when CRX_INSTALLER_DONE fires, Complete() will not be called. |
| 184 registrar_.Add(this, | 180 registrar_.Add(this, |
| 185 chrome::NOTIFICATION_CRX_INSTALLER_DONE, | 181 chrome::NOTIFICATION_CRX_INSTALLER_DONE, |
| 186 content::Source<CrxInstaller>(crx_installer.get())); | 182 content::Source<CrxInstaller>(crx_installer.get())); |
| 187 | 183 |
| 188 crx_installers_[crx_installer.get()] = item->id(); | 184 crx_installers_[crx_installer.get()] = item->id(); |
| 189 // The status text and percent complete indicator will change now | 185 // The status text and percent complete indicator will change now |
| 190 // that we are installing a CRX. Update observers so that they pick | 186 // that we are installing a CRX. Update observers so that they pick |
| 191 // up the change. | 187 // up the change. |
| 192 item->UpdateObservers(); | 188 item->UpdateObservers(); |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 337 registrar_.Remove(this, | 333 registrar_.Remove(this, |
| 338 chrome::NOTIFICATION_CRX_INSTALLER_DONE, | 334 chrome::NOTIFICATION_CRX_INSTALLER_DONE, |
| 339 source); | 335 source); |
| 340 | 336 |
| 341 CrxInstaller* installer = content::Source<CrxInstaller>(source).ptr(); | 337 CrxInstaller* installer = content::Source<CrxInstaller>(source).ptr(); |
| 342 int download_id = crx_installers_[installer]; | 338 int download_id = crx_installers_[installer]; |
| 343 crx_installers_.erase(installer); | 339 crx_installers_.erase(installer); |
| 344 | 340 |
| 345 DownloadItem* item = download_manager_->GetActiveDownloadItem(download_id); | 341 DownloadItem* item = download_manager_->GetActiveDownloadItem(download_id); |
| 346 if (item) | 342 if (item) |
| 347 item->CompleteDelayedDownload(); | 343 item->DelayedDownloadOpened(); |
| 348 } | 344 } |
| 349 | 345 |
| 350 void ChromeDownloadManagerDelegate::CheckVisitedReferrerBeforeDone( | 346 void ChromeDownloadManagerDelegate::CheckVisitedReferrerBeforeDone( |
| 351 int32 download_id, | 347 int32 download_id, |
| 352 bool visited_referrer_before) { | 348 bool visited_referrer_before) { |
| 353 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 349 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 354 | 350 |
| 355 DownloadItem* download = | 351 DownloadItem* download = |
| 356 download_manager_->GetActiveDownloadItem(download_id); | 352 download_manager_->GetActiveDownloadItem(download_id); |
| 357 if (!download) | 353 if (!download) |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 562 // TODO(noelutz): This function currently works as a callback place holder. | 558 // TODO(noelutz): This function currently works as a callback place holder. |
| 563 // Once we decide the hash check is reliable, we could move the | 559 // Once we decide the hash check is reliable, we could move the |
| 564 // MaybeCompleteDownload in OnAllDataSaved to this function. | 560 // MaybeCompleteDownload in OnAllDataSaved to this function. |
| 565 void ChromeDownloadManagerDelegate::CheckDownloadHashDone( | 561 void ChromeDownloadManagerDelegate::CheckDownloadHashDone( |
| 566 int32 download_id, | 562 int32 download_id, |
| 567 bool is_dangerous_hash) { | 563 bool is_dangerous_hash) { |
| 568 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 564 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 569 DVLOG(1) << "CheckDownloadHashDone, download_id: " << download_id | 565 DVLOG(1) << "CheckDownloadHashDone, download_id: " << download_id |
| 570 << " is dangerous_hash: " << is_dangerous_hash; | 566 << " is dangerous_hash: " << is_dangerous_hash; |
| 571 } | 567 } |
| OLD | NEW |