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 "extensions/browser/event_router.h" | 5 #include "extensions/browser/event_router.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
12 #include "base/stl_util.h" | 12 #include "base/stl_util.h" |
13 #include "base/values.h" | 13 #include "base/values.h" |
14 #include "chrome/browser/chrome_notification_types.h" | 14 #include "chrome/browser/chrome_notification_types.h" |
15 #include "chrome/browser/extensions/extension_host.h" | 15 #include "chrome/browser/extensions/extension_host.h" |
16 #include "chrome/browser/extensions/extension_prefs.h" | 16 #include "chrome/browser/extensions/extension_prefs.h" |
17 #include "chrome/browser/extensions/extension_service.h" | 17 #include "chrome/browser/extensions/extension_service.h" |
18 #include "chrome/browser/extensions/extension_system.h" | 18 #include "chrome/browser/extensions/extension_system.h" |
19 #include "chrome/browser/extensions/extension_util.h" | 19 #include "chrome/browser/extensions/extension_util.h" |
20 #include "chrome/common/extensions/extension_messages.h" | 20 #include "chrome/common/extensions/extension_messages.h" |
21 #include "content/public/browser/notification_service.h" | 21 #include "content/public/browser/notification_service.h" |
22 #include "content/public/browser/render_process_host.h" | 22 #include "content/public/browser/render_process_host.h" |
| 23 #include "extensions/browser/extension_registry.h" |
23 #include "extensions/browser/extensions_browser_client.h" | 24 #include "extensions/browser/extensions_browser_client.h" |
24 #include "extensions/browser/lazy_background_task_queue.h" | 25 #include "extensions/browser/lazy_background_task_queue.h" |
25 #include "extensions/browser/process_manager.h" | 26 #include "extensions/browser/process_manager.h" |
26 #include "extensions/browser/process_map.h" | 27 #include "extensions/browser/process_map.h" |
27 #include "extensions/common/extension.h" | 28 #include "extensions/common/extension.h" |
28 #include "extensions/common/extension_api.h" | 29 #include "extensions/common/extension_api.h" |
29 #include "extensions/common/extension_urls.h" | 30 #include "extensions/common/extension_urls.h" |
30 #include "extensions/common/manifest_handlers/background_info.h" | 31 #include "extensions/common/manifest_handlers/background_info.h" |
31 #include "extensions/common/manifest_handlers/incognito_info.h" | 32 #include "extensions/common/manifest_handlers/incognito_info.h" |
32 | 33 |
(...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
475 } | 476 } |
476 } | 477 } |
477 } | 478 } |
478 } | 479 } |
479 } | 480 } |
480 | 481 |
481 void EventRouter::DispatchLazyEvent( | 482 void EventRouter::DispatchLazyEvent( |
482 const std::string& extension_id, | 483 const std::string& extension_id, |
483 const linked_ptr<Event>& event, | 484 const linked_ptr<Event>& event, |
484 std::set<EventDispatchIdentifier>* already_dispatched) { | 485 std::set<EventDispatchIdentifier>* already_dispatched) { |
485 ExtensionService* service = ExtensionSystem::GetForBrowserContext( | |
486 browser_context_)->extension_service(); | |
487 // Check both the original and the incognito browser context to see if we | 486 // Check both the original and the incognito browser context to see if we |
488 // should load a lazy bg page to handle the event. The latter case | 487 // should load a lazy bg page to handle the event. The latter case |
489 // occurs in the case of split-mode extensions. | 488 // occurs in the case of split-mode extensions. |
490 const Extension* extension = service->extensions()->GetByID(extension_id); | 489 const Extension* extension = |
| 490 ExtensionRegistry::Get(browser_context_)->enabled_extensions().GetByID( |
| 491 extension_id); |
491 if (!extension) | 492 if (!extension) |
492 return; | 493 return; |
493 | 494 |
494 if (MaybeLoadLazyBackgroundPageToDispatchEvent( | 495 if (MaybeLoadLazyBackgroundPageToDispatchEvent( |
495 browser_context_, extension, event)) { | 496 browser_context_, extension, event)) { |
496 already_dispatched->insert(std::make_pair(browser_context_, extension_id)); | 497 already_dispatched->insert(std::make_pair(browser_context_, extension_id)); |
497 } | 498 } |
498 | 499 |
499 ExtensionsBrowserClient* browser_client = ExtensionsBrowserClient::Get(); | 500 ExtensionsBrowserClient* browser_client = ExtensionsBrowserClient::Get(); |
500 if (browser_client->HasOffTheRecordContext(browser_context_) && | 501 if (browser_client->HasOffTheRecordContext(browser_context_) && |
501 IncognitoInfo::IsSplitMode(extension)) { | 502 IncognitoInfo::IsSplitMode(extension)) { |
502 BrowserContext* incognito_context = | 503 BrowserContext* incognito_context = |
503 browser_client->GetOffTheRecordContext(browser_context_); | 504 browser_client->GetOffTheRecordContext(browser_context_); |
504 if (MaybeLoadLazyBackgroundPageToDispatchEvent( | 505 if (MaybeLoadLazyBackgroundPageToDispatchEvent( |
505 incognito_context, extension, event)) { | 506 incognito_context, extension, event)) { |
506 already_dispatched->insert( | 507 already_dispatched->insert( |
507 std::make_pair(incognito_context, extension_id)); | 508 std::make_pair(incognito_context, extension_id)); |
508 } | 509 } |
509 } | 510 } |
510 } | 511 } |
511 | 512 |
512 void EventRouter::DispatchEventToProcess(const std::string& extension_id, | 513 void EventRouter::DispatchEventToProcess(const std::string& extension_id, |
513 content::RenderProcessHost* process, | 514 content::RenderProcessHost* process, |
514 const linked_ptr<Event>& event) { | 515 const linked_ptr<Event>& event) { |
515 ExtensionService* service = ExtensionSystem::GetForBrowserContext( | 516 const Extension* extension = |
516 browser_context_)->extension_service(); | 517 ExtensionRegistry::Get(browser_context_)->enabled_extensions().GetByID( |
517 const Extension* extension = service->extensions()->GetByID(extension_id); | 518 extension_id); |
518 | 519 |
519 // The extension could have been removed, but we do not unregister it until | 520 // The extension could have been removed, but we do not unregister it until |
520 // the extension process is unloaded. | 521 // the extension process is unloaded. |
521 if (!extension) | 522 if (!extension) |
522 return; | 523 return; |
523 | 524 |
524 BrowserContext* listener_context = process->GetBrowserContext(); | 525 BrowserContext* listener_context = process->GetBrowserContext(); |
525 ProcessMap* process_map = | 526 ProcessMap* process_map = |
526 ExtensionSystem::GetForBrowserContext(listener_context) | 527 ExtensionSystem::GetForBrowserContext(listener_context) |
527 ->extension_service() | 528 ->extension_service() |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
610 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 611 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
611 BrowserContext* browser_context = | 612 BrowserContext* browser_context = |
612 reinterpret_cast<BrowserContext*>(browser_context_id); | 613 reinterpret_cast<BrowserContext*>(browser_context_id); |
613 if (!ExtensionsBrowserClient::Get()->IsValidContext(browser_context)) | 614 if (!ExtensionsBrowserClient::Get()->IsValidContext(browser_context)) |
614 return; | 615 return; |
615 ExtensionSystem* extension_system = | 616 ExtensionSystem* extension_system = |
616 ExtensionSystem::GetForBrowserContext(browser_context); | 617 ExtensionSystem::GetForBrowserContext(browser_context); |
617 EventRouter* event_router = extension_system->event_router(); | 618 EventRouter* event_router = extension_system->event_router(); |
618 if (!event_router) | 619 if (!event_router) |
619 return; | 620 return; |
620 ExtensionService* extension_service = extension_system->extension_service(); | |
621 const Extension* extension = | 621 const Extension* extension = |
622 extension_service->extensions()->GetByID(extension_id); | 622 ExtensionRegistry::Get(browser_context)->enabled_extensions().GetByID( |
| 623 extension_id); |
623 if (!extension) | 624 if (!extension) |
624 return; | 625 return; |
625 event_router->IncrementInFlightEvents(browser_context, extension); | 626 event_router->IncrementInFlightEvents(browser_context, extension); |
626 } | 627 } |
627 | 628 |
628 void EventRouter::IncrementInFlightEvents(BrowserContext* context, | 629 void EventRouter::IncrementInFlightEvents(BrowserContext* context, |
629 const Extension* extension) { | 630 const Extension* extension) { |
630 // Only increment in-flight events if the lazy background page is active, | 631 // Only increment in-flight events if the lazy background page is active, |
631 // because that's the only time we'll get an ACK. | 632 // because that's the only time we'll get an ACK. |
632 if (BackgroundInfo::HasLazyBackgroundPage(extension)) { | 633 if (BackgroundInfo::HasLazyBackgroundPage(extension)) { |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
774 EventDispatchInfo::EventDispatchInfo(const std::string& extension_id, | 775 EventDispatchInfo::EventDispatchInfo(const std::string& extension_id, |
775 const std::string& event_name, | 776 const std::string& event_name, |
776 scoped_ptr<ListValue> event_args) | 777 scoped_ptr<ListValue> event_args) |
777 : extension_id(extension_id), | 778 : extension_id(extension_id), |
778 event_name(event_name), | 779 event_name(event_name), |
779 event_args(event_args.Pass()) {} | 780 event_args(event_args.Pass()) {} |
780 | 781 |
781 EventDispatchInfo::~EventDispatchInfo() {} | 782 EventDispatchInfo::~EventDispatchInfo() {} |
782 | 783 |
783 } // namespace extensions | 784 } // namespace extensions |
OLD | NEW |