Avi Drissman | 4a8573c | 2022-09-09 19:35:54 | [diff] [blame] | 1 | // Copyright 2012 The Chromium Authors |
[email protected] | 33ca232f | 2012-04-10 00:08:45 | [diff] [blame] | 2 | // 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 Sherman | 982457e6 | 2017-12-13 02:19:36 | [diff] [blame] | 7 | #include "base/metrics/histogram_functions.h" |
jialiul | 70cd6f2c | 2016-02-02 23:24:57 | [diff] [blame] | 8 | #include "base/strings/stringprintf.h" |
jialiul | 7f11b74 | 2015-11-26 04:54:49 | [diff] [blame] | 9 | #include "chrome/browser/browser_process.h" |
Xinghui Lu | 21b5237e | 2022-11-18 03:59:59 | [diff] [blame] | 10 | #include "chrome/browser/download/download_item_warning_data.h" |
Micah Morton | 5675f90 | 2017-08-16 22:35:19 | [diff] [blame] | 11 | #include "chrome/browser/safe_browsing/download_protection/download_protection_service.h" |
Xinghui Lu | 2db98ab | 2021-07-12 23:26:43 | [diff] [blame] | 12 | #include "chrome/browser/safe_browsing/download_protection/download_protection_util.h" |
jialiul | 7f11b74 | 2015-11-26 04:54:49 | [diff] [blame] | 13 | #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
Min Qin | 0ca8e1ee | 2018-01-31 00:49:35 | [diff] [blame] | 14 | #include "components/download/public/common/download_danger_type.h" |
Min Qin | a9f48787 | 2018-02-09 20:43:23 | [diff] [blame] | 15 | #include "components/download/public/common/download_item.h" |
Colin Blundell | 641e4e4 | 2021-06-24 16:09:53 | [diff] [blame] | 16 | #include "components/safe_browsing/content/browser/web_ui/safe_browsing_ui.h" |
Colin Blundell | 6c4f3fd | 2021-07-01 15:28:33 | [diff] [blame] | 17 | #include "components/safe_browsing/content/common/file_type_policies.h" |
Xinghui Lu | 2db98ab | 2021-07-12 23:26:43 | [diff] [blame] | 18 | #include "components/safe_browsing/core/common/proto/csd.pb.h" |
Xinghui Lu | 09e84f58 | 2021-05-11 19:18:29 | [diff] [blame] | 19 | #include "content/public/browser/browser_task_traits.h" |
| 20 | #include "content/public/browser/browser_thread.h" |
Daniel Rubery | dd3f5a49 | 2020-08-18 19:20:35 | [diff] [blame] | 21 | #include "content/public/browser/download_item_utils.h" |
[email protected] | 33ca232f | 2012-04-10 00:08:45 | [diff] [blame] | 22 | |
jialiul | ee910ec1 | 2016-01-11 19:42:46 | [diff] [blame] | 23 | using safe_browsing::ClientDownloadResponse; |
jialiul | 7f11b74 | 2015-11-26 04:54:49 | [diff] [blame] | 24 | using safe_browsing::ClientSafeBrowsingReportRequest; |
[email protected] | f85a34b | 2014-08-16 01:10:16 | [diff] [blame] | 25 | |
[email protected] | 33ca232f | 2012-04-10 00:08:45 | [diff] [blame] | 26 | namespace { |
jialiul | 70cd6f2c | 2016-02-02 23:24:57 | [diff] [blame] | 27 | const char kDownloadDangerPromptPrefix[] = "Download.DownloadDangerPrompt"; |
[email protected] | cce1bad6 | 2013-01-04 02:26:38 | [diff] [blame] | 28 | } // namespace |
[email protected] | 33ca232f | 2012-04-10 00:08:45 | [diff] [blame] | 29 | |
jialiul | 2c263858 | 2016-06-08 22:18:08 | [diff] [blame] | 30 | void DownloadDangerPrompt::SendSafeBrowsingDownloadReport( |
| 31 | ClientSafeBrowsingReportRequest::ReportType report_type, |
jialiul | 7f11b74 | 2015-11-26 04:54:49 | [diff] [blame] | 32 | bool did_proceed, |
Xinghui Lu | 4274b60 | 2022-09-08 03:06:02 | [diff] [blame] | 33 | download::DownloadItem* download) { |
Xinghui Lu | 2db98ab | 2021-07-12 23:26:43 | [diff] [blame] | 34 | ClientDownloadResponse::Verdict download_verdict = |
Xinghui Lu | e3e8da0 | 2022-09-10 07:46:03 | [diff] [blame] | 35 | safe_browsing::DownloadProtectionService::GetDownloadProtectionVerdict( |
| 36 | download); |
Xinghui Lu | 2db98ab | 2021-07-12 23:26:43 | [diff] [blame] | 37 | if (download_verdict == ClientDownloadResponse::SAFE) { |
| 38 | // Don't send report if the verdict is SAFE. |
| 39 | return; |
jialiul | ee910ec1 | 2016-01-11 19:42:46 | [diff] [blame] | 40 | } |
Xinghui Lu | 4274b60 | 2022-09-08 03:06:02 | [diff] [blame] | 41 | g_browser_process->safe_browsing_service()->SendDownloadReport( |
| 42 | download, report_type, did_proceed, |
| 43 | /*show_download_in_folder=*/absl::nullopt); |
jialiul | 7f11b74 | 2015-11-26 04:54:49 | [diff] [blame] | 44 | } |
jialiul | 70cd6f2c | 2016-02-02 23:24:57 | [diff] [blame] | 45 | |
| 46 | void DownloadDangerPrompt::RecordDownloadDangerPrompt( |
| 47 | bool did_proceed, |
Min Qin | a9f48787 | 2018-02-09 20:43:23 | [diff] [blame] | 48 | const download::DownloadItem& download) { |
nparker | ac9da06 | 2016-05-19 21:47:23 | [diff] [blame] | 49 | int64_t file_type_uma_value = |
| 50 | safe_browsing::FileTypePolicies::GetInstance()->UmaValueForFile( |
| 51 | download.GetTargetFilePath()); |
Min Qin | 0ca8e1ee | 2018-01-31 00:49:35 | [diff] [blame] | 52 | download::DownloadDangerType danger_type = download.GetDangerType(); |
jialiul | 70cd6f2c | 2016-02-02 23:24:57 | [diff] [blame] | 53 | |
Ilya Sherman | 982457e6 | 2017-12-13 02:19:36 | [diff] [blame] | 54 | base::UmaHistogramSparse( |
jialiul | 70cd6f2c | 2016-02-02 23:24:57 | [diff] [blame] | 55 | base::StringPrintf("%s.%s.Shown", kDownloadDangerPromptPrefix, |
Rohit Bhatia | 6674a8f8a | 2022-04-26 01:58:59 | [diff] [blame] | 56 | download::GetDownloadDangerTypeString(danger_type)), |
nparker | ac9da06 | 2016-05-19 21:47:23 | [diff] [blame] | 57 | file_type_uma_value); |
jialiul | 70cd6f2c | 2016-02-02 23:24:57 | [diff] [blame] | 58 | if (did_proceed) { |
Ilya Sherman | 982457e6 | 2017-12-13 02:19:36 | [diff] [blame] | 59 | base::UmaHistogramSparse( |
jialiul | 70cd6f2c | 2016-02-02 23:24:57 | [diff] [blame] | 60 | base::StringPrintf("%s.%s.Proceed", kDownloadDangerPromptPrefix, |
Rohit Bhatia | 6674a8f8a | 2022-04-26 01:58:59 | [diff] [blame] | 61 | download::GetDownloadDangerTypeString(danger_type)), |
nparker | ac9da06 | 2016-05-19 21:47:23 | [diff] [blame] | 62 | file_type_uma_value); |
jialiul | 70cd6f2c | 2016-02-02 23:24:57 | [diff] [blame] | 63 | } |
| 64 | } |
Xinghui Lu | 21b5237e | 2022-11-18 03:59:59 | [diff] [blame] | 65 | |
| 66 | void DownloadDangerPrompt::RecordDownloadWarningEvent( |
| 67 | Action action, |
| 68 | download::DownloadItem* download) { |
| 69 | DownloadItemWarningData::WarningAction warning_action; |
| 70 | switch (action) { |
| 71 | case Action::ACCEPT: |
Xinghui Lu | b907e8cf | 2022-12-14 22:35:13 | [diff] [blame] | 72 | warning_action = DownloadItemWarningData::WarningAction::PROCEED; |
Xinghui Lu | 21b5237e | 2022-11-18 03:59:59 | [diff] [blame] | 73 | break; |
| 74 | case Action::CANCEL: |
Xinghui Lu | b907e8cf | 2022-12-14 22:35:13 | [diff] [blame] | 75 | warning_action = DownloadItemWarningData::WarningAction::CANCEL; |
Xinghui Lu | 21b5237e | 2022-11-18 03:59:59 | [diff] [blame] | 76 | break; |
| 77 | case Action::DISMISS: |
Xinghui Lu | b907e8cf | 2022-12-14 22:35:13 | [diff] [blame] | 78 | warning_action = DownloadItemWarningData::WarningAction::CLOSE; |
Xinghui Lu | 21b5237e | 2022-11-18 03:59:59 | [diff] [blame] | 79 | break; |
| 80 | } |
| 81 | DownloadItemWarningData::AddWarningActionEvent( |
Xinghui Lu | b907e8cf | 2022-12-14 22:35:13 | [diff] [blame] | 82 | download, DownloadItemWarningData::WarningSurface::DOWNLOAD_PROMPT, |
| 83 | warning_action); |
Xinghui Lu | 21b5237e | 2022-11-18 03:59:59 | [diff] [blame] | 84 | } |