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