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_PROMPT_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_INSTALL_UI_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_INSTALL_PROMPT_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
13 #include "base/memory/scoped_ptr.h" | |
13 #include "base/string16.h" | 14 #include "base/string16.h" |
14 #include "chrome/browser/extensions/image_loading_tracker.h" | 15 #include "chrome/browser/extensions/image_loading_tracker.h" |
15 #include "chrome/common/extensions/url_pattern.h" | 16 #include "chrome/common/extensions/url_pattern.h" |
16 #include "third_party/skia/include/core/SkBitmap.h" | 17 #include "third_party/skia/include/core/SkBitmap.h" |
17 #include "ui/gfx/image/image.h" | 18 #include "ui/gfx/image/image.h" |
18 #include "ui/gfx/native_widget_types.h" | 19 #include "ui/gfx/native_widget_types.h" |
19 | 20 |
20 class Browser; | 21 class ExtensionInstallUI; |
21 class ExtensionPermissionSet; | 22 class ExtensionPermissionSet; |
22 class MessageLoop; | 23 class MessageLoop; |
23 class Profile; | 24 class Profile; |
24 class InfoBarDelegate; | 25 class InfoBarDelegate; |
25 class TabContentsWrapper; | 26 class TabContentsWrapper; |
26 | 27 |
27 namespace base { | 28 namespace base { |
28 class DictionaryValue; | 29 class DictionaryValue; |
29 } | 30 } // namespace base |
30 | 31 |
31 namespace extensions { | 32 namespace extensions { |
32 class BundleInstaller; | 33 class BundleInstaller; |
33 class Extension; | 34 class Extension; |
34 } | 35 } // namespace extensions |
35 | 36 |
36 // Displays all the UI around extension installation. | 37 // Displays all the UI around extension installation. |
37 class ExtensionInstallUI : public ImageLoadingTracker::Observer { | 38 class ExtensionInstallPrompt : public ImageLoadingTracker::Observer { |
38 public: | 39 public: |
39 enum PromptType { | 40 enum PromptType { |
40 UNSET_PROMPT_TYPE = -1, | 41 UNSET_PROMPT_TYPE = -1, |
41 INSTALL_PROMPT = 0, | 42 INSTALL_PROMPT = 0, |
42 INLINE_INSTALL_PROMPT, | 43 INLINE_INSTALL_PROMPT, |
43 BUNDLE_INSTALL_PROMPT, | 44 BUNDLE_INSTALL_PROMPT, |
44 RE_ENABLE_PROMPT, | 45 RE_ENABLE_PROMPT, |
45 PERMISSIONS_PROMPT, | 46 PERMISSIONS_PROMPT, |
46 NUM_PROMPT_TYPES | 47 NUM_PROMPT_TYPES |
47 }; | 48 }; |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
140 | 141 |
141 // Creates a dummy extension from the |manifest|, replacing the name and | 142 // Creates a dummy extension from the |manifest|, replacing the name and |
142 // description with the localizations if provided. | 143 // description with the localizations if provided. |
143 static scoped_refptr<extensions::Extension> GetLocalizedExtensionForDisplay( | 144 static scoped_refptr<extensions::Extension> GetLocalizedExtensionForDisplay( |
144 const base::DictionaryValue* manifest, | 145 const base::DictionaryValue* manifest, |
145 const std::string& id, | 146 const std::string& id, |
146 const std::string& localized_name, | 147 const std::string& localized_name, |
147 const std::string& localized_description, | 148 const std::string& localized_description, |
148 std::string* error); | 149 std::string* error); |
149 | 150 |
150 explicit ExtensionInstallUI(Profile* profile); | 151 explicit ExtensionInstallPrompt(Profile* profile); |
151 virtual ~ExtensionInstallUI(); | 152 virtual ~ExtensionInstallPrompt(); |
152 | 153 |
153 // TODO(asargent) Normally we navigate to the new tab page when an app is | 154 // TODO(asargent) Normally we navigate to the new tab page when an app is |
154 // installed, but we're experimenting with instead showing a bubble when | 155 // installed, but we're experimenting with instead showing a bubble when |
155 // an app is installed which points to the new tab button. This may become | 156 // an app is installed which points to the new tab button. This may become |
156 // the default behavior in the future. | 157 // the default behavior in the future. |
157 void set_use_app_installed_bubble(bool use_bubble) { | 158 void set_use_app_installed_bubble(bool use_bubble) { |
158 use_app_installed_bubble_ = use_bubble; | 159 use_app_installed_bubble_ = use_bubble; |
159 } | 160 } |
160 | 161 |
161 // Whether or not to show the default UI after completing the installation. | 162 // Whether or not to show the default UI after completing the installation. |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
203 | 204 |
204 // This is called by the extension permissions API to verify whether an | 205 // This is called by the extension permissions API to verify whether an |
205 // extension may be granted additional permissions. | 206 // extension may be granted additional permissions. |
206 // | 207 // |
207 // We *MUST* eventually call either Proceed() or Abort() on |delegate|. | 208 // We *MUST* eventually call either Proceed() or Abort() on |delegate|. |
208 virtual void ConfirmPermissions(Delegate* delegate, | 209 virtual void ConfirmPermissions(Delegate* delegate, |
209 const extensions::Extension* extension, | 210 const extensions::Extension* extension, |
210 const ExtensionPermissionSet* permissions); | 211 const ExtensionPermissionSet* permissions); |
211 | 212 |
212 // Installation was successful. This is declared virtual for testing. | 213 // Installation was successful. This is declared virtual for testing. |
213 virtual void OnInstallSuccess(const extensions::Extension* extension, | 214 virtual void OnInstallSuccess(const extensions::Extension* extension, |
Yoyo Zhou
2012/05/23 23:17:49
I was originally thinking that OnInstallSuccess an
Jay Civelli
2012/05/30 20:20:35
Good idea! Done.
| |
214 SkBitmap* icon); | 215 SkBitmap* icon); |
215 | 216 |
216 // Installation failed. This is declared virtual for testing. | 217 // Installation failed. This is declared virtual for testing. |
217 virtual void OnInstallFailure(const string16& error); | 218 virtual void OnInstallFailure(const string16& error); |
218 | 219 |
219 // ImageLoadingTracker::Observer: | 220 // ImageLoadingTracker::Observer: |
220 virtual void OnImageLoaded(const gfx::Image& image, | 221 virtual void OnImageLoaded(const gfx::Image& image, |
221 const std::string& extension_id, | 222 const std::string& extension_id, |
222 int index) OVERRIDE; | 223 int index) OVERRIDE; |
223 | 224 |
224 // 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); | |
226 | |
227 protected: | 225 protected: |
228 friend class ExtensionNoConfirmWebstorePrivateApiTest; | 226 friend class ExtensionNoConfirmWebstorePrivateApiTest; |
229 friend class WebstoreInlineInstallUnpackFailureTest; | 227 friend class WebstoreInlineInstallUnpackFailureTest; |
230 | 228 |
231 // Disables showing UI (ErrorBox, etc.) for install failures. To be used only | 229 // Disables showing UI (ErrorBox, etc.) for install failures. To be used only |
232 // in tests. | 230 // in tests. |
233 static void DisableFailureUIForTests(); | 231 static void DisableFailureUIForTests(); |
234 | 232 |
235 private: | 233 private: |
236 friend class GalleryInstallApiTestObserver; | 234 friend class GalleryInstallApiTestObserver; |
237 | 235 |
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 | 236 // 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. | 237 // an empty bitmap, then a default icon will be used instead. |
247 void SetIcon(const SkBitmap* icon); | 238 void SetIcon(const SkBitmap* icon); |
248 | 239 |
249 // Starts the process of showing a confirmation UI, which is split into two. | 240 // Starts the process of showing a confirmation UI, which is split into two. |
250 // 1) Set off a 'load icon' task. | 241 // 1) Set off a 'load icon' task. |
251 // 2) Handle the load icon response and show the UI (OnImageLoaded). | 242 // 2) Handle the load icon response and show the UI (OnImageLoaded). |
252 void LoadImageIfNeeded(); | 243 void LoadImageIfNeeded(); |
253 | 244 |
254 // Shows the actual UI (the icon should already be loaded). | 245 // Shows the actual UI (the icon should already be loaded). |
255 void ShowConfirmation(); | 246 void ShowConfirmation(); |
256 | 247 |
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_; | 248 Profile* profile_; |
266 MessageLoop* ui_loop_; | 249 MessageLoop* ui_loop_; |
267 | 250 |
268 // Used to undo theme installation. | |
269 std::string previous_theme_id_; | |
270 bool previous_using_native_theme_; | |
271 | |
272 // The extensions installation icon. | 251 // The extensions installation icon. |
273 SkBitmap icon_; | 252 SkBitmap icon_; |
274 | 253 |
275 // The extension we are showing the UI for. | 254 // The extension we are showing the UI for. |
276 const extensions::Extension* extension_; | 255 const extensions::Extension* extension_; |
277 | 256 |
278 // The bundle we are showing the UI for, if type BUNDLE_INSTALL_PROMPT. | 257 // The bundle we are showing the UI for, if type BUNDLE_INSTALL_PROMPT. |
279 const extensions::BundleInstaller* bundle_; | 258 const extensions::BundleInstaller* bundle_; |
280 | 259 |
281 // The permissions being prompted for. | 260 // The permissions being prompted for. |
282 scoped_refptr<const ExtensionPermissionSet> permissions_; | 261 scoped_refptr<const ExtensionPermissionSet> permissions_; |
283 | 262 |
263 // The object responsible for doing the UI specific actions. | |
264 scoped_ptr<ExtensionInstallUI> install_ui_; | |
265 | |
284 // The delegate we will call Proceed/Abort on after confirmation UI. | 266 // The delegate we will call Proceed/Abort on after confirmation UI. |
285 Delegate* delegate_; | 267 Delegate* delegate_; |
286 | 268 |
287 // A pre-filled prompt. | 269 // A pre-filled prompt. |
288 Prompt prompt_; | 270 Prompt prompt_; |
289 | 271 |
290 // The type of prompt we are going to show. | 272 // The type of prompt we are going to show. |
291 PromptType prompt_type_; | 273 PromptType prompt_type_; |
292 | 274 |
293 // Keeps track of extension images being loaded on the File thread for the | 275 // Keeps track of extension images being loaded on the File thread for the |
294 // purpose of showing the install UI. | 276 // purpose of showing the install UI. |
295 ImageLoadingTracker tracker_; | 277 ImageLoadingTracker tracker_; |
296 | 278 |
297 // Whether to show an installed bubble on app install, or use the default | 279 // Whether to show an installed bubble on app install, or use the default |
298 // action of opening a new tab page. | 280 // action of opening a new tab page. |
299 bool use_app_installed_bubble_; | 281 bool use_app_installed_bubble_; |
300 | 282 |
301 // Whether or not to show the default UI after completing the installation. | 283 // Whether or not to show the default UI after completing the installation. |
302 bool skip_post_install_ui_; | 284 bool skip_post_install_ui_; |
303 }; | 285 }; |
304 | 286 |
305 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_INSTALL_UI_H_ | 287 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_INSTALL_PROMPT_H_ |
OLD | NEW |