blob: 8dc335d71b4dcba44ecc99b39103acaf718384f5 [file] [log] [blame]
Avi Drissman4a8573c2022-09-09 19:35:541// Copyright 2012 The Chromium Authors
[email protected]33ca232f2012-04-10 00:08:452// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "chrome/browser/download/download_danger_prompt.h"
6
Ilya Sherman982457e62017-12-13 02:19:367#include "base/metrics/histogram_functions.h"
jialiul70cd6f2c2016-02-02 23:24:578#include "base/strings/stringprintf.h"
jialiul7f11b742015-11-26 04:54:499#include "chrome/browser/browser_process.h"
Xinghui Lu21b5237e2022-11-18 03:59:5910#include "chrome/browser/download/download_item_warning_data.h"
Micah Morton5675f902017-08-16 22:35:1911#include "chrome/browser/safe_browsing/download_protection/download_protection_service.h"
Xinghui Lu2db98ab2021-07-12 23:26:4312#include "chrome/browser/safe_browsing/download_protection/download_protection_util.h"
jialiul7f11b742015-11-26 04:54:4913#include "chrome/browser/safe_browsing/safe_browsing_service.h"
Min Qin0ca8e1ee2018-01-31 00:49:3514#include "components/download/public/common/download_danger_type.h"
Min Qina9f487872018-02-09 20:43:2315#include "components/download/public/common/download_item.h"
Colin Blundell641e4e42021-06-24 16:09:5316#include "components/safe_browsing/content/browser/web_ui/safe_browsing_ui.h"
Colin Blundell6c4f3fd2021-07-01 15:28:3317#include "components/safe_browsing/content/common/file_type_policies.h"
Xinghui Lu2db98ab2021-07-12 23:26:4318#include "components/safe_browsing/core/common/proto/csd.pb.h"
Xinghui Lu09e84f582021-05-11 19:18:2919#include "content/public/browser/browser_task_traits.h"
20#include "content/public/browser/browser_thread.h"
Daniel Ruberydd3f5a492020-08-18 19:20:3521#include "content/public/browser/download_item_utils.h"
[email protected]33ca232f2012-04-10 00:08:4522
jialiulee910ec12016-01-11 19:42:4623using safe_browsing::ClientDownloadResponse;
jialiul7f11b742015-11-26 04:54:4924using safe_browsing::ClientSafeBrowsingReportRequest;
[email protected]f85a34b2014-08-16 01:10:1625
[email protected]33ca232f2012-04-10 00:08:4526namespace {
jialiul70cd6f2c2016-02-02 23:24:5727const char kDownloadDangerPromptPrefix[] = "Download.DownloadDangerPrompt";
[email protected]cce1bad62013-01-04 02:26:3828} // namespace
[email protected]33ca232f2012-04-10 00:08:4529
jialiul2c2638582016-06-08 22:18:0830void DownloadDangerPrompt::SendSafeBrowsingDownloadReport(
31 ClientSafeBrowsingReportRequest::ReportType report_type,
jialiul7f11b742015-11-26 04:54:4932 bool did_proceed,
Xinghui Lu4274b602022-09-08 03:06:0233 download::DownloadItem* download) {
Xinghui Lu2db98ab2021-07-12 23:26:4334 ClientDownloadResponse::Verdict download_verdict =
Xinghui Lue3e8da02022-09-10 07:46:0335 safe_browsing::DownloadProtectionService::GetDownloadProtectionVerdict(
36 download);
Xinghui Lu2db98ab2021-07-12 23:26:4337 if (download_verdict == ClientDownloadResponse::SAFE) {
38 // Don't send report if the verdict is SAFE.
39 return;
jialiulee910ec12016-01-11 19:42:4640 }
Xinghui Lu4274b602022-09-08 03:06:0241 g_browser_process->safe_browsing_service()->SendDownloadReport(
42 download, report_type, did_proceed,
43 /*show_download_in_folder=*/absl::nullopt);
jialiul7f11b742015-11-26 04:54:4944}
jialiul70cd6f2c2016-02-02 23:24:5745
46void DownloadDangerPrompt::RecordDownloadDangerPrompt(
47 bool did_proceed,
Min Qina9f487872018-02-09 20:43:2348 const download::DownloadItem& download) {
nparkerac9da062016-05-19 21:47:2349 int64_t file_type_uma_value =
50 safe_browsing::FileTypePolicies::GetInstance()->UmaValueForFile(
51 download.GetTargetFilePath());
Min Qin0ca8e1ee2018-01-31 00:49:3552 download::DownloadDangerType danger_type = download.GetDangerType();
jialiul70cd6f2c2016-02-02 23:24:5753
Ilya Sherman982457e62017-12-13 02:19:3654 base::UmaHistogramSparse(
jialiul70cd6f2c2016-02-02 23:24:5755 base::StringPrintf("%s.%s.Shown", kDownloadDangerPromptPrefix,
Rohit Bhatia6674a8f8a2022-04-26 01:58:5956 download::GetDownloadDangerTypeString(danger_type)),
nparkerac9da062016-05-19 21:47:2357 file_type_uma_value);
jialiul70cd6f2c2016-02-02 23:24:5758 if (did_proceed) {
Ilya Sherman982457e62017-12-13 02:19:3659 base::UmaHistogramSparse(
jialiul70cd6f2c2016-02-02 23:24:5760 base::StringPrintf("%s.%s.Proceed", kDownloadDangerPromptPrefix,
Rohit Bhatia6674a8f8a2022-04-26 01:58:5961 download::GetDownloadDangerTypeString(danger_type)),
nparkerac9da062016-05-19 21:47:2362 file_type_uma_value);
jialiul70cd6f2c2016-02-02 23:24:5763 }
64}
Xinghui Lu21b5237e2022-11-18 03:59:5965
66void DownloadDangerPrompt::RecordDownloadWarningEvent(
67 Action action,
68 download::DownloadItem* download) {
69 DownloadItemWarningData::WarningAction warning_action;
70 switch (action) {
71 case Action::ACCEPT:
Xinghui Lub907e8cf2022-12-14 22:35:1372 warning_action = DownloadItemWarningData::WarningAction::PROCEED;
Xinghui Lu21b5237e2022-11-18 03:59:5973 break;
74 case Action::CANCEL:
Xinghui Lub907e8cf2022-12-14 22:35:1375 warning_action = DownloadItemWarningData::WarningAction::CANCEL;
Xinghui Lu21b5237e2022-11-18 03:59:5976 break;
77 case Action::DISMISS:
Xinghui Lub907e8cf2022-12-14 22:35:1378 warning_action = DownloadItemWarningData::WarningAction::CLOSE;
Xinghui Lu21b5237e2022-11-18 03:59:5979 break;
80 }
81 DownloadItemWarningData::AddWarningActionEvent(
Xinghui Lub907e8cf2022-12-14 22:35:1382 download, DownloadItemWarningData::WarningSurface::DOWNLOAD_PROMPT,
83 warning_action);
Xinghui Lu21b5237e2022-11-18 03:59:5984}