Index: chrome/browser/extensions/extension_event_router.cc |
diff --git a/chrome/browser/extensions/extension_event_router.cc b/chrome/browser/extensions/extension_event_router.cc |
index 9d4d97c7e123bce7d7d02c01eb26b3d9e2586ac0..56c2e67601e42165066619be2f055e8e32c863fb 100644 |
--- a/chrome/browser/extensions/extension_event_router.cc |
+++ b/chrome/browser/extensions/extension_event_router.cc |
@@ -374,6 +374,23 @@ void ExtensionEventRouter::DispatchEventImpl( |
std::set<const EventListener*> listeners( |
listeners_.GetEventListeners(*event)); |
+ |
+ // We dispatch events for lazy background pages first because attempting to do |
+ // so will cause those that are being suspended to cancel that suspension. |
+ // As canceling a suspension entails sending an event to the affected |
+ // background page, and as that event needs to be delivered before we dispatch |
+ // the event we are dispatching here, we dispatch to the lazy listeners here |
+ // first. |
+ for (std::set<const EventListener*>::iterator it = listeners.begin(); |
+ it != listeners.end(); it++) { |
+ const EventListener* listener = *it; |
+ if (restrict_to_extension_id.empty() || |
+ restrict_to_extension_id == listener->extension_id) { |
+ if (!listener->process) |
+ DispatchLazyEvent(listener->extension_id, event); |
+ } |
+ } |
+ |
for (std::set<const EventListener*>::iterator it = listeners.begin(); |
it != listeners.end(); it++) { |
const EventListener* listener = *it; |
@@ -382,8 +399,6 @@ void ExtensionEventRouter::DispatchEventImpl( |
if (listener->process) { |
DispatchEventToProcess(listener->extension_id, listener->process, |
event); |
- } else { |
- DispatchLazyEvent(listener->extension_id, event); |
} |
} |
} |
@@ -436,16 +451,11 @@ void ExtensionEventRouter::DispatchEventToProcess( |
return; |
} |
- // We need to call IncrementInFlightEvents() before DispatchEvent() because |
- // the former may prevent this extension from getting suspended and so send |
- // the onSuspendCanceled() to the extension, which needs to arrive before the |
- // event that DispatchEvent() is dispatching. |
- IncrementInFlightEvents(listener_profile, extension); |
- |
DispatchEvent(process, extension_id, |
event->event_name, *event_args, |
event->event_url, event->user_gesture, |
event->info); |
+ IncrementInFlightEvents(listener_profile, extension); |
} |
bool ExtensionEventRouter::CanDispatchEventToProfile( |
@@ -498,8 +508,7 @@ void ExtensionEventRouter::IncrementInFlightEvents( |
extensions::ExtensionSystem::Get(profile)->process_manager(); |
ExtensionHost* host = pm->GetBackgroundHostForExtension(extension->id()); |
if (host) |
- pm->IncrementLazyKeepaliveCount( |
- extension, ExtensionProcessManager::CANCEL_SUSPEND); |
+ pm->IncrementLazyKeepaliveCount(extension); |
} |
} |