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_INSTALL_UI_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_INSTALL_UI_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_INSTALL_UI_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_INSTALL_UI_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 #include <vector> | |
11 | 10 |
12 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
13 #include "base/string16.h" | 12 #include "base/string16.h" |
14 #include "chrome/browser/extensions/image_loading_tracker.h" | |
15 #include "chrome/common/extensions/url_pattern.h" | |
16 #include "third_party/skia/include/core/SkBitmap.h" | |
17 #include "ui/gfx/image/image.h" | |
18 #include "ui/gfx/native_widget_types.h" | |
19 | 13 |
20 class Browser; | 14 class Browser; |
21 class ExtensionPermissionSet; | |
22 class MessageLoop; | |
23 class Profile; | 15 class Profile; |
24 class InfoBarDelegate; | 16 class SkBitmap; |
25 class TabContentsWrapper; | |
26 | |
27 namespace base { | |
28 class DictionaryValue; | |
29 } | |
30 | 17 |
31 namespace extensions { | 18 namespace extensions { |
32 class BundleInstaller; | |
33 class Extension; | 19 class Extension; |
34 } | 20 } |
35 | 21 |
36 // Displays all the UI around extension installation. | 22 // Interface that should be implemented for each platform to display all the UI |
37 class ExtensionInstallUI : public ImageLoadingTracker::Observer { | 23 // around extension installation. |
24 class ExtensionInstallUI { | |
38 public: | 25 public: |
39 enum PromptType { | 26 static ExtensionInstallUI* Create(Profile* profile); |
Yoyo Zhou
2012/06/01 21:07:43
Is it okay that this isn't implemented in Android?
Jay Civelli
2012/06/04 17:15:30
I had not built on Android in a while.
Done, added
Yoyo Zhou
2012/06/04 21:02:01
This one still looks unimplemented on Android, for
| |
40 UNSET_PROMPT_TYPE = -1, | |
41 INSTALL_PROMPT = 0, | |
42 INLINE_INSTALL_PROMPT, | |
43 BUNDLE_INSTALL_PROMPT, | |
44 RE_ENABLE_PROMPT, | |
45 PERMISSIONS_PROMPT, | |
46 NUM_PROMPT_TYPES | |
47 }; | |
48 | 27 |
49 // Extra information needed to display an installation or uninstallation | |
50 // prompt. Gets populated with raw data and exposes getters for formatted | |
51 // strings so that the GTK/views/Cocoa install dialogs don't have to repeat | |
52 // that logic. | |
53 class Prompt { | |
54 public: | |
55 explicit Prompt(PromptType type); | |
56 ~Prompt(); | |
57 | |
58 void SetPermissions(const std::vector<string16>& permissions); | |
59 void SetInlineInstallWebstoreData(const std::string& localized_user_count, | |
60 double average_rating, | |
61 int rating_count); | |
62 | |
63 PromptType type() const { return type_; } | |
64 void set_type(PromptType type) { type_ = type; } | |
65 | |
66 // Getters for UI element labels. | |
67 string16 GetDialogTitle() const; | |
68 string16 GetHeading() const; | |
69 string16 GetAcceptButtonLabel() const; | |
70 bool HasAbortButtonLabel() const; | |
71 string16 GetAbortButtonLabel() const; | |
72 string16 GetPermissionsHeading() const; | |
73 | |
74 // Getters for webstore metadata. Only populated when the type is | |
75 // INLINE_INSTALL_PROMPT. | |
76 | |
77 // The star display logic replicates the one used by the webstore (from | |
78 // components.ratingutils.setFractionalYellowStars). Callers pass in an | |
79 // "appender", which will be repeatedly called back with the star images | |
80 // that they append to the star display area. | |
81 typedef void(*StarAppender)(const SkBitmap*, void*); | |
82 void AppendRatingStars(StarAppender appender, void* data) const; | |
83 string16 GetRatingCount() const; | |
84 string16 GetUserCount() const; | |
85 size_t GetPermissionCount() const; | |
86 string16 GetPermission(size_t index) const; | |
87 | |
88 // Populated for BUNDLE_INSTALL_PROMPT. | |
89 const extensions::BundleInstaller* bundle() const { return bundle_; } | |
90 void set_bundle(const extensions::BundleInstaller* bundle) { | |
91 bundle_ = bundle; | |
92 } | |
93 | |
94 // Populated for all other types. | |
95 const extensions::Extension* extension() const { return extension_; } | |
96 void set_extension(const extensions::Extension* extension) { | |
97 extension_ = extension; | |
98 } | |
99 | |
100 const gfx::Image& icon() const { return icon_; } | |
101 void set_icon(const gfx::Image& icon) { icon_ = icon; } | |
102 | |
103 private: | |
104 PromptType type_; | |
105 // Permissions that are being requested (may not be all of an extension's | |
106 // permissions if only additional ones are being requested) | |
107 std::vector<string16> permissions_; | |
108 | |
109 // The extension or bundle being installed. | |
110 const extensions::Extension* extension_; | |
111 const extensions::BundleInstaller* bundle_; | |
112 | |
113 // The icon to be displayed. | |
114 gfx::Image icon_; | |
115 | |
116 // These fields are populated only when the prompt type is | |
117 // INLINE_INSTALL_PROMPT | |
118 // Already formatted to be locale-specific. | |
119 std::string localized_user_count_; | |
120 // Range is kMinExtensionRating to kMaxExtensionRating | |
121 double average_rating_; | |
122 int rating_count_; | |
123 }; | |
124 | |
125 static const int kMinExtensionRating = 0; | |
126 static const int kMaxExtensionRating = 5; | |
127 | |
128 class Delegate { | |
129 public: | |
130 // We call this method to signal that the installation should continue. | |
131 virtual void InstallUIProceed() = 0; | |
132 | |
133 // We call this method to signal that the installation should stop, with | |
134 // |user_initiated| true if the installation was stopped by the user. | |
135 virtual void InstallUIAbort(bool user_initiated) = 0; | |
136 | |
137 protected: | |
138 virtual ~Delegate() {} | |
139 }; | |
140 | |
141 // Creates a dummy extension from the |manifest|, replacing the name and | |
142 // description with the localizations if provided. | |
143 static scoped_refptr<extensions::Extension> GetLocalizedExtensionForDisplay( | |
144 const base::DictionaryValue* manifest, | |
145 const std::string& id, | |
146 const std::string& localized_name, | |
147 const std::string& localized_description, | |
148 std::string* error); | |
149 | |
150 explicit ExtensionInstallUI(Profile* profile); | |
151 virtual ~ExtensionInstallUI(); | 28 virtual ~ExtensionInstallUI(); |
152 | 29 |
153 // TODO(asargent) Normally we navigate to the new tab page when an app is | 30 // Called when an extension was installed. |
154 // installed, but we're experimenting with instead showing a bubble when | 31 virtual void OnInstallSuccess(const extensions::Extension* extension, |
155 // an app is installed which points to the new tab button. This may become | 32 SkBitmap* icon) = 0; |
156 // the default behavior in the future. | 33 // Called when an extension failed to install. |
157 void set_use_app_installed_bubble(bool use_bubble) { | 34 virtual void OnInstallFailure(const string16& error) = 0; |
158 use_app_installed_bubble_ = use_bubble; | |
159 } | |
160 | 35 |
161 // Whether or not to show the default UI after completing the installation. | 36 // Whether or not to show the default UI after completing the installation. |
162 void set_skip_post_install_ui(bool skip_ui) { | 37 virtual void SetSkipPostInstallUI(bool skip_ui) = 0; |
Yoyo Zhou
2012/06/01 21:07:43
This one also isn't implemented on Android.
Jay Civelli
2012/06/04 17:15:30
Done.
| |
163 skip_post_install_ui_ = skip_ui; | |
164 } | |
165 | |
166 // This is called by the bundle installer to verify whether the bundle | |
167 // should be installed. | |
168 // | |
169 // We *MUST* eventually call either Proceed() or Abort() on |delegate|. | |
170 virtual void ConfirmBundleInstall(extensions::BundleInstaller* bundle, | |
171 const ExtensionPermissionSet* permissions); | |
172 | |
173 // This is called by the inline installer to verify whether the inline | |
174 // install from the webstore should proceed. | |
175 // | |
176 // We *MUST* eventually call either Proceed() or Abort() on |delegate|. | |
177 virtual void ConfirmInlineInstall(Delegate* delegate, | |
178 const extensions::Extension* extension, | |
179 SkBitmap* icon, | |
180 const Prompt& prompt); | |
181 | |
182 // This is called by the installer to verify whether the installation from | |
183 // the webstore should proceed. | |
184 // | |
185 // We *MUST* eventually call either Proceed() or Abort() on |delegate|. | |
186 virtual void ConfirmWebstoreInstall(Delegate* delegate, | |
187 const extensions::Extension* extension, | |
188 const SkBitmap* icon); | |
189 | |
190 // This is called by the installer to verify whether the installation should | |
191 // proceed. This is declared virtual for testing. | |
192 // | |
193 // We *MUST* eventually call either Proceed() or Abort() on |delegate|. | |
194 virtual void ConfirmInstall(Delegate* delegate, | |
195 const extensions::Extension* extension); | |
196 | |
197 // This is called by the app handler launcher to verify whether the app | |
198 // should be re-enabled. This is declared virtual for testing. | |
199 // | |
200 // We *MUST* eventually call either Proceed() or Abort() on |delegate|. | |
201 virtual void ConfirmReEnable(Delegate* delegate, | |
202 const extensions::Extension* extension); | |
203 | |
204 // This is called by the extension permissions API to verify whether an | |
205 // extension may be granted additional permissions. | |
206 // | |
207 // We *MUST* eventually call either Proceed() or Abort() on |delegate|. | |
208 virtual void ConfirmPermissions(Delegate* delegate, | |
209 const extensions::Extension* extension, | |
210 const ExtensionPermissionSet* permissions); | |
211 | |
212 // Installation was successful. This is declared virtual for testing. | |
213 virtual void OnInstallSuccess(const extensions::Extension* extension, | |
214 SkBitmap* icon); | |
215 | |
216 // Installation failed. This is declared virtual for testing. | |
217 virtual void OnInstallFailure(const string16& error); | |
218 | |
219 // ImageLoadingTracker::Observer: | |
220 virtual void OnImageLoaded(const gfx::Image& image, | |
221 const std::string& extension_id, | |
222 int index) OVERRIDE; | |
223 | 38 |
224 // Opens apps UI and animates the app icon for the app with id |app_id|. | 39 // Opens apps UI and animates the app icon for the app with id |app_id|. |
225 static void OpenAppInstalledUI(Browser* browser, const std::string& app_id); | 40 static void OpenAppInstalledUI(Browser* browser, const std::string& app_id); |
226 | 41 |
227 protected: | |
228 friend class ExtensionNoConfirmWebstorePrivateApiTest; | |
229 friend class WebstoreInlineInstallUnpackFailureTest; | |
230 | |
231 // Disables showing UI (ErrorBox, etc.) for install failures. To be used only | 42 // Disables showing UI (ErrorBox, etc.) for install failures. To be used only |
232 // in tests. | 43 // in tests. |
233 static void DisableFailureUIForTests(); | 44 static void DisableFailureUIForTests(); |
234 | 45 |
235 private: | 46 protected: |
236 friend class GalleryInstallApiTestObserver; | 47 ExtensionInstallUI(); |
237 | |
238 // Show an infobar for a newly-installed theme. previous_theme_id | |
239 // should be empty if the previous theme was the system/default | |
240 // theme. | |
241 static void ShowThemeInfoBar( | |
242 const std::string& previous_theme_id, bool previous_using_native_theme, | |
243 const extensions::Extension* new_theme, Profile* profile); | |
244 | |
245 // Sets the icon that will be used in any UI. If |icon| is NULL, or contains | |
246 // an empty bitmap, then a default icon will be used instead. | |
247 void SetIcon(const SkBitmap* icon); | |
248 | |
249 // Starts the process of showing a confirmation UI, which is split into two. | |
250 // 1) Set off a 'load icon' task. | |
251 // 2) Handle the load icon response and show the UI (OnImageLoaded). | |
252 void LoadImageIfNeeded(); | |
253 | |
254 // Shows the actual UI (the icon should already be loaded). | |
255 void ShowConfirmation(); | |
256 | |
257 // Returns the delegate to control the browser's info bar. This is | |
258 // within its own function due to its platform-specific nature. | |
259 static InfoBarDelegate* GetNewThemeInstalledInfoBarDelegate( | |
260 TabContentsWrapper* tab_contents, | |
261 const extensions::Extension* new_theme, | |
262 const std::string& previous_theme_id, | |
263 bool previous_using_native_theme); | |
264 | |
265 Profile* profile_; | |
266 MessageLoop* ui_loop_; | |
267 | |
268 // Used to undo theme installation. | |
269 std::string previous_theme_id_; | |
270 bool previous_using_native_theme_; | |
271 | |
272 // The extensions installation icon. | |
273 SkBitmap icon_; | |
274 | |
275 // The extension we are showing the UI for. | |
276 const extensions::Extension* extension_; | |
277 | |
278 // The bundle we are showing the UI for, if type BUNDLE_INSTALL_PROMPT. | |
279 const extensions::BundleInstaller* bundle_; | |
280 | |
281 // The permissions being prompted for. | |
282 scoped_refptr<const ExtensionPermissionSet> permissions_; | |
283 | |
284 // The delegate we will call Proceed/Abort on after confirmation UI. | |
285 Delegate* delegate_; | |
286 | |
287 // A pre-filled prompt. | |
288 Prompt prompt_; | |
289 | |
290 // The type of prompt we are going to show. | |
291 PromptType prompt_type_; | |
292 | |
293 // Keeps track of extension images being loaded on the File thread for the | |
294 // purpose of showing the install UI. | |
295 ImageLoadingTracker tracker_; | |
296 | |
297 // Whether to show an installed bubble on app install, or use the default | |
298 // action of opening a new tab page. | |
299 bool use_app_installed_bubble_; | |
300 | |
301 // Whether or not to show the default UI after completing the installation. | |
302 bool skip_post_install_ui_; | |
303 }; | 48 }; |
304 | 49 |
305 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_INSTALL_UI_H_ | 50 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_INSTALL_UI_H_ |
OLD | NEW |