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 <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <tuple> | 9 #include <tuple> |
10 #include <utility> | 10 #include <utility> |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 // A dictionary of event names to lists of filters that this extension has | 56 // A dictionary of event names to lists of filters that this extension has |
57 // registered from its lazy background page. | 57 // registered from its lazy background page. |
58 const char kFilteredEvents[] = "filtered_events"; | 58 const char kFilteredEvents[] = "filtered_events"; |
59 | 59 |
60 // Sends a notification about an event to the API activity monitor and the | 60 // Sends a notification about an event to the API activity monitor and the |
61 // ExtensionHost for |extension_id| on the UI thread. Can be called from any | 61 // ExtensionHost for |extension_id| on the UI thread. Can be called from any |
62 // thread. | 62 // thread. |
63 void NotifyEventDispatched(void* browser_context_id, | 63 void NotifyEventDispatched(void* browser_context_id, |
64 const std::string& extension_id, | 64 const std::string& extension_id, |
65 const std::string& event_name, | 65 const std::string& event_name, |
66 std::unique_ptr<ListValue> args) { | 66 const base::ListValue& args) { |
67 // The ApiActivityMonitor can only be accessed from the UI thread. | |
68 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | |
69 BrowserThread::PostTask( | |
70 BrowserThread::UI, FROM_HERE, | |
71 base::Bind(&NotifyEventDispatched, browser_context_id, extension_id, | |
72 event_name, base::Passed(&args))); | |
73 return; | |
74 } | |
75 | |
76 // Notify the ApiActivityMonitor about the event dispatch. | 67 // Notify the ApiActivityMonitor about the event dispatch. |
77 BrowserContext* context = static_cast<BrowserContext*>(browser_context_id); | 68 BrowserContext* context = static_cast<BrowserContext*>(browser_context_id); |
78 if (!ExtensionsBrowserClient::Get()->IsValidContext(context)) | 69 activity_monitor::OnApiEventDispatched(context, extension_id, event_name, |
79 return; | 70 args); |
80 ApiActivityMonitor* monitor = | |
81 ExtensionsBrowserClient::Get()->GetApiActivityMonitor(context); | |
82 if (monitor) | |
83 monitor->OnApiEventDispatched(extension_id, event_name, std::move(args)); | |
84 } | 71 } |
85 | 72 |
86 // A global identifier used to distinguish extension events. | 73 // A global identifier used to distinguish extension events. |
87 base::StaticAtomicSequenceNumber g_extension_event_id; | 74 base::StaticAtomicSequenceNumber g_extension_event_id; |
88 | 75 |
89 } // namespace | 76 } // namespace |
90 | 77 |
91 const char EventRouter::kRegisteredEvents[] = "events"; | 78 const char EventRouter::kRegisteredEvents[] = "events"; |
92 | 79 |
93 struct EventRouter::ListenerProcess { | 80 struct EventRouter::ListenerProcess { |
(...skipping 13 matching lines...) Expand all Loading... |
107 // static | 94 // static |
108 void EventRouter::DispatchExtensionMessage(IPC::Sender* ipc_sender, | 95 void EventRouter::DispatchExtensionMessage(IPC::Sender* ipc_sender, |
109 void* browser_context_id, | 96 void* browser_context_id, |
110 const std::string& extension_id, | 97 const std::string& extension_id, |
111 int event_id, | 98 int event_id, |
112 const std::string& event_name, | 99 const std::string& event_name, |
113 ListValue* event_args, | 100 ListValue* event_args, |
114 UserGestureState user_gesture, | 101 UserGestureState user_gesture, |
115 const EventFilteringInfo& info) { | 102 const EventFilteringInfo& info) { |
116 NotifyEventDispatched(browser_context_id, extension_id, event_name, | 103 NotifyEventDispatched(browser_context_id, extension_id, event_name, |
117 base::WrapUnique(event_args->DeepCopy())); | 104 *event_args); |
118 | 105 |
119 // TODO(chirantan): Make event dispatch a separate IPC so that it doesn't | 106 // TODO(chirantan): Make event dispatch a separate IPC so that it doesn't |
120 // piggyback off MessageInvoke, which is used for other things. | 107 // piggyback off MessageInvoke, which is used for other things. |
121 ListValue args; | 108 ListValue args; |
122 args.Set(0, new base::StringValue(event_name)); | 109 args.Set(0, new base::StringValue(event_name)); |
123 args.Set(1, event_args); | 110 args.Set(1, event_args); |
124 args.Set(2, info.AsValue().release()); | 111 args.Set(2, info.AsValue().release()); |
125 args.Set(3, new base::FundamentalValue(event_id)); | 112 args.Set(3, new base::FundamentalValue(event_id)); |
126 ipc_sender->Send(new ExtensionMsg_MessageInvoke( | 113 ipc_sender->Send(new ExtensionMsg_MessageInvoke( |
127 MSG_ROUTING_CONTROL, | 114 MSG_ROUTING_CONTROL, |
(...skipping 778 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
906 const std::string& extension_id, | 893 const std::string& extension_id, |
907 const GURL& listener_url, | 894 const GURL& listener_url, |
908 content::BrowserContext* browser_context) | 895 content::BrowserContext* browser_context) |
909 : event_name(event_name), | 896 : event_name(event_name), |
910 extension_id(extension_id), | 897 extension_id(extension_id), |
911 listener_url(listener_url), | 898 listener_url(listener_url), |
912 browser_context(browser_context) { | 899 browser_context(browser_context) { |
913 } | 900 } |
914 | 901 |
915 } // namespace extensions | 902 } // namespace extensions |
OLD | NEW |