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