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/extension_event_router.h" | 5 #include "chrome/browser/extensions/extension_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 19 matching lines...) Expand all Loading... | |
30 #include "content/public/browser/render_process_host.h" | 30 #include "content/public/browser/render_process_host.h" |
31 | 31 |
32 using base::Value; | 32 using base::Value; |
33 using content::BrowserThread; | 33 using content::BrowserThread; |
34 using extensions::Extension; | 34 using extensions::Extension; |
35 using extensions::ExtensionAPI; | 35 using extensions::ExtensionAPI; |
36 | 36 |
37 namespace { | 37 namespace { |
38 | 38 |
39 const char kDispatchEvent[] = "Event.dispatchJSON"; | 39 const char kDispatchEvent[] = "Event.dispatchJSON"; |
40 const char kOnSuspendCanceledEvent[] = "runtime.onSuspendCanceled"; | |
40 | 41 |
41 void NotifyEventListenerRemovedOnIOThread( | 42 void NotifyEventListenerRemovedOnIOThread( |
42 void* profile, | 43 void* profile, |
43 const std::string& extension_id, | 44 const std::string& extension_id, |
44 const std::string& sub_event_name) { | 45 const std::string& sub_event_name) { |
45 ExtensionWebRequestEventRouter::GetInstance()->RemoveEventListener( | 46 ExtensionWebRequestEventRouter::GetInstance()->RemoveEventListener( |
46 profile, extension_id, sub_event_name); | 47 profile, extension_id, sub_event_name); |
47 } | 48 } |
48 | 49 |
49 } // namespace | 50 } // namespace |
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
429 !process_map->Contains(extension->id(), process->GetID())) { | 430 !process_map->Contains(extension->id(), process->GetID())) { |
430 return; | 431 return; |
431 } | 432 } |
432 | 433 |
433 const Value* event_args = NULL; | 434 const Value* event_args = NULL; |
434 if (!CanDispatchEventToProfile(listener_profile, extension, | 435 if (!CanDispatchEventToProfile(listener_profile, extension, |
435 event, &event_args)) { | 436 event, &event_args)) { |
436 return; | 437 return; |
437 } | 438 } |
438 | 439 |
440 if (IsClosing(listener_profile, extension)) { | |
441 DispatchOnSuspendCanceled(process, extension_id); | |
442 IncrementInFlightEvents(listener_profile, extension); | |
443 } | |
444 | |
439 DispatchEvent(process, extension_id, | 445 DispatchEvent(process, extension_id, |
440 event->event_name, *event_args, | 446 event->event_name, *event_args, |
441 event->event_url, event->user_gesture, | 447 event->event_url, event->user_gesture, |
442 event->info); | 448 event->info); |
443 IncrementInFlightEvents(listener_profile, extension); | 449 IncrementInFlightEvents(listener_profile, extension); |
444 } | 450 } |
445 | 451 |
452 bool ExtensionEventRouter::IsClosing( | |
453 Profile* profile, const Extension* extension) { | |
454 // Only lazy background pages can be in the closing state. | |
455 if (extension->has_lazy_background_page()) { | |
456 ExtensionProcessManager* pm = | |
457 extensions::ExtensionSystem::Get(profile)->process_manager(); | |
458 ExtensionHost* host = pm->GetBackgroundHostForExtension(extension->id()); | |
459 return host && pm->IsBackgroundHostClosing(extension->id()); | |
460 } | |
benwells
2012/07/19 04:01:21
Nit: blank line after early return.
koz (OOO until 15th September)
2012/07/19 06:52:11
Done.
| |
461 return false; | |
462 } | |
463 | |
464 void ExtensionEventRouter::DispatchOnSuspendCanceled( | |
465 content::RenderProcessHost* process, const std::string& extension_id) { | |
466 ListValue args; | |
467 DispatchEvent(process, extension_id, kOnSuspendCanceledEvent, args, GURL(), | |
468 USER_GESTURE_NOT_ENABLED, EventFilteringInfo()); | |
469 } | |
470 | |
446 bool ExtensionEventRouter::CanDispatchEventToProfile( | 471 bool ExtensionEventRouter::CanDispatchEventToProfile( |
447 Profile* profile, | 472 Profile* profile, |
448 const Extension* extension, | 473 const Extension* extension, |
449 const linked_ptr<ExtensionEvent>& event, | 474 const linked_ptr<ExtensionEvent>& event, |
450 const Value** event_args) { | 475 const Value** event_args) { |
451 *event_args = event->event_args.get(); | 476 *event_args = event->event_args.get(); |
452 | 477 |
453 // Is this event from a different profile than the renderer (ie, an | 478 // Is this event from a different profile than the renderer (ie, an |
454 // incognito tab event sent to a normal process, or vice versa). | 479 // incognito tab event sent to a normal process, or vice versa). |
455 bool cross_incognito = event->restrict_to_profile && | 480 bool cross_incognito = event->restrict_to_profile && |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
619 event_args(event_args.DeepCopy()), | 644 event_args(event_args.DeepCopy()), |
620 event_url(event_url), | 645 event_url(event_url), |
621 restrict_to_profile(restrict_to_profile), | 646 restrict_to_profile(restrict_to_profile), |
622 cross_incognito_args(NULL), | 647 cross_incognito_args(NULL), |
623 user_gesture(user_gesture), | 648 user_gesture(user_gesture), |
624 info(info) { | 649 info(info) { |
625 } | 650 } |
626 | 651 |
627 ExtensionEvent::~ExtensionEvent() { | 652 ExtensionEvent::~ExtensionEvent() { |
628 } | 653 } |
OLD | NEW |