summaryrefslogtreecommitdiffstats
path: root/chrome/browser/download/download_danger_prompt.h
blob: e1b5c612c08994378a2e598440e948009d6aef82 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_DOWNLOAD_DOWNLOAD_DANGER_PROMPT_H_
#define CHROME_BROWSER_DOWNLOAD_DOWNLOAD_DANGER_PROMPT_H_

#include "base/callback_forward.h"

namespace content {
class DownloadItem;
class WebContents;
}

// Prompts the user for whether to Keep a dangerous DownloadItem using native
// UI. This prompt is invoked by the DownloadsDOMHandler when the user wants to
// accept a dangerous download. Having a native dialog intervene during the this
// workflow means that the chrome://downloads page no longer has the privilege
// to accept a dangerous download from script without user intervention. This
// step is necessary to prevent a malicious script form abusing such a
// privilege.
class DownloadDangerPrompt {
 public:
  // Actions resulting from showing the danger prompt.
  enum Action {
    ACCEPT,
    CANCEL,
    DISMISS,
  };
  typedef base::Callback<void(Action)> OnDone;

  // Return a new self-deleting DownloadDangerPrompt. |accepted| or |canceled|
  // will be run when the the respective action is invoked. |canceled| may also
  // be called when |item| is either no longer dangerous or no longer in
  // progress, or if the tab corresponding to |web_contents| is
  // closing. The returned DownloadDangerPrompt* is only used for testing. The
  // caller does not own the object and receive no guarantees about lifetime.
  // If |show_context|, then the prompt message will contain some information
  // about the download and its danger; otherwise it won't.
  static DownloadDangerPrompt* Create(
      content::DownloadItem* item,
      content::WebContents* web_contents,
      bool show_context,
      const OnDone& done);

  // Only to be used by tests. Subclasses must override to manually call the
  // respective button click handler.
  virtual void InvokeActionForTesting(Action action) = 0;
};

#endif  // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_DANGER_PROMPT_H_