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 |
162 ExtensionInstallUI* install_ui() const { return install_ui_.get(); } | |
163 | |
161 // Whether or not to show the default UI after completing the installation. | 164 // Whether or not to show the default UI after completing the installation. |
162 void set_skip_post_install_ui(bool skip_ui) { | 165 void SetSkipPostInstallUI(bool skip_ui); |
Yoyo Zhou
2012/06/01 21:07:43
Can this be removed too? It's UI-specific, and the
Jay Civelli
2012/06/04 17:15:30
Done.
| |
163 skip_post_install_ui_ = skip_ui; | |
164 } | |
165 | 166 |
166 // This is called by the bundle installer to verify whether the bundle | 167 // This is called by the bundle installer to verify whether the bundle |
167 // should be installed. | 168 // should be installed. |
168 // | 169 // |
169 // We *MUST* eventually call either Proceed() or Abort() on |delegate|. | 170 // We *MUST* eventually call either Proceed() or Abort() on |delegate|. |
170 virtual void ConfirmBundleInstall(extensions::BundleInstaller* bundle, | 171 virtual void ConfirmBundleInstall(extensions::BundleInstaller* bundle, |
171 const ExtensionPermissionSet* permissions); | 172 const ExtensionPermissionSet* permissions); |
172 | 173 |
173 // This is called by the inline installer to verify whether the inline | 174 // This is called by the inline installer to verify whether the inline |
174 // install from the webstore should proceed. | 175 // install from the webstore should proceed. |
(...skipping 27 matching lines...) Expand all Loading... | |
202 const extensions::Extension* extension); | 203 const extensions::Extension* extension); |
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 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: | 213 // ImageLoadingTracker::Observer: |
220 virtual void OnImageLoaded(const gfx::Image& image, | 214 virtual void OnImageLoaded(const gfx::Image& image, |
221 const std::string& extension_id, | 215 const std::string& extension_id, |
222 int index) OVERRIDE; | 216 int index) OVERRIDE; |
223 | 217 |
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: | 218 protected: |
228 friend class ExtensionNoConfirmWebstorePrivateApiTest; | 219 friend class ExtensionNoConfirmWebstorePrivateApiTest; |
229 friend class WebstoreInlineInstallUnpackFailureTest; | 220 friend class WebstoreInlineInstallUnpackFailureTest; |
230 | 221 |
231 // Disables showing UI (ErrorBox, etc.) for install failures. To be used only | |
232 // in tests. | |
233 static void DisableFailureUIForTests(); | |
234 | |
235 private: | 222 private: |
236 friend class GalleryInstallApiTestObserver; | 223 friend class GalleryInstallApiTestObserver; |
237 | 224 |
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 | 225 // 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. | 226 // an empty bitmap, then a default icon will be used instead. |
247 void SetIcon(const SkBitmap* icon); | 227 void SetIcon(const SkBitmap* icon); |
248 | 228 |
249 // Starts the process of showing a confirmation UI, which is split into two. | 229 // Starts the process of showing a confirmation UI, which is split into two. |
250 // 1) Set off a 'load icon' task. | 230 // 1) Set off a 'load icon' task. |
251 // 2) Handle the load icon response and show the UI (OnImageLoaded). | 231 // 2) Handle the load icon response and show the UI (OnImageLoaded). |
252 void LoadImageIfNeeded(); | 232 void LoadImageIfNeeded(); |
253 | 233 |
254 // Shows the actual UI (the icon should already be loaded). | 234 // Shows the actual UI (the icon should already be loaded). |
255 void ShowConfirmation(); | 235 void ShowConfirmation(); |
256 | 236 |
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_; | 237 Profile* profile_; |
266 MessageLoop* ui_loop_; | 238 MessageLoop* ui_loop_; |
267 | 239 |
268 // Used to undo theme installation. | |
269 std::string previous_theme_id_; | |
270 bool previous_using_native_theme_; | |
271 | |
272 // The extensions installation icon. | 240 // The extensions installation icon. |
273 SkBitmap icon_; | 241 SkBitmap icon_; |
274 | 242 |
275 // The extension we are showing the UI for. | 243 // The extension we are showing the UI for. |
276 const extensions::Extension* extension_; | 244 const extensions::Extension* extension_; |
277 | 245 |
278 // The bundle we are showing the UI for, if type BUNDLE_INSTALL_PROMPT. | 246 // The bundle we are showing the UI for, if type BUNDLE_INSTALL_PROMPT. |
279 const extensions::BundleInstaller* bundle_; | 247 const extensions::BundleInstaller* bundle_; |
280 | 248 |
281 // The permissions being prompted for. | 249 // The permissions being prompted for. |
282 scoped_refptr<const ExtensionPermissionSet> permissions_; | 250 scoped_refptr<const ExtensionPermissionSet> permissions_; |
283 | 251 |
252 // The object responsible for doing the UI specific actions. | |
253 scoped_ptr<ExtensionInstallUI> install_ui_; | |
254 | |
284 // The delegate we will call Proceed/Abort on after confirmation UI. | 255 // The delegate we will call Proceed/Abort on after confirmation UI. |
285 Delegate* delegate_; | 256 Delegate* delegate_; |
286 | 257 |
287 // A pre-filled prompt. | 258 // A pre-filled prompt. |
288 Prompt prompt_; | 259 Prompt prompt_; |
289 | 260 |
290 // The type of prompt we are going to show. | 261 // The type of prompt we are going to show. |
291 PromptType prompt_type_; | 262 PromptType prompt_type_; |
292 | 263 |
293 // Keeps track of extension images being loaded on the File thread for the | 264 // Keeps track of extension images being loaded on the File thread for the |
294 // purpose of showing the install UI. | 265 // purpose of showing the install UI. |
295 ImageLoadingTracker tracker_; | 266 ImageLoadingTracker tracker_; |
296 | 267 |
297 // Whether to show an installed bubble on app install, or use the default | 268 // Whether to show an installed bubble on app install, or use the default |
298 // action of opening a new tab page. | 269 // action of opening a new tab page. |
299 bool use_app_installed_bubble_; | 270 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 }; | 271 }; |
304 | 272 |
305 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_INSTALL_UI_H_ | 273 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_INSTALL_PROMPT_H_ |
OLD | NEW |