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

Unified Diff: chrome/browser/extensions/api/app_runtime/app_runtime_api.cc

Issue 11348301: Force-load a lazy background page whenever an extension is enabled. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: comment Created 8 years, 1 month 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 | « no previous file | chrome/browser/extensions/event_router.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/extensions/api/app_runtime/app_runtime_api.cc
diff --git a/chrome/browser/extensions/api/app_runtime/app_runtime_api.cc b/chrome/browser/extensions/api/app_runtime/app_runtime_api.cc
index c52920ac8fd8c60a8f985a7ffbd57b508789b0df..4ac08edaf7cb8ed3824105139557e3eec9922870 100644
--- a/chrome/browser/extensions/api/app_runtime/app_runtime_api.cc
+++ b/chrome/browser/extensions/api/app_runtime/app_runtime_api.cc
@@ -30,6 +30,24 @@ const char kOnRestartedEvent[] = "app.runtime.onRestarted";
const char kCallbackNotFoundError[] =
"WebIntent callback not found; perhaps already responded to";
+void DispatchOnLaunchedEventImpl(const std::string& extension_id,
+ scoped_ptr<base::ListValue> args,
+ Profile* profile) {
+ extensions::ExtensionSystem* system =
+ extensions::ExtensionSystem::Get(profile);
+ // Special case: normally, extensions add their own lazy event listeners.
+ // However, since the extension might have just been enabled, it hasn't had a
+ // chance to register for events. So we register on its behalf. If the
+ // extension does not actually have a listener, the event will just be
+ // ignored (but an app that doesn't listen for the onLaunched event doesn't
+ // make sense anyway).
+ system->event_router()->AddLazyEventListener(kOnLaunchedEvent, extension_id);
+ system->event_router()->DispatchEventToExtension(
+ extension_id, kOnLaunchedEvent, args.Pass(), profile, GURL());
+ system->event_router()->RemoveLazyEventListener(kOnLaunchedEvent,
+ extension_id);
+}
+
} // anonymous namespace
namespace extensions {
@@ -38,9 +56,7 @@ namespace extensions {
void AppEventRouter::DispatchOnLaunchedEvent(
Profile* profile, const Extension* extension) {
scoped_ptr<ListValue> arguments(new ListValue());
- extensions::ExtensionSystem::Get(profile)->event_router()->
- DispatchEventToExtension(extension->id(), kOnLaunchedEvent,
- arguments.Pass(), profile, GURL());
+ DispatchOnLaunchedEventImpl(extension->id(), arguments.Pass(), profile);
}
// static.
@@ -68,9 +84,7 @@ void AppEventRouter::DispatchOnLaunchedEventWithFileEntry(
items->Append(launch_item);
launch_data->Set("items", items);
args->Append(launch_data);
- extensions::ExtensionSystem::Get(profile)->event_router()->
- DispatchEventToExtension(extension->id(), kOnLaunchedEvent, args.Pass(),
- profile, GURL());
+ DispatchOnLaunchedEventImpl(extension->id(), args.Pass(), profile);
}
// static.
@@ -126,9 +140,7 @@ void AppEventRouter::DispatchOnLaunchedEventWithWebIntent(
int intent_id =
callbacks->RegisterCallback(extension, intents_dispatcher, source);
args->Append(base::Value::CreateIntegerValue(intent_id));
- extensions::ExtensionSystem::Get(profile)->event_router()->
- DispatchEventToExtension(extension->id(), kOnLaunchedEvent, args.Pass(),
- profile, GURL());
+ DispatchOnLaunchedEventImpl(extension->id(), args.Pass(), profile);
}
bool AppRuntimePostIntentResponseFunction::RunImpl() {
« no previous file with comments | « no previous file | chrome/browser/extensions/event_router.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698