Switch global error menu icon to vectorized MD asset
[chromium-blink-merge.git] / chrome / browser / extensions / extension_uninstall_dialog.h
blob384bd8e9212cdf1b258792a9e61af608c4696fda
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.
5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_UNINSTALL_DIALOG_H_
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_UNINSTALL_DIALOG_H_
8 #include "base/macros.h"
9 #include "base/memory/weak_ptr.h"
10 #include "base/strings/string16.h"
11 #include "base/threading/thread_checker.h"
12 #include "extensions/browser/uninstall_reason.h"
13 #include "ui/gfx/image/image_skia.h"
14 #include "ui/gfx/native_widget_types.h"
16 class Profile;
18 namespace gfx {
19 class Image;
22 namespace extensions {
23 class Extension;
25 class ExtensionUninstallDialog
26 : public base::SupportsWeakPtr<ExtensionUninstallDialog> {
27 public:
28 // The type of action the dialog took at close.
29 // Do not reorder this enum, as it is used in UMA histograms.
30 enum CloseAction {
31 CLOSE_ACTION_UNINSTALL = 0,
32 CLOSE_ACTION_UNINSTALL_AND_REPORT_ABUSE = 1,
33 CLOSE_ACTION_CANCELED = 2,
34 CLOSE_ACTION_LAST = 3,
37 // TODO(devlin): For a single method like this, a callback is probably more
38 // appropriate than a delegate.
39 class Delegate {
40 public:
41 // Called when the dialog closes.
42 // |did_start_uninstall| indicates whether the uninstall process for the
43 // extension started. If this is false, |error| will contain the reason.
44 virtual void OnExtensionUninstallDialogClosed(
45 bool did_start_uninstall,
46 const base::string16& error) = 0;
48 protected:
49 virtual ~Delegate() {}
52 // Creates a platform specific implementation of ExtensionUninstallDialog. The
53 // dialog will be modal to |parent|, or a non-modal dialog if |parent| is
54 // NULL.
55 static ExtensionUninstallDialog* Create(Profile* profile,
56 gfx::NativeWindow parent,
57 Delegate* delegate);
59 virtual ~ExtensionUninstallDialog();
61 // This is called to verify whether the uninstallation should proceed.
62 // Starts the process of showing a confirmation UI, which is split into two.
63 // 1) Set off a 'load icon' task.
64 // 2) Handle the load icon response and show the UI (OnImageLoaded).
65 void ConfirmUninstall(const scoped_refptr<const Extension>& extension,
66 UninstallReason reason,
67 UninstallSource source);
69 // This shows the same dialog as above, except it also shows which extension
70 // triggered the dialog.
71 void ConfirmUninstallByExtension(
72 const scoped_refptr<const Extension>& extension,
73 const scoped_refptr<const Extension>& triggering_extension,
74 UninstallReason reason,
75 UninstallSource source);
77 std::string GetHeadingText();
79 // Returns true if a checkbox for reporting abuse should be shown.
80 bool ShouldShowReportAbuseCheckbox() const;
82 // Called when the dialog is closing to do any book-keeping.
83 void OnDialogClosed(CloseAction action);
85 protected:
86 // Constructor used by the derived classes.
87 ExtensionUninstallDialog(Profile* profile, Delegate* delegate);
89 // Accessors for members.
90 const Profile* profile() const { return profile_; }
91 Delegate* delegate() const { return delegate_; }
92 const Extension* extension() const { return extension_.get(); }
93 const Extension* triggering_extension() const {
94 return triggering_extension_.get(); }
95 const gfx::ImageSkia& icon() const { return icon_; }
97 private:
98 // Handles the "report abuse" checkbox being checked at the close of the
99 // dialog.
100 void HandleReportAbuse();
102 // Sets the icon that will be used in the dialog. If |icon| contains an empty
103 // image, then we use a default icon instead.
104 void SetIcon(const gfx::Image& image);
106 void OnImageLoaded(const std::string& extension_id, const gfx::Image& image);
108 // Displays the prompt. This should only be called after loading the icon.
109 // The implementations of this method are platform-specific.
110 virtual void Show() = 0;
112 Profile* const profile_;
114 // The delegate we will call Accepted/Canceled on after confirmation dialog.
115 Delegate* delegate_;
117 // The extension we are showing the dialog for.
118 scoped_refptr<const Extension> extension_;
120 // The extension triggering the dialog if the dialog was shown by
121 // chrome.management.uninstall.
122 scoped_refptr<const Extension> triggering_extension_;
124 // The extensions icon.
125 gfx::ImageSkia icon_;
127 UninstallReason uninstall_reason_;
129 base::ThreadChecker thread_checker_;
131 DISALLOW_COPY_AND_ASSIGN(ExtensionUninstallDialog);
134 } // namespace extensions
136 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_UNINSTALL_DIALOG_H_