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 |
11 #include "base/callback.h" | 11 #include "base/callback.h" |
12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
13 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
| 14 #include "base/memory/ref_counted.h" |
14 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
15 #include "base/memory/weak_ptr.h" | 16 #include "base/memory/weak_ptr.h" |
16 #include "base/strings/string16.h" | 17 #include "base/strings/string16.h" |
17 #include "chrome/browser/extensions/crx_installer_error.h" | 18 #include "chrome/browser/extensions/crx_installer_error.h" |
18 #include "chrome/browser/extensions/extension_install_prompt_experiment.h" | 19 #include "chrome/browser/extensions/extension_install_prompt_experiment.h" |
19 #include "extensions/common/url_pattern.h" | 20 #include "extensions/common/url_pattern.h" |
20 #include "third_party/skia/include/core/SkBitmap.h" | 21 #include "third_party/skia/include/core/SkBitmap.h" |
21 #include "ui/gfx/image/image.h" | 22 #include "ui/gfx/image/image.h" |
22 #include "ui/gfx/image/image_skia.h" | 23 #include "ui/gfx/image/image_skia.h" |
23 #include "ui/gfx/native_widget_types.h" | 24 #include "ui/gfx/native_widget_types.h" |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 | 71 |
71 enum DetailsType { | 72 enum DetailsType { |
72 PERMISSIONS_DETAILS = 0, | 73 PERMISSIONS_DETAILS = 0, |
73 RETAINED_FILES_DETAILS, | 74 RETAINED_FILES_DETAILS, |
74 }; | 75 }; |
75 | 76 |
76 // Extra information needed to display an installation or uninstallation | 77 // Extra information needed to display an installation or uninstallation |
77 // prompt. Gets populated with raw data and exposes getters for formatted | 78 // prompt. Gets populated with raw data and exposes getters for formatted |
78 // strings so that the GTK/views/Cocoa install dialogs don't have to repeat | 79 // strings so that the GTK/views/Cocoa install dialogs don't have to repeat |
79 // that logic. | 80 // that logic. |
80 class Prompt { | 81 // Ref-counted because we pass around the prompt independent of the full |
| 82 // ExtensionInstallPrompt. |
| 83 class Prompt : public base::RefCountedThreadSafe<Prompt> { |
81 public: | 84 public: |
82 explicit Prompt(PromptType type); | 85 explicit Prompt(PromptType type); |
83 ~Prompt(); | |
84 | 86 |
85 // Sets the permission list for this prompt. | 87 // Sets the permission list for this prompt. |
86 void SetPermissions(const std::vector<base::string16>& permissions); | 88 void SetPermissions(const std::vector<base::string16>& permissions); |
87 // Sets the permission list details for this prompt. | 89 // Sets the permission list details for this prompt. |
88 void SetPermissionsDetails(const std::vector<base::string16>& details); | 90 void SetPermissionsDetails(const std::vector<base::string16>& details); |
89 void SetIsShowingDetails(DetailsType type, | 91 void SetIsShowingDetails(DetailsType type, |
90 size_t index, | 92 size_t index, |
91 bool is_showing_details); | 93 bool is_showing_details); |
92 void SetWebstoreData(const std::string& localized_user_count, | 94 void SetWebstoreData(const std::string& localized_user_count, |
93 bool show_user_count, | 95 bool show_user_count, |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 bool has_webstore_data() const { return has_webstore_data_; } | 156 bool has_webstore_data() const { return has_webstore_data_; } |
155 | 157 |
156 const ExtensionInstallPromptExperiment* experiment() const { | 158 const ExtensionInstallPromptExperiment* experiment() const { |
157 return experiment_; | 159 return experiment_; |
158 } | 160 } |
159 void set_experiment(ExtensionInstallPromptExperiment* experiment) { | 161 void set_experiment(ExtensionInstallPromptExperiment* experiment) { |
160 experiment_ = experiment; | 162 experiment_ = experiment; |
161 } | 163 } |
162 | 164 |
163 private: | 165 private: |
| 166 friend class base::RefCountedThreadSafe<Prompt>; |
| 167 |
| 168 virtual ~Prompt(); |
| 169 |
164 bool ShouldDisplayRevokeFilesButton() const; | 170 bool ShouldDisplayRevokeFilesButton() const; |
165 | 171 |
166 PromptType type_; | 172 PromptType type_; |
167 | 173 |
168 // Permissions that are being requested (may not be all of an extension's | 174 // Permissions that are being requested (may not be all of an extension's |
169 // permissions if only additional ones are being requested) | 175 // permissions if only additional ones are being requested) |
170 std::vector<base::string16> permissions_; | 176 std::vector<base::string16> permissions_; |
171 std::vector<base::string16> details_; | 177 std::vector<base::string16> details_; |
172 std::vector<bool> is_showing_details_for_permissions_; | 178 std::vector<bool> is_showing_details_for_permissions_; |
173 bool is_showing_details_for_retained_files_; | 179 bool is_showing_details_for_retained_files_; |
(...skipping 17 matching lines...) Expand all Loading... |
191 // false if localized_user_count_ represents the number zero). | 197 // false if localized_user_count_ represents the number zero). |
192 bool show_user_count_; | 198 bool show_user_count_; |
193 | 199 |
194 // Whether or not this prompt has been populated with data from the | 200 // Whether or not this prompt has been populated with data from the |
195 // webstore. | 201 // webstore. |
196 bool has_webstore_data_; | 202 bool has_webstore_data_; |
197 | 203 |
198 std::vector<base::FilePath> retained_files_; | 204 std::vector<base::FilePath> retained_files_; |
199 | 205 |
200 scoped_refptr<ExtensionInstallPromptExperiment> experiment_; | 206 scoped_refptr<ExtensionInstallPromptExperiment> experiment_; |
| 207 |
| 208 DISALLOW_COPY_AND_ASSIGN(Prompt); |
201 }; | 209 }; |
202 | 210 |
203 static const int kMinExtensionRating = 0; | 211 static const int kMinExtensionRating = 0; |
204 static const int kMaxExtensionRating = 5; | 212 static const int kMaxExtensionRating = 5; |
205 | 213 |
206 class Delegate { | 214 class Delegate { |
207 public: | 215 public: |
208 // We call this method to signal that the installation should continue. | 216 // We call this method to signal that the installation should continue. |
209 virtual void InstallUIProceed() = 0; | 217 virtual void InstallUIProceed() = 0; |
210 | 218 |
(...skipping 16 matching lines...) Expand all Loading... |
227 content::WebContents* parent_web_contents; | 235 content::WebContents* parent_web_contents; |
228 | 236 |
229 // NativeWindow parent and navigator. If initialized using a parent web | 237 // NativeWindow parent and navigator. If initialized using a parent web |
230 // contents, these are derived from it. | 238 // contents, these are derived from it. |
231 gfx::NativeWindow parent_window; | 239 gfx::NativeWindow parent_window; |
232 content::PageNavigator* navigator; | 240 content::PageNavigator* navigator; |
233 }; | 241 }; |
234 | 242 |
235 typedef base::Callback<void(const ExtensionInstallPrompt::ShowParams&, | 243 typedef base::Callback<void(const ExtensionInstallPrompt::ShowParams&, |
236 ExtensionInstallPrompt::Delegate*, | 244 ExtensionInstallPrompt::Delegate*, |
237 const ExtensionInstallPrompt::Prompt&)> | 245 scoped_refptr<ExtensionInstallPrompt::Prompt>)> |
238 ShowDialogCallback; | 246 ShowDialogCallback; |
239 | 247 |
240 // Callback to show the default extension install dialog. | 248 // Callback to show the default extension install dialog. |
241 // The implementations of this function are platform-specific. | 249 // The implementations of this function are platform-specific. |
242 static ShowDialogCallback GetDefaultShowDialogCallback(); | 250 static ShowDialogCallback GetDefaultShowDialogCallback(); |
243 | 251 |
244 // Creates a dummy extension from the |manifest|, replacing the name and | 252 // Creates a dummy extension from the |manifest|, replacing the name and |
245 // description with the localizations if provided. | 253 // description with the localizations if provided. |
246 static scoped_refptr<extensions::Extension> GetLocalizedExtensionForDisplay( | 254 static scoped_refptr<extensions::Extension> GetLocalizedExtensionForDisplay( |
247 const base::DictionaryValue* manifest, | 255 const base::DictionaryValue* manifest, |
(...skipping 27 matching lines...) Expand all Loading... |
275 extensions::BundleInstaller* bundle, | 283 extensions::BundleInstaller* bundle, |
276 const extensions::PermissionSet* permissions); | 284 const extensions::PermissionSet* permissions); |
277 | 285 |
278 // This is called by the standalone installer to verify whether the install | 286 // This is called by the standalone installer to verify whether the install |
279 // from the webstore should proceed. | 287 // from the webstore should proceed. |
280 // | 288 // |
281 // We *MUST* eventually call either Proceed() or Abort() on |delegate|. | 289 // We *MUST* eventually call either Proceed() or Abort() on |delegate|. |
282 virtual void ConfirmStandaloneInstall(Delegate* delegate, | 290 virtual void ConfirmStandaloneInstall(Delegate* delegate, |
283 const extensions::Extension* extension, | 291 const extensions::Extension* extension, |
284 SkBitmap* icon, | 292 SkBitmap* icon, |
285 const Prompt& prompt); | 293 scoped_refptr<Prompt> prompt); |
286 | 294 |
287 // This is called by the installer to verify whether the installation from | 295 // This is called by the installer to verify whether the installation from |
288 // the webstore should proceed. |show_dialog_callback| is optional and can be | 296 // the webstore should proceed. |show_dialog_callback| is optional and can be |
289 // NULL. | 297 // NULL. |
290 // | 298 // |
291 // We *MUST* eventually call either Proceed() or Abort() on |delegate|. | 299 // We *MUST* eventually call either Proceed() or Abort() on |delegate|. |
292 virtual void ConfirmWebstoreInstall( | 300 virtual void ConfirmWebstoreInstall( |
293 Delegate* delegate, | 301 Delegate* delegate, |
294 const extensions::Extension* extension, | 302 const extensions::Extension* extension, |
295 const SkBitmap* icon, | 303 const SkBitmap* icon, |
(...skipping 16 matching lines...) Expand all Loading... |
312 const extensions::Extension* extension); | 320 const extensions::Extension* extension); |
313 | 321 |
314 // This is called by the external install alert UI to verify whether the | 322 // This is called by the external install alert UI to verify whether the |
315 // extension should be enabled (external extensions are installed disabled). | 323 // extension should be enabled (external extensions are installed disabled). |
316 // | 324 // |
317 // We *MUST* eventually call either Proceed() or Abort() on |delegate|. | 325 // We *MUST* eventually call either Proceed() or Abort() on |delegate|. |
318 virtual void ConfirmExternalInstall( | 326 virtual void ConfirmExternalInstall( |
319 Delegate* delegate, | 327 Delegate* delegate, |
320 const extensions::Extension* extension, | 328 const extensions::Extension* extension, |
321 const ShowDialogCallback& show_dialog_callback, | 329 const ShowDialogCallback& show_dialog_callback, |
322 const Prompt& prompt); | 330 scoped_refptr<Prompt> prompt); |
323 | 331 |
324 // This is called by the extension permissions API to verify whether an | 332 // This is called by the extension permissions API to verify whether an |
325 // extension may be granted additional permissions. | 333 // extension may be granted additional permissions. |
326 // | 334 // |
327 // We *MUST* eventually call either Proceed() or Abort() on |delegate|. | 335 // We *MUST* eventually call either Proceed() or Abort() on |delegate|. |
328 virtual void ConfirmPermissions(Delegate* delegate, | 336 virtual void ConfirmPermissions(Delegate* delegate, |
329 const extensions::Extension* extension, | 337 const extensions::Extension* extension, |
330 const extensions::PermissionSet* permissions); | 338 const extensions::PermissionSet* permissions); |
331 | 339 |
332 // This is called by the app handler launcher to review what permissions the | 340 // This is called by the app handler launcher to review what permissions the |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
388 // The object responsible for doing the UI specific actions. | 396 // The object responsible for doing the UI specific actions. |
389 scoped_ptr<ExtensionInstallUI> install_ui_; | 397 scoped_ptr<ExtensionInstallUI> install_ui_; |
390 | 398 |
391 // Parameters to show the confirmation UI. | 399 // Parameters to show the confirmation UI. |
392 ShowParams show_params_; | 400 ShowParams show_params_; |
393 | 401 |
394 // The delegate we will call Proceed/Abort on after confirmation UI. | 402 // The delegate we will call Proceed/Abort on after confirmation UI. |
395 Delegate* delegate_; | 403 Delegate* delegate_; |
396 | 404 |
397 // A pre-filled prompt. | 405 // A pre-filled prompt. |
398 Prompt prompt_; | 406 scoped_refptr<Prompt> prompt_; |
399 | 407 |
400 // Used to show the confirm dialog. | 408 // Used to show the confirm dialog. |
401 ShowDialogCallback show_dialog_callback_; | 409 ShowDialogCallback show_dialog_callback_; |
402 }; | 410 }; |
403 | 411 |
404 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_INSTALL_PROMPT_H_ | 412 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_INSTALL_PROMPT_H_ |
OLD | NEW |