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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 scoped_ptr<base::ListValue> event_args, | 86 scoped_ptr<base::ListValue> event_args, |
87 UserGestureState user_gesture, | 87 UserGestureState user_gesture, |
88 const EventFilteringInfo& info); | 88 const EventFilteringInfo& info); |
89 | 89 |
90 // An EventRouter is shared between |browser_context| and its associated | 90 // An EventRouter is shared between |browser_context| and its associated |
91 // incognito context. |extension_prefs| may be NULL in tests. | 91 // incognito context. |extension_prefs| may be NULL in tests. |
92 EventRouter(content::BrowserContext* browser_context, | 92 EventRouter(content::BrowserContext* browser_context, |
93 ExtensionPrefs* extension_prefs); | 93 ExtensionPrefs* extension_prefs); |
94 virtual ~EventRouter(); | 94 virtual ~EventRouter(); |
95 | 95 |
96 // Add or remove the process/extension pair as a listener for |event_name|. | 96 // Add or remove a listener for |event_name| given the listener's |
| 97 // |extension_id| and/or |listener_url|. |
| 98 // |
97 // Note that multiple extensions can share a process due to process | 99 // Note that multiple extensions can share a process due to process |
98 // collapsing. Also, a single extension can have 2 processes if it is a split | 100 // collapsing. Also, a single extension can have 2 processes if it is a split |
99 // mode extension. | 101 // mode extension. |
100 void AddEventListener(const std::string& event_name, | 102 void AddEventListener(const std::string& event_name, |
101 content::RenderProcessHost* process, | 103 content::RenderProcessHost* process, |
102 const std::string& extension_id); | 104 const std::string& extension_id); |
103 void RemoveEventListener(const std::string& event_name, | 105 void RemoveEventListener(const std::string& event_name, |
104 content::RenderProcessHost* process, | 106 content::RenderProcessHost* process, |
105 const std::string& extension_id); | 107 const std::string& extension_id); |
106 | 108 |
| 109 // Add or remove a listener for |event_name| given the listener's |
| 110 // URL. TODO better comment. |
| 111 void AddEventListenerForURL(const std::string& event_name, |
| 112 content::RenderProcessHost* process, |
| 113 const GURL& listener_url); |
| 114 void RemoveEventListenerForURL(const std::string& event_name, |
| 115 content::RenderProcessHost* process, |
| 116 const GURL& listener_url); |
| 117 |
107 EventListenerMap& listeners() { return listeners_; } | 118 EventListenerMap& listeners() { return listeners_; } |
108 | 119 |
109 // Registers an observer to be notified when an event listener for | 120 // Registers an observer to be notified when an event listener for |
110 // |event_name| is added or removed. There can currently be only one observer | 121 // |event_name| is added or removed. There can currently be only one observer |
111 // for each distinct |event_name|. | 122 // for each distinct |event_name|. |
112 void RegisterObserver(Observer* observer, | 123 void RegisterObserver(Observer* observer, |
113 const std::string& event_name); | 124 const std::string& event_name); |
114 | 125 |
115 // Unregisters an observer from all events. | 126 // Unregisters an observer from all events. |
116 void UnregisterObserver(Observer* observer); | 127 void UnregisterObserver(Observer* observer); |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 // Ensures that all lazy background pages that are interested in the given | 227 // Ensures that all lazy background pages that are interested in the given |
217 // event are loaded, and queues the event if the page is not ready yet. | 228 // event are loaded, and queues the event if the page is not ready yet. |
218 // Inserts an EventDispatchIdentifier into |already_dispatched| for each lazy | 229 // Inserts an EventDispatchIdentifier into |already_dispatched| for each lazy |
219 // event dispatch that is queued. | 230 // event dispatch that is queued. |
220 void DispatchLazyEvent(const std::string& extension_id, | 231 void DispatchLazyEvent(const std::string& extension_id, |
221 const linked_ptr<Event>& event, | 232 const linked_ptr<Event>& event, |
222 std::set<EventDispatchIdentifier>* already_dispatched); | 233 std::set<EventDispatchIdentifier>* already_dispatched); |
223 | 234 |
224 // Dispatches the event to the specified extension running in |process|. | 235 // Dispatches the event to the specified extension running in |process|. |
225 void DispatchEventToProcess(const std::string& extension_id, | 236 void DispatchEventToProcess(const std::string& extension_id, |
| 237 const GURL& listener_url, |
226 content::RenderProcessHost* process, | 238 content::RenderProcessHost* process, |
227 const linked_ptr<Event>& event); | 239 const linked_ptr<Event>& event); |
228 | 240 |
229 // Returns false when the event is scoped to a context and the listening | 241 // Returns false when the event is scoped to a context and the listening |
230 // extension does not have access to events from that context. Also fills | 242 // extension does not have access to events from that context. Also fills |
231 // |event_args| with the proper arguments to send, which may differ if | 243 // |event_args| with the proper arguments to send, which may differ if |
232 // the event crosses the incognito boundary. | 244 // the event crosses the incognito boundary. |
233 bool CanDispatchEventToBrowserContext(content::BrowserContext* context, | 245 bool CanDispatchEventToBrowserContext(content::BrowserContext* context, |
234 const Extension* extension, | 246 const Extension* extension, |
235 const linked_ptr<Event>& event); | 247 const linked_ptr<Event>& event); |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
350 ~Event(); | 362 ~Event(); |
351 | 363 |
352 // Makes a deep copy of this instance. Ownership is transferred to the | 364 // Makes a deep copy of this instance. Ownership is transferred to the |
353 // caller. | 365 // caller. |
354 Event* DeepCopy(); | 366 Event* DeepCopy(); |
355 }; | 367 }; |
356 | 368 |
357 struct EventListenerInfo { | 369 struct EventListenerInfo { |
358 EventListenerInfo(const std::string& event_name, | 370 EventListenerInfo(const std::string& event_name, |
359 const std::string& extension_id, | 371 const std::string& extension_id, |
| 372 const GURL& listener_url, |
360 content::BrowserContext* browser_context); | 373 content::BrowserContext* browser_context); |
361 // The event name including any sub-event, e.g. "runtime.onStartup" or | 374 // The event name including any sub-event, e.g. "runtime.onStartup" or |
362 // "webRequest.onCompleted/123". | 375 // "webRequest.onCompleted/123". |
363 const std::string event_name; | 376 const std::string event_name; |
364 | 377 |
365 const std::string extension_id; | 378 const std::string extension_id; |
| 379 const GURL listener_url; |
366 content::BrowserContext* browser_context; | 380 content::BrowserContext* browser_context; |
367 }; | 381 }; |
368 | 382 |
369 } // namespace extensions | 383 } // namespace extensions |
370 | 384 |
371 #endif // EXTENSIONS_BROWSER_EVENT_ROUTER_H_ | 385 #endif // EXTENSIONS_BROWSER_EVENT_ROUTER_H_ |
OLD | NEW |