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 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 BUNDLE_INSTALL_PROMPT, | 71 BUNDLE_INSTALL_PROMPT, |
72 RE_ENABLE_PROMPT, | 72 RE_ENABLE_PROMPT, |
73 PERMISSIONS_PROMPT, | 73 PERMISSIONS_PROMPT, |
74 EXTERNAL_INSTALL_PROMPT, | 74 EXTERNAL_INSTALL_PROMPT, |
75 POST_INSTALL_PERMISSIONS_PROMPT, | 75 POST_INSTALL_PERMISSIONS_PROMPT, |
76 LAUNCH_PROMPT, | 76 LAUNCH_PROMPT, |
77 REMOTE_INSTALL_PROMPT, | 77 REMOTE_INSTALL_PROMPT, |
78 NUM_PROMPT_TYPES | 78 NUM_PROMPT_TYPES |
79 }; | 79 }; |
80 | 80 |
| 81 // Enumeration for permissions and retained files details. |
81 enum DetailsType { | 82 enum DetailsType { |
82 PERMISSIONS_DETAILS = 0, | 83 PERMISSIONS_DETAILS = 0, |
| 84 WITHHELD_PERMISSIONS_DETAILS, |
83 RETAINED_FILES_DETAILS, | 85 RETAINED_FILES_DETAILS, |
84 }; | 86 }; |
85 | 87 |
| 88 // This enum is used to differentiate regular and withheld permissions for |
| 89 // segregation in the install prompt. |
| 90 enum PermissionsType { |
| 91 REGULAR_PERMISSIONS = 0, |
| 92 WITHHELD_PERMISSIONS, |
| 93 ALL_PERMISSIONS, |
| 94 }; |
| 95 |
86 static std::string PromptTypeToString(PromptType type); | 96 static std::string PromptTypeToString(PromptType type); |
87 | 97 |
88 // Extra information needed to display an installation or uninstallation | 98 // Extra information needed to display an installation or uninstallation |
89 // prompt. Gets populated with raw data and exposes getters for formatted | 99 // prompt. Gets populated with raw data and exposes getters for formatted |
90 // strings so that the GTK/views/Cocoa install dialogs don't have to repeat | 100 // strings so that the GTK/views/Cocoa install dialogs don't have to repeat |
91 // that logic. | 101 // that logic. |
92 // Ref-counted because we pass around the prompt independent of the full | 102 // Ref-counted because we pass around the prompt independent of the full |
93 // ExtensionInstallPrompt. | 103 // ExtensionInstallPrompt. |
94 class Prompt : public base::RefCountedThreadSafe<Prompt> { | 104 class Prompt : public base::RefCountedThreadSafe<Prompt> { |
95 public: | 105 public: |
96 explicit Prompt(PromptType type); | 106 explicit Prompt(PromptType type); |
97 | 107 |
98 // Sets the permission list for this prompt. | 108 // Sets the permission list for this prompt. |
99 void SetPermissions(const std::vector<base::string16>& permissions); | 109 void SetPermissions(const std::vector<base::string16>& permissions, |
| 110 PermissionsType permissions_type); |
100 // Sets the permission list details for this prompt. | 111 // Sets the permission list details for this prompt. |
101 void SetPermissionsDetails(const std::vector<base::string16>& details); | 112 void SetPermissionsDetails(const std::vector<base::string16>& details, |
| 113 PermissionsType permissions_type); |
102 void SetIsShowingDetails(DetailsType type, | 114 void SetIsShowingDetails(DetailsType type, |
103 size_t index, | 115 size_t index, |
104 bool is_showing_details); | 116 bool is_showing_details); |
105 void SetWebstoreData(const std::string& localized_user_count, | 117 void SetWebstoreData(const std::string& localized_user_count, |
106 bool show_user_count, | 118 bool show_user_count, |
107 double average_rating, | 119 double average_rating, |
108 int rating_count); | 120 int rating_count); |
109 void SetUserNameFromProfile(Profile* profile); | 121 void SetUserNameFromProfile(Profile* profile); |
110 | 122 |
111 PromptType type() const { return type_; } | 123 PromptType type() const { return type_; } |
112 void set_type(PromptType type) { type_ = type; } | 124 void set_type(PromptType type) { type_ = type; } |
113 | 125 |
114 // Getters for UI element labels. | 126 // Getters for UI element labels. |
115 base::string16 GetDialogTitle() const; | 127 base::string16 GetDialogTitle() const; |
116 base::string16 GetHeading() const; | 128 base::string16 GetHeading() const; |
117 int GetDialogButtons() const; | 129 int GetDialogButtons() const; |
118 bool HasAcceptButtonLabel() const; | 130 bool HasAcceptButtonLabel() const; |
119 base::string16 GetAcceptButtonLabel() const; | 131 base::string16 GetAcceptButtonLabel() const; |
120 bool HasAbortButtonLabel() const; | 132 bool HasAbortButtonLabel() const; |
121 base::string16 GetAbortButtonLabel() const; | 133 base::string16 GetAbortButtonLabel() const; |
122 base::string16 GetPermissionsHeading() const; | 134 base::string16 GetPermissionsHeading( |
| 135 PermissionsType permissions_type) const; |
123 base::string16 GetRetainedFilesHeading() const; | 136 base::string16 GetRetainedFilesHeading() const; |
124 | 137 |
125 bool ShouldShowPermissions() const; | 138 bool ShouldShowPermissions() const; |
126 bool ShouldShowExplanationText() const; | 139 bool ShouldShowExplanationText() const; |
127 | 140 |
128 // Getters for webstore metadata. Only populated when the type is | 141 // Getters for webstore metadata. Only populated when the type is |
129 // INLINE_INSTALL_PROMPT. | 142 // INLINE_INSTALL_PROMPT. |
130 | 143 |
131 // The star display logic replicates the one used by the webstore (from | 144 // The star display logic replicates the one used by the webstore (from |
132 // components.ratingutils.setFractionalYellowStars). Callers pass in an | 145 // components.ratingutils.setFractionalYellowStars). Callers pass in an |
133 // "appender", which will be repeatedly called back with the star images | 146 // "appender", which will be repeatedly called back with the star images |
134 // that they append to the star display area. | 147 // that they append to the star display area. |
135 typedef void(*StarAppender)(const gfx::ImageSkia*, void*); | 148 typedef void(*StarAppender)(const gfx::ImageSkia*, void*); |
136 void AppendRatingStars(StarAppender appender, void* data) const; | 149 void AppendRatingStars(StarAppender appender, void* data) const; |
137 base::string16 GetRatingCount() const; | 150 base::string16 GetRatingCount() const; |
138 base::string16 GetUserCount() const; | 151 base::string16 GetUserCount() const; |
139 size_t GetPermissionCount() const; | 152 size_t GetPermissionCount(PermissionsType permissions_type) const; |
140 size_t GetPermissionsDetailsCount() const; | 153 size_t GetPermissionsDetailsCount(PermissionsType permissions_type) const; |
141 base::string16 GetPermission(size_t index) const; | 154 base::string16 GetPermission(size_t index, |
142 base::string16 GetPermissionsDetails(size_t index) const; | 155 PermissionsType permissions_type) const; |
| 156 base::string16 GetPermissionsDetails( |
| 157 size_t index, |
| 158 PermissionsType permissions_type) const; |
143 bool GetIsShowingDetails(DetailsType type, size_t index) const; | 159 bool GetIsShowingDetails(DetailsType type, size_t index) const; |
144 size_t GetRetainedFileCount() const; | 160 size_t GetRetainedFileCount() const; |
145 base::string16 GetRetainedFile(size_t index) const; | 161 base::string16 GetRetainedFile(size_t index) const; |
146 | 162 |
147 // Populated for BUNDLE_INSTALL_PROMPT. | 163 // Populated for BUNDLE_INSTALL_PROMPT. |
148 const extensions::BundleInstaller* bundle() const { return bundle_; } | 164 const extensions::BundleInstaller* bundle() const { return bundle_; } |
149 void set_bundle(const extensions::BundleInstaller* bundle) { | 165 void set_bundle(const extensions::BundleInstaller* bundle) { |
150 bundle_ = bundle; | 166 bundle_ = bundle; |
151 } | 167 } |
152 | 168 |
(...skipping 16 matching lines...) Expand all Loading... |
169 const ExtensionInstallPromptExperiment* experiment() const { | 185 const ExtensionInstallPromptExperiment* experiment() const { |
170 return experiment_.get(); | 186 return experiment_.get(); |
171 } | 187 } |
172 void set_experiment(ExtensionInstallPromptExperiment* experiment) { | 188 void set_experiment(ExtensionInstallPromptExperiment* experiment) { |
173 experiment_ = experiment; | 189 experiment_ = experiment; |
174 } | 190 } |
175 | 191 |
176 private: | 192 private: |
177 friend class base::RefCountedThreadSafe<Prompt>; | 193 friend class base::RefCountedThreadSafe<Prompt>; |
178 | 194 |
| 195 struct InstallPromptPermissions { |
| 196 InstallPromptPermissions(); |
| 197 ~InstallPromptPermissions(); |
| 198 |
| 199 std::vector<base::string16> permissions; |
| 200 std::vector<base::string16> details; |
| 201 std::vector<bool> is_showing_details; |
| 202 }; |
| 203 |
179 virtual ~Prompt(); | 204 virtual ~Prompt(); |
180 | 205 |
| 206 // Returns the InstallPromptPermissions corresponding to |
| 207 // |permissions_type|. |
| 208 InstallPromptPermissions& GetPermissionsForType( |
| 209 PermissionsType permissions_type); |
| 210 const InstallPromptPermissions& GetPermissionsForType( |
| 211 PermissionsType permissions_type) const; |
| 212 |
181 bool ShouldDisplayRevokeFilesButton() const; | 213 bool ShouldDisplayRevokeFilesButton() const; |
182 | 214 |
183 PromptType type_; | 215 PromptType type_; |
184 | 216 |
185 // Permissions that are being requested (may not be all of an extension's | 217 // Permissions that are being requested (may not be all of an extension's |
186 // permissions if only additional ones are being requested) | 218 // permissions if only additional ones are being requested) |
187 std::vector<base::string16> permissions_; | 219 InstallPromptPermissions prompt_permissions_; |
188 std::vector<base::string16> details_; | 220 // Permissions that will be withheld upon install. |
189 std::vector<bool> is_showing_details_for_permissions_; | 221 InstallPromptPermissions withheld_prompt_permissions_; |
| 222 |
190 bool is_showing_details_for_retained_files_; | 223 bool is_showing_details_for_retained_files_; |
191 | 224 |
192 // The extension or bundle being installed. | 225 // The extension or bundle being installed. |
193 const extensions::Extension* extension_; | 226 const extensions::Extension* extension_; |
194 const extensions::BundleInstaller* bundle_; | 227 const extensions::BundleInstaller* bundle_; |
195 | 228 |
196 // The icon to be displayed. | 229 // The icon to be displayed. |
197 gfx::Image icon_; | 230 gfx::Image icon_; |
198 | 231 |
199 // These fields are populated only when the prompt type is | 232 // These fields are populated only when the prompt type is |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
398 // The extensions installation icon. | 431 // The extensions installation icon. |
399 SkBitmap icon_; | 432 SkBitmap icon_; |
400 | 433 |
401 // The extension we are showing the UI for, if type is not | 434 // The extension we are showing the UI for, if type is not |
402 // BUNDLE_INSTALL_PROMPT. | 435 // BUNDLE_INSTALL_PROMPT. |
403 const extensions::Extension* extension_; | 436 const extensions::Extension* extension_; |
404 | 437 |
405 // The bundle we are showing the UI for, if type BUNDLE_INSTALL_PROMPT. | 438 // The bundle we are showing the UI for, if type BUNDLE_INSTALL_PROMPT. |
406 const extensions::BundleInstaller* bundle_; | 439 const extensions::BundleInstaller* bundle_; |
407 | 440 |
408 // The permissions being prompted for. | 441 // A custom set of permissions to show in the install prompt instead of the |
409 scoped_refptr<const extensions::PermissionSet> permissions_; | 442 // extension's active permissions. |
| 443 scoped_refptr<const extensions::PermissionSet> custom_permissions_; |
410 | 444 |
411 // The object responsible for doing the UI specific actions. | 445 // The object responsible for doing the UI specific actions. |
412 scoped_ptr<ExtensionInstallUI> install_ui_; | 446 scoped_ptr<ExtensionInstallUI> install_ui_; |
413 | 447 |
414 // Parameters to show the confirmation UI. | 448 // Parameters to show the confirmation UI. |
415 ShowParams show_params_; | 449 ShowParams show_params_; |
416 | 450 |
417 // The delegate we will call Proceed/Abort on after confirmation UI. | 451 // The delegate we will call Proceed/Abort on after confirmation UI. |
418 Delegate* delegate_; | 452 Delegate* delegate_; |
419 | 453 |
420 // A pre-filled prompt. | 454 // A pre-filled prompt. |
421 scoped_refptr<Prompt> prompt_; | 455 scoped_refptr<Prompt> prompt_; |
422 | 456 |
423 // Used to show the confirm dialog. | 457 // Used to show the confirm dialog. |
424 ShowDialogCallback show_dialog_callback_; | 458 ShowDialogCallback show_dialog_callback_; |
425 }; | 459 }; |
426 | 460 |
427 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_INSTALL_PROMPT_H_ | 461 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_INSTALL_PROMPT_H_ |
OLD | NEW |