[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" |
jialiul | 2c263858 | 2016-06-08 22:18:08 | [diff] [blame^] | 9 | #include "chrome/common/safe_browsing/csd.pb.h" |
[email protected] | 33ca232f | 2012-04-10 00:08:45 | [diff] [blame] | 10 | |
jialiul | 7f11b74 | 2015-11-26 04:54:49 | [diff] [blame] | 11 | class GURL; |
| 12 | |
[email protected] | 33ca232f | 2012-04-10 00:08:45 | [diff] [blame] | 13 | namespace content { |
| 14 | class DownloadItem; |
[email protected] | f9f616c | 2012-12-11 02:07:13 | [diff] [blame] | 15 | class WebContents; |
[email protected] | 33ca232f | 2012-04-10 00:08:45 | [diff] [blame] | 16 | } |
| 17 | |
| 18 | // Prompts the user for whether to Keep a dangerous DownloadItem using native |
| 19 | // UI. This prompt is invoked by the DownloadsDOMHandler when the user wants to |
| 20 | // accept a dangerous download. Having a native dialog intervene during the this |
| 21 | // workflow means that the chrome://downloads page no longer has the privilege |
| 22 | // to accept a dangerous download from script without user intervention. This |
| 23 | // step is necessary to prevent a malicious script form abusing such a |
| 24 | // privilege. |
| 25 | class DownloadDangerPrompt { |
| 26 | public: |
| 27 | // Actions resulting from showing the danger prompt. |
| 28 | enum Action { |
estade | bc8d9a6 | 2016-02-09 00:52:20 | [diff] [blame] | 29 | // The user chose to proceed down the dangerous path. |
[email protected] | 33ca232f | 2012-04-10 00:08:45 | [diff] [blame] | 30 | ACCEPT, |
estade | bc8d9a6 | 2016-02-09 00:52:20 | [diff] [blame] | 31 | // The user chose not to proceed down the dangerous path. |
[email protected] | f1d784d6 | 2013-07-28 18:36:09 | [diff] [blame] | 32 | CANCEL, |
estade | bc8d9a6 | 2016-02-09 00:52:20 | [diff] [blame] | 33 | // The user dismissed the dialog without making an explicit choice. |
[email protected] | f1d784d6 | 2013-07-28 18:36:09 | [diff] [blame] | 34 | DISMISS, |
[email protected] | 33ca232f | 2012-04-10 00:08:45 | [diff] [blame] | 35 | }; |
[email protected] | f1d784d6 | 2013-07-28 18:36:09 | [diff] [blame] | 36 | typedef base::Callback<void(Action)> OnDone; |
[email protected] | 33ca232f | 2012-04-10 00:08:45 | [diff] [blame] | 37 | |
| 38 | // Return a new self-deleting DownloadDangerPrompt. |accepted| or |canceled| |
| 39 | // will be run when the the respective action is invoked. |canceled| may also |
| 40 | // be called when |item| is either no longer dangerous or no longer in |
[email protected] | 371d64a | 2012-12-14 21:11:32 | [diff] [blame] | 41 | // progress, or if the tab corresponding to |web_contents| is |
[email protected] | 33ca232f | 2012-04-10 00:08:45 | [diff] [blame] | 42 | // closing. The returned DownloadDangerPrompt* is only used for testing. The |
| 43 | // caller does not own the object and receive no guarantees about lifetime. |
[email protected] | f82d999 | 2013-01-18 19:19:03 | [diff] [blame] | 44 | // If |show_context|, then the prompt message will contain some information |
| 45 | // about the download and its danger; otherwise it won't. |
jialiul | 7f11b74 | 2015-11-26 04:54:49 | [diff] [blame] | 46 | static DownloadDangerPrompt* Create(content::DownloadItem* item, |
| 47 | content::WebContents* web_contents, |
| 48 | bool show_context, |
| 49 | const OnDone& done); |
[email protected] | 33ca232f | 2012-04-10 00:08:45 | [diff] [blame] | 50 | |
[email protected] | 33ca232f | 2012-04-10 00:08:45 | [diff] [blame] | 51 | // Only to be used by tests. Subclasses must override to manually call the |
| 52 | // respective button click handler. |
| 53 | virtual void InvokeActionForTesting(Action action) = 0; |
jialiul | 7f11b74 | 2015-11-26 04:54:49 | [diff] [blame] | 54 | |
| 55 | protected: |
| 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, |
| 65 | const content::DownloadItem& download); |
jialiul | 70cd6f2c | 2016-02-02 23:24:57 | [diff] [blame] | 66 | |
| 67 | // Records UMA stats for a download danger prompt event. |
| 68 | static void RecordDownloadDangerPrompt(bool did_proceed, |
| 69 | const content::DownloadItem& download); |
[email protected] | 33ca232f | 2012-04-10 00:08:45 | [diff] [blame] | 70 | }; |
| 71 | |
| 72 | #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_DANGER_PROMPT_H_ |