| 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 #include "chrome/browser/extensions/extension_disabled_ui.h" | 5 #include "chrome/browser/extensions/extension_disabled_ui.h" |
| 6 | 6 |
| 7 #include <bitset> | 7 #include <bitset> |
| 8 #include <memory> |
| 8 #include <string> | 9 #include <string> |
| 9 #include <utility> | 10 #include <utility> |
| 10 | 11 |
| 11 #include "base/bind.h" | 12 #include "base/bind.h" |
| 12 #include "base/lazy_instance.h" | 13 #include "base/lazy_instance.h" |
| 13 #include "base/location.h" | 14 #include "base/location.h" |
| 14 #include "base/macros.h" | 15 #include "base/macros.h" |
| 16 #include "base/memory/ptr_util.h" |
| 15 #include "base/memory/ref_counted.h" | 17 #include "base/memory/ref_counted.h" |
| 16 #include "base/memory/scoped_ptr.h" | |
| 17 #include "base/metrics/histogram.h" | 18 #include "base/metrics/histogram.h" |
| 18 #include "base/scoped_observer.h" | 19 #include "base/scoped_observer.h" |
| 19 #include "base/single_thread_task_runner.h" | 20 #include "base/single_thread_task_runner.h" |
| 20 #include "base/strings/string_util.h" | 21 #include "base/strings/string_util.h" |
| 21 #include "base/strings/utf_string_conversions.h" | 22 #include "base/strings/utf_string_conversions.h" |
| 22 #include "base/thread_task_runner_handle.h" | 23 #include "base/thread_task_runner_handle.h" |
| 23 #include "chrome/app/chrome_command_ids.h" | 24 #include "chrome/app/chrome_command_ids.h" |
| 24 #include "chrome/browser/extensions/extension_install_error_menu_item_id_provide
r.h" | 25 #include "chrome/browser/extensions/extension_install_error_menu_item_id_provide
r.h" |
| 25 #include "chrome/browser/extensions/extension_install_prompt.h" | 26 #include "chrome/browser/extensions/extension_install_prompt.h" |
| 26 #include "chrome/browser/extensions/extension_service.h" | 27 #include "chrome/browser/extensions/extension_service.h" |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 namespace { | 65 namespace { |
| 65 | 66 |
| 66 static const int kIconSize = extension_misc::EXTENSION_ICON_SMALL; | 67 static const int kIconSize = extension_misc::EXTENSION_ICON_SMALL; |
| 67 | 68 |
| 68 } // namespace | 69 } // namespace |
| 69 | 70 |
| 70 // ExtensionDisabledDialogDelegate -------------------------------------------- | 71 // ExtensionDisabledDialogDelegate -------------------------------------------- |
| 71 | 72 |
| 72 class ExtensionDisabledDialogDelegate { | 73 class ExtensionDisabledDialogDelegate { |
| 73 public: | 74 public: |
| 74 ExtensionDisabledDialogDelegate(ExtensionService* service, | 75 ExtensionDisabledDialogDelegate( |
| 75 scoped_ptr<ExtensionInstallPrompt> install_ui, | 76 ExtensionService* service, |
| 76 const Extension* extension); | 77 std::unique_ptr<ExtensionInstallPrompt> install_ui, |
| 78 const Extension* extension); |
| 77 | 79 |
| 78 private: | 80 private: |
| 79 ~ExtensionDisabledDialogDelegate(); | 81 ~ExtensionDisabledDialogDelegate(); |
| 80 | 82 |
| 81 void InstallPromptDone(ExtensionInstallPrompt::Result result); | 83 void InstallPromptDone(ExtensionInstallPrompt::Result result); |
| 82 | 84 |
| 83 // The UI for showing the install dialog when enabling. | 85 // The UI for showing the install dialog when enabling. |
| 84 scoped_ptr<ExtensionInstallPrompt> install_ui_; | 86 std::unique_ptr<ExtensionInstallPrompt> install_ui_; |
| 85 | 87 |
| 86 ExtensionService* service_; | 88 ExtensionService* service_; |
| 87 const Extension* extension_; | 89 const Extension* extension_; |
| 88 | 90 |
| 89 DISALLOW_COPY_AND_ASSIGN(ExtensionDisabledDialogDelegate); | 91 DISALLOW_COPY_AND_ASSIGN(ExtensionDisabledDialogDelegate); |
| 90 }; | 92 }; |
| 91 | 93 |
| 92 ExtensionDisabledDialogDelegate::ExtensionDisabledDialogDelegate( | 94 ExtensionDisabledDialogDelegate::ExtensionDisabledDialogDelegate( |
| 93 ExtensionService* service, | 95 ExtensionService* service, |
| 94 scoped_ptr<ExtensionInstallPrompt> install_ui, | 96 std::unique_ptr<ExtensionInstallPrompt> install_ui, |
| 95 const Extension* extension) | 97 const Extension* extension) |
| 96 : install_ui_(std::move(install_ui)), | 98 : install_ui_(std::move(install_ui)), |
| 97 service_(service), | 99 service_(service), |
| 98 extension_(extension) { | 100 extension_(extension) { |
| 99 ExtensionInstallPrompt::PromptType type = | 101 ExtensionInstallPrompt::PromptType type = |
| 100 ExtensionInstallPrompt::GetReEnablePromptTypeForExtension( | 102 ExtensionInstallPrompt::GetReEnablePromptTypeForExtension( |
| 101 service_->profile(), extension); | 103 service_->profile(), extension); |
| 102 // Unretained() is safe since this object manages its own lifetime and deletes | 104 // Unretained() is safe since this object manages its own lifetime and deletes |
| 103 // itself only once the prompt finishes. | 105 // itself only once the prompt finishes. |
| 104 install_ui_->ShowDialog( | 106 install_ui_->ShowDialog( |
| 105 base::Bind(&ExtensionDisabledDialogDelegate::InstallPromptDone, | 107 base::Bind(&ExtensionDisabledDialogDelegate::InstallPromptDone, |
| 106 base::Unretained(this)), | 108 base::Unretained(this)), |
| 107 extension_, nullptr, | 109 extension_, nullptr, |
| 108 make_scoped_ptr(new ExtensionInstallPrompt::Prompt(type)), | 110 base::WrapUnique(new ExtensionInstallPrompt::Prompt(type)), |
| 109 ExtensionInstallPrompt::GetDefaultShowDialogCallback()); | 111 ExtensionInstallPrompt::GetDefaultShowDialogCallback()); |
| 110 } | 112 } |
| 111 | 113 |
| 112 ExtensionDisabledDialogDelegate::~ExtensionDisabledDialogDelegate() { | 114 ExtensionDisabledDialogDelegate::~ExtensionDisabledDialogDelegate() { |
| 113 } | 115 } |
| 114 | 116 |
| 115 void ExtensionDisabledDialogDelegate::InstallPromptDone( | 117 void ExtensionDisabledDialogDelegate::InstallPromptDone( |
| 116 ExtensionInstallPrompt::Result result) { | 118 ExtensionInstallPrompt::Result result) { |
| 117 if (result == ExtensionInstallPrompt::Result::ACCEPTED) { | 119 if (result == ExtensionInstallPrompt::Result::ACCEPTED) { |
| 118 service_->GrantPermissionsAndEnableExtension(extension_); | 120 service_->GrantPermissionsAndEnableExtension(extension_); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 | 186 |
| 185 // How the user responded to the error; used for metrics. | 187 // How the user responded to the error; used for metrics. |
| 186 enum UserResponse { | 188 enum UserResponse { |
| 187 IGNORED, | 189 IGNORED, |
| 188 REENABLE, | 190 REENABLE, |
| 189 UNINSTALL, | 191 UNINSTALL, |
| 190 EXTENSION_DISABLED_UI_BUCKET_BOUNDARY | 192 EXTENSION_DISABLED_UI_BUCKET_BOUNDARY |
| 191 }; | 193 }; |
| 192 UserResponse user_response_; | 194 UserResponse user_response_; |
| 193 | 195 |
| 194 scoped_ptr<extensions::ExtensionUninstallDialog> uninstall_dialog_; | 196 std::unique_ptr<extensions::ExtensionUninstallDialog> uninstall_dialog_; |
| 195 | 197 |
| 196 // Helper to get menu command ID assigned for this extension's error. | 198 // Helper to get menu command ID assigned for this extension's error. |
| 197 extensions::ExtensionInstallErrorMenuItemIdProvider id_provider_; | 199 extensions::ExtensionInstallErrorMenuItemIdProvider id_provider_; |
| 198 | 200 |
| 199 content::NotificationRegistrar registrar_; | 201 content::NotificationRegistrar registrar_; |
| 200 | 202 |
| 201 ScopedObserver<extensions::ExtensionRegistry, | 203 ScopedObserver<extensions::ExtensionRegistry, |
| 202 extensions::ExtensionRegistryObserver> registry_observer_; | 204 extensions::ExtensionRegistryObserver> registry_observer_; |
| 203 }; | 205 }; |
| 204 | 206 |
| (...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 487 size, | 489 size, |
| 488 base::Bind(&AddExtensionDisabledErrorWithIcon, | 490 base::Bind(&AddExtensionDisabledErrorWithIcon, |
| 489 service->AsWeakPtr(), | 491 service->AsWeakPtr(), |
| 490 extension->id(), | 492 extension->id(), |
| 491 is_remote_install)); | 493 is_remote_install)); |
| 492 } | 494 } |
| 493 | 495 |
| 494 void ShowExtensionDisabledDialog(ExtensionService* service, | 496 void ShowExtensionDisabledDialog(ExtensionService* service, |
| 495 content::WebContents* web_contents, | 497 content::WebContents* web_contents, |
| 496 const Extension* extension) { | 498 const Extension* extension) { |
| 497 scoped_ptr<ExtensionInstallPrompt> install_ui( | 499 std::unique_ptr<ExtensionInstallPrompt> install_ui( |
| 498 new ExtensionInstallPrompt(web_contents)); | 500 new ExtensionInstallPrompt(web_contents)); |
| 499 // This object manages its own lifetime. | 501 // This object manages its own lifetime. |
| 500 new ExtensionDisabledDialogDelegate(service, std::move(install_ui), | 502 new ExtensionDisabledDialogDelegate(service, std::move(install_ui), |
| 501 extension); | 503 extension); |
| 502 } | 504 } |
| 503 | 505 |
| 504 } // namespace extensions | 506 } // namespace extensions |
| OLD | NEW |