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 #ifndef EXTENSIONS_BROWSER_EVENT_ROUTER_H_ | 5 #ifndef EXTENSIONS_BROWSER_EVENT_ROUTER_H_ |
6 #define EXTENSIONS_BROWSER_EVENT_ROUTER_H_ | 6 #define EXTENSIONS_BROWSER_EVENT_ROUTER_H_ |
7 | 7 |
8 #include <set> | 8 #include <set> |
9 #include <string> | 9 #include <string> |
10 #include <utility> | 10 #include <utility> |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
156 const base::DictionaryValue& filter, | 156 const base::DictionaryValue& filter, |
157 bool remove_lazy_listener); | 157 bool remove_lazy_listener); |
158 | 158 |
159 // Returns true if there is at least one listener for the given event. | 159 // Returns true if there is at least one listener for the given event. |
160 bool HasEventListener(const std::string& event_name); | 160 bool HasEventListener(const std::string& event_name); |
161 | 161 |
162 // Returns true if the extension is listening to the given event. | 162 // Returns true if the extension is listening to the given event. |
163 virtual bool ExtensionHasEventListener(const std::string& extension_id, | 163 virtual bool ExtensionHasEventListener(const std::string& extension_id, |
164 const std::string& event_name); | 164 const std::string& event_name); |
165 | 165 |
166 // Return or set the list of events for which the given extension has | |
167 // registered. | |
168 std::set<std::string> GetRegisteredEvents(const std::string& extension_id); | |
169 void SetRegisteredEvents(const std::string& extension_id, | |
170 const std::set<std::string>& events); | |
171 | |
172 // Broadcasts an event to every listener registered for that event. | 166 // Broadcasts an event to every listener registered for that event. |
173 virtual void BroadcastEvent(std::unique_ptr<Event> event); | 167 virtual void BroadcastEvent(std::unique_ptr<Event> event); |
174 | 168 |
175 // Dispatches an event to the given extension. | 169 // Dispatches an event to the given extension. |
176 virtual void DispatchEventToExtension(const std::string& extension_id, | 170 virtual void DispatchEventToExtension(const std::string& extension_id, |
177 std::unique_ptr<Event> event); | 171 std::unique_ptr<Event> event); |
178 | 172 |
179 // Dispatches |event| to the given extension as if the extension has a lazy | 173 // Dispatches |event| to the given extension as if the extension has a lazy |
180 // listener for it. NOTE: This should be used rarely, for dispatching events | 174 // listener for it. NOTE: This should be used rarely, for dispatching events |
181 // to extensions that haven't had a chance to add their own listeners yet, eg: | 175 // to extensions that haven't had a chance to add their own listeners yet, eg: |
182 // newly installed extensions. | 176 // newly installed extensions. |
183 void DispatchEventWithLazyListener(const std::string& extension_id, | 177 void DispatchEventWithLazyListener(const std::string& extension_id, |
184 std::unique_ptr<Event> event); | 178 std::unique_ptr<Event> event); |
185 | 179 |
186 // Record the Event Ack from the renderer. (One less event in-flight.) | 180 // Record the Event Ack from the renderer. (One less event in-flight.) |
187 void OnEventAck(content::BrowserContext* context, | 181 void OnEventAck(content::BrowserContext* context, |
188 const std::string& extension_id); | 182 const std::string& extension_id); |
189 | 183 |
184 // Returns whether or not the given extension has any registered events. | |
185 bool HasRegisteredEvents(const ExtensionId& extension_id) const; | |
karandeepb
2017/05/12 00:34:25
The other functions don't use the ExtensionId type
lazyboy
2017/05/12 00:56:25
We started preferring ExtensionId for new code to
| |
186 | |
187 // Clears registered events for testing purposes. | |
188 void ClearRegisteredEventsForTest(const ExtensionId& extension_id); | |
karandeepb
2017/05/12 00:34:25
Optional nit: Both of these can be inlined.
lazyboy
2017/05/12 00:56:25
Done.
| |
189 | |
190 // Reports UMA for an event dispatched to |extension| with histogram value | 190 // Reports UMA for an event dispatched to |extension| with histogram value |
191 // |histogram_value|. Must be called on the UI thread. | 191 // |histogram_value|. Must be called on the UI thread. |
192 // | 192 // |
193 // |did_enqueue| should be true if the event was queued waiting for a process | 193 // |did_enqueue| should be true if the event was queued waiting for a process |
194 // to start, like an event page. | 194 // to start, like an event page. |
195 void ReportEvent(events::HistogramValue histogram_value, | 195 void ReportEvent(events::HistogramValue histogram_value, |
196 const Extension* extension, | 196 const Extension* extension, |
197 bool did_enqueue); | 197 bool did_enqueue); |
198 | 198 |
199 private: | 199 private: |
200 friend class EventRouterFilterTest; | 200 friend class EventRouterFilterTest; |
201 friend class EventRouterTest; | 201 friend class EventRouterTest; |
202 | 202 |
203 // An identifier for an event dispatch that is used to prevent double dispatch | 203 // An identifier for an event dispatch that is used to prevent double dispatch |
204 // due to race conditions between the direct and lazy dispatch paths. | 204 // due to race conditions between the direct and lazy dispatch paths. |
205 typedef std::pair<const content::BrowserContext*, std::string> | 205 typedef std::pair<const content::BrowserContext*, std::string> |
206 EventDispatchIdentifier; | 206 EventDispatchIdentifier; |
207 | 207 |
208 // TODO(gdk): Document this. | 208 // TODO(gdk): Document this. |
209 static void DispatchExtensionMessage( | 209 static void DispatchExtensionMessage( |
210 IPC::Sender* ipc_sender, | 210 IPC::Sender* ipc_sender, |
211 void* browser_context_id, | 211 void* browser_context_id, |
212 const std::string& extension_id, | 212 const std::string& extension_id, |
213 int event_id, | 213 int event_id, |
214 const std::string& event_name, | 214 const std::string& event_name, |
215 base::ListValue* event_args, | 215 base::ListValue* event_args, |
216 UserGestureState user_gesture, | 216 UserGestureState user_gesture, |
217 const extensions::EventFilteringInfo& info); | 217 const extensions::EventFilteringInfo& info); |
218 | 218 |
219 // Returns or sets the list of events for which the given extension has | |
220 // registered. | |
221 std::set<std::string> GetRegisteredEvents( | |
222 const std::string& extension_id) const; | |
223 void SetRegisteredEvents(const std::string& extension_id, | |
224 const std::set<std::string>& events); | |
225 | |
219 void Observe(int type, | 226 void Observe(int type, |
220 const content::NotificationSource& source, | 227 const content::NotificationSource& source, |
221 const content::NotificationDetails& details) override; | 228 const content::NotificationDetails& details) override; |
222 // ExtensionRegistryObserver implementation. | 229 // ExtensionRegistryObserver implementation. |
223 void OnExtensionLoaded(content::BrowserContext* browser_context, | 230 void OnExtensionLoaded(content::BrowserContext* browser_context, |
224 const Extension* extension) override; | 231 const Extension* extension) override; |
225 void OnExtensionUnloaded(content::BrowserContext* browser_context, | 232 void OnExtensionUnloaded(content::BrowserContext* browser_context, |
226 const Extension* extension, | 233 const Extension* extension, |
227 UnloadedExtensionReason reason) override; | 234 UnloadedExtensionReason reason) override; |
228 | 235 |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
411 const std::string event_name; | 418 const std::string event_name; |
412 | 419 |
413 const std::string extension_id; | 420 const std::string extension_id; |
414 const GURL listener_url; | 421 const GURL listener_url; |
415 content::BrowserContext* browser_context; | 422 content::BrowserContext* browser_context; |
416 }; | 423 }; |
417 | 424 |
418 } // namespace extensions | 425 } // namespace extensions |
419 | 426 |
420 #endif // EXTENSIONS_BROWSER_EVENT_ROUTER_H_ | 427 #endif // EXTENSIONS_BROWSER_EVENT_ROUTER_H_ |
OLD | NEW |