[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 | #ifndef CHROME_BROWSER_DOWNLOAD_DOWNLOAD_DANGER_PROMPT_H_ |
| 6 | #define CHROME_BROWSER_DOWNLOAD_DOWNLOAD_DANGER_PROMPT_H_ |
[email protected] | 33ca232f | 2012-04-10 00:08:45 | [diff] [blame] | 7 | |
| 8 | #include "base/callback_forward.h" |
Ali Juma | fb3dc1f | 2020-01-07 17:33:47 | [diff] [blame] | 9 | #include "components/safe_browsing/core/proto/csd.pb.h" |
[email protected] | 33ca232f | 2012-04-10 00:08:45 | [diff] [blame] | 10 | |
[email protected] | 33ca232f | 2012-04-10 00:08:45 | [diff] [blame] | 11 | namespace content { |
[email protected] | f9f616c | 2012-12-11 02:07:13 | [diff] [blame] | 12 | class WebContents; |
[email protected] | 33ca232f | 2012-04-10 00:08:45 | [diff] [blame] | 13 | } |
| 14 | |
Min Qin | a9f48787 | 2018-02-09 20:43:23 | [diff] [blame] | 15 | namespace download { |
| 16 | class DownloadItem; |
| 17 | } |
| 18 | |
[email protected] | 33ca232f | 2012-04-10 00:08:45 | [diff] [blame] | 19 | // Prompts the user for whether to Keep a dangerous DownloadItem using native |
| 20 | // UI. This prompt is invoked by the DownloadsDOMHandler when the user wants to |
| 21 | // accept a dangerous download. Having a native dialog intervene during the this |
| 22 | // workflow means that the chrome://downloads page no longer has the privilege |
| 23 | // to accept a dangerous download from script without user intervention. This |
| 24 | // step is necessary to prevent a malicious script form abusing such a |
| 25 | // privilege. |
| 26 | class DownloadDangerPrompt { |
| 27 | public: |
| 28 | // Actions resulting from showing the danger prompt. |
| 29 | enum Action { |
estade | bc8d9a6 | 2016-02-09 00:52:20 | [diff] [blame] | 30 | // The user chose to proceed down the dangerous path. |
[email protected] | 33ca232f | 2012-04-10 00:08:45 | [diff] [blame] | 31 | ACCEPT, |
estade | bc8d9a6 | 2016-02-09 00:52:20 | [diff] [blame] | 32 | // The user chose not to proceed down the dangerous path. |
[email protected] | f1d784d6 | 2013-07-28 18:36:09 | [diff] [blame] | 33 | CANCEL, |
estade | bc8d9a6 | 2016-02-09 00:52:20 | [diff] [blame] | 34 | // The user dismissed the dialog without making an explicit choice. |
[email protected] | f1d784d6 | 2013-07-28 18:36:09 | [diff] [blame] | 35 | DISMISS, |
[email protected] | 33ca232f | 2012-04-10 00:08:45 | [diff] [blame] | 36 | }; |
[email protected] | f1d784d6 | 2013-07-28 18:36:09 | [diff] [blame] | 37 | typedef base::Callback<void(Action)> OnDone; |
[email protected] | 33ca232f | 2012-04-10 00:08:45 | [diff] [blame] | 38 | |
karandeepb | 5fba2166 | 2017-01-25 11:07:44 | [diff] [blame] | 39 | // Return a new self-deleting DownloadDangerPrompt. The returned |
| 40 | // DownloadDangerPrompt* is only used for testing. The caller does not own the |
| 41 | // object and receives no guarantees about lifetime. If |show_context|, then |
| 42 | // the prompt message will contain some information about the download and its |
| 43 | // danger; otherwise it won't. |done| is a callback called when the ACCEPT, |
| 44 | // CANCEL or DISMISS action is invoked. |done| may be called with the CANCEL |
| 45 | // action even when |item| is either no longer dangerous or no longer in |
| 46 | // progress, or if the tab corresponding to |web_contents| is closing. |
Min Qin | a9f48787 | 2018-02-09 20:43:23 | [diff] [blame] | 47 | static DownloadDangerPrompt* Create(download::DownloadItem* item, |
jialiul | 7f11b74 | 2015-11-26 04:54:49 | [diff] [blame] | 48 | content::WebContents* web_contents, |
| 49 | bool show_context, |
| 50 | const OnDone& done); |
[email protected] | 33ca232f | 2012-04-10 00:08:45 | [diff] [blame] | 51 | |
[email protected] | 33ca232f | 2012-04-10 00:08:45 | [diff] [blame] | 52 | // Only to be used by tests. Subclasses must override to manually call the |
| 53 | // respective button click handler. |
| 54 | virtual void InvokeActionForTesting(Action action) = 0; |
jialiul | 7f11b74 | 2015-11-26 04:54:49 | [diff] [blame] | 55 | |
jialiul | 7f11b74 | 2015-11-26 04:54:49 | [diff] [blame] | 56 | // Sends download recovery report to safe browsing backend. |
jialiul | ee910ec1 | 2016-01-11 19:42:46 | [diff] [blame] | 57 | // Since it only records download url (DownloadItem::GetURL()), user's |
| 58 | // action (click through or not) and its download danger type, it isn't gated |
| 59 | // by user's extended reporting preference (i.e. |
| 60 | // prefs::kSafeBrowsingExtendedReportingEnabled). We should not put any extra |
| 61 | // information in this report. |
jialiul | 2c263858 | 2016-06-08 22:18:08 | [diff] [blame] | 62 | static void SendSafeBrowsingDownloadReport( |
| 63 | safe_browsing::ClientSafeBrowsingReportRequest::ReportType report_type, |
jialiul | ee910ec1 | 2016-01-11 19:42:46 | [diff] [blame] | 64 | bool did_proceed, |
Min Qin | a9f48787 | 2018-02-09 20:43:23 | [diff] [blame] | 65 | const download::DownloadItem& download); |
jialiul | 70cd6f2c | 2016-02-02 23:24:57 | [diff] [blame] | 66 | |
jialiul | f857966 | 2016-09-13 19:43:12 | [diff] [blame] | 67 | protected: |
jialiul | 70cd6f2c | 2016-02-02 23:24:57 | [diff] [blame] | 68 | // Records UMA stats for a download danger prompt event. |
Min Qin | a9f48787 | 2018-02-09 20:43:23 | [diff] [blame] | 69 | static void RecordDownloadDangerPrompt( |
| 70 | bool did_proceed, |
| 71 | const download::DownloadItem& download); |
karandeepb | 5fba2166 | 2017-01-25 11:07:44 | [diff] [blame] | 72 | |
[email protected] | 33ca232f | 2012-04-10 00:08:45 | [diff] [blame] | 73 | }; |
| 74 | |
| 75 | #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_DANGER_PROMPT_H_ |