Chromium Code Reviews| Index: chrome/browser/ui/webui/extensions/extension_settings_handler.cc |
| diff --git a/chrome/browser/ui/webui/extensions/extension_settings_handler.cc b/chrome/browser/ui/webui/extensions/extension_settings_handler.cc |
| index 1605be8e34c3544b53109b4e68bceeae01e27ec9..01fa7bc3ea79b0411a19ad467da8a2dc2a0b180e 100644 |
| --- a/chrome/browser/ui/webui/extensions/extension_settings_handler.cc |
| +++ b/chrome/browser/ui/webui/extensions/extension_settings_handler.cc |
| @@ -29,6 +29,7 @@ |
| #include "chrome/browser/profiles/profile.h" |
| #include "chrome/browser/tab_contents/background_contents.h" |
| #include "chrome/browser/ui/browser_finder.h" |
| +#include "chrome/browser/ui/extensions/application_launch.h" |
| #include "chrome/browser/ui/webui/extensions/extension_icon_source.h" |
| #include "chrome/browser/view_type_utils.h" |
| #include "chrome/common/chrome_notification_types.h" |
| @@ -71,7 +72,8 @@ ExtensionSettingsHandler::ExtensionSettingsHandler() |
| management_policy_(NULL), |
| ignore_notifications_(false), |
| deleting_rvh_(NULL), |
| - registered_for_notifications_(false) { |
| + registered_for_notifications_(false), |
| + ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { |
| } |
| ExtensionSettingsHandler::~ExtensionSettingsHandler() { |
| @@ -89,7 +91,8 @@ ExtensionSettingsHandler::ExtensionSettingsHandler(ExtensionService* service, |
| management_policy_(policy), |
| ignore_notifications_(false), |
| deleting_rvh_(NULL), |
| - registered_for_notifications_(false) { |
| + registered_for_notifications_(false), |
| + ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { |
| } |
| // static |
| @@ -396,10 +399,32 @@ void ExtensionSettingsHandler::Observe( |
| case chrome::NOTIFICATION_EXTENSION_HOST_CREATED: |
| source_profile = content::Source<Profile>(source).ptr(); |
| if (!profile->IsSameProfile(source_profile)) |
| - return; |
| + return; |
| MaybeUpdateAfterNotification(); |
| break; |
| - case chrome::NOTIFICATION_EXTENSION_LOADED: |
| + case chrome::NOTIFICATION_EXTENSION_LOADED: { |
| + source_profile = content::Source<Profile>(source).ptr(); |
| + const Extension* extension = |
| + content::Details<const Extension>(details).ptr(); |
| + std::list<std::string>::iterator iter = |
| + std::find(relaunch_app_ids_.begin(), relaunch_app_ids_.end(), |
| + extension->id()); |
| + |
| + if (profile->IsSameProfile(source_profile) && |
| + iter != relaunch_app_ids_.end()) { |
| + relaunch_app_ids_.erase(iter); |
| + extensions::LazyBackgroundTaskQueue* queue = |
| + ExtensionSystem::Get(profile)->lazy_background_task_queue(); |
| + if (queue->ShouldEnqueueTask(profile, extension)) { |
|
Evan Stade
2012/06/22 22:29:50
you would expect this to work, but it doesn't, bec
|
| + queue->AddPendingTask(profile, extension->id(), |
| + base::Bind(&ExtensionSettingsHandler::LaunchApplication, |
| + weak_factory_.GetWeakPtr())); |
| + } |
| + } |
| + |
| + MaybeUpdateAfterNotification(); |
| + break; |
| + } |
| case chrome::NOTIFICATION_EXTENSION_UNLOADED: |
| case chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED: |
| case chrome::NOTIFICATION_EXTENSION_WARNING_CHANGED: |
| @@ -412,6 +437,21 @@ void ExtensionSettingsHandler::Observe( |
| } |
| } |
| +void ExtensionSettingsHandler::LaunchApplication( |
| + ExtensionHost* extension_host) { |
| + if (!extension_host) |
| + return; |
| + |
| + const Extension* extension = extension_host->extension(); |
| + extension_misc::LaunchContainer launch_container = |
| + extension_service_->extension_prefs()->GetLaunchContainer( |
| + extension, ExtensionPrefs::LAUNCH_REGULAR); |
| + |
| + application_launch::OpenApplication( |
| + extension_service_->profile(), extension, launch_container, GURL(), |
| + NEW_BACKGROUND_TAB, NULL); |
| +} |
| + |
| void ExtensionSettingsHandler::ExtensionUninstallAccepted() { |
| DCHECK(!extension_id_prompting_.empty()); |
| @@ -455,10 +495,23 @@ void ExtensionSettingsHandler::ReloadUnpackedExtensions() { |
| for (std::vector<const Extension*>::iterator iter = |
| unpacked_extensions.begin(); iter != unpacked_extensions.end(); ++iter) { |
| - extension_service_->ReloadExtension((*iter)->id()); |
| + ReloadExtension(*iter); |
| } |
| } |
| +void ExtensionSettingsHandler::ReloadExtension(const Extension* extension) { |
| + Profile* profile = Profile::FromWebUI(web_ui()); |
| + // If the extension is a platform app, and is "running" (i.e. has at least one |
| + // open render view), then mark it for relaunch later. |
| + if (extension->is_platform_app() && |
| + !profile->GetExtensionProcessManager()-> |
| + GetRenderViewHostsWithTypeForExtension( |
| + extension->id(), chrome::VIEW_TYPE_APP_SHELL).empty()) { |
| + relaunch_app_ids_.push_back(extension->id()); |
| + } |
| + extension_service_->ReloadExtension(extension->id()); |
| +} |
| + |
| void ExtensionSettingsHandler::HandleRequestExtensionsData( |
| const ListValue* args) { |
| DictionaryValue results; |
| @@ -581,7 +634,10 @@ void ExtensionSettingsHandler::HandleInspectMessage(const ListValue* args) { |
| void ExtensionSettingsHandler::HandleReloadMessage(const ListValue* args) { |
| std::string extension_id = UTF16ToUTF8(ExtractStringValue(args)); |
| CHECK(!extension_id.empty()); |
| - extension_service_->ReloadExtension(extension_id); |
| + |
| + const Extension* extension = |
| + extension_service_->GetExtensionById(extension_id, false); |
| + ReloadExtension(extension); |
| } |
| void ExtensionSettingsHandler::HandleEnableMessage(const ListValue* args) { |