Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2939)

Unified Diff: chrome/browser/ui/webui/extensions/extension_settings_handler.cc

Issue 10641017: make "reload" on chrome://extensions automatically relaunch running apps (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: hack Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/ui/webui/extensions/extension_settings_handler.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 163ffdf3b8cf918fd8e800834fb2462fbebc9f75..670255b5f55299a5902bdc550b624029e6aa9f96 100644
--- a/chrome/browser/ui/webui/extensions/extension_settings_handler.cc
+++ b/chrome/browser/ui/webui/extensions/extension_settings_handler.cc
@@ -23,6 +23,8 @@
#include "chrome/browser/extensions/extension_system.h"
#include "chrome/browser/extensions/extension_warning_set.h"
#include "chrome/browser/extensions/lazy_background_task_queue.h"
+#include "chrome/browser/extensions/platform_app_launcher.h"
+#include "chrome/browser/extensions/shell_window_registry.h"
#include "chrome/browser/extensions/unpacked_installer.h"
#include "chrome/browser/extensions/updater/extension_updater.h"
#include "chrome/browser/google/google_util.h"
@@ -32,6 +34,7 @@
#include "chrome/browser/tab_contents/background_contents.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/chrome_select_file_policy.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"
@@ -75,7 +78,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() {
@@ -93,7 +97,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
@@ -404,10 +409,40 @@ 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_ENABLED: {
+ const Extension* extension =
+ content::Details<const Extension>(details).ptr();
+ RelaunchApps::iterator iter = relaunch_app_ids_.find(extension->id());
+ if (iter != relaunch_app_ids_.end())
+ iter->second = true;
+
+ break;
+ }
+ case chrome::NOTIFICATION_EXTENSION_LOADED: {
+ const Extension* extension =
+ content::Details<const Extension>(details).ptr();
+ RelaunchApps::iterator iter = relaunch_app_ids_.find(extension->id());
+
+ if (profile->IsSameProfile(source_profile) &&
+ iter != relaunch_app_ids_.end() &&
+ iter->second) {
+ relaunch_app_ids_.erase(iter);
+ extensions::LazyBackgroundTaskQueue* queue =
+ extensions::ExtensionSystem::Get(profile)->
+ lazy_background_task_queue();
+ if (queue->ShouldEnqueueTask(profile, extension)) {
+ queue->AddPendingTask(profile, extension->id(),
+ base::Bind(&ExtensionSettingsHandler::LaunchApplication,
+ weak_factory_.GetWeakPtr()));
Mihai Parparita -not on Chrome 2012/08/21 22:38:35 You can get both the Extension and Profile instanc
+ }
+ }
+
MaybeUpdateAfterNotification();
break;
- case chrome::NOTIFICATION_EXTENSION_LOADED:
+ }
case chrome::NOTIFICATION_EXTENSION_UNLOADED:
case chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED:
case chrome::NOTIFICATION_EXTENSION_WARNING_CHANGED:
@@ -420,6 +455,16 @@ void ExtensionSettingsHandler::Observe(
}
}
+void ExtensionSettingsHandler::LaunchApplication(
+ extensions::ExtensionHost* extension_host) {
+ if (!extension_host)
+ return;
+
+ const Extension* extension = extension_host->extension();
+ extensions::LaunchPlatformApp(extension_service_->profile(), extension,
+ NULL, FilePath());
+}
+
void ExtensionSettingsHandler::ExtensionUninstallAccepted() {
DCHECK(!extension_id_prompting_.empty());
@@ -463,8 +508,20 @@ 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 window), then mark it for relaunch later.
+ if (extension->is_platform_app() &&
+ !extensions::ShellWindowRegistry::Get(profile)->
+ GetShellWindowsForApp(extension->id()).empty()) {
+ relaunch_app_ids_[extension->id()] = false;
}
+ extension_service_->ReloadExtension(extension->id());
}
void ExtensionSettingsHandler::HandleRequestExtensionsData(
@@ -599,7 +656,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) {
@@ -777,6 +837,8 @@ void ExtensionSettingsHandler::MaybeRegisterForNotifications() {
content::Source<Profile>(profile));
registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED,
content::Source<Profile>(profile));
+ registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_ENABLED,
+ content::Source<Profile>(profile));
registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED,
content::Source<Profile>(profile));
registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_WARNING_CHANGED,
« no previous file with comments | « chrome/browser/ui/webui/extensions/extension_settings_handler.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698