blob: d457d9773913956a3b525fc34828d4f87ed2f35e [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"
Ali Jumafb3dc1f2020-01-07 17:33:479#include "components/safe_browsing/core/proto/csd.pb.h"
[email protected]33ca232f2012-04-10 00:08:4510
[email protected]33ca232f2012-04-10 00:08:4511namespace content {
[email protected]f9f616c2012-12-11 02:07:1312class WebContents;
[email protected]33ca232f2012-04-10 00:08:4513}
14
Min Qina9f487872018-02-09 20:43:2315namespace download {
16class DownloadItem;
17}
18
[email protected]33ca232f2012-04-10 00:08:4519// 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.
26class DownloadDangerPrompt {
27 public:
28 // Actions resulting from showing the danger prompt.
29 enum Action {
estadebc8d9a62016-02-09 00:52:2030 // The user chose to proceed down the dangerous path.
[email protected]33ca232f2012-04-10 00:08:4531 ACCEPT,
estadebc8d9a62016-02-09 00:52:2032 // The user chose not to proceed down the dangerous path.
[email protected]f1d784d62013-07-28 18:36:0933 CANCEL,
estadebc8d9a62016-02-09 00:52:2034 // The user dismissed the dialog without making an explicit choice.
[email protected]f1d784d62013-07-28 18:36:0935 DISMISS,
[email protected]33ca232f2012-04-10 00:08:4536 };
[email protected]f1d784d62013-07-28 18:36:0937 typedef base::Callback<void(Action)> OnDone;
[email protected]33ca232f2012-04-10 00:08:4538
karandeepb5fba21662017-01-25 11:07:4439 // 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 Qina9f487872018-02-09 20:43:2347 static DownloadDangerPrompt* Create(download::DownloadItem* item,
jialiul7f11b742015-11-26 04:54:4948 content::WebContents* web_contents,
49 bool show_context,
50 const OnDone& done);
[email protected]33ca232f2012-04-10 00:08:4551
[email protected]33ca232f2012-04-10 00:08:4552 // 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;
jialiul7f11b742015-11-26 04:54:4955
jialiul7f11b742015-11-26 04:54:4956 // Sends download recovery report to safe browsing backend.
jialiulee910ec12016-01-11 19:42:4657 // 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.
jialiul2c2638582016-06-08 22:18:0862 static void SendSafeBrowsingDownloadReport(
63 safe_browsing::ClientSafeBrowsingReportRequest::ReportType report_type,
jialiulee910ec12016-01-11 19:42:4664 bool did_proceed,
Min Qina9f487872018-02-09 20:43:2365 const download::DownloadItem& download);
jialiul70cd6f2c2016-02-02 23:24:5766
jialiulf8579662016-09-13 19:43:1267 protected:
jialiul70cd6f2c2016-02-02 23:24:5768 // Records UMA stats for a download danger prompt event.
Min Qina9f487872018-02-09 20:43:2369 static void RecordDownloadDangerPrompt(
70 bool did_proceed,
71 const download::DownloadItem& download);
karandeepb5fba21662017-01-25 11:07:4472
[email protected]33ca232f2012-04-10 00:08:4573};
74
75#endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_DANGER_PROMPT_H_