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" |
11 #include "chrome/browser/browser_process.h" | |
12 #include "chrome/browser/extensions/api/runtime/runtime_api.h" | 11 #include "chrome/browser/extensions/api/runtime/runtime_api.h" |
13 #include "chrome/browser/extensions/api/web_request/web_request_api.h" | 12 #include "chrome/browser/extensions/api/web_request/web_request_api.h" |
14 #include "chrome/browser/extensions/extension_devtools_manager.h" | 13 #include "chrome/browser/extensions/extension_devtools_manager.h" |
15 #include "chrome/browser/extensions/extension_host.h" | 14 #include "chrome/browser/extensions/extension_host.h" |
16 #include "chrome/browser/extensions/extension_process_manager.h" | 15 #include "chrome/browser/extensions/extension_process_manager.h" |
17 #include "chrome/browser/extensions/extension_processes_api.h" | 16 #include "chrome/browser/extensions/extension_processes_api.h" |
18 #include "chrome/browser/extensions/extension_processes_api_constants.h" | 17 #include "chrome/browser/extensions/extension_processes_api_constants.h" |
19 #include "chrome/browser/extensions/extension_service.h" | 18 #include "chrome/browser/extensions/extension_service.h" |
20 #include "chrome/browser/extensions/extension_system.h" | 19 #include "chrome/browser/extensions/extension_system.h" |
21 #include "chrome/browser/extensions/lazy_background_task_queue.h" | 20 #include "chrome/browser/extensions/lazy_background_task_queue.h" |
22 #include "chrome/browser/extensions/process_map.h" | 21 #include "chrome/browser/extensions/process_map.h" |
23 #include "chrome/browser/profiles/profile.h" | 22 #include "chrome/browser/profiles/profile.h" |
24 #include "chrome/browser/profiles/profile_manager.h" | |
25 #include "chrome/common/chrome_notification_types.h" | 23 #include "chrome/common/chrome_notification_types.h" |
26 #include "chrome/common/chrome_switches.h" | 24 #include "chrome/common/chrome_switches.h" |
27 #include "chrome/common/extensions/extension.h" | 25 #include "chrome/common/extensions/extension.h" |
28 #include "chrome/common/extensions/extension_messages.h" | 26 #include "chrome/common/extensions/extension_messages.h" |
29 #include "chrome/common/extensions/api/extension_api.h" | 27 #include "chrome/common/extensions/api/extension_api.h" |
30 #include "chrome/common/view_type.h" | 28 #include "chrome/common/view_type.h" |
31 #include "content/public/browser/notification_service.h" | 29 #include "content/public/browser/notification_service.h" |
32 #include "content/public/browser/render_process_host.h" | 30 #include "content/public/browser/render_process_host.h" |
33 | 31 |
34 using base::Value; | 32 using base::Value; |
35 using content::BrowserThread; | 33 using content::BrowserThread; |
36 | 34 |
37 namespace extensions { | |
38 | |
39 namespace { | 35 namespace { |
40 | 36 |
41 const char kDispatchEvent[] = "Event.dispatchEvent"; | 37 const char kDispatchEvent[] = "Event.dispatchEvent"; |
42 | 38 |
43 void NotifyEventListenerRemovedOnIOThread( | 39 void NotifyEventListenerRemovedOnIOThread( |
44 void* profile, | 40 void* profile, |
45 const std::string& extension_id, | 41 const std::string& extension_id, |
46 const std::string& sub_event_name) { | 42 const std::string& sub_event_name) { |
47 ExtensionWebRequestEventRouter::GetInstance()->RemoveEventListener( | 43 ExtensionWebRequestEventRouter::GetInstance()->RemoveEventListener( |
48 profile, extension_id, sub_event_name); | 44 profile, extension_id, sub_event_name); |
49 } | 45 } |
50 | 46 |
51 void DispatchOnInstalledEvent( | |
52 Profile* profile, const std::string& extension_id) { | |
53 if (!g_browser_process->profile_manager()->IsValidProfile(profile)) | |
54 return; | |
55 | |
56 RuntimeEventRouter::DispatchOnInstalledEvent(profile, extension_id); | |
57 } | |
58 | |
59 } // namespace | 47 } // namespace |
60 | 48 |
| 49 namespace extensions { |
| 50 |
61 struct EventRouter::ListenerProcess { | 51 struct EventRouter::ListenerProcess { |
62 content::RenderProcessHost* process; | 52 content::RenderProcessHost* process; |
63 std::string extension_id; | 53 std::string extension_id; |
64 | 54 |
65 ListenerProcess(content::RenderProcessHost* process, | 55 ListenerProcess(content::RenderProcessHost* process, |
66 const std::string& extension_id) | 56 const std::string& extension_id) |
67 : process(process), extension_id(extension_id) {} | 57 : process(process), extension_id(extension_id) {} |
68 | 58 |
69 bool operator<(const ListenerProcess& that) const { | 59 bool operator<(const ListenerProcess& that) const { |
70 if (process < that.process) | 60 if (process < that.process) |
(...skipping 490 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
561 UnloadedExtensionInfo* unloaded = | 551 UnloadedExtensionInfo* unloaded = |
562 content::Details<UnloadedExtensionInfo>(details).ptr(); | 552 content::Details<UnloadedExtensionInfo>(details).ptr(); |
563 listeners_.RemoveLazyListenersForExtension(unloaded->extension->id()); | 553 listeners_.RemoveLazyListenersForExtension(unloaded->extension->id()); |
564 break; | 554 break; |
565 } | 555 } |
566 case chrome::NOTIFICATION_EXTENSION_INSTALLED: { | 556 case chrome::NOTIFICATION_EXTENSION_INSTALLED: { |
567 // Dispatch the onInstalled event. | 557 // Dispatch the onInstalled event. |
568 const Extension* extension = | 558 const Extension* extension = |
569 content::Details<const Extension>(details).ptr(); | 559 content::Details<const Extension>(details).ptr(); |
570 MessageLoop::current()->PostTask(FROM_HERE, | 560 MessageLoop::current()->PostTask(FROM_HERE, |
571 base::Bind(&DispatchOnInstalledEvent, profile_, extension->id())); | 561 base::Bind(&RuntimeEventRouter::DispatchOnInstalledEvent, |
| 562 profile_, extension->id())); |
572 break; | 563 break; |
573 } | 564 } |
574 default: | 565 default: |
575 NOTREACHED(); | 566 NOTREACHED(); |
576 return; | 567 return; |
577 } | 568 } |
578 } | 569 } |
579 | 570 |
580 Event::Event(const std::string& event_name, | 571 Event::Event(const std::string& event_name, |
581 scoped_ptr<ListValue> event_args, | 572 scoped_ptr<ListValue> event_args, |
(...skipping 20 matching lines...) Expand all Loading... |
602 event_args(event_args.Pass()), | 593 event_args(event_args.Pass()), |
603 event_url(event_url), | 594 event_url(event_url), |
604 restrict_to_profile(restrict_to_profile), | 595 restrict_to_profile(restrict_to_profile), |
605 cross_incognito_args(NULL), | 596 cross_incognito_args(NULL), |
606 user_gesture(user_gesture), | 597 user_gesture(user_gesture), |
607 info(info) {} | 598 info(info) {} |
608 | 599 |
609 Event::~Event() {} | 600 Event::~Event() {} |
610 | 601 |
611 } // namespace extensions | 602 } // namespace extensions |
OLD | NEW |