blob: 4301ea6958a7e51b7b6bcb58cc292d130a817b45 [file] [log] [blame]
[email protected]33ca232f2012-04-10 00:08:451// 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]33ca232f2012-04-10 00:08:457
8#include "base/callback_forward.h"
9
jialiul7f11b742015-11-26 04:54:4910class GURL;
11
[email protected]33ca232f2012-04-10 00:08:4512namespace content {
13class DownloadItem;
[email protected]f9f616c2012-12-11 02:07:1314class WebContents;
[email protected]33ca232f2012-04-10 00:08:4515}
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.
24class DownloadDangerPrompt {
25 public:
26 // Actions resulting from showing the danger prompt.
27 enum Action {
estadebc8d9a62016-02-09 00:52:2028 // The user chose to proceed down the dangerous path.
[email protected]33ca232f2012-04-10 00:08:4529 ACCEPT,
estadebc8d9a62016-02-09 00:52:2030 // The user chose not to proceed down the dangerous path.
[email protected]f1d784d62013-07-28 18:36:0931 CANCEL,
estadebc8d9a62016-02-09 00:52:2032 // The user dismissed the dialog without making an explicit choice.
[email protected]f1d784d62013-07-28 18:36:0933 DISMISS,
[email protected]33ca232f2012-04-10 00:08:4534 };
[email protected]f1d784d62013-07-28 18:36:0935 typedef base::Callback<void(Action)> OnDone;
[email protected]33ca232f2012-04-10 00:08:4536
37 // Return a new self-deleting DownloadDangerPrompt. |accepted| or |canceled|
38 // will be run when the the respective action is invoked. |canceled| may also
39 // be called when |item| is either no longer dangerous or no longer in
[email protected]371d64a2012-12-14 21:11:3240 // progress, or if the tab corresponding to |web_contents| is
[email protected]33ca232f2012-04-10 00:08:4541 // closing. The returned DownloadDangerPrompt* is only used for testing. The
42 // caller does not own the object and receive no guarantees about lifetime.
[email protected]f82d9992013-01-18 19:19:0343 // If |show_context|, then the prompt message will contain some information
44 // about the download and its danger; otherwise it won't.
jialiul7f11b742015-11-26 04:54:4945 static DownloadDangerPrompt* Create(content::DownloadItem* item,
46 content::WebContents* web_contents,
47 bool show_context,
48 const OnDone& done);
[email protected]33ca232f2012-04-10 00:08:4549
[email protected]33ca232f2012-04-10 00:08:4550 // Only to be used by tests. Subclasses must override to manually call the
51 // respective button click handler.
52 virtual void InvokeActionForTesting(Action action) = 0;
jialiul7f11b742015-11-26 04:54:4953
54 protected:
55 // Sends download recovery report to safe browsing backend.
jialiulee910ec12016-01-11 19:42:4656 // Since it only records download url (DownloadItem::GetURL()), user's
57 // action (click through or not) and its download danger type, it isn't gated
58 // by user's extended reporting preference (i.e.
59 // prefs::kSafeBrowsingExtendedReportingEnabled). We should not put any extra
60 // information in this report.
61 static void SendSafeBrowsingDownloadRecoveryReport(
62 bool did_proceed,
63 const content::DownloadItem& download);
jialiul70cd6f2c2016-02-02 23:24:5764
65 // Records UMA stats for a download danger prompt event.
66 static void RecordDownloadDangerPrompt(bool did_proceed,
67 const content::DownloadItem& download);
[email protected]33ca232f2012-04-10 00:08:4568};
69
70#endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_DANGER_PROMPT_H_