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" | |
11 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
12 #include "content/public/browser/notification_observer.h" | |
13 #include "content/public/browser/notification_registrar.h" | |
14 #include "ui/gfx/image/image_skia.h" | 11 #include "ui/gfx/image/image_skia.h" |
| 12 #include "ui/gfx/native_widget_types.h" |
15 | 13 |
16 class Browser; | |
17 class Profile; | 14 class Profile; |
18 | 15 |
19 namespace base { | 16 namespace base { |
20 class MessageLoop; | 17 class MessageLoop; |
21 } | 18 } |
22 | 19 |
23 namespace gfx { | 20 namespace gfx { |
24 class Image; | 21 class Image; |
25 } | 22 } |
26 | 23 |
27 namespace extensions { | 24 namespace extensions { |
28 class Extension; | 25 class Extension; |
29 | 26 |
30 class ExtensionUninstallDialog | 27 class ExtensionUninstallDialog |
31 : public content::NotificationObserver, | 28 : public base::SupportsWeakPtr<ExtensionUninstallDialog> { |
32 public base::SupportsWeakPtr<ExtensionUninstallDialog> { | |
33 public: | 29 public: |
34 class Delegate { | 30 class Delegate { |
35 public: | 31 public: |
36 // We call this method to signal that the uninstallation should continue. | 32 // We call this method to signal that the uninstallation should continue. |
37 virtual void ExtensionUninstallAccepted() = 0; | 33 virtual void ExtensionUninstallAccepted() = 0; |
38 | 34 |
39 // We call this method to signal that the uninstallation should stop. | 35 // We call this method to signal that the uninstallation should stop. |
40 virtual void ExtensionUninstallCanceled() = 0; | 36 virtual void ExtensionUninstallCanceled() = 0; |
41 | 37 |
42 protected: | 38 protected: |
43 virtual ~Delegate() {} | 39 virtual ~Delegate() {} |
44 }; | 40 }; |
45 | 41 |
46 // Creates a platform specific implementation of ExtensionUninstallDialog. | 42 // Creates a platform specific implementation of ExtensionUninstallDialog. The |
47 // |profile| and |delegate| can never be NULL. | 43 // dialog will be modal to |parent|, or a non-modal dialog if |parent| is |
48 // |browser| can be NULL only for Ash when this is used with the applist | 44 // NULL. |
49 // window. | |
50 static ExtensionUninstallDialog* Create(Profile* profile, | 45 static ExtensionUninstallDialog* Create(Profile* profile, |
51 Browser* browser, | 46 gfx::NativeWindow parent, |
52 Delegate* delegate); | 47 Delegate* delegate); |
53 | 48 |
54 virtual ~ExtensionUninstallDialog(); | 49 virtual ~ExtensionUninstallDialog(); |
55 | 50 |
56 // This is called to verify whether the uninstallation should proceed. | 51 // This is called to verify whether the uninstallation should proceed. |
57 // Starts the process of showing a confirmation UI, which is split into two. | 52 // Starts the process of showing a confirmation UI, which is split into two. |
58 // 1) Set off a 'load icon' task. | 53 // 1) Set off a 'load icon' task. |
59 // 2) Handle the load icon response and show the UI (OnImageLoaded). | 54 // 2) Handle the load icon response and show the UI (OnImageLoaded). |
60 void ConfirmUninstall(const Extension* extension); | 55 void ConfirmUninstall(const Extension* extension); |
61 | 56 |
62 // This shows the same dialog as above, except it also shows which extension | 57 // This shows the same dialog as above, except it also shows which extension |
63 // triggered the dialog by calling chrome.management.uninstall API. | 58 // triggered the dialog by calling chrome.management.uninstall API. |
64 void ConfirmProgrammaticUninstall(const Extension* extension, | 59 void ConfirmProgrammaticUninstall(const Extension* extension, |
65 const Extension* triggering_extension); | 60 const Extension* triggering_extension); |
66 | 61 |
67 std::string GetHeadingText(); | 62 std::string GetHeadingText(); |
68 | 63 |
69 protected: | 64 protected: |
70 // Constructor used by the derived classes. | 65 // Constructor used by the derived classes. |
71 ExtensionUninstallDialog(Profile* profile, | 66 ExtensionUninstallDialog(Profile* profile, |
72 Browser* browser, | 67 gfx::NativeWindow parent, |
73 Delegate* delegate); | 68 Delegate* delegate); |
74 | 69 |
| 70 // TODO(sashab): Remove protected members: crbug.com/397395 |
75 Profile* const profile_; | 71 Profile* const profile_; |
76 | 72 |
77 Browser* browser_; | 73 // TODO(sashab): Investigate lifetime issue of this window variable: |
| 74 // crbug.com/397396 |
| 75 gfx::NativeWindow parent_; |
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_; | |
120 | |
121 DISALLOW_COPY_AND_ASSIGN(ExtensionUninstallDialog); | 103 DISALLOW_COPY_AND_ASSIGN(ExtensionUninstallDialog); |
122 }; | 104 }; |
123 | 105 |
124 } // namespace extensions | 106 } // namespace extensions |
125 | 107 |
126 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_UNINSTALL_DIALOG_H_ | 108 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_UNINSTALL_DIALOG_H_ |
OLD | NEW |