[email protected] | 33ca232f | 2012-04-10 00:08:45 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 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 | |
avi | e4d7b6f | 2015-12-26 00:59:18 | [diff] [blame] | 7 | #include "base/macros.h" |
Ilya Sherman | 982457e6 | 2017-12-13 02:19:36 | [diff] [blame] | 8 | #include "base/metrics/histogram_functions.h" |
jialiul | 70cd6f2c | 2016-02-02 23:24:57 | [diff] [blame] | 9 | #include "base/strings/stringprintf.h" |
jialiul | 7f11b74 | 2015-11-26 04:54:49 | [diff] [blame] | 10 | #include "chrome/browser/browser_process.h" |
Micah Morton | 5675f90 | 2017-08-16 22:35:19 | [diff] [blame] | 11 | #include "chrome/browser/safe_browsing/download_protection/download_protection_service.h" |
jialiul | 7f11b74 | 2015-11-26 04:54:49 | [diff] [blame] | 12 | #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
Min Qin | 0ca8e1ee | 2018-01-31 00:49:35 | [diff] [blame] | 13 | #include "components/download/public/common/download_danger_type.h" |
Min Qin | a9f48787 | 2018-02-09 20:43:23 | [diff] [blame] | 14 | #include "components/download/public/common/download_item.h" |
Daniel Rubery | af17ad3 | 2020-03-02 20:06:49 | [diff] [blame^] | 15 | #include "components/safe_browsing/core/file_type_policies.h" |
[email protected] | 33ca232f | 2012-04-10 00:08:45 | [diff] [blame] | 16 | |
jialiul | ee910ec1 | 2016-01-11 19:42:46 | [diff] [blame] | 17 | using safe_browsing::ClientDownloadResponse; |
jialiul | 7f11b74 | 2015-11-26 04:54:49 | [diff] [blame] | 18 | using safe_browsing::ClientSafeBrowsingReportRequest; |
[email protected] | f85a34b | 2014-08-16 01:10:16 | [diff] [blame] | 19 | |
[email protected] | 33ca232f | 2012-04-10 00:08:45 | [diff] [blame] | 20 | namespace { |
| 21 | |
jialiul | 70cd6f2c | 2016-02-02 23:24:57 | [diff] [blame] | 22 | const char kDownloadDangerPromptPrefix[] = "Download.DownloadDangerPrompt"; |
| 23 | |
jialiul | 70cd6f2c | 2016-02-02 23:24:57 | [diff] [blame] | 24 | // Converts DownloadDangerType into their corresponding string. |
| 25 | const char* GetDangerTypeString( |
Min Qin | 0ca8e1ee | 2018-01-31 00:49:35 | [diff] [blame] | 26 | const download::DownloadDangerType& danger_type) { |
jialiul | 70cd6f2c | 2016-02-02 23:24:57 | [diff] [blame] | 27 | switch (danger_type) { |
Min Qin | 0ca8e1ee | 2018-01-31 00:49:35 | [diff] [blame] | 28 | case download::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE: |
jialiul | 70cd6f2c | 2016-02-02 23:24:57 | [diff] [blame] | 29 | return "DangerousFile"; |
Min Qin | 0ca8e1ee | 2018-01-31 00:49:35 | [diff] [blame] | 30 | case download::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL: |
jialiul | 70cd6f2c | 2016-02-02 23:24:57 | [diff] [blame] | 31 | return "DangerousURL"; |
Min Qin | 0ca8e1ee | 2018-01-31 00:49:35 | [diff] [blame] | 32 | case download::DOWNLOAD_DANGER_TYPE_DANGEROUS_CONTENT: |
jialiul | 70cd6f2c | 2016-02-02 23:24:57 | [diff] [blame] | 33 | return "DangerousContent"; |
Min Qin | 0ca8e1ee | 2018-01-31 00:49:35 | [diff] [blame] | 34 | case download::DOWNLOAD_DANGER_TYPE_DANGEROUS_HOST: |
jialiul | 70cd6f2c | 2016-02-02 23:24:57 | [diff] [blame] | 35 | return "DangerousHost"; |
Min Qin | 0ca8e1ee | 2018-01-31 00:49:35 | [diff] [blame] | 36 | case download::DOWNLOAD_DANGER_TYPE_UNCOMMON_CONTENT: |
jialiul | 70cd6f2c | 2016-02-02 23:24:57 | [diff] [blame] | 37 | return "UncommonContent"; |
Min Qin | 0ca8e1ee | 2018-01-31 00:49:35 | [diff] [blame] | 38 | case download::DOWNLOAD_DANGER_TYPE_POTENTIALLY_UNWANTED: |
jialiul | 70cd6f2c | 2016-02-02 23:24:57 | [diff] [blame] | 39 | return "PotentiallyUnwanted"; |
Daniel Rubery | e357cb41a | 2019-07-08 20:22:20 | [diff] [blame] | 40 | case download::DOWNLOAD_DANGER_TYPE_ASYNC_SCANNING: |
| 41 | return "AsyncScanning"; |
Daniel Rubery | 7746d12 | 2019-07-17 01:28:59 | [diff] [blame] | 42 | case download::DOWNLOAD_DANGER_TYPE_BLOCKED_PASSWORD_PROTECTED: |
| 43 | return "BlockedPasswordProtected"; |
Daniel Rubery | 0b556b9 | 2019-10-15 20:35:09 | [diff] [blame] | 44 | case download::DOWNLOAD_DANGER_TYPE_BLOCKED_TOO_LARGE: |
| 45 | return "BlockedTooLarge"; |
| 46 | case download::DOWNLOAD_DANGER_TYPE_SENSITIVE_CONTENT_WARNING: |
| 47 | return "SensitiveContentWarning"; |
| 48 | case download::DOWNLOAD_DANGER_TYPE_SENSITIVE_CONTENT_BLOCK: |
| 49 | return "SensitiveContentBlock"; |
| 50 | case download::DOWNLOAD_DANGER_TYPE_DEEP_SCANNED_SAFE: |
| 51 | return "DeepScannedSafe"; |
| 52 | case download::DOWNLOAD_DANGER_TYPE_DEEP_SCANNED_OPENED_DANGEROUS: |
| 53 | return "DeepScannedOpenedDangerous"; |
Daniel Rubery | e6247df | 2019-12-16 19:51:53 | [diff] [blame] | 54 | case download::DOWNLOAD_DANGER_TYPE_PROMPT_FOR_SCANNING: |
| 55 | return "PromptForScanning"; |
Min Qin | 0ca8e1ee | 2018-01-31 00:49:35 | [diff] [blame] | 56 | case download::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS: |
| 57 | case download::DOWNLOAD_DANGER_TYPE_MAYBE_DANGEROUS_CONTENT: |
| 58 | case download::DOWNLOAD_DANGER_TYPE_USER_VALIDATED: |
Jialiu Lin | 93850e0 | 2018-05-16 16:32:05 | [diff] [blame] | 59 | case download::DOWNLOAD_DANGER_TYPE_WHITELISTED_BY_POLICY: |
Min Qin | 0ca8e1ee | 2018-01-31 00:49:35 | [diff] [blame] | 60 | case download::DOWNLOAD_DANGER_TYPE_MAX: |
jialiul | 70cd6f2c | 2016-02-02 23:24:57 | [diff] [blame] | 61 | break; |
| 62 | } |
| 63 | NOTREACHED(); |
| 64 | return nullptr; |
| 65 | } |
| 66 | |
[email protected] | cce1bad6 | 2013-01-04 02:26:38 | [diff] [blame] | 67 | } // namespace |
[email protected] | 33ca232f | 2012-04-10 00:08:45 | [diff] [blame] | 68 | |
jialiul | 2c263858 | 2016-06-08 22:18:08 | [diff] [blame] | 69 | void DownloadDangerPrompt::SendSafeBrowsingDownloadReport( |
| 70 | ClientSafeBrowsingReportRequest::ReportType report_type, |
jialiul | 7f11b74 | 2015-11-26 04:54:49 | [diff] [blame] | 71 | bool did_proceed, |
Min Qin | a9f48787 | 2018-02-09 20:43:23 | [diff] [blame] | 72 | const download::DownloadItem& download) { |
jialiul | 7f11b74 | 2015-11-26 04:54:49 | [diff] [blame] | 73 | safe_browsing::SafeBrowsingService* sb_service = |
| 74 | g_browser_process->safe_browsing_service(); |
| 75 | ClientSafeBrowsingReportRequest report; |
jialiul | 2c263858 | 2016-06-08 22:18:08 | [diff] [blame] | 76 | report.set_type(report_type); |
jialiul | ee910ec1 | 2016-01-11 19:42:46 | [diff] [blame] | 77 | switch (download.GetDangerType()) { |
Min Qin | 0ca8e1ee | 2018-01-31 00:49:35 | [diff] [blame] | 78 | case download::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL: |
| 79 | case download::DOWNLOAD_DANGER_TYPE_DANGEROUS_CONTENT: |
jialiul | ee910ec1 | 2016-01-11 19:42:46 | [diff] [blame] | 80 | report.set_download_verdict(ClientDownloadResponse::DANGEROUS); |
| 81 | break; |
Min Qin | 0ca8e1ee | 2018-01-31 00:49:35 | [diff] [blame] | 82 | case download::DOWNLOAD_DANGER_TYPE_UNCOMMON_CONTENT: |
jialiul | ee910ec1 | 2016-01-11 19:42:46 | [diff] [blame] | 83 | report.set_download_verdict(ClientDownloadResponse::UNCOMMON); |
| 84 | break; |
Min Qin | 0ca8e1ee | 2018-01-31 00:49:35 | [diff] [blame] | 85 | case download::DOWNLOAD_DANGER_TYPE_POTENTIALLY_UNWANTED: |
jialiul | ee910ec1 | 2016-01-11 19:42:46 | [diff] [blame] | 86 | report.set_download_verdict(ClientDownloadResponse::POTENTIALLY_UNWANTED); |
| 87 | break; |
Min Qin | 0ca8e1ee | 2018-01-31 00:49:35 | [diff] [blame] | 88 | case download::DOWNLOAD_DANGER_TYPE_DANGEROUS_HOST: |
jialiul | ee910ec1 | 2016-01-11 19:42:46 | [diff] [blame] | 89 | report.set_download_verdict(ClientDownloadResponse::DANGEROUS_HOST); |
| 90 | break; |
jialiul | 7526f82 | 2016-05-20 22:22:27 | [diff] [blame] | 91 | default: // Don't send report for any other danger types. |
| 92 | return; |
jialiul | ee910ec1 | 2016-01-11 19:42:46 | [diff] [blame] | 93 | } |
| 94 | report.set_url(download.GetURL().spec()); |
jialiul | 7f11b74 | 2015-11-26 04:54:49 | [diff] [blame] | 95 | report.set_did_proceed(did_proceed); |
jialiul | 2c263858 | 2016-06-08 22:18:08 | [diff] [blame] | 96 | std::string token = |
| 97 | safe_browsing::DownloadProtectionService::GetDownloadPingToken( |
| 98 | &download); |
| 99 | if (!token.empty()) |
| 100 | report.set_token(token); |
jialiul | 7f11b74 | 2015-11-26 04:54:49 | [diff] [blame] | 101 | std::string serialized_report; |
| 102 | if (report.SerializeToString(&serialized_report)) |
jialiul | bd9ba65 | 2016-03-18 20:23:46 | [diff] [blame] | 103 | sb_service->SendSerializedDownloadReport(serialized_report); |
jialiul | 7f11b74 | 2015-11-26 04:54:49 | [diff] [blame] | 104 | else |
| 105 | DLOG(ERROR) << "Unable to serialize the threat report."; |
| 106 | } |
jialiul | 70cd6f2c | 2016-02-02 23:24:57 | [diff] [blame] | 107 | |
| 108 | void DownloadDangerPrompt::RecordDownloadDangerPrompt( |
| 109 | bool did_proceed, |
Min Qin | a9f48787 | 2018-02-09 20:43:23 | [diff] [blame] | 110 | const download::DownloadItem& download) { |
nparker | ac9da06 | 2016-05-19 21:47:23 | [diff] [blame] | 111 | int64_t file_type_uma_value = |
| 112 | safe_browsing::FileTypePolicies::GetInstance()->UmaValueForFile( |
| 113 | download.GetTargetFilePath()); |
Min Qin | 0ca8e1ee | 2018-01-31 00:49:35 | [diff] [blame] | 114 | download::DownloadDangerType danger_type = download.GetDangerType(); |
jialiul | 70cd6f2c | 2016-02-02 23:24:57 | [diff] [blame] | 115 | |
Ilya Sherman | 982457e6 | 2017-12-13 02:19:36 | [diff] [blame] | 116 | base::UmaHistogramSparse( |
jialiul | 70cd6f2c | 2016-02-02 23:24:57 | [diff] [blame] | 117 | base::StringPrintf("%s.%s.Shown", kDownloadDangerPromptPrefix, |
| 118 | GetDangerTypeString(danger_type)), |
nparker | ac9da06 | 2016-05-19 21:47:23 | [diff] [blame] | 119 | file_type_uma_value); |
jialiul | 70cd6f2c | 2016-02-02 23:24:57 | [diff] [blame] | 120 | if (did_proceed) { |
Ilya Sherman | 982457e6 | 2017-12-13 02:19:36 | [diff] [blame] | 121 | base::UmaHistogramSparse( |
jialiul | 70cd6f2c | 2016-02-02 23:24:57 | [diff] [blame] | 122 | base::StringPrintf("%s.%s.Proceed", kDownloadDangerPromptPrefix, |
| 123 | GetDangerTypeString(danger_type)), |
nparker | ac9da06 | 2016-05-19 21:47:23 | [diff] [blame] | 124 | file_type_uma_value); |
jialiul | 70cd6f2c | 2016-02-02 23:24:57 | [diff] [blame] | 125 | } |
| 126 | } |