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 67ea6dc5e69d015ad762896bce3ae4ce31c905ec..cbf2a800de0cf1106809477f4b640efc20fb0f0d 100644 |
| --- a/chrome/browser/download/chrome_download_manager_delegate.cc |
| +++ b/chrome/browser/download/chrome_download_manager_delegate.cc |
| @@ -49,6 +49,7 @@ |
| #include "components/pref_registry/pref_registry_syncable.h" |
| #include "components/prefs/pref_member.h" |
| #include "components/prefs/pref_service.h" |
| +#include "content/public/browser/download_interrupt_reasons.h" |
| #include "content/public/browser/download_item.h" |
| #include "content/public/browser/download_manager.h" |
| #include "content/public/browser/notification_source.h" |
| @@ -368,8 +369,17 @@ bool ChromeDownloadManagerDelegate::IsDownloadReadyForCompletion( |
| content::DOWNLOAD_DANGER_TYPE_MAYBE_DANGEROUS_CONTENT)) { |
| DVLOG(2) << __func__ |
| << "() SB service disabled. Marking download as DANGEROUS FILE"; |
| - item->OnContentCheckCompleted( |
| - content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE); |
| + if (ShouldBlockFile(content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE)) { |
| + item->OnContentCheckCompleted( |
| + // Specifying a dangerous type here would take precendence over the |
| + // blocking of the file. |
| + content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, |
| + content::DOWNLOAD_INTERRUPT_REASON_FILE_BLOCKED); |
| + } else { |
| + item->OnContentCheckCompleted( |
| + content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE, |
| + content::DOWNLOAD_INTERRUPT_REASON_NONE); |
| + } |
| UMA_HISTOGRAM_ENUMERATION("Download.DangerousFile.Reason", |
| SB_NOT_AVAILABLE, DANGEROUS_FILE_REASON_MAX); |
| content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, |
| @@ -723,8 +733,7 @@ void ChromeDownloadManagerDelegate::CheckDownloadUrl( |
| DVLOG(2) << __func__ << "() Start SB URL check for download = " |
| << download->DebugString(false); |
| service->CheckDownloadUrl(download, |
| - base::Bind(&CheckDownloadUrlDone, |
| - callback, |
| + base::Bind(&CheckDownloadUrlDone, callback, |
| is_content_check_supported)); |
| return; |
| } |
| @@ -795,8 +804,18 @@ void ChromeDownloadManagerDelegate::CheckClientDownloadDone( |
| DCHECK_NE(danger_type, |
| content::DOWNLOAD_DANGER_TYPE_MAYBE_DANGEROUS_CONTENT); |
| - if (danger_type != content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS) |
| - item->OnContentCheckCompleted(danger_type); |
| + if (danger_type != content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS) { |
| + if (ShouldBlockFile(danger_type)) { |
| + item->OnContentCheckCompleted( |
| + // Specifying a dangerous type here would take precendence over the |
| + // blocking of the file. |
| + content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, |
| + content::DOWNLOAD_INTERRUPT_REASON_FILE_BLOCKED); |
| + } else { |
| + item->OnContentCheckCompleted(danger_type, |
| + content::DOWNLOAD_INTERRUPT_REASON_NONE); |
| + } |
| + } |
| } |
| SafeBrowsingState* state = static_cast<SafeBrowsingState*>( |
| @@ -843,6 +862,12 @@ void ChromeDownloadManagerDelegate::OnDownloadTargetDetermined( |
| DownloadItemModel(item).SetDangerLevel(target_info->danger_level); |
| } |
| + if (ShouldBlockFile(target_info->danger_type)) { |
| + target_info->result = content::DOWNLOAD_INTERRUPT_REASON_FILE_BLOCKED; |
| + // A dangerous type would take precendence over the blocking of the file. |
| + target_info->danger_type = content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS; |
| + } |
| + |
| callback.Run(target_info->target_path, target_info->target_disposition, |
| target_info->danger_type, target_info->intermediate_path, |
| target_info->result); |
| @@ -877,3 +902,26 @@ bool ChromeDownloadManagerDelegate::IsOpenInBrowserPreferreredForFile( |
| #endif |
| return false; |
| } |
| + |
| +bool ChromeDownloadManagerDelegate::ShouldBlockFile( |
| + content::DownloadDangerType danger_type) const { |
| + DownloadPrefs::DownloadRestriction download_restriction = |
| + download_prefs_->download_restriction(); |
| + |
| + if (download_restriction == DownloadPrefs::DownloadRestriction::ALL_FILES) |
|
jochen (gone - plz use gerrit)
2017/06/14 08:16:49
what about using a switch statement here, and havi
MAD
2017/06/14 17:50:21
dtrainor asked for the same thing, and I thought i
|
| + return true; |
| + |
| + if (download_restriction == DownloadPrefs::DownloadRestriction::NONE || |
| + danger_type == content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS) { |
| + return false; |
| + } |
| + |
| + return (download_restriction == |
| + DownloadPrefs::DownloadRestriction::DANGEROUS_FILES && |
| + (danger_type == content::DOWNLOAD_DANGER_TYPE_DANGEROUS_CONTENT || |
| + danger_type == content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE || |
| + danger_type == content::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL)) || |
| + // DANGEROUS_HOST, UNKNOWN, POTENTIALLY & MAYBE_DANGEROUS types. |
| + (download_restriction == |
| + DownloadPrefs::DownloadRestriction::POTENTIALLY_DANGEROUS_FILES); |
| +} |