[email protected] | 6280b588 | 2012-06-05 21:56:41 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 502e3961 | 2011-03-26 01:36:28 | [diff] [blame] | 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_EXTENSIONS_EXTENSION_UNINSTALL_DIALOG_H_ |
| 6 | #define CHROME_BROWSER_EXTENSIONS_EXTENSION_UNINSTALL_DIALOG_H_ |
[email protected] | 502e3961 | 2011-03-26 01:36:28 | [diff] [blame] | 7 | |
rdevlin.cronin | ac8ce8c | 2015-05-27 23:00:02 | [diff] [blame] | 8 | #include "base/macros.h" |
[email protected] | 6280b588 | 2012-06-05 21:56:41 | [diff] [blame] | 9 | #include "base/memory/weak_ptr.h" |
khmel | 0df82202 | 2017-06-23 02:02:56 | [diff] [blame] | 10 | #include "base/scoped_observer.h" |
rdevlin.cronin | ac8ce8c | 2015-05-27 23:00:02 | [diff] [blame] | 11 | #include "base/strings/string16.h" |
| 12 | #include "base/threading/thread_checker.h" |
khmel | 0df82202 | 2017-06-23 02:02:56 | [diff] [blame] | 13 | #include "chrome/browser/extensions/chrome_app_icon.h" |
| 14 | #include "chrome/browser/extensions/chrome_app_icon_delegate.h" |
| 15 | #include "extensions/browser/extension_registry_observer.h" |
rdevlin.cronin | ac8ce8c | 2015-05-27 23:00:02 | [diff] [blame] | 16 | #include "extensions/browser/uninstall_reason.h" |
[email protected] | 6280b588 | 2012-06-05 21:56:41 | [diff] [blame] | 17 | #include "ui/gfx/image/image_skia.h" |
[email protected] | 2a4939a | 2014-07-25 09:22:52 | [diff] [blame] | 18 | #include "ui/gfx/native_widget_types.h" |
[email protected] | 502e3961 | 2011-03-26 01:36:28 | [diff] [blame] | 19 | |
khmel | 0df82202 | 2017-06-23 02:02:56 | [diff] [blame] | 20 | class NativeWindowTracker; |
[email protected] | 520414b1 | 2013-01-22 19:27:36 | [diff] [blame] | 21 | class Profile; |
[email protected] | 502e3961 | 2011-03-26 01:36:28 | [diff] [blame] | 22 | |
[email protected] | d405067 | 2014-06-04 09:18:40 | [diff] [blame] | 23 | namespace extensions { |
| 24 | class Extension; |
| 25 | |
[email protected] | 5211222 | 2012-04-07 00:52:37 | [diff] [blame] | 26 | class ExtensionUninstallDialog |
khmel | 0df82202 | 2017-06-23 02:02:56 | [diff] [blame] | 27 | : public base::SupportsWeakPtr<ExtensionUninstallDialog>, |
| 28 | public ChromeAppIconDelegate, |
| 29 | public ExtensionRegistryObserver { |
[email protected] | 502e3961 | 2011-03-26 01:36:28 | [diff] [blame] | 30 | public: |
Bettina Dea | 7264a04b6 | 2018-04-06 04:27:45 | [diff] [blame] | 31 | // Implement this callback to handle checking for the dialog's header message. |
| 32 | using OnWillShowCallback = |
| 33 | base::RepeatingCallback<void(ExtensionUninstallDialog*)>; |
| 34 | |
rdevlin.cronin | 4f01c5f1 | 2015-05-07 17:52:00 | [diff] [blame] | 35 | // The type of action the dialog took at close. |
| 36 | // Do not reorder this enum, as it is used in UMA histograms. |
| 37 | enum CloseAction { |
| 38 | CLOSE_ACTION_UNINSTALL = 0, |
| 39 | CLOSE_ACTION_UNINSTALL_AND_REPORT_ABUSE = 1, |
| 40 | CLOSE_ACTION_CANCELED = 2, |
| 41 | CLOSE_ACTION_LAST = 3, |
| 42 | }; |
| 43 | |
rdevlin.cronin | ac8ce8c | 2015-05-27 23:00:02 | [diff] [blame] | 44 | // TODO(devlin): For a single method like this, a callback is probably more |
| 45 | // appropriate than a delegate. |
[email protected] | 502e3961 | 2011-03-26 01:36:28 | [diff] [blame] | 46 | class Delegate { |
| 47 | public: |
rdevlin.cronin | ac8ce8c | 2015-05-27 23:00:02 | [diff] [blame] | 48 | // Called when the dialog closes. |
| 49 | // |did_start_uninstall| indicates whether the uninstall process for the |
| 50 | // extension started. If this is false, |error| will contain the reason. |
Alan Cutter | a0ec9e44 | 2018-08-27 01:18:06 | [diff] [blame] | 51 | virtual void OnExtensionUninstallDialogClosed(bool did_start_uninstall, |
| 52 | const base::string16& error) { |
| 53 | } |
[email protected] | 502e3961 | 2011-03-26 01:36:28 | [diff] [blame] | 54 | |
| 55 | protected: |
| 56 | virtual ~Delegate() {} |
| 57 | }; |
| 58 | |
[email protected] | 2a4939a | 2014-07-25 09:22:52 | [diff] [blame] | 59 | // Creates a platform specific implementation of ExtensionUninstallDialog. The |
| 60 | // dialog will be modal to |parent|, or a non-modal dialog if |parent| is |
| 61 | // NULL. |
[email protected] | 520414b1 | 2013-01-22 19:27:36 | [diff] [blame] | 62 | static ExtensionUninstallDialog* Create(Profile* profile, |
[email protected] | 2a4939a | 2014-07-25 09:22:52 | [diff] [blame] | 63 | gfx::NativeWindow parent, |
[email protected] | 520414b1 | 2013-01-22 19:27:36 | [diff] [blame] | 64 | Delegate* delegate); |
[email protected] | 6f03db06 | 2011-09-22 20:37:14 | [diff] [blame] | 65 | |
Elly Fong-Jones | cfb85565 | 2017-07-25 16:41:37 | [diff] [blame] | 66 | // Create the Views implementation of ExtensionUninstallDialog, for use on |
| 67 | // platforms where that is not the native platform implementation. |
| 68 | static ExtensionUninstallDialog* CreateViews(Profile* profile, |
| 69 | gfx::NativeWindow parent, |
| 70 | Delegate* delegate); |
| 71 | |
khmel | 0df82202 | 2017-06-23 02:02:56 | [diff] [blame] | 72 | ~ExtensionUninstallDialog() override; |
[email protected] | 502e3961 | 2011-03-26 01:36:28 | [diff] [blame] | 73 | |
[email protected] | 6f03db06 | 2011-09-22 20:37:14 | [diff] [blame] | 74 | // This is called to verify whether the uninstallation should proceed. |
[email protected] | 502e3961 | 2011-03-26 01:36:28 | [diff] [blame] | 75 | // Starts the process of showing a confirmation UI, which is split into two. |
| 76 | // 1) Set off a 'load icon' task. |
| 77 | // 2) Handle the load icon response and show the UI (OnImageLoaded). |
rdevlin.cronin | ac8ce8c | 2015-05-27 23:00:02 | [diff] [blame] | 78 | void ConfirmUninstall(const scoped_refptr<const Extension>& extension, |
rdevlin.cronin | e18eb8cd | 2015-07-16 16:31:28 | [diff] [blame] | 79 | UninstallReason reason, |
| 80 | UninstallSource source); |
[email protected] | 6f03db06 | 2011-09-22 20:37:14 | [diff] [blame] | 81 | |
[email protected] | 226d79ad | 2014-03-14 21:34:57 | [diff] [blame] | 82 | // This shows the same dialog as above, except it also shows which extension |
rdevlin.cronin | ac8ce8c | 2015-05-27 23:00:02 | [diff] [blame] | 83 | // triggered the dialog. |
| 84 | void ConfirmUninstallByExtension( |
| 85 | const scoped_refptr<const Extension>& extension, |
| 86 | const scoped_refptr<const Extension>& triggering_extension, |
rdevlin.cronin | e18eb8cd | 2015-07-16 16:31:28 | [diff] [blame] | 87 | UninstallReason reason, |
| 88 | UninstallSource source); |
[email protected] | 226d79ad | 2014-03-14 21:34:57 | [diff] [blame] | 89 | |
| 90 | std::string GetHeadingText(); |
| 91 | |
rdevlin.cronin | f3af70d5 | 2015-03-20 03:55:04 | [diff] [blame] | 92 | // Returns true if a checkbox for reporting abuse should be shown. |
| 93 | bool ShouldShowReportAbuseCheckbox() const; |
| 94 | |
rdevlin.cronin | 4f01c5f1 | 2015-05-07 17:52:00 | [diff] [blame] | 95 | // Called when the dialog is closing to do any book-keeping. |
| 96 | void OnDialogClosed(CloseAction action); |
| 97 | |
Bettina Dea | 7264a04b6 | 2018-04-06 04:27:45 | [diff] [blame] | 98 | // Called from unit test to check callbacks in dialog. |
| 99 | static void SetOnShownCallbackForTesting(OnWillShowCallback* callback); |
| 100 | |
[email protected] | 6f03db06 | 2011-09-22 20:37:14 | [diff] [blame] | 101 | protected: |
| 102 | // Constructor used by the derived classes. |
khmel | 0df82202 | 2017-06-23 02:02:56 | [diff] [blame] | 103 | ExtensionUninstallDialog(Profile* profile, |
| 104 | gfx::NativeWindow parent, |
| 105 | Delegate* delegate); |
[email protected] | 520414b1 | 2013-01-22 19:27:36 | [diff] [blame] | 106 | |
rdevlin.cronin | ac8ce8c | 2015-05-27 23:00:02 | [diff] [blame] | 107 | // Accessors for members. |
kcarattini | c4fee66 | 2015-05-26 06:02:55 | [diff] [blame] | 108 | const Profile* profile() const { return profile_; } |
| 109 | Delegate* delegate() const { return delegate_; } |
| 110 | const Extension* extension() const { return extension_.get(); } |
| 111 | const Extension* triggering_extension() const { |
| 112 | return triggering_extension_.get(); } |
khmel | 0df82202 | 2017-06-23 02:02:56 | [diff] [blame] | 113 | const gfx::ImageSkia& icon() const { return icon_->image_skia(); } |
| 114 | gfx::NativeWindow parent() { return parent_; } |
kcarattini | c4fee66 | 2015-05-26 06:02:55 | [diff] [blame] | 115 | |
| 116 | private: |
catmullings | ff559d9 | 2017-05-20 01:43:36 | [diff] [blame] | 117 | // Uninstalls the extension. Returns true on success, and populates |error| on |
| 118 | // failure. |
| 119 | bool Uninstall(base::string16* error); |
| 120 | |
rdevlin.cronin | ac8ce8c | 2015-05-27 23:00:02 | [diff] [blame] | 121 | // Handles the "report abuse" checkbox being checked at the close of the |
| 122 | // dialog. |
| 123 | void HandleReportAbuse(); |
| 124 | |
khmel | 0df82202 | 2017-06-23 02:02:56 | [diff] [blame] | 125 | // ChromeAppIconDelegate: |
| 126 | void OnIconUpdated(ChromeAppIcon* icon) override; |
kcarattini | c4fee66 | 2015-05-26 06:02:55 | [diff] [blame] | 127 | |
khmel | 0df82202 | 2017-06-23 02:02:56 | [diff] [blame] | 128 | // ExtensionRegistryObserver: |
| 129 | void OnExtensionUninstalled(content::BrowserContext* browser_context, |
| 130 | const Extension* extension, |
| 131 | UninstallReason reason) override; |
kcarattini | c4fee66 | 2015-05-26 06:02:55 | [diff] [blame] | 132 | |
| 133 | // Displays the prompt. This should only be called after loading the icon. |
| 134 | // The implementations of this method are platform-specific. |
| 135 | virtual void Show() = 0; |
| 136 | |
[email protected] | 520414b1 | 2013-01-22 19:27:36 | [diff] [blame] | 137 | Profile* const profile_; |
[email protected] | 6f03db06 | 2011-09-22 20:37:14 | [diff] [blame] | 138 | |
khmel | 0df82202 | 2017-06-23 02:02:56 | [diff] [blame] | 139 | // The dialog's parent window. |
| 140 | gfx::NativeWindow parent_; |
| 141 | |
[email protected] | 6f03db06 | 2011-09-22 20:37:14 | [diff] [blame] | 142 | // The delegate we will call Accepted/Canceled on after confirmation dialog. |
| 143 | Delegate* delegate_; |
| 144 | |
| 145 | // The extension we are showing the dialog for. |
rdevlin.cronin | 90367644 | 2015-05-15 18:34:10 | [diff] [blame] | 146 | scoped_refptr<const Extension> extension_; |
[email protected] | 6f03db06 | 2011-09-22 20:37:14 | [diff] [blame] | 147 | |
[email protected] | 226d79ad | 2014-03-14 21:34:57 | [diff] [blame] | 148 | // The extension triggering the dialog if the dialog was shown by |
| 149 | // chrome.management.uninstall. |
rdevlin.cronin | 90367644 | 2015-05-15 18:34:10 | [diff] [blame] | 150 | scoped_refptr<const Extension> triggering_extension_; |
[email protected] | 226d79ad | 2014-03-14 21:34:57 | [diff] [blame] | 151 | |
khmel | 0df82202 | 2017-06-23 02:02:56 | [diff] [blame] | 152 | std::unique_ptr<ChromeAppIcon> icon_; |
[email protected] | 502e3961 | 2011-03-26 01:36:28 | [diff] [blame] | 153 | |
khmel | 0df82202 | 2017-06-23 02:02:56 | [diff] [blame] | 154 | // Tracks whether |parent_| got destroyed. |
| 155 | std::unique_ptr<NativeWindowTracker> parent_window_tracker_; |
| 156 | |
| 157 | // Indicates that dialog was shown. |
| 158 | bool dialog_shown_ = false; |
| 159 | |
| 160 | UninstallReason uninstall_reason_ = UNINSTALL_REASON_FOR_TESTING; |
| 161 | |
| 162 | ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> observer_; |
rdevlin.cronin | ac8ce8c | 2015-05-27 23:00:02 | [diff] [blame] | 163 | |
| 164 | base::ThreadChecker thread_checker_; |
[email protected] | 502e3961 | 2011-03-26 01:36:28 | [diff] [blame] | 165 | |
[email protected] | 502e3961 | 2011-03-26 01:36:28 | [diff] [blame] | 166 | DISALLOW_COPY_AND_ASSIGN(ExtensionUninstallDialog); |
| 167 | }; |
| 168 | |
[email protected] | d405067 | 2014-06-04 09:18:40 | [diff] [blame] | 169 | } // namespace extensions |
| 170 | |
[email protected] | 502e3961 | 2011-03-26 01:36:28 | [diff] [blame] | 171 | #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_UNINSTALL_DIALOG_H_ |