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

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: restrict to platform apps 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..d3a17b2c9f345488653920efe4621d35ea962dc0 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,34 @@ 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: {
+ 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);
+ // For platform apps, there's not a really good way to know when the
+ // background page has started up and is ready to receive the
+ // onLaunched event, so we just wait half a second.
Evan Stade 2012/06/22 05:17:51 suggestions for improvement welcome.
Aaron Boodman 2012/06/22 05:35:02 LazyBackgroundTaskQueue ?
Evan Stade 2012/06/22 19:39:51 awesome
+ MessageLoop::current()->PostDelayedTask(
+ FROM_HERE,
+ base::Bind(&ExtensionSettingsHandler::LaunchApplication,
+ weak_factory_.GetWeakPtr(),
+ extension->id()),
+ base::TimeDelta::FromMilliseconds(500));
+ }
+
MaybeUpdateAfterNotification();
break;
- case chrome::NOTIFICATION_EXTENSION_LOADED:
+ }
case chrome::NOTIFICATION_EXTENSION_UNLOADED:
case chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED:
case chrome::NOTIFICATION_EXTENSION_WARNING_CHANGED:
@@ -412,6 +439,22 @@ void ExtensionSettingsHandler::Observe(
}
}
+void ExtensionSettingsHandler::LaunchApplication(
+ const std::string& extension_id) {
+ const Extension* extension =
+ extension_service_->GetExtensionById(extension_id, false);
+ if (!extension)
+ return;
+
+ 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,8 +498,21 @@ 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 open render
+ // views), then mark it for relaunch later.
Evan Stade 2012/06/22 05:17:51 this is kind of a hokey definition of "running", b
Aaron Boodman 2012/06/22 05:35:02 I think if there are no running render views, the
Evan Stade 2012/06/22 19:39:51 I don't want to count background pages.
Aaron Boodman 2012/06/22 20:30:54 I'm surprised that the event page is not returned
Evan Stade 2012/06/22 22:29:50 oh, it does. I was confused because the background
+ if (extension->is_platform_app() &&
+ !profile->GetExtensionProcessManager()->
+ GetRenderViewHostsForExtension(extension->id()).empty()) {
+ relaunch_app_ids_.push_back(extension->id());
}
+ extension_service_->ReloadExtension(extension->id());
}
void ExtensionSettingsHandler::HandleRequestExtensionsData(
@@ -581,7 +637,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