| Index: chrome/browser/download/download_danger_prompt.cc
|
| diff --git a/chrome/browser/download/download_danger_prompt.cc b/chrome/browser/download/download_danger_prompt.cc
|
| index f581e42b6408ba8d18ccab4cf71b672b937b6a56..00bdd1129bdefc12077196595a5c6c8ac4d66076 100644
|
| --- a/chrome/browser/download/download_danger_prompt.cc
|
| +++ b/chrome/browser/download/download_danger_prompt.cc
|
| @@ -6,12 +6,16 @@
|
|
|
| #include "base/bind.h"
|
| #include "base/strings/utf_string_conversions.h"
|
| +#include "chrome/browser/browser_process.h"
|
| #include "chrome/browser/chrome_notification_types.h"
|
| #include "chrome/browser/download/chrome_download_manager_delegate.h"
|
| #include "chrome/browser/download/download_stats.h"
|
| #include "chrome/browser/extensions/api/experience_sampling_private/experience_sampling.h"
|
| +#include "chrome/browser/safe_browsing/ping_manager.h"
|
| +#include "chrome/browser/safe_browsing/safe_browsing_service.h"
|
| #include "chrome/browser/ui/tab_modal_confirm_dialog.h"
|
| #include "chrome/browser/ui/tab_modal_confirm_dialog_delegate.h"
|
| +#include "chrome/common/safe_browsing/csd.pb.h"
|
| #include "chrome/grit/chromium_strings.h"
|
| #include "chrome/grit/generated_resources.h"
|
| #include "content/public/browser/download_danger_type.h"
|
| @@ -19,6 +23,7 @@
|
| #include "ui/base/l10n/l10n_util.h"
|
|
|
| using extensions::ExperienceSamplingEvent;
|
| +using safe_browsing::ClientSafeBrowsingReportRequest;
|
|
|
| namespace {
|
|
|
| @@ -38,7 +43,7 @@ class DownloadDangerPromptImpl : public DownloadDangerPrompt,
|
| ~DownloadDangerPromptImpl() override;
|
|
|
| // DownloadDangerPrompt:
|
| - void InvokeActionForTesting(Action action) override;
|
| + std::string InvokeActionForTesting(Action action, const GURL& url) override;
|
|
|
| private:
|
| // content::DownloadItem::Observer:
|
| @@ -92,7 +97,8 @@ DownloadDangerPromptImpl::~DownloadDangerPromptImpl() {
|
| RunDone(DISMISS);
|
| }
|
|
|
| -void DownloadDangerPromptImpl::InvokeActionForTesting(Action action) {
|
| +std::string DownloadDangerPromptImpl::InvokeActionForTesting(
|
| + Action action, const GURL& url) {
|
| switch (action) {
|
| case ACCEPT: Accept(); break;
|
| case CANCEL: Cancel(); break;
|
| @@ -101,6 +107,7 @@ void DownloadDangerPromptImpl::InvokeActionForTesting(Action action) {
|
| Cancel();
|
| break;
|
| }
|
| + return CreateSafeBrowsingDownloadRecoveryReport(action == ACCEPT, url);
|
| }
|
|
|
| void DownloadDangerPromptImpl::OnDownloadUpdated(
|
| @@ -240,6 +247,12 @@ void DownloadDangerPromptImpl::RunDone(Action action) {
|
| OnDone done = done_;
|
| done_.Reset();
|
| if (download_ != NULL) {
|
| + if (!download_->GetURL().is_empty()) {
|
| + std::string report = CreateSafeBrowsingDownloadRecoveryReport(
|
| + action == DownloadDangerPrompt::ACCEPT, download_->GetURL());
|
| + if (!report.empty())
|
| + SendSerializedReport(report);
|
| + }
|
| download_->RemoveObserver(this);
|
| download_ = NULL;
|
| }
|
| @@ -263,3 +276,28 @@ DownloadDangerPrompt* DownloadDangerPrompt::Create(
|
| return prompt;
|
| }
|
| #endif
|
| +
|
| +std::string DownloadDangerPrompt::CreateSafeBrowsingDownloadRecoveryReport(
|
| + bool did_proceed,
|
| + const GURL& url) {
|
| + ClientSafeBrowsingReportRequest report;
|
| + report.set_type(ClientSafeBrowsingReportRequest::MALICIOUS_DOWNLOAD_RECOVERY);
|
| + report.set_url(url.spec());
|
| + report.set_did_proceed(did_proceed);
|
| +
|
| + std::string serialized_report;
|
| + if (!report.SerializeToString(&serialized_report)) {
|
| + DLOG(ERROR) << "Unable to serialize the threat report.";
|
| + return "";
|
| + }
|
| +
|
| + return serialized_report;
|
| +}
|
| +
|
| +void DownloadDangerPrompt::SendSerializedReport(
|
| + const std::string& serialized_report) {
|
| + SafeBrowsingService* sb_service = g_browser_process->safe_browsing_service();
|
| + if (sb_service) {
|
| + sb_service->SendDownloadRecoveryReport(serialized_report);
|
| + }
|
| +}
|
|
|