| 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> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
| 13 #include "base/string16.h" | 13 #include "base/string16.h" |
| 14 #include "chrome/browser/extensions/image_loading_tracker.h" | 14 #include "chrome/browser/extensions/image_loading_tracker.h" |
| 15 #include "chrome/common/extensions/url_pattern.h" | 15 #include "chrome/common/extensions/url_pattern.h" |
| 16 #include "third_party/skia/include/core/SkBitmap.h" | 16 #include "third_party/skia/include/core/SkBitmap.h" |
| 17 #include "ui/gfx/image/image.h" | 17 #include "ui/gfx/image/image.h" |
| 18 #include "ui/gfx/native_widget_types.h" | 18 #include "ui/gfx/native_widget_types.h" |
| 19 | 19 |
| 20 class Browser; | 20 class Browser; |
| 21 class Extension; | |
| 22 class ExtensionPermissionSet; | 21 class ExtensionPermissionSet; |
| 23 class MessageLoop; | 22 class MessageLoop; |
| 24 class Profile; | 23 class Profile; |
| 25 class InfoBarDelegate; | 24 class InfoBarDelegate; |
| 26 class TabContentsWrapper; | 25 class TabContentsWrapper; |
| 27 | 26 |
| 28 namespace base { | 27 namespace base { |
| 29 class DictionaryValue; | 28 class DictionaryValue; |
| 30 } // namespace base | 29 } |
| 31 | 30 |
| 32 namespace extensions { | 31 namespace extensions { |
| 33 class BundleInstaller; | 32 class BundleInstaller; |
| 34 } // namespace extensions | 33 class Extension; |
| 34 } |
| 35 | 35 |
| 36 // Displays all the UI around extension installation. | 36 // Displays all the UI around extension installation. |
| 37 class ExtensionInstallUI : public ImageLoadingTracker::Observer { | 37 class ExtensionInstallUI : public ImageLoadingTracker::Observer { |
| 38 public: | 38 public: |
| 39 enum PromptType { | 39 enum PromptType { |
| 40 UNSET_PROMPT_TYPE = -1, | 40 UNSET_PROMPT_TYPE = -1, |
| 41 INSTALL_PROMPT = 0, | 41 INSTALL_PROMPT = 0, |
| 42 INLINE_INSTALL_PROMPT, | 42 INLINE_INSTALL_PROMPT, |
| 43 BUNDLE_INSTALL_PROMPT, | 43 BUNDLE_INSTALL_PROMPT, |
| 44 RE_ENABLE_PROMPT, | 44 RE_ENABLE_PROMPT, |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 size_t GetPermissionCount() const; | 85 size_t GetPermissionCount() const; |
| 86 string16 GetPermission(size_t index) const; | 86 string16 GetPermission(size_t index) const; |
| 87 | 87 |
| 88 // Populated for BUNDLE_INSTALL_PROMPT. | 88 // Populated for BUNDLE_INSTALL_PROMPT. |
| 89 const extensions::BundleInstaller* bundle() const { return bundle_; } | 89 const extensions::BundleInstaller* bundle() const { return bundle_; } |
| 90 void set_bundle(const extensions::BundleInstaller* bundle) { | 90 void set_bundle(const extensions::BundleInstaller* bundle) { |
| 91 bundle_ = bundle; | 91 bundle_ = bundle; |
| 92 } | 92 } |
| 93 | 93 |
| 94 // Populated for all other types. | 94 // Populated for all other types. |
| 95 const Extension* extension() const { return extension_; } | 95 const extensions::Extension* extension() const { return extension_; } |
| 96 void set_extension(const Extension* extension) { extension_ = extension; } | 96 void set_extension(const extensions::Extension* extension) { |
| 97 extension_ = extension; |
| 98 } |
| 97 | 99 |
| 98 const gfx::Image& icon() const { return icon_; } | 100 const gfx::Image& icon() const { return icon_; } |
| 99 void set_icon(const gfx::Image& icon) { icon_ = icon; } | 101 void set_icon(const gfx::Image& icon) { icon_ = icon; } |
| 100 | 102 |
| 101 private: | 103 private: |
| 102 PromptType type_; | 104 PromptType type_; |
| 103 // Permissions that are being requested (may not be all of an extension's | 105 // Permissions that are being requested (may not be all of an extension's |
| 104 // permissions if only additional ones are being requested) | 106 // permissions if only additional ones are being requested) |
| 105 std::vector<string16> permissions_; | 107 std::vector<string16> permissions_; |
| 106 | 108 |
| 107 // The extension or bundle being installed. | 109 // The extension or bundle being installed. |
| 108 const Extension* extension_; | 110 const extensions::Extension* extension_; |
| 109 const extensions::BundleInstaller* bundle_; | 111 const extensions::BundleInstaller* bundle_; |
| 110 | 112 |
| 111 // The icon to be displayed. | 113 // The icon to be displayed. |
| 112 gfx::Image icon_; | 114 gfx::Image icon_; |
| 113 | 115 |
| 114 // These fields are populated only when the prompt type is | 116 // These fields are populated only when the prompt type is |
| 115 // INLINE_INSTALL_PROMPT | 117 // INLINE_INSTALL_PROMPT |
| 116 // Already formatted to be locale-specific. | 118 // Already formatted to be locale-specific. |
| 117 std::string localized_user_count_; | 119 std::string localized_user_count_; |
| 118 // Range is kMinExtensionRating to kMaxExtensionRating | 120 // Range is kMinExtensionRating to kMaxExtensionRating |
| (...skipping 12 matching lines...) Expand all Loading... |
| 131 // We call this method to signal that the installation should stop, with | 133 // We call this method to signal that the installation should stop, with |
| 132 // |user_initiated| true if the installation was stopped by the user. | 134 // |user_initiated| true if the installation was stopped by the user. |
| 133 virtual void InstallUIAbort(bool user_initiated) = 0; | 135 virtual void InstallUIAbort(bool user_initiated) = 0; |
| 134 | 136 |
| 135 protected: | 137 protected: |
| 136 virtual ~Delegate() {} | 138 virtual ~Delegate() {} |
| 137 }; | 139 }; |
| 138 | 140 |
| 139 // Creates a dummy extension from the |manifest|, replacing the name and | 141 // Creates a dummy extension from the |manifest|, replacing the name and |
| 140 // description with the localizations if provided. | 142 // description with the localizations if provided. |
| 141 static scoped_refptr<Extension> GetLocalizedExtensionForDisplay( | 143 static scoped_refptr<extensions::Extension> GetLocalizedExtensionForDisplay( |
| 142 const base::DictionaryValue* manifest, | 144 const base::DictionaryValue* manifest, |
| 143 const std::string& id, | 145 const std::string& id, |
| 144 const std::string& localized_name, | 146 const std::string& localized_name, |
| 145 const std::string& localized_description, | 147 const std::string& localized_description, |
| 146 std::string* error); | 148 std::string* error); |
| 147 | 149 |
| 148 explicit ExtensionInstallUI(Profile* profile); | 150 explicit ExtensionInstallUI(Profile* profile); |
| 149 virtual ~ExtensionInstallUI(); | 151 virtual ~ExtensionInstallUI(); |
| 150 | 152 |
| 151 // TODO(asargent) Normally we navigate to the new tab page when an app is | 153 // TODO(asargent) Normally we navigate to the new tab page when an app is |
| (...skipping 14 matching lines...) Expand all Loading... |
| 166 // | 168 // |
| 167 // We *MUST* eventually call either Proceed() or Abort() on |delegate|. | 169 // We *MUST* eventually call either Proceed() or Abort() on |delegate|. |
| 168 virtual void ConfirmBundleInstall(extensions::BundleInstaller* bundle, | 170 virtual void ConfirmBundleInstall(extensions::BundleInstaller* bundle, |
| 169 const ExtensionPermissionSet* permissions); | 171 const ExtensionPermissionSet* permissions); |
| 170 | 172 |
| 171 // This is called by the inline installer to verify whether the inline | 173 // This is called by the inline installer to verify whether the inline |
| 172 // install from the webstore should proceed. | 174 // install from the webstore should proceed. |
| 173 // | 175 // |
| 174 // We *MUST* eventually call either Proceed() or Abort() on |delegate|. | 176 // We *MUST* eventually call either Proceed() or Abort() on |delegate|. |
| 175 virtual void ConfirmInlineInstall(Delegate* delegate, | 177 virtual void ConfirmInlineInstall(Delegate* delegate, |
| 176 const Extension* extension, | 178 const extensions::Extension* extension, |
| 177 SkBitmap* icon, | 179 SkBitmap* icon, |
| 178 const Prompt& prompt); | 180 const Prompt& prompt); |
| 179 | 181 |
| 180 // This is called by the installer to verify whether the installation from | 182 // This is called by the installer to verify whether the installation from |
| 181 // the webstore should proceed. | 183 // the webstore should proceed. |
| 182 // | 184 // |
| 183 // We *MUST* eventually call either Proceed() or Abort() on |delegate|. | 185 // We *MUST* eventually call either Proceed() or Abort() on |delegate|. |
| 184 virtual void ConfirmWebstoreInstall(Delegate* delegate, | 186 virtual void ConfirmWebstoreInstall(Delegate* delegate, |
| 185 const Extension* extension, | 187 const extensions::Extension* extension, |
| 186 const SkBitmap* icon); | 188 const SkBitmap* icon); |
| 187 | 189 |
| 188 // This is called by the installer to verify whether the installation should | 190 // This is called by the installer to verify whether the installation should |
| 189 // proceed. This is declared virtual for testing. | 191 // proceed. This is declared virtual for testing. |
| 190 // | 192 // |
| 191 // We *MUST* eventually call either Proceed() or Abort() on |delegate|. | 193 // We *MUST* eventually call either Proceed() or Abort() on |delegate|. |
| 192 virtual void ConfirmInstall(Delegate* delegate, const Extension* extension); | 194 virtual void ConfirmInstall(Delegate* delegate, |
| 195 const extensions::Extension* extension); |
| 193 | 196 |
| 194 // This is called by the app handler launcher to verify whether the app | 197 // This is called by the app handler launcher to verify whether the app |
| 195 // should be re-enabled. This is declared virtual for testing. | 198 // should be re-enabled. This is declared virtual for testing. |
| 196 // | 199 // |
| 197 // We *MUST* eventually call either Proceed() or Abort() on |delegate|. | 200 // We *MUST* eventually call either Proceed() or Abort() on |delegate|. |
| 198 virtual void ConfirmReEnable(Delegate* delegate, const Extension* extension); | 201 virtual void ConfirmReEnable(Delegate* delegate, |
| 202 const extensions::Extension* extension); |
| 199 | 203 |
| 200 // This is called by the extension permissions API to verify whether an | 204 // This is called by the extension permissions API to verify whether an |
| 201 // extension may be granted additional permissions. | 205 // extension may be granted additional permissions. |
| 202 // | 206 // |
| 203 // We *MUST* eventually call either Proceed() or Abort() on |delegate|. | 207 // We *MUST* eventually call either Proceed() or Abort() on |delegate|. |
| 204 virtual void ConfirmPermissions(Delegate* delegate, | 208 virtual void ConfirmPermissions(Delegate* delegate, |
| 205 const Extension* extension, | 209 const extensions::Extension* extension, |
| 206 const ExtensionPermissionSet* permissions); | 210 const ExtensionPermissionSet* permissions); |
| 207 | 211 |
| 208 // Installation was successful. This is declared virtual for testing. | 212 // Installation was successful. This is declared virtual for testing. |
| 209 virtual void OnInstallSuccess(const Extension* extension, SkBitmap* icon); | 213 virtual void OnInstallSuccess(const extensions::Extension* extension, |
| 214 SkBitmap* icon); |
| 210 | 215 |
| 211 // Installation failed. This is declared virtual for testing. | 216 // Installation failed. This is declared virtual for testing. |
| 212 virtual void OnInstallFailure(const string16& error); | 217 virtual void OnInstallFailure(const string16& error); |
| 213 | 218 |
| 214 // ImageLoadingTracker::Observer: | 219 // ImageLoadingTracker::Observer: |
| 215 virtual void OnImageLoaded(const gfx::Image& image, | 220 virtual void OnImageLoaded(const gfx::Image& image, |
| 216 const std::string& extension_id, | 221 const std::string& extension_id, |
| 217 int index) OVERRIDE; | 222 int index) OVERRIDE; |
| 218 | 223 |
| 219 // Opens apps UI and animates the app icon for the app with id |app_id|. | 224 // Opens apps UI and animates the app icon for the app with id |app_id|. |
| 220 static void OpenAppInstalledUI(Browser* browser, const std::string& app_id); | 225 static void OpenAppInstalledUI(Browser* browser, const std::string& app_id); |
| 221 | 226 |
| 222 protected: | 227 protected: |
| 223 friend class ExtensionNoConfirmWebstorePrivateApiTest; | 228 friend class ExtensionNoConfirmWebstorePrivateApiTest; |
| 224 friend class WebstoreInlineInstallUnpackFailureTest; | 229 friend class WebstoreInlineInstallUnpackFailureTest; |
| 225 | 230 |
| 226 // Disables showing UI (ErrorBox, etc.) for install failures. To be used only | 231 // Disables showing UI (ErrorBox, etc.) for install failures. To be used only |
| 227 // in tests. | 232 // in tests. |
| 228 static void DisableFailureUIForTests(); | 233 static void DisableFailureUIForTests(); |
| 229 | 234 |
| 230 private: | 235 private: |
| 231 friend class GalleryInstallApiTestObserver; | 236 friend class GalleryInstallApiTestObserver; |
| 232 | 237 |
| 233 // Show an infobar for a newly-installed theme. previous_theme_id | 238 // Show an infobar for a newly-installed theme. previous_theme_id |
| 234 // should be empty if the previous theme was the system/default | 239 // should be empty if the previous theme was the system/default |
| 235 // theme. | 240 // theme. |
| 236 static void ShowThemeInfoBar( | 241 static void ShowThemeInfoBar( |
| 237 const std::string& previous_theme_id, bool previous_using_native_theme, | 242 const std::string& previous_theme_id, bool previous_using_native_theme, |
| 238 const Extension* new_theme, Profile* profile); | 243 const extensions::Extension* new_theme, Profile* profile); |
| 239 | 244 |
| 240 // Sets the icon that will be used in any UI. If |icon| is NULL, or contains | 245 // Sets the icon that will be used in any UI. If |icon| is NULL, or contains |
| 241 // an empty bitmap, then a default icon will be used instead. | 246 // an empty bitmap, then a default icon will be used instead. |
| 242 void SetIcon(const SkBitmap* icon); | 247 void SetIcon(const SkBitmap* icon); |
| 243 | 248 |
| 244 // Starts the process of showing a confirmation UI, which is split into two. | 249 // Starts the process of showing a confirmation UI, which is split into two. |
| 245 // 1) Set off a 'load icon' task. | 250 // 1) Set off a 'load icon' task. |
| 246 // 2) Handle the load icon response and show the UI (OnImageLoaded). | 251 // 2) Handle the load icon response and show the UI (OnImageLoaded). |
| 247 void LoadImageIfNeeded(); | 252 void LoadImageIfNeeded(); |
| 248 | 253 |
| 249 // Shows the actual UI (the icon should already be loaded). | 254 // Shows the actual UI (the icon should already be loaded). |
| 250 void ShowConfirmation(); | 255 void ShowConfirmation(); |
| 251 | 256 |
| 252 // Returns the delegate to control the browser's info bar. This is | 257 // Returns the delegate to control the browser's info bar. This is |
| 253 // within its own function due to its platform-specific nature. | 258 // within its own function due to its platform-specific nature. |
| 254 static InfoBarDelegate* GetNewThemeInstalledInfoBarDelegate( | 259 static InfoBarDelegate* GetNewThemeInstalledInfoBarDelegate( |
| 255 TabContentsWrapper* tab_contents, | 260 TabContentsWrapper* tab_contents, |
| 256 const Extension* new_theme, | 261 const extensions::Extension* new_theme, |
| 257 const std::string& previous_theme_id, | 262 const std::string& previous_theme_id, |
| 258 bool previous_using_native_theme); | 263 bool previous_using_native_theme); |
| 259 | 264 |
| 260 Profile* profile_; | 265 Profile* profile_; |
| 261 MessageLoop* ui_loop_; | 266 MessageLoop* ui_loop_; |
| 262 | 267 |
| 263 // Used to undo theme installation. | 268 // Used to undo theme installation. |
| 264 std::string previous_theme_id_; | 269 std::string previous_theme_id_; |
| 265 bool previous_using_native_theme_; | 270 bool previous_using_native_theme_; |
| 266 | 271 |
| 267 // The extensions installation icon. | 272 // The extensions installation icon. |
| 268 SkBitmap icon_; | 273 SkBitmap icon_; |
| 269 | 274 |
| 270 // The extension we are showing the UI for. | 275 // The extension we are showing the UI for. |
| 271 const Extension* extension_; | 276 const extensions::Extension* extension_; |
| 272 | 277 |
| 273 // The bundle we are showing the UI for, if type BUNDLE_INSTALL_PROMPT. | 278 // The bundle we are showing the UI for, if type BUNDLE_INSTALL_PROMPT. |
| 274 const extensions::BundleInstaller* bundle_; | 279 const extensions::BundleInstaller* bundle_; |
| 275 | 280 |
| 276 // The permissions being prompted for. | 281 // The permissions being prompted for. |
| 277 scoped_refptr<const ExtensionPermissionSet> permissions_; | 282 scoped_refptr<const ExtensionPermissionSet> permissions_; |
| 278 | 283 |
| 279 // The delegate we will call Proceed/Abort on after confirmation UI. | 284 // The delegate we will call Proceed/Abort on after confirmation UI. |
| 280 Delegate* delegate_; | 285 Delegate* delegate_; |
| 281 | 286 |
| 282 // A pre-filled prompt. | 287 // A pre-filled prompt. |
| 283 Prompt prompt_; | 288 Prompt prompt_; |
| 284 | 289 |
| 285 // The type of prompt we are going to show. | 290 // The type of prompt we are going to show. |
| 286 PromptType prompt_type_; | 291 PromptType prompt_type_; |
| 287 | 292 |
| 288 // Keeps track of extension images being loaded on the File thread for the | 293 // Keeps track of extension images being loaded on the File thread for the |
| 289 // purpose of showing the install UI. | 294 // purpose of showing the install UI. |
| 290 ImageLoadingTracker tracker_; | 295 ImageLoadingTracker tracker_; |
| 291 | 296 |
| 292 // Whether to show an installed bubble on app install, or use the default | 297 // Whether to show an installed bubble on app install, or use the default |
| 293 // action of opening a new tab page. | 298 // action of opening a new tab page. |
| 294 bool use_app_installed_bubble_; | 299 bool use_app_installed_bubble_; |
| 295 | 300 |
| 296 // Whether or not to show the default UI after completing the installation. | 301 // Whether or not to show the default UI after completing the installation. |
| 297 bool skip_post_install_ui_; | 302 bool skip_post_install_ui_; |
| 298 }; | 303 }; |
| 299 | 304 |
| 300 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_INSTALL_UI_H_ | 305 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_INSTALL_UI_H_ |
| OLD | NEW |