blob: 5c3bb4107c89d43b89c74f1d2eac7884048eedc1 [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"
jialiul2c2638582016-06-08 22:18:089#include "chrome/common/safe_browsing/csd.pb.h"
[email protected]33ca232f2012-04-10 00:08:4510
[email protected]33ca232f2012-04-10 00:08:4511namespace content {
12class DownloadItem;
[email protected]f9f616c2012-12-11 02:07:1313class WebContents;
[email protected]33ca232f2012-04-10 00:08:4514}
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.
23class DownloadDangerPrompt {
24 public:
25 // Actions resulting from showing the danger prompt.
26 enum Action {
estadebc8d9a62016-02-09 00:52:2027 // The user chose to proceed down the dangerous path.
[email protected]33ca232f2012-04-10 00:08:4528 ACCEPT,
estadebc8d9a62016-02-09 00:52:2029 // The user chose not to proceed down the dangerous path.
[email protected]f1d784d62013-07-28 18:36:0930 CANCEL,
estadebc8d9a62016-02-09 00:52:2031 // The user dismissed the dialog without making an explicit choice.
[email protected]f1d784d62013-07-28 18:36:0932 DISMISS,
[email protected]33ca232f2012-04-10 00:08:4533 };
[email protected]f1d784d62013-07-28 18:36:0934 typedef base::Callback<void(Action)> OnDone;
[email protected]33ca232f2012-04-10 00:08:4535
karandeepb5fba21662017-01-25 11:07:4436 // 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.
jialiul7f11b742015-11-26 04:54:4944 static DownloadDangerPrompt* Create(content::DownloadItem* item,
45 content::WebContents* web_contents,
46 bool show_context,
47 const OnDone& done);
[email protected]33ca232f2012-04-10 00:08:4548
[email protected]33ca232f2012-04-10 00:08:4549 // 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;
jialiul7f11b742015-11-26 04:54:4952
jialiul7f11b742015-11-26 04:54:4953 // Sends download recovery report to safe browsing backend.
jialiulee910ec12016-01-11 19:42:4654 // 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.
jialiul2c2638582016-06-08 22:18:0859 static void SendSafeBrowsingDownloadReport(
60 safe_browsing::ClientSafeBrowsingReportRequest::ReportType report_type,
jialiulee910ec12016-01-11 19:42:4661 bool did_proceed,
62 const content::DownloadItem& download);
jialiul70cd6f2c2016-02-02 23:24:5763
jialiulf8579662016-09-13 19:43:1264 protected:
jialiul70cd6f2c2016-02-02 23:24:5765 // Records UMA stats for a download danger prompt event.
66 static void RecordDownloadDangerPrompt(bool did_proceed,
67 const content::DownloadItem& download);
karandeepb5fba21662017-01-25 11:07:4468
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]33ca232f2012-04-10 00:08:4576};
77
78#endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_DANGER_PROMPT_H_