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 <map> | 8 #include <map> |
9 #include <set> | 9 #include <set> |
10 #include <string> | 10 #include <string> |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 // Sends an event via ipc_sender to the given extension. Can be called on any | 88 // Sends an event via ipc_sender to the given extension. Can be called on any |
89 // thread. | 89 // thread. |
90 // | 90 // |
91 // It is very rare to call this function directly. Instead use the instance | 91 // It is very rare to call this function directly. Instead use the instance |
92 // methods BroadcastEvent or DispatchEventToExtension. | 92 // methods BroadcastEvent or DispatchEventToExtension. |
93 static void DispatchEventToSender(IPC::Sender* ipc_sender, | 93 static void DispatchEventToSender(IPC::Sender* ipc_sender, |
94 void* browser_context_id, | 94 void* browser_context_id, |
95 const std::string& extension_id, | 95 const std::string& extension_id, |
96 events::HistogramValue histogram_value, | 96 events::HistogramValue histogram_value, |
97 const std::string& event_name, | 97 const std::string& event_name, |
98 scoped_ptr<base::ListValue> event_args, | 98 std::unique_ptr<base::ListValue> event_args, |
99 UserGestureState user_gesture, | 99 UserGestureState user_gesture, |
100 const EventFilteringInfo& info); | 100 const EventFilteringInfo& info); |
101 | 101 |
102 // An EventRouter is shared between |browser_context| and its associated | 102 // An EventRouter is shared between |browser_context| and its associated |
103 // incognito context. |extension_prefs| may be NULL in tests. | 103 // incognito context. |extension_prefs| may be NULL in tests. |
104 EventRouter(content::BrowserContext* browser_context, | 104 EventRouter(content::BrowserContext* browser_context, |
105 ExtensionPrefs* extension_prefs); | 105 ExtensionPrefs* extension_prefs); |
106 ~EventRouter() override; | 106 ~EventRouter() override; |
107 | 107 |
108 // Add or remove an extension as an event listener for |event_name|. | 108 // Add or remove an extension as an event listener for |event_name|. |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 virtual bool ExtensionHasEventListener(const std::string& extension_id, | 167 virtual bool ExtensionHasEventListener(const std::string& extension_id, |
168 const std::string& event_name); | 168 const std::string& event_name); |
169 | 169 |
170 // Return or set the list of events for which the given extension has | 170 // Return or set the list of events for which the given extension has |
171 // registered. | 171 // registered. |
172 std::set<std::string> GetRegisteredEvents(const std::string& extension_id); | 172 std::set<std::string> GetRegisteredEvents(const std::string& extension_id); |
173 void SetRegisteredEvents(const std::string& extension_id, | 173 void SetRegisteredEvents(const std::string& extension_id, |
174 const std::set<std::string>& events); | 174 const std::set<std::string>& events); |
175 | 175 |
176 // Broadcasts an event to every listener registered for that event. | 176 // Broadcasts an event to every listener registered for that event. |
177 virtual void BroadcastEvent(scoped_ptr<Event> event); | 177 virtual void BroadcastEvent(std::unique_ptr<Event> event); |
178 | 178 |
179 // Dispatches an event to the given extension. | 179 // Dispatches an event to the given extension. |
180 virtual void DispatchEventToExtension(const std::string& extension_id, | 180 virtual void DispatchEventToExtension(const std::string& extension_id, |
181 scoped_ptr<Event> event); | 181 std::unique_ptr<Event> event); |
182 | 182 |
183 // Dispatches |event| to the given extension as if the extension has a lazy | 183 // Dispatches |event| to the given extension as if the extension has a lazy |
184 // listener for it. NOTE: This should be used rarely, for dispatching events | 184 // listener for it. NOTE: This should be used rarely, for dispatching events |
185 // to extensions that haven't had a chance to add their own listeners yet, eg: | 185 // to extensions that haven't had a chance to add their own listeners yet, eg: |
186 // newly installed extensions. | 186 // newly installed extensions. |
187 void DispatchEventWithLazyListener(const std::string& extension_id, | 187 void DispatchEventWithLazyListener(const std::string& extension_id, |
188 scoped_ptr<Event> event); | 188 std::unique_ptr<Event> event); |
189 | 189 |
190 // Record the Event Ack from the renderer. (One less event in-flight.) | 190 // Record the Event Ack from the renderer. (One less event in-flight.) |
191 void OnEventAck(content::BrowserContext* context, | 191 void OnEventAck(content::BrowserContext* context, |
192 const std::string& extension_id); | 192 const std::string& extension_id); |
193 | 193 |
194 // Reports UMA for an event dispatched to |extension| with histogram value | 194 // Reports UMA for an event dispatched to |extension| with histogram value |
195 // |histogram_value|. Must be called on the UI thread. | 195 // |histogram_value|. Must be called on the UI thread. |
196 // | 196 // |
197 // |did_enqueue| should be true if the event was queued waiting for a process | 197 // |did_enqueue| should be true if the event was queued waiting for a process |
198 // to start, like an event page. | 198 // to start, like an event page. |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
361 | 361 |
362 // The identifier for the event, for histograms. In most cases this | 362 // The identifier for the event, for histograms. In most cases this |
363 // correlates 1:1 with |event_name|, in some cases events will generate | 363 // correlates 1:1 with |event_name|, in some cases events will generate |
364 // their own names, but they cannot generate their own identifier. | 364 // their own names, but they cannot generate their own identifier. |
365 events::HistogramValue histogram_value; | 365 events::HistogramValue histogram_value; |
366 | 366 |
367 // The event to dispatch. | 367 // The event to dispatch. |
368 std::string event_name; | 368 std::string event_name; |
369 | 369 |
370 // Arguments to send to the event listener. | 370 // Arguments to send to the event listener. |
371 scoped_ptr<base::ListValue> event_args; | 371 std::unique_ptr<base::ListValue> event_args; |
372 | 372 |
373 // If non-NULL, then the event will not be sent to other BrowserContexts | 373 // If non-NULL, then the event will not be sent to other BrowserContexts |
374 // unless the extension has permission (e.g. incognito tab update -> normal | 374 // unless the extension has permission (e.g. incognito tab update -> normal |
375 // tab only works if extension is allowed incognito access). | 375 // tab only works if extension is allowed incognito access). |
376 content::BrowserContext* restrict_to_browser_context; | 376 content::BrowserContext* restrict_to_browser_context; |
377 | 377 |
378 // If not empty, the event is only sent to extensions with host permissions | 378 // If not empty, the event is only sent to extensions with host permissions |
379 // for this url. | 379 // for this url. |
380 GURL event_url; | 380 GURL event_url; |
381 | 381 |
382 // Whether a user gesture triggered the event. | 382 // Whether a user gesture triggered the event. |
383 EventRouter::UserGestureState user_gesture; | 383 EventRouter::UserGestureState user_gesture; |
384 | 384 |
385 // Extra information used to filter which events are sent to the listener. | 385 // Extra information used to filter which events are sent to the listener. |
386 EventFilteringInfo filter_info; | 386 EventFilteringInfo filter_info; |
387 | 387 |
388 // If specified, this is called before dispatching an event to each | 388 // If specified, this is called before dispatching an event to each |
389 // extension. The third argument is a mutable reference to event_args, | 389 // extension. The third argument is a mutable reference to event_args, |
390 // allowing the caller to provide different arguments depending on the | 390 // allowing the caller to provide different arguments depending on the |
391 // extension and profile. This is guaranteed to be called synchronously with | 391 // extension and profile. This is guaranteed to be called synchronously with |
392 // DispatchEvent, so callers don't need to worry about lifetime. | 392 // DispatchEvent, so callers don't need to worry about lifetime. |
393 // | 393 // |
394 // NOTE: the Extension argument to this may be NULL because it's possible for | 394 // NOTE: the Extension argument to this may be NULL because it's possible for |
395 // this event to be dispatched to non-extension processes, like WebUI. | 395 // this event to be dispatched to non-extension processes, like WebUI. |
396 WillDispatchCallback will_dispatch_callback; | 396 WillDispatchCallback will_dispatch_callback; |
397 | 397 |
398 Event(events::HistogramValue histogram_value, | 398 Event(events::HistogramValue histogram_value, |
399 const std::string& event_name, | 399 const std::string& event_name, |
400 scoped_ptr<base::ListValue> event_args); | 400 std::unique_ptr<base::ListValue> event_args); |
401 | 401 |
402 Event(events::HistogramValue histogram_value, | 402 Event(events::HistogramValue histogram_value, |
403 const std::string& event_name, | 403 const std::string& event_name, |
404 scoped_ptr<base::ListValue> event_args, | 404 std::unique_ptr<base::ListValue> event_args, |
405 content::BrowserContext* restrict_to_browser_context); | 405 content::BrowserContext* restrict_to_browser_context); |
406 | 406 |
407 Event(events::HistogramValue histogram_value, | 407 Event(events::HistogramValue histogram_value, |
408 const std::string& event_name, | 408 const std::string& event_name, |
409 scoped_ptr<base::ListValue> event_args, | 409 std::unique_ptr<base::ListValue> event_args, |
410 content::BrowserContext* restrict_to_browser_context, | 410 content::BrowserContext* restrict_to_browser_context, |
411 const GURL& event_url, | 411 const GURL& event_url, |
412 EventRouter::UserGestureState user_gesture, | 412 EventRouter::UserGestureState user_gesture, |
413 const EventFilteringInfo& info); | 413 const EventFilteringInfo& info); |
414 | 414 |
415 ~Event(); | 415 ~Event(); |
416 | 416 |
417 // Makes a deep copy of this instance. Ownership is transferred to the | 417 // Makes a deep copy of this instance. Ownership is transferred to the |
418 // caller. | 418 // caller. |
419 Event* DeepCopy(); | 419 Event* DeepCopy(); |
420 }; | 420 }; |
421 | 421 |
422 struct EventListenerInfo { | 422 struct EventListenerInfo { |
423 EventListenerInfo(const std::string& event_name, | 423 EventListenerInfo(const std::string& event_name, |
424 const std::string& extension_id, | 424 const std::string& extension_id, |
425 const GURL& listener_url, | 425 const GURL& listener_url, |
426 content::BrowserContext* browser_context); | 426 content::BrowserContext* browser_context); |
427 // The event name including any sub-event, e.g. "runtime.onStartup" or | 427 // The event name including any sub-event, e.g. "runtime.onStartup" or |
428 // "webRequest.onCompleted/123". | 428 // "webRequest.onCompleted/123". |
429 const std::string event_name; | 429 const std::string event_name; |
430 | 430 |
431 const std::string extension_id; | 431 const std::string extension_id; |
432 const GURL listener_url; | 432 const GURL listener_url; |
433 content::BrowserContext* browser_context; | 433 content::BrowserContext* browser_context; |
434 }; | 434 }; |
435 | 435 |
436 } // namespace extensions | 436 } // namespace extensions |
437 | 437 |
438 #endif // EXTENSIONS_BROWSER_EVENT_ROUTER_H_ | 438 #endif // EXTENSIONS_BROWSER_EVENT_ROUTER_H_ |
OLD | NEW |