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

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: review improvements Created 8 years, 6 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 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) {
« 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