Chromium Code Reviews| Index: chrome/browser/download/chrome_download_manager_delegate.cc |
| diff --git a/chrome/browser/download/chrome_download_manager_delegate.cc b/chrome/browser/download/chrome_download_manager_delegate.cc |
| index 3fec07e7020ead50e96076ac5894ddd46e259064..d89ceb508d2745e5fb1970bc187354d491c8d1fe 100644 |
| --- a/chrome/browser/download/chrome_download_manager_delegate.cc |
| +++ b/chrome/browser/download/chrome_download_manager_delegate.cc |
| @@ -87,13 +87,11 @@ bool ChromeDownloadManagerDelegate::ShouldStartDownload(int32 download_id) { |
| return false; |
| #if defined(ENABLE_SAFE_BROWSING) |
| - SafeBrowsingService* sb_service = |
| - g_browser_process->safe_browsing_service(); |
| - if (sb_service && sb_service->download_protection_service() && |
| - profile_->GetPrefs()->GetBoolean(prefs::kSafeBrowsingEnabled)) { |
| + DownloadProtectionService* service = download_protection_service(); |
| + if (service) { |
| VLOG(2) << __FUNCTION__ << "() Start SB URL check for download = " |
| << download->DebugString(false); |
| - sb_service->download_protection_service()->CheckDownloadUrl( |
| + service->CheckDownloadUrl( |
| DownloadProtectionService::DownloadInfo::FromDownloadItem(*download), |
| base::Bind( |
| &ChromeDownloadManagerDelegate::CheckDownloadUrlDone, |
| @@ -118,9 +116,9 @@ void ChromeDownloadManagerDelegate::ChooseDownloadPath( |
| bool ChromeDownloadManagerDelegate::OverrideIntermediatePath( |
| DownloadItem* item, |
| FilePath* intermediate_path) { |
| - if (item->IsDangerous()) { |
| - // The download is not safe. It's name is already set to an intermediate |
| - // name, so no need to override. |
| + if (item->needs_quarantine_file()) { |
| + // The download might not be safe. It's name is already set to an |
| + // intermediate name, so no need to override. |
| return false; |
| } |
| @@ -164,13 +162,11 @@ bool ChromeDownloadManagerDelegate::ShouldCompleteDownload(DownloadItem* item) { |
| return !state.pending; |
| } |
| // Begin the safe browsing download protection check. |
| - SafeBrowsingService* sb_service = |
| - g_browser_process->safe_browsing_service(); |
| - if (sb_service && sb_service->download_protection_service() && |
| - profile_->GetPrefs()->GetBoolean(prefs::kSafeBrowsingEnabled)) { |
| + DownloadProtectionService* service = download_protection_service(); |
| + if (service) { |
| VLOG(2) << __FUNCTION__ << "() Start SB download check for download = " |
| << item->DebugString(false); |
| - sb_service->download_protection_service()->CheckClientDownload( |
| + service->CheckClientDownload( |
| DownloadProtectionService::DownloadInfo::FromDownloadItem(*item), |
| base::Bind( |
| &ChromeDownloadManagerDelegate::CheckClientDownloadDone, |
| @@ -299,6 +295,18 @@ void ChromeDownloadManagerDelegate::DownloadProgressUpdated() { |
| download_count, progress_known, progress); |
| } |
| +DownloadProtectionService* |
| + ChromeDownloadManagerDelegate::download_protection_service() { |
|
asanka
2011/11/16 03:23:48
Nit: This is not a trivial accessor.
noelutz
2011/11/16 03:50:26
Done.
|
| +#if defined(ENABLE_SAFE_BROWSING) |
| + SafeBrowsingService* sb_service = g_browser_process->safe_browsing_service(); |
| + if (sb_service && sb_service->download_protection_service() && |
| + profile_->GetPrefs()->GetBoolean(prefs::kSafeBrowsingEnabled)) { |
| + return sb_service->download_protection_service(); |
| + } |
| +#endif |
| + return NULL; |
| +} |
| + |
| void ChromeDownloadManagerDelegate::CheckDownloadUrlDone( |
| int32 download_id, |
| DownloadProtectionService::DownloadCheckResult result) { |
| @@ -330,10 +338,9 @@ void ChromeDownloadManagerDelegate::CheckClientDownloadDone( |
| VLOG(2) << __FUNCTION__ << "() download = " << item->DebugString(false) |
| << " verdict = " << result; |
| - // TODO(noelutz): |
| - // 1) display a warning if the result is DANGEROUS. |
| - // 2) make sure we haven't already displayed a warning for the URL. |
| - // 3) disable the existing dangerous file warning for executables. |
| + // TODO(noelutz): ensure that URL warning was not already shown. |
|
asanka
2011/11/16 03:23:48
Shall we, instead, ensure that the DownloadItem is
noelutz
2011/11/16 03:50:26
Much easier. Done.
|
| + if (result == DownloadProtectionService::DANGEROUS) |
| + item->MarkContentDangerous(); |
| SafeBrowsingStateMap::iterator it = safe_browsing_state_.find(item->id()); |
| DCHECK(it != safe_browsing_state_.end() && it->second.pending); |
| @@ -418,7 +425,19 @@ void ChromeDownloadManagerDelegate::CheckVisitedReferrerBeforeDone( |
| if (!state.prompt_user_for_save_location && state.force_file_name.empty()) { |
| state.is_dangerous_file = |
| IsDangerousFile(*download, state, visited_referrer_before); |
| + state.needs_quarantine_file = true; |
| + } |
| + |
| +#if defined(ENABLE_SAFE_BROWSING) |
| + DownloadProtectionService* service = download_protection_service(); |
| + // Return false if this type of files is handled by the enhanced SafeBrowsing |
| + // download protection. |
| + if (service && service->enabled() && |
| + service->IsSupportedFileType(state.suggested_path.BaseName())) { |
| + state.is_dangerous_file = false; |
| + state.needs_quarantine_file = true; |
| } |
| +#endif |
| // We need to move over to the download thread because we don't want to stat |
| // the suggested path on the UI thread. |
| @@ -454,7 +473,7 @@ void ChromeDownloadManagerDelegate::CheckIfSuggestedPathExists( |
| } |
| // If the download is deemed dangerous, we'll use a temporary name for it. |
| - if (state.IsDangerous()) { |
| + if (state.needs_quarantine_file) { |
| state.target_name = FilePath(state.suggested_path).BaseName(); |
| // Create a temporary file to hold the file until the user approves its |
| // download. |
| @@ -506,7 +525,7 @@ void ChromeDownloadManagerDelegate::CheckIfSuggestedPathExists( |
| // See: http://code.google.com/p/chromium/issues/detail?id=3662 |
| if (!state.prompt_user_for_save_location && |
| state.force_file_name.empty()) { |
| - if (state.IsDangerous()) |
| + if (state.needs_quarantine_file) |
| file_util::WriteFile(state.suggested_path, "", 0); |
| else |
| file_util::WriteFile(download_util::GetCrDownloadPath( |
| @@ -541,10 +560,6 @@ bool ChromeDownloadManagerDelegate::IsDangerousFile( |
| if (state.transition_type & content::PAGE_TRANSITION_FROM_ADDRESS_BAR) |
| return false; |
| - // Return false if this type of files is handled by the enhanced SafeBrowsing |
| - // download protection. |
| - // TODO(noelutz): implement that check. |
| - |
| // Extensions that are not from the gallery are considered dangerous. |
| if (IsExtensionDownload(&download)) { |
| ExtensionService* service = profile_->GetExtensionService(); |