[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" |
| 9 | |
jialiul | 7f11b74 | 2015-11-26 04:54:49 | [diff] [blame] | 10 | class GURL; |
| 11 | |
[email protected] | 33ca232f | 2012-04-10 00:08:45 | [diff] [blame] | 12 | namespace content { |
| 13 | class DownloadItem; |
[email protected] | f9f616c | 2012-12-11 02:07:13 | [diff] [blame] | 14 | class WebContents; |
[email protected] | 33ca232f | 2012-04-10 00:08:45 | [diff] [blame] | 15 | } |
| 16 | |
| 17 | // Prompts the user for whether to Keep a dangerous DownloadItem using native |
| 18 | // UI. This prompt is invoked by the DownloadsDOMHandler when the user wants to |
| 19 | // accept a dangerous download. Having a native dialog intervene during the this |
| 20 | // workflow means that the chrome://downloads page no longer has the privilege |
| 21 | // to accept a dangerous download from script without user intervention. This |
| 22 | // step is necessary to prevent a malicious script form abusing such a |
| 23 | // privilege. |
| 24 | class DownloadDangerPrompt { |
| 25 | public: |
| 26 | // Actions resulting from showing the danger prompt. |
| 27 | enum Action { |
| 28 | ACCEPT, |
[email protected] | f1d784d6 | 2013-07-28 18:36:09 | [diff] [blame] | 29 | CANCEL, |
| 30 | DISMISS, |
[email protected] | 33ca232f | 2012-04-10 00:08:45 | [diff] [blame] | 31 | }; |
[email protected] | f1d784d6 | 2013-07-28 18:36:09 | [diff] [blame] | 32 | typedef base::Callback<void(Action)> OnDone; |
[email protected] | 33ca232f | 2012-04-10 00:08:45 | [diff] [blame] | 33 | |
| 34 | // Return a new self-deleting DownloadDangerPrompt. |accepted| or |canceled| |
| 35 | // will be run when the the respective action is invoked. |canceled| may also |
| 36 | // be called when |item| is either no longer dangerous or no longer in |
[email protected] | 371d64a | 2012-12-14 21:11:32 | [diff] [blame] | 37 | // progress, or if the tab corresponding to |web_contents| is |
[email protected] | 33ca232f | 2012-04-10 00:08:45 | [diff] [blame] | 38 | // closing. The returned DownloadDangerPrompt* is only used for testing. The |
| 39 | // caller does not own the object and receive no guarantees about lifetime. |
[email protected] | f82d999 | 2013-01-18 19:19:03 | [diff] [blame] | 40 | // If |show_context|, then the prompt message will contain some information |
| 41 | // about the download and its danger; otherwise it won't. |
jialiul | 7f11b74 | 2015-11-26 04:54:49 | [diff] [blame] | 42 | static DownloadDangerPrompt* Create(content::DownloadItem* item, |
| 43 | content::WebContents* web_contents, |
| 44 | bool show_context, |
| 45 | const OnDone& done); |
[email protected] | 33ca232f | 2012-04-10 00:08:45 | [diff] [blame] | 46 | |
[email protected] | 33ca232f | 2012-04-10 00:08:45 | [diff] [blame] | 47 | // Only to be used by tests. Subclasses must override to manually call the |
| 48 | // respective button click handler. |
| 49 | virtual void InvokeActionForTesting(Action action) = 0; |
jialiul | 7f11b74 | 2015-11-26 04:54:49 | [diff] [blame] | 50 | |
| 51 | protected: |
| 52 | // Sends download recovery report to safe browsing backend. |
jialiul | ee910ec1 | 2016-01-11 19:42:46 | [diff] [blame^] | 53 | // Since it only records download url (DownloadItem::GetURL()), user's |
| 54 | // action (click through or not) and its download danger type, it isn't gated |
| 55 | // by user's extended reporting preference (i.e. |
| 56 | // prefs::kSafeBrowsingExtendedReportingEnabled). We should not put any extra |
| 57 | // information in this report. |
| 58 | static void SendSafeBrowsingDownloadRecoveryReport( |
| 59 | bool did_proceed, |
| 60 | const content::DownloadItem& download); |
[email protected] | 33ca232f | 2012-04-10 00:08:45 | [diff] [blame] | 61 | }; |
| 62 | |
| 63 | #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_DANGER_PROMPT_H_ |