| 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 <unordered_map> | 10 #include <unordered_map> |
| 11 | 11 |
| 12 #include "base/callback.h" | 12 #include "base/callback.h" |
| 13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
| 14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/memory/linked_ptr.h" | 15 #include "base/memory/linked_ptr.h" |
| 16 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
| 17 #include "base/memory/weak_ptr.h" | 17 #include "base/memory/weak_ptr.h" |
| 18 #include "base/scoped_observer.h" | 18 #include "base/scoped_observer.h" |
| 19 #include "base/values.h" | 19 #include "base/values.h" |
| 20 #include "components/keyed_service/core/keyed_service.h" | 20 #include "components/keyed_service/core/keyed_service.h" |
| 21 #include "content/public/browser/render_process_host_observer.h" | 21 #include "content/public/browser/render_process_host_observer.h" |
| 22 #include "extensions/browser/event_listener_map.h" | 22 #include "extensions/browser/event_listener_map.h" |
| 23 #include "extensions/browser/events/lazy_event_dispatch_util.h" | 23 #include "extensions/browser/events/lazy_event_dispatch_util.h" |
| 24 #include "extensions/browser/extension_event_histogram_value.h" | 24 #include "extensions/browser/extension_event_histogram_value.h" |
| 25 #include "extensions/browser/extension_registry_observer.h" | 25 #include "extensions/browser/extension_registry_observer.h" |
| 26 #include "extensions/browser/lazy_context_task_queue.h" |
| 26 #include "extensions/common/constants.h" | 27 #include "extensions/common/constants.h" |
| 27 #include "extensions/common/event_filtering_info.h" | 28 #include "extensions/common/event_filtering_info.h" |
| 28 #include "ipc/ipc_sender.h" | 29 #include "ipc/ipc_sender.h" |
| 29 #include "url/gurl.h" | 30 #include "url/gurl.h" |
| 30 | 31 |
| 31 class GURL; | 32 class GURL; |
| 32 | 33 |
| 33 namespace content { | 34 namespace content { |
| 34 class BrowserContext; | 35 class BrowserContext; |
| 35 class RenderProcessHost; | 36 class RenderProcessHost; |
| 36 } | 37 } |
| 37 | 38 |
| 38 namespace extensions { | 39 namespace extensions { |
| 39 class Extension; | 40 class Extension; |
| 40 class ExtensionHost; | |
| 41 class ExtensionPrefs; | 41 class ExtensionPrefs; |
| 42 class ExtensionRegistry; | 42 class ExtensionRegistry; |
| 43 | 43 |
| 44 struct Event; | 44 struct Event; |
| 45 struct EventListenerInfo; | 45 struct EventListenerInfo; |
| 46 | 46 |
| 47 // TODO(lazyboy): Document how extension events work, including how listeners | 47 // TODO(lazyboy): Document how extension events work, including how listeners |
| 48 // are registered and how listeners are tracked in renderer and browser process. | 48 // are registered and how listeners are tracked in renderer and browser process. |
| 49 class EventRouter : public KeyedService, | 49 class EventRouter : public KeyedService, |
| 50 public ExtensionRegistryObserver, | 50 public ExtensionRegistryObserver, |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 // | 118 // |
| 119 // Note that multiple extensions can share a process due to process | 119 // Note that multiple extensions can share a process due to process |
| 120 // collapsing. Also, a single extension can have 2 processes if it is a split | 120 // collapsing. Also, a single extension can have 2 processes if it is a split |
| 121 // mode extension. | 121 // mode extension. |
| 122 void AddEventListener(const std::string& event_name, | 122 void AddEventListener(const std::string& event_name, |
| 123 content::RenderProcessHost* process, | 123 content::RenderProcessHost* process, |
| 124 const ExtensionId& extension_id); | 124 const ExtensionId& extension_id); |
| 125 void AddServiceWorkerEventListener(const std::string& event_name, | 125 void AddServiceWorkerEventListener(const std::string& event_name, |
| 126 content::RenderProcessHost* process, | 126 content::RenderProcessHost* process, |
| 127 const ExtensionId& extension_id, | 127 const ExtensionId& extension_id, |
| 128 const GURL& service_worker_scope, |
| 128 int worker_thread_id); | 129 int worker_thread_id); |
| 129 void RemoveEventListener(const std::string& event_name, | 130 void RemoveEventListener(const std::string& event_name, |
| 130 content::RenderProcessHost* process, | 131 content::RenderProcessHost* process, |
| 131 const ExtensionId& extension_id); | 132 const ExtensionId& extension_id); |
| 132 void RemoveServiceWorkerEventListener(const std::string& event_name, | 133 void RemoveServiceWorkerEventListener(const std::string& event_name, |
| 133 content::RenderProcessHost* process, | 134 content::RenderProcessHost* process, |
| 134 const ExtensionId& extension_id, | 135 const ExtensionId& extension_id, |
| 136 const GURL& service_worker_scope, |
| 135 int worker_thread_id); | 137 int worker_thread_id); |
| 136 | 138 |
| 137 // Add or remove a URL as an event listener for |event_name|. | 139 // Add or remove a URL as an event listener for |event_name|. |
| 138 void AddEventListenerForURL(const std::string& event_name, | 140 void AddEventListenerForURL(const std::string& event_name, |
| 139 content::RenderProcessHost* process, | 141 content::RenderProcessHost* process, |
| 140 const GURL& listener_url); | 142 const GURL& listener_url); |
| 141 void RemoveEventListenerForURL(const std::string& event_name, | 143 void RemoveEventListenerForURL(const std::string& event_name, |
| 142 content::RenderProcessHost* process, | 144 content::RenderProcessHost* process, |
| 143 const GURL& listener_url); | 145 const GURL& listener_url); |
| 144 | 146 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 157 // remembered even after the process goes away. We use this list to decide | 159 // remembered even after the process goes away. We use this list to decide |
| 158 // which extension pages to load when dispatching an event. | 160 // which extension pages to load when dispatching an event. |
| 159 void AddLazyEventListener(const std::string& event_name, | 161 void AddLazyEventListener(const std::string& event_name, |
| 160 const ExtensionId& extension_id); | 162 const ExtensionId& extension_id); |
| 161 void RemoveLazyEventListener(const std::string& event_name, | 163 void RemoveLazyEventListener(const std::string& event_name, |
| 162 const ExtensionId& extension_id); | 164 const ExtensionId& extension_id); |
| 163 // Similar to Add/RemoveLazyEventListener, but applies to extension service | 165 // Similar to Add/RemoveLazyEventListener, but applies to extension service |
| 164 // workers. | 166 // workers. |
| 165 void AddLazyServiceWorkerEventListener(const std::string& event_name, | 167 void AddLazyServiceWorkerEventListener(const std::string& event_name, |
| 166 const ExtensionId& extension_id, | 168 const ExtensionId& extension_id, |
| 167 int worker_thread_id); | 169 const GURL& service_worker_scope); |
| 168 void RemoveLazyServiceWorkerEventListener(const std::string& event_name, | 170 void RemoveLazyServiceWorkerEventListener(const std::string& event_name, |
| 169 const ExtensionId& extension_id, | 171 const ExtensionId& extension_id, |
| 170 int worker_thread_id); | 172 const GURL& service_worker_scope); |
| 171 | 173 |
| 172 // If |add_lazy_listener| is true also add the lazy version of this listener. | 174 // If |add_lazy_listener| is true also add the lazy version of this listener. |
| 173 void AddFilteredEventListener(const std::string& event_name, | 175 void AddFilteredEventListener(const std::string& event_name, |
| 174 content::RenderProcessHost* process, | 176 content::RenderProcessHost* process, |
| 175 const std::string& extension_id, | 177 const std::string& extension_id, |
| 176 const base::DictionaryValue& filter, | 178 const base::DictionaryValue& filter, |
| 177 bool add_lazy_listener); | 179 bool add_lazy_listener); |
| 178 | 180 |
| 179 // If |remove_lazy_listener| is true also remove the lazy version of this | 181 // If |remove_lazy_listener| is true also remove the lazy version of this |
| 180 // listener. | 182 // listener. |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 const std::set<std::string>& events, | 263 const std::set<std::string>& events, |
| 262 RegisteredEventType type); | 264 RegisteredEventType type); |
| 263 | 265 |
| 264 // ExtensionRegistryObserver implementation. | 266 // ExtensionRegistryObserver implementation. |
| 265 void OnExtensionLoaded(content::BrowserContext* browser_context, | 267 void OnExtensionLoaded(content::BrowserContext* browser_context, |
| 266 const Extension* extension) override; | 268 const Extension* extension) override; |
| 267 void OnExtensionUnloaded(content::BrowserContext* browser_context, | 269 void OnExtensionUnloaded(content::BrowserContext* browser_context, |
| 268 const Extension* extension, | 270 const Extension* extension, |
| 269 UnloadedExtensionReason reason) override; | 271 UnloadedExtensionReason reason) override; |
| 270 | 272 |
| 271 void AddLazyEventListenerImpl(const std::string& event_name, | 273 void AddLazyEventListenerImpl(std::unique_ptr<EventListener> listener, |
| 272 const ExtensionId& extension_id, | 274 RegisteredEventType type); |
| 273 int worker_thread_id); | 275 void RemoveLazyEventListenerImpl(std::unique_ptr<EventListener> listener, |
| 274 void RemoveLazyEventListenerImpl(const std::string& event_name, | 276 RegisteredEventType type); |
| 275 const ExtensionId& extension_id, | |
| 276 int worker_thread_id); | |
| 277 | 277 |
| 278 // Shared by all event dispatch methods. If |restrict_to_extension_id| is | 278 // Shared by all event dispatch methods. If |restrict_to_extension_id| is |
| 279 // empty, the event is broadcast. An event that just came off the pending | 279 // empty, the event is broadcast. An event that just came off the pending |
| 280 // list may not be delayed again. | 280 // list may not be delayed again. |
| 281 void DispatchEventImpl(const std::string& restrict_to_extension_id, | 281 void DispatchEventImpl(const std::string& restrict_to_extension_id, |
| 282 const linked_ptr<Event>& event); | 282 const linked_ptr<Event>& event); |
| 283 | 283 |
| 284 // Dispatches the event to the specified extension or URL running in | 284 // Dispatches the event to the specified extension or URL running in |
| 285 // |process|. | 285 // |process|. |
| 286 void DispatchEventToProcess(const std::string& extension_id, | 286 void DispatchEventToProcess(const std::string& extension_id, |
| (...skipping 27 matching lines...) Expand all Loading... |
| 314 const std::string& event_name); | 314 const std::string& event_name); |
| 315 | 315 |
| 316 // static | 316 // static |
| 317 static void DoDispatchEventToSenderBookkeepingOnUI( | 317 static void DoDispatchEventToSenderBookkeepingOnUI( |
| 318 void* browser_context_id, | 318 void* browser_context_id, |
| 319 const std::string& extension_id, | 319 const std::string& extension_id, |
| 320 int event_id, | 320 int event_id, |
| 321 events::HistogramValue histogram_value, | 321 events::HistogramValue histogram_value, |
| 322 const std::string& event_name); | 322 const std::string& event_name); |
| 323 | 323 |
| 324 void DispatchPendingEvent(const linked_ptr<Event>& event, | 324 void DispatchPendingEvent( |
| 325 ExtensionHost* host); | 325 const linked_ptr<Event>& event, |
| 326 std::unique_ptr<LazyContextTaskQueue::ContextInfo> params); |
| 326 | 327 |
| 327 // Implementation of EventListenerMap::Delegate. | 328 // Implementation of EventListenerMap::Delegate. |
| 328 void OnListenerAdded(const EventListener* listener) override; | 329 void OnListenerAdded(const EventListener* listener) override; |
| 329 void OnListenerRemoved(const EventListener* listener) override; | 330 void OnListenerRemoved(const EventListener* listener) override; |
| 330 | 331 |
| 331 // RenderProcessHostObserver implementation. | 332 // RenderProcessHostObserver implementation. |
| 332 void RenderProcessExited(content::RenderProcessHost* host, | 333 void RenderProcessExited(content::RenderProcessHost* host, |
| 333 base::TerminationStatus status, | 334 base::TerminationStatus status, |
| 334 int exit_code) override; | 335 int exit_code) override; |
| 335 void RenderProcessHostDestroyed(content::RenderProcessHost* host) override; | 336 void RenderProcessHostDestroyed(content::RenderProcessHost* host) override; |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 442 const std::string event_name; | 443 const std::string event_name; |
| 443 | 444 |
| 444 const std::string extension_id; | 445 const std::string extension_id; |
| 445 const GURL listener_url; | 446 const GURL listener_url; |
| 446 content::BrowserContext* const browser_context; | 447 content::BrowserContext* const browser_context; |
| 447 }; | 448 }; |
| 448 | 449 |
| 449 } // namespace extensions | 450 } // namespace extensions |
| 450 | 451 |
| 451 #endif // EXTENSIONS_BROWSER_EVENT_ROUTER_H_ | 452 #endif // EXTENSIONS_BROWSER_EVENT_ROUTER_H_ |
| OLD | NEW |