OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_UNINSTALL_DIALOG_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_UNINSTALL_DIALOG_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_UNINSTALL_DIALOG_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_UNINSTALL_DIALOG_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
12 #include "content/public/browser/notification_observer.h" | |
13 #include "content/public/browser/notification_registrar.h" | 12 #include "content/public/browser/notification_registrar.h" |
14 #include "ui/gfx/image/image_skia.h" | 13 #include "ui/gfx/image/image_skia.h" |
14 #include "ui/gfx/native_widget_types.h" | |
15 | 15 |
16 class Browser; | 16 class Browser; |
17 class Profile; | 17 class Profile; |
18 | 18 |
19 namespace base { | 19 namespace base { |
20 class MessageLoop; | 20 class MessageLoop; |
21 } | 21 } |
22 | 22 |
23 namespace gfx { | 23 namespace gfx { |
24 class Image; | 24 class Image; |
25 } | 25 } |
26 | 26 |
27 namespace extensions { | 27 namespace extensions { |
28 class Extension; | 28 class Extension; |
29 | 29 |
30 class ExtensionUninstallDialog | 30 class ExtensionUninstallDialog |
31 : public content::NotificationObserver, | 31 : public base::SupportsWeakPtr<ExtensionUninstallDialog> { |
32 public base::SupportsWeakPtr<ExtensionUninstallDialog> { | |
33 public: | 32 public: |
34 class Delegate { | 33 class Delegate { |
35 public: | 34 public: |
36 // We call this method to signal that the uninstallation should continue. | 35 // We call this method to signal that the uninstallation should continue. |
37 virtual void ExtensionUninstallAccepted() = 0; | 36 virtual void ExtensionUninstallAccepted() = 0; |
38 | 37 |
39 // We call this method to signal that the uninstallation should stop. | 38 // We call this method to signal that the uninstallation should stop. |
40 virtual void ExtensionUninstallCanceled() = 0; | 39 virtual void ExtensionUninstallCanceled() = 0; |
41 | 40 |
42 protected: | 41 protected: |
43 virtual ~Delegate() {} | 42 virtual ~Delegate() {} |
44 }; | 43 }; |
45 | 44 |
46 // Creates a platform specific implementation of ExtensionUninstallDialog. | 45 // Creates a platform specific implementation of ExtensionUninstallDialog. |
47 // |profile| and |delegate| can never be NULL. | 46 // |profile| and |delegate| can never be NULL. If |parent| is not NULL, makes |
48 // |browser| can be NULL only for Ash when this is used with the applist | 47 // the dialog modal to |parent|, otherwise creates a standalone dialog. |
49 // window. | |
50 static ExtensionUninstallDialog* Create(Profile* profile, | 48 static ExtensionUninstallDialog* Create(Profile* profile, |
51 Browser* browser, | 49 gfx::NativeWindow parent, |
52 Delegate* delegate); | 50 Delegate* delegate); |
53 | 51 |
54 virtual ~ExtensionUninstallDialog(); | 52 virtual ~ExtensionUninstallDialog(); |
55 | 53 |
56 // This is called to verify whether the uninstallation should proceed. | 54 // This is called to verify whether the uninstallation should proceed. |
57 // Starts the process of showing a confirmation UI, which is split into two. | 55 // Starts the process of showing a confirmation UI, which is split into two. |
58 // 1) Set off a 'load icon' task. | 56 // 1) Set off a 'load icon' task. |
59 // 2) Handle the load icon response and show the UI (OnImageLoaded). | 57 // 2) Handle the load icon response and show the UI (OnImageLoaded). |
60 void ConfirmUninstall(const Extension* extension); | 58 void ConfirmUninstall(const Extension* extension); |
61 | 59 |
62 // This shows the same dialog as above, except it also shows which extension | 60 // This shows the same dialog as above, except it also shows which extension |
63 // triggered the dialog by calling chrome.management.uninstall API. | 61 // triggered the dialog by calling chrome.management.uninstall API. |
64 void ConfirmProgrammaticUninstall(const Extension* extension, | 62 void ConfirmProgrammaticUninstall(const Extension* extension, |
65 const Extension* triggering_extension); | 63 const Extension* triggering_extension); |
66 | 64 |
67 std::string GetHeadingText(); | 65 std::string GetHeadingText(); |
68 | 66 |
69 protected: | 67 protected: |
70 // Constructor used by the derived classes. | 68 // Constructor used by the derived classes. |
71 ExtensionUninstallDialog(Profile* profile, | 69 ExtensionUninstallDialog(Profile* profile, |
72 Browser* browser, | 70 gfx::NativeWindow parent, |
73 Delegate* delegate); | 71 Delegate* delegate); |
74 | 72 |
75 Profile* const profile_; | 73 Profile* const profile_; |
tapted
2014/07/24 07:46:33
Hm - I just noticed these protected data members a
sashab
2014/07/25 02:44:32
Opened crbug.com/397395 to track this. Simple fix
| |
76 | 74 |
77 Browser* browser_; | 75 gfx::NativeWindow parent_; |
tapted
2014/07/24 07:46:33
it would be nice to get rid of this too (I think t
| |
78 | 76 |
79 // The delegate we will call Accepted/Canceled on after confirmation dialog. | 77 // The delegate we will call Accepted/Canceled on after confirmation dialog. |
80 Delegate* delegate_; | 78 Delegate* delegate_; |
81 | 79 |
82 // The extension we are showing the dialog for. | 80 // The extension we are showing the dialog for. |
83 const Extension* extension_; | 81 const Extension* extension_; |
84 | 82 |
85 // The extension triggering the dialog if the dialog was shown by | 83 // The extension triggering the dialog if the dialog was shown by |
86 // chrome.management.uninstall. | 84 // chrome.management.uninstall. |
87 const Extension* triggering_extension_; | 85 const Extension* triggering_extension_; |
88 | 86 |
89 // The extensions icon. | 87 // The extensions icon. |
90 gfx::ImageSkia icon_; | 88 gfx::ImageSkia icon_; |
91 | 89 |
92 private: | 90 private: |
93 // Sets the icon that will be used in the dialog. If |icon| contains an empty | 91 // Sets the icon that will be used in the dialog. If |icon| contains an empty |
94 // image, then we use a default icon instead. | 92 // image, then we use a default icon instead. |
95 void SetIcon(const gfx::Image& image); | 93 void SetIcon(const gfx::Image& image); |
96 | 94 |
97 void OnImageLoaded(const std::string& extension_id, const gfx::Image& image); | 95 void OnImageLoaded(const std::string& extension_id, const gfx::Image& image); |
98 | 96 |
99 // content::NotificationObserver implementation. | |
100 virtual void Observe(int type, | |
101 const content::NotificationSource& source, | |
102 const content::NotificationDetails& details) OVERRIDE; | |
103 | |
104 // Displays the prompt. This should only be called after loading the icon. | 97 // Displays the prompt. This should only be called after loading the icon. |
105 // The implementations of this method are platform-specific. | 98 // The implementations of this method are platform-specific. |
106 virtual void Show() = 0; | 99 virtual void Show() = 0; |
107 | 100 |
108 // Keeps track of whether we're still waiting for an image to load before | |
109 // we show the dialog. | |
110 enum State { | |
111 kImageIsLoading, // Image is loading asynchronously. | |
112 kDialogIsShowing, // Dialog is shown after image is loaded. | |
113 kBrowserIsClosing // Browser is closed while image is still loading. | |
114 }; | |
115 State state_; | |
116 | |
117 base::MessageLoop* ui_loop_; | 101 base::MessageLoop* ui_loop_; |
118 | 102 |
119 content::NotificationRegistrar registrar_; | 103 content::NotificationRegistrar registrar_; |
120 | 104 |
121 DISALLOW_COPY_AND_ASSIGN(ExtensionUninstallDialog); | 105 DISALLOW_COPY_AND_ASSIGN(ExtensionUninstallDialog); |
122 }; | 106 }; |
123 | 107 |
124 } // namespace extensions | 108 } // namespace extensions |
125 | 109 |
126 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_UNINSTALL_DIALOG_H_ | 110 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_UNINSTALL_DIALOG_H_ |
OLD | NEW |