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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 enum DetailsType { | 81 enum DetailsType { |
82 PERMISSIONS_DETAILS = 0, | 82 PERMISSIONS_DETAILS = 0, |
83 WITHHELD_PERMISSIONS_DETAILS, | |
83 RETAINED_FILES_DETAILS, | 84 RETAINED_FILES_DETAILS, |
84 }; | 85 }; |
85 | 86 |
87 enum PermissionsType { | |
88 REGULAR_PERMISSIONS = 0, | |
89 WITHHELD_PERMISSIONS, | |
90 ALL_PERMISSIONS, | |
91 }; | |
92 | |
86 static std::string PromptTypeToString(PromptType type); | 93 static std::string PromptTypeToString(PromptType type); |
87 | 94 |
88 // Extra information needed to display an installation or uninstallation | 95 // Extra information needed to display an installation or uninstallation |
89 // prompt. Gets populated with raw data and exposes getters for formatted | 96 // 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 | 97 // strings so that the GTK/views/Cocoa install dialogs don't have to repeat |
91 // that logic. | 98 // that logic. |
92 // Ref-counted because we pass around the prompt independent of the full | 99 // Ref-counted because we pass around the prompt independent of the full |
93 // ExtensionInstallPrompt. | 100 // ExtensionInstallPrompt. |
94 class Prompt : public base::RefCountedThreadSafe<Prompt> { | 101 class Prompt : public base::RefCountedThreadSafe<Prompt> { |
95 public: | 102 public: |
96 explicit Prompt(PromptType type); | 103 explicit Prompt(PromptType type); |
97 | 104 |
98 // Sets the permission list for this prompt. | 105 // Sets the permission list for this prompt. |
99 void SetPermissions(const std::vector<base::string16>& permissions); | 106 void SetPermissions(const std::vector<base::string16>& permissions, |
107 PermissionsType permissions_type); | |
100 // Sets the permission list details for this prompt. | 108 // Sets the permission list details for this prompt. |
101 void SetPermissionsDetails(const std::vector<base::string16>& details); | 109 void SetPermissionsDetails(const std::vector<base::string16>& details, |
110 PermissionsType permissions_type); | |
102 void SetIsShowingDetails(DetailsType type, | 111 void SetIsShowingDetails(DetailsType type, |
103 size_t index, | 112 size_t index, |
104 bool is_showing_details); | 113 bool is_showing_details); |
105 void SetWebstoreData(const std::string& localized_user_count, | 114 void SetWebstoreData(const std::string& localized_user_count, |
106 bool show_user_count, | 115 bool show_user_count, |
107 double average_rating, | 116 double average_rating, |
108 int rating_count); | 117 int rating_count); |
109 void SetUserNameFromProfile(Profile* profile); | 118 void SetUserNameFromProfile(Profile* profile); |
110 | 119 |
111 PromptType type() const { return type_; } | 120 PromptType type() const { return type_; } |
112 void set_type(PromptType type) { type_ = type; } | 121 void set_type(PromptType type) { type_ = type; } |
113 | 122 |
114 // Getters for UI element labels. | 123 // Getters for UI element labels. |
115 base::string16 GetDialogTitle() const; | 124 base::string16 GetDialogTitle() const; |
116 base::string16 GetHeading() const; | 125 base::string16 GetHeading() const; |
117 int GetDialogButtons() const; | 126 int GetDialogButtons() const; |
118 bool HasAcceptButtonLabel() const; | 127 bool HasAcceptButtonLabel() const; |
119 base::string16 GetAcceptButtonLabel() const; | 128 base::string16 GetAcceptButtonLabel() const; |
120 bool HasAbortButtonLabel() const; | 129 bool HasAbortButtonLabel() const; |
121 base::string16 GetAbortButtonLabel() const; | 130 base::string16 GetAbortButtonLabel() const; |
122 base::string16 GetPermissionsHeading() const; | 131 base::string16 GetPermissionsHeading( |
132 PermissionsType permissions_type) const; | |
123 base::string16 GetRetainedFilesHeading() const; | 133 base::string16 GetRetainedFilesHeading() const; |
124 | 134 |
125 bool ShouldShowPermissions() const; | 135 bool ShouldShowPermissions() const; |
126 bool ShouldShowExplanationText() const; | 136 bool ShouldShowExplanationText() const; |
127 | 137 |
128 // Getters for webstore metadata. Only populated when the type is | 138 // Getters for webstore metadata. Only populated when the type is |
129 // INLINE_INSTALL_PROMPT. | 139 // INLINE_INSTALL_PROMPT. |
130 | 140 |
131 // The star display logic replicates the one used by the webstore (from | 141 // The star display logic replicates the one used by the webstore (from |
132 // components.ratingutils.setFractionalYellowStars). Callers pass in an | 142 // components.ratingutils.setFractionalYellowStars). Callers pass in an |
133 // "appender", which will be repeatedly called back with the star images | 143 // "appender", which will be repeatedly called back with the star images |
134 // that they append to the star display area. | 144 // that they append to the star display area. |
135 typedef void(*StarAppender)(const gfx::ImageSkia*, void*); | 145 typedef void(*StarAppender)(const gfx::ImageSkia*, void*); |
136 void AppendRatingStars(StarAppender appender, void* data) const; | 146 void AppendRatingStars(StarAppender appender, void* data) const; |
137 base::string16 GetRatingCount() const; | 147 base::string16 GetRatingCount() const; |
138 base::string16 GetUserCount() const; | 148 base::string16 GetUserCount() const; |
139 size_t GetPermissionCount() const; | 149 size_t GetPermissionCount(PermissionsType permissions_type) const; |
140 size_t GetPermissionsDetailsCount() const; | 150 size_t GetPermissionsDetailsCount(PermissionsType permissions_type) const; |
141 base::string16 GetPermission(size_t index) const; | 151 base::string16 GetPermission(size_t index, |
142 base::string16 GetPermissionsDetails(size_t index) const; | 152 PermissionsType permissions_type) const; |
153 base::string16 GetPermissionsDetails( | |
154 size_t index, | |
155 PermissionsType permissions_type) const; | |
143 bool GetIsShowingDetails(DetailsType type, size_t index) const; | 156 bool GetIsShowingDetails(DetailsType type, size_t index) const; |
144 size_t GetRetainedFileCount() const; | 157 size_t GetRetainedFileCount() const; |
145 base::string16 GetRetainedFile(size_t index) const; | 158 base::string16 GetRetainedFile(size_t index) const; |
146 | 159 |
147 // Populated for BUNDLE_INSTALL_PROMPT. | 160 // Populated for BUNDLE_INSTALL_PROMPT. |
148 const extensions::BundleInstaller* bundle() const { return bundle_; } | 161 const extensions::BundleInstaller* bundle() const { return bundle_; } |
149 void set_bundle(const extensions::BundleInstaller* bundle) { | 162 void set_bundle(const extensions::BundleInstaller* bundle) { |
150 bundle_ = bundle; | 163 bundle_ = bundle; |
151 } | 164 } |
152 | 165 |
(...skipping 14 matching lines...) Expand all Loading... | |
167 bool has_webstore_data() const { return has_webstore_data_; } | 180 bool has_webstore_data() const { return has_webstore_data_; } |
168 | 181 |
169 const ExtensionInstallPromptExperiment* experiment() const { | 182 const ExtensionInstallPromptExperiment* experiment() const { |
170 return experiment_.get(); | 183 return experiment_.get(); |
171 } | 184 } |
172 void set_experiment(ExtensionInstallPromptExperiment* experiment) { | 185 void set_experiment(ExtensionInstallPromptExperiment* experiment) { |
173 experiment_ = experiment; | 186 experiment_ = experiment; |
174 } | 187 } |
175 | 188 |
176 private: | 189 private: |
190 struct PermissionsInfo { | |
Devlin
2014/09/04 22:06:08
We already have a PermissionsInfo, so this may be
gpdavis
2014/09/05 20:23:01
Done.
| |
191 PermissionsInfo(); | |
192 ~PermissionsInfo(); | |
Devlin
2014/09/04 22:06:08
nit: newline between destructor and members.
gpdavis
2014/09/05 20:23:01
Done.
| |
193 std::vector<base::string16> permissions; | |
194 std::vector<base::string16> details; | |
195 std::vector<bool> is_showing_details; | |
196 }; | |
197 | |
177 friend class base::RefCountedThreadSafe<Prompt>; | 198 friend class base::RefCountedThreadSafe<Prompt>; |
Devlin
2014/09/04 22:06:08
nit: leave friend class above the struct.
gpdavis
2014/09/05 20:23:02
Done.
| |
178 | 199 |
179 virtual ~Prompt(); | 200 virtual ~Prompt(); |
180 | 201 |
181 bool ShouldDisplayRevokeFilesButton() const; | 202 bool ShouldDisplayRevokeFilesButton() const; |
182 | 203 |
183 PromptType type_; | 204 PromptType type_; |
184 | 205 |
185 // Permissions that are being requested (may not be all of an extension's | 206 // Permissions that are being requested (may not be all of an extension's |
186 // permissions if only additional ones are being requested) | 207 // permissions if only additional ones are being requested) |
187 std::vector<base::string16> permissions_; | 208 PermissionsInfo permissions_info_; |
188 std::vector<base::string16> details_; | 209 // Permissions that will be withheld upon install. |
189 std::vector<bool> is_showing_details_for_permissions_; | 210 PermissionsInfo withheld_permissions_info_; |
211 | |
190 bool is_showing_details_for_retained_files_; | 212 bool is_showing_details_for_retained_files_; |
191 | 213 |
192 // The extension or bundle being installed. | 214 // The extension or bundle being installed. |
193 const extensions::Extension* extension_; | 215 const extensions::Extension* extension_; |
194 const extensions::BundleInstaller* bundle_; | 216 const extensions::BundleInstaller* bundle_; |
195 | 217 |
196 // The icon to be displayed. | 218 // The icon to be displayed. |
197 gfx::Image icon_; | 219 gfx::Image icon_; |
198 | 220 |
199 // These fields are populated only when the prompt type is | 221 // These fields are populated only when the prompt type is |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
418 Delegate* delegate_; | 440 Delegate* delegate_; |
419 | 441 |
420 // A pre-filled prompt. | 442 // A pre-filled prompt. |
421 scoped_refptr<Prompt> prompt_; | 443 scoped_refptr<Prompt> prompt_; |
422 | 444 |
423 // Used to show the confirm dialog. | 445 // Used to show the confirm dialog. |
424 ShowDialogCallback show_dialog_callback_; | 446 ShowDialogCallback show_dialog_callback_; |
425 }; | 447 }; |
426 | 448 |
427 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_INSTALL_PROMPT_H_ | 449 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_INSTALL_PROMPT_H_ |
OLD | NEW |