| 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_PROMPT_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_INSTALL_PROMPT_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_INSTALL_PROMPT_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/memory/scoped_ptr.h" |
| 14 #include "base/string16.h" | 14 #include "base/string16.h" |
| 15 #include "chrome/browser/extensions/crx_installer_error.h" | 15 #include "chrome/browser/extensions/crx_installer_error.h" |
| 16 #include "chrome/browser/extensions/image_loading_tracker.h" | 16 #include "chrome/browser/extensions/image_loading_tracker.h" |
| 17 #include "chrome/common/extensions/url_pattern.h" | 17 #include "chrome/common/extensions/url_pattern.h" |
| 18 #include "chrome/common/net/gaia/oauth2_mint_token_flow.h" | |
| 19 #include "third_party/skia/include/core/SkBitmap.h" | 18 #include "third_party/skia/include/core/SkBitmap.h" |
| 20 #include "ui/gfx/image/image.h" | 19 #include "ui/gfx/image/image.h" |
| 21 #include "ui/gfx/image/image_skia.h" | 20 #include "ui/gfx/image/image_skia.h" |
| 22 #include "ui/gfx/native_widget_types.h" | 21 #include "ui/gfx/native_widget_types.h" |
| 23 | 22 |
| 24 class Browser; | 23 class Browser; |
| 25 class ExtensionInstallUI; | 24 class ExtensionInstallUI; |
| 26 class MessageLoop; | 25 class MessageLoop; |
| 27 class InfoBarDelegate; | 26 class InfoBarDelegate; |
| 28 | 27 |
| 29 namespace base { | 28 namespace base { |
| 30 class DictionaryValue; | 29 class DictionaryValue; |
| 31 } // namespace base | 30 } // namespace base |
| 32 | 31 |
| 33 namespace extensions { | 32 namespace extensions { |
| 34 class BundleInstaller; | 33 class BundleInstaller; |
| 35 class Extension; | 34 class Extension; |
| 36 class ExtensionWebstorePrivateApiTest; | 35 class ExtensionWebstorePrivateApiTest; |
| 37 class PermissionSet; | 36 class PermissionSet; |
| 38 } // namespace extensions | 37 } // namespace extensions |
| 39 | 38 |
| 40 // Displays all the UI around extension installation. | 39 // Displays all the UI around extension installation. |
| 41 class ExtensionInstallPrompt : public ImageLoadingTracker::Observer, | 40 class ExtensionInstallPrompt : public ImageLoadingTracker::Observer { |
| 42 public OAuth2MintTokenFlow::Delegate { | |
| 43 public: | 41 public: |
| 44 enum PromptType { | 42 enum PromptType { |
| 45 UNSET_PROMPT_TYPE = -1, | 43 UNSET_PROMPT_TYPE = -1, |
| 46 INSTALL_PROMPT = 0, | 44 INSTALL_PROMPT = 0, |
| 47 INLINE_INSTALL_PROMPT, | 45 INLINE_INSTALL_PROMPT, |
| 48 BUNDLE_INSTALL_PROMPT, | 46 BUNDLE_INSTALL_PROMPT, |
| 49 RE_ENABLE_PROMPT, | 47 RE_ENABLE_PROMPT, |
| 50 PERMISSIONS_PROMPT, | 48 PERMISSIONS_PROMPT, |
| 51 NUM_PROMPT_TYPES | 49 NUM_PROMPT_TYPES |
| 52 }; | 50 }; |
| 53 | 51 |
| 54 // Extra information needed to display an installation or uninstallation | 52 // Extra information needed to display an installation or uninstallation |
| 55 // prompt. Gets populated with raw data and exposes getters for formatted | 53 // prompt. Gets populated with raw data and exposes getters for formatted |
| 56 // strings so that the GTK/views/Cocoa install dialogs don't have to repeat | 54 // strings so that the GTK/views/Cocoa install dialogs don't have to repeat |
| 57 // that logic. | 55 // that logic. |
| 58 class Prompt { | 56 class Prompt { |
| 59 public: | 57 public: |
| 60 explicit Prompt(PromptType type); | 58 explicit Prompt(PromptType type); |
| 61 ~Prompt(); | 59 ~Prompt(); |
| 62 | 60 |
| 63 void SetPermissions(const std::vector<string16>& permissions); | 61 void SetPermissions(const std::vector<string16>& permissions); |
| 64 void SetInlineInstallWebstoreData(const std::string& localized_user_count, | 62 void SetInlineInstallWebstoreData(const std::string& localized_user_count, |
| 65 double average_rating, | 63 double average_rating, |
| 66 int rating_count); | 64 int rating_count); |
| 67 void SetOAuthIssueAdvice(const IssueAdviceInfo& issue_advice); | |
| 68 | 65 |
| 69 PromptType type() const { return type_; } | 66 PromptType type() const { return type_; } |
| 70 void set_type(PromptType type) { type_ = type; } | 67 void set_type(PromptType type) { type_ = type; } |
| 71 | 68 |
| 72 // Getters for UI element labels. | 69 // Getters for UI element labels. |
| 73 string16 GetDialogTitle() const; | 70 string16 GetDialogTitle() const; |
| 74 string16 GetHeading() const; | 71 string16 GetHeading() const; |
| 75 string16 GetAcceptButtonLabel() const; | 72 string16 GetAcceptButtonLabel() const; |
| 76 bool HasAbortButtonLabel() const; | 73 bool HasAbortButtonLabel() const; |
| 77 string16 GetAbortButtonLabel() const; | 74 string16 GetAbortButtonLabel() const; |
| 78 string16 GetPermissionsHeading() const; | 75 string16 GetPermissionsHeading() const; |
| 79 | 76 |
| 80 // Getters for webstore metadata. Only populated when the type is | 77 // Getters for webstore metadata. Only populated when the type is |
| 81 // INLINE_INSTALL_PROMPT. | 78 // INLINE_INSTALL_PROMPT. |
| 82 | 79 |
| 83 // The star display logic replicates the one used by the webstore (from | 80 // The star display logic replicates the one used by the webstore (from |
| 84 // components.ratingutils.setFractionalYellowStars). Callers pass in an | 81 // components.ratingutils.setFractionalYellowStars). Callers pass in an |
| 85 // "appender", which will be repeatedly called back with the star images | 82 // "appender", which will be repeatedly called back with the star images |
| 86 // that they append to the star display area. | 83 // that they append to the star display area. |
| 87 typedef void(*StarAppender)(const gfx::ImageSkia*, void*); | 84 typedef void(*StarAppender)(const gfx::ImageSkia*, void*); |
| 88 void AppendRatingStars(StarAppender appender, void* data) const; | 85 void AppendRatingStars(StarAppender appender, void* data) const; |
| 89 string16 GetRatingCount() const; | 86 string16 GetRatingCount() const; |
| 90 string16 GetUserCount() const; | 87 string16 GetUserCount() const; |
| 91 size_t GetPermissionCount() const; | 88 size_t GetPermissionCount() const; |
| 92 string16 GetPermission(size_t index) const; | 89 string16 GetPermission(size_t index) const; |
| 93 size_t GetOAuthIssueCount() const; | |
| 94 const IssueAdviceInfoEntry& GetOAuthIssue(size_t index) const; | |
| 95 | 90 |
| 96 // Populated for BUNDLE_INSTALL_PROMPT. | 91 // Populated for BUNDLE_INSTALL_PROMPT. |
| 97 const extensions::BundleInstaller* bundle() const { return bundle_; } | 92 const extensions::BundleInstaller* bundle() const { return bundle_; } |
| 98 void set_bundle(const extensions::BundleInstaller* bundle) { | 93 void set_bundle(const extensions::BundleInstaller* bundle) { |
| 99 bundle_ = bundle; | 94 bundle_ = bundle; |
| 100 } | 95 } |
| 101 | 96 |
| 102 // Populated for all other types. | 97 // Populated for all other types. |
| 103 const extensions::Extension* extension() const { return extension_; } | 98 const extensions::Extension* extension() const { return extension_; } |
| 104 void set_extension(const extensions::Extension* extension) { | 99 void set_extension(const extensions::Extension* extension) { |
| 105 extension_ = extension; | 100 extension_ = extension; |
| 106 } | 101 } |
| 107 | 102 |
| 108 const gfx::Image& icon() const { return icon_; } | 103 const gfx::Image& icon() const { return icon_; } |
| 109 void set_icon(const gfx::Image& icon) { icon_ = icon; } | 104 void set_icon(const gfx::Image& icon) { icon_ = icon; } |
| 110 | 105 |
| 111 private: | 106 private: |
| 112 PromptType type_; | 107 PromptType type_; |
| 113 // Permissions that are being requested (may not be all of an extension's | 108 // Permissions that are being requested (may not be all of an extension's |
| 114 // permissions if only additional ones are being requested) | 109 // permissions if only additional ones are being requested) |
| 115 std::vector<string16> permissions_; | 110 std::vector<string16> permissions_; |
| 116 | 111 |
| 117 // Descriptions and details for OAuth2 permissions to display to the user. | |
| 118 // These correspond to permission scopes. | |
| 119 IssueAdviceInfo oauth_issue_advice_; | |
| 120 | |
| 121 // The extension or bundle being installed. | 112 // The extension or bundle being installed. |
| 122 const extensions::Extension* extension_; | 113 const extensions::Extension* extension_; |
| 123 const extensions::BundleInstaller* bundle_; | 114 const extensions::BundleInstaller* bundle_; |
| 124 | 115 |
| 125 // The icon to be displayed. | 116 // The icon to be displayed. |
| 126 gfx::Image icon_; | 117 gfx::Image icon_; |
| 127 | 118 |
| 128 // These fields are populated only when the prompt type is | 119 // These fields are populated only when the prompt type is |
| 129 // INLINE_INSTALL_PROMPT | 120 // INLINE_INSTALL_PROMPT |
| 130 // Already formatted to be locale-specific. | 121 // Already formatted to be locale-specific. |
| (...skipping 26 matching lines...) Expand all Loading... |
| 157 const std::string& id, | 148 const std::string& id, |
| 158 const std::string& localized_name, | 149 const std::string& localized_name, |
| 159 const std::string& localized_description, | 150 const std::string& localized_description, |
| 160 std::string* error); | 151 std::string* error); |
| 161 | 152 |
| 162 explicit ExtensionInstallPrompt(Browser* browser); | 153 explicit ExtensionInstallPrompt(Browser* browser); |
| 163 virtual ~ExtensionInstallPrompt(); | 154 virtual ~ExtensionInstallPrompt(); |
| 164 | 155 |
| 165 ExtensionInstallUI* install_ui() const { return install_ui_.get(); } | 156 ExtensionInstallUI* install_ui() const { return install_ui_.get(); } |
| 166 | 157 |
| 167 bool record_oauth2_grant() const { return record_oauth2_grant_; } | |
| 168 | |
| 169 // This is called by the bundle installer to verify whether the bundle | 158 // This is called by the bundle installer to verify whether the bundle |
| 170 // should be installed. | 159 // should be installed. |
| 171 // | 160 // |
| 172 // We *MUST* eventually call either Proceed() or Abort() on |delegate|. | 161 // We *MUST* eventually call either Proceed() or Abort() on |delegate|. |
| 173 virtual void ConfirmBundleInstall( | 162 virtual void ConfirmBundleInstall( |
| 174 extensions::BundleInstaller* bundle, | 163 extensions::BundleInstaller* bundle, |
| 175 const extensions::PermissionSet* permissions); | 164 const extensions::PermissionSet* permissions); |
| 176 | 165 |
| 177 // This is called by the inline installer to verify whether the inline | 166 // This is called by the inline installer to verify whether the inline |
| 178 // install from the webstore should proceed. | 167 // install from the webstore should proceed. |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 SkBitmap* icon); | 207 SkBitmap* icon); |
| 219 | 208 |
| 220 // Installation failed. This is declared virtual for testing. | 209 // Installation failed. This is declared virtual for testing. |
| 221 virtual void OnInstallFailure(const CrxInstallerError& error); | 210 virtual void OnInstallFailure(const CrxInstallerError& error); |
| 222 | 211 |
| 223 // ImageLoadingTracker::Observer: | 212 // ImageLoadingTracker::Observer: |
| 224 virtual void OnImageLoaded(const gfx::Image& image, | 213 virtual void OnImageLoaded(const gfx::Image& image, |
| 225 const std::string& extension_id, | 214 const std::string& extension_id, |
| 226 int index) OVERRIDE; | 215 int index) OVERRIDE; |
| 227 | 216 |
| 228 // Returns true if extension scopes should be approved without asking the | |
| 229 // user. This is controlled by a flag; before the identity api is taken out | |
| 230 // of experimental the flag should be removed and this should always be false. | |
| 231 static bool ShouldAutomaticallyApproveScopes(); | |
| 232 | |
| 233 protected: | 217 protected: |
| 234 friend class extensions::ExtensionWebstorePrivateApiTest; | 218 friend class extensions::ExtensionWebstorePrivateApiTest; |
| 235 friend class WebstoreInlineInstallUnpackFailureTest; | 219 friend class WebstoreInlineInstallUnpackFailureTest; |
| 236 | 220 |
| 237 // Whether or not we should record the oauth2 grant upon successful install. | |
| 238 bool record_oauth2_grant_; | |
| 239 | |
| 240 private: | 221 private: |
| 241 friend class GalleryInstallApiTestObserver; | 222 friend class GalleryInstallApiTestObserver; |
| 242 | 223 |
| 243 // Sets the icon that will be used in any UI. If |icon| is NULL, or contains | 224 // Sets the icon that will be used in any UI. If |icon| is NULL, or contains |
| 244 // an empty bitmap, then a default icon will be used instead. | 225 // an empty bitmap, then a default icon will be used instead. |
| 245 void SetIcon(const SkBitmap* icon); | 226 void SetIcon(const SkBitmap* icon); |
| 246 | 227 |
| 247 // Starts the process of showing a confirmation UI, which is split into two. | 228 // Starts the process of showing a confirmation UI, which is split into two. |
| 248 // 1) Set off a 'load icon' task. | 229 // 1) Set off a 'load icon' task. |
| 249 // 2) Handle the load icon response and show the UI (OnImageLoaded). | 230 // 2) Handle the load icon response and show the UI (OnImageLoaded). |
| 250 void LoadImageIfNeeded(); | 231 void LoadImageIfNeeded(); |
| 251 | 232 |
| 252 // Starts fetching warnings for OAuth2 scopes, if there are any. | |
| 253 void FetchOAuthIssueAdviceIfNeeded(); | |
| 254 | |
| 255 // OAuth2MintTokenFlow::Delegate implementation: | |
| 256 virtual void OnIssueAdviceSuccess( | |
| 257 const IssueAdviceInfo& issue_advice) OVERRIDE; | |
| 258 virtual void OnMintTokenFailure( | |
| 259 const GoogleServiceAuthError& error) OVERRIDE; | |
| 260 | |
| 261 // Shows the actual UI (the icon should already be loaded). | 233 // Shows the actual UI (the icon should already be loaded). |
| 262 void ShowConfirmation(); | 234 void ShowConfirmation(); |
| 263 | 235 |
| 264 Browser* browser_; | 236 Browser* browser_; |
| 265 MessageLoop* ui_loop_; | 237 MessageLoop* ui_loop_; |
| 266 | 238 |
| 267 // The extensions installation icon. | 239 // The extensions installation icon. |
| 268 SkBitmap icon_; | 240 SkBitmap icon_; |
| 269 | 241 |
| 270 // The extension we are showing the UI for. | 242 // The extension we are showing the UI for. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 281 | 253 |
| 282 // The delegate we will call Proceed/Abort on after confirmation UI. | 254 // The delegate we will call Proceed/Abort on after confirmation UI. |
| 283 Delegate* delegate_; | 255 Delegate* delegate_; |
| 284 | 256 |
| 285 // A pre-filled prompt. | 257 // A pre-filled prompt. |
| 286 Prompt prompt_; | 258 Prompt prompt_; |
| 287 | 259 |
| 288 // The type of prompt we are going to show. | 260 // The type of prompt we are going to show. |
| 289 PromptType prompt_type_; | 261 PromptType prompt_type_; |
| 290 | 262 |
| 291 scoped_ptr<OAuth2MintTokenFlow> token_flow_; | |
| 292 | |
| 293 // Keeps track of extension images being loaded on the File thread for the | 263 // Keeps track of extension images being loaded on the File thread for the |
| 294 // purpose of showing the install UI. | 264 // purpose of showing the install UI. |
| 295 ImageLoadingTracker tracker_; | 265 ImageLoadingTracker tracker_; |
| 296 }; | 266 }; |
| 297 | 267 |
| 298 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_INSTALL_PROMPT_H_ | 268 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_INSTALL_PROMPT_H_ |
| OLD | NEW |