OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/extensions/event_router.h" | 5 #include "chrome/browser/extensions/event_router.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
350 } | 350 } |
351 | 351 |
352 void EventRouter::DispatchEventImpl(const std::string& restrict_to_extension_id, | 352 void EventRouter::DispatchEventImpl(const std::string& restrict_to_extension_id, |
353 const linked_ptr<Event>& event) { | 353 const linked_ptr<Event>& event) { |
354 // We don't expect to get events from a completely different profile. | 354 // We don't expect to get events from a completely different profile. |
355 DCHECK(!event->restrict_to_profile || | 355 DCHECK(!event->restrict_to_profile || |
356 profile_->IsSameProfile(event->restrict_to_profile)); | 356 profile_->IsSameProfile(event->restrict_to_profile)); |
357 | 357 |
358 std::set<const EventListener*> listeners( | 358 std::set<const EventListener*> listeners( |
359 listeners_.GetEventListeners(*event)); | 359 listeners_.GetEventListeners(*event)); |
| 360 |
| 361 // We dispatch events for lazy background pages first because attempting to do |
| 362 // so will cause those that are being suspended to cancel that suspension. |
| 363 // As canceling a suspension entails sending an event to the affected |
| 364 // background page, and as that event needs to be delivered before we dispatch |
| 365 // the event we are dispatching here, we dispatch to the lazy listeners here |
| 366 // first. |
360 for (std::set<const EventListener*>::iterator it = listeners.begin(); | 367 for (std::set<const EventListener*>::iterator it = listeners.begin(); |
361 it != listeners.end(); it++) { | 368 it != listeners.end(); it++) { |
362 const EventListener* listener = *it; | 369 const EventListener* listener = *it; |
| 370 if (restrict_to_extension_id.empty() || |
| 371 restrict_to_extension_id == listener->extension_id) { |
| 372 if (!listener->process) |
| 373 DispatchLazyEvent(listener->extension_id, event); |
| 374 } |
| 375 } |
| 376 |
| 377 for (std::set<const EventListener*>::iterator it = listeners.begin(); |
| 378 it != listeners.end(); it++) { |
| 379 const EventListener* listener = *it; |
363 if (restrict_to_extension_id.empty() || | 380 if (restrict_to_extension_id.empty() || |
364 restrict_to_extension_id == listener->extension_id) { | 381 restrict_to_extension_id == listener->extension_id) { |
365 if (listener->process) { | 382 if (listener->process) { |
366 DispatchEventToProcess(listener->extension_id, listener->process, | 383 DispatchEventToProcess(listener->extension_id, listener->process, |
367 event); | 384 event); |
368 } else { | |
369 DispatchLazyEvent(listener->extension_id, event); | |
370 } | 385 } |
371 } | 386 } |
372 } | 387 } |
373 } | 388 } |
374 | 389 |
375 void EventRouter::DispatchLazyEvent(const std::string& extension_id, | 390 void EventRouter::DispatchLazyEvent(const std::string& extension_id, |
376 const linked_ptr<Event>& event) { | 391 const linked_ptr<Event>& event) { |
377 ExtensionService* service = profile_->GetExtensionService(); | 392 ExtensionService* service = profile_->GetExtensionService(); |
378 // Check both the original and the incognito profile to see if we | 393 // Check both the original and the incognito profile to see if we |
379 // should load a lazy bg page to handle the event. The latter case | 394 // should load a lazy bg page to handle the event. The latter case |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
595 restrict_to_profile(restrict_to_profile), | 610 restrict_to_profile(restrict_to_profile), |
596 cross_incognito_args(NULL), | 611 cross_incognito_args(NULL), |
597 user_gesture(user_gesture), | 612 user_gesture(user_gesture), |
598 info(info) { | 613 info(info) { |
599 } | 614 } |
600 | 615 |
601 Event::~Event() { | 616 Event::~Event() { |
602 } | 617 } |
603 | 618 |
604 } // namespace extensions | 619 } // namespace extensions |
OLD | NEW |