| 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> |
| 11 #include <utility> | 11 #include <utility> |
| 12 | 12 |
| 13 #include "base/callback.h" | 13 #include "base/callback.h" |
| 14 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
| 15 #include "base/containers/hash_tables.h" | 15 #include "base/containers/hash_tables.h" |
| 16 #include "base/memory/linked_ptr.h" | 16 #include "base/memory/linked_ptr.h" |
| 17 #include "base/memory/ref_counted.h" | 17 #include "base/memory/ref_counted.h" |
| 18 #include "base/scoped_observer.h" |
| 18 #include "base/values.h" | 19 #include "base/values.h" |
| 19 #include "content/public/browser/notification_observer.h" | 20 #include "content/public/browser/notification_observer.h" |
| 20 #include "content/public/browser/notification_registrar.h" | 21 #include "content/public/browser/notification_registrar.h" |
| 21 #include "extensions/browser/event_listener_map.h" | 22 #include "extensions/browser/event_listener_map.h" |
| 23 #include "extensions/browser/extension_registry_observer.h" |
| 22 #include "extensions/common/event_filtering_info.h" | 24 #include "extensions/common/event_filtering_info.h" |
| 23 #include "ipc/ipc_sender.h" | 25 #include "ipc/ipc_sender.h" |
| 24 | 26 |
| 25 class GURL; | 27 class GURL; |
| 26 class PrefService; | 28 class PrefService; |
| 27 | 29 |
| 28 namespace content { | 30 namespace content { |
| 29 class BrowserContext; | 31 class BrowserContext; |
| 30 class RenderProcessHost; | 32 class RenderProcessHost; |
| 31 } | 33 } |
| 32 | 34 |
| 33 namespace extensions { | 35 namespace extensions { |
| 34 class ActivityLog; | 36 class ActivityLog; |
| 35 class Extension; | 37 class Extension; |
| 36 class ExtensionHost; | 38 class ExtensionHost; |
| 37 class ExtensionPrefs; | 39 class ExtensionPrefs; |
| 40 class ExtensionRegistry; |
| 38 | 41 |
| 39 struct Event; | 42 struct Event; |
| 40 struct EventDispatchInfo; | 43 struct EventDispatchInfo; |
| 41 struct EventListenerInfo; | 44 struct EventListenerInfo; |
| 42 | 45 |
| 43 class EventRouter : public content::NotificationObserver, | 46 class EventRouter : public content::NotificationObserver, |
| 47 public ExtensionRegistryObserver, |
| 44 public EventListenerMap::Delegate { | 48 public EventListenerMap::Delegate { |
| 45 public: | 49 public: |
| 46 // These constants convey the state of our knowledge of whether we're in | 50 // These constants convey the state of our knowledge of whether we're in |
| 47 // a user-caused gesture as part of DispatchEvent. | 51 // a user-caused gesture as part of DispatchEvent. |
| 48 enum UserGestureState { | 52 enum UserGestureState { |
| 49 USER_GESTURE_UNKNOWN = 0, | 53 USER_GESTURE_UNKNOWN = 0, |
| 50 USER_GESTURE_ENABLED = 1, | 54 USER_GESTURE_ENABLED = 1, |
| 51 USER_GESTURE_NOT_ENABLED = 2, | 55 USER_GESTURE_NOT_ENABLED = 2, |
| 52 }; | 56 }; |
| 53 | 57 |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 void* browser_context_id, | 204 void* browser_context_id, |
| 201 const std::string& extension_id, | 205 const std::string& extension_id, |
| 202 const std::string& event_name, | 206 const std::string& event_name, |
| 203 base::ListValue* event_args, | 207 base::ListValue* event_args, |
| 204 UserGestureState user_gesture, | 208 UserGestureState user_gesture, |
| 205 const extensions::EventFilteringInfo& info); | 209 const extensions::EventFilteringInfo& info); |
| 206 | 210 |
| 207 virtual void Observe(int type, | 211 virtual void Observe(int type, |
| 208 const content::NotificationSource& source, | 212 const content::NotificationSource& source, |
| 209 const content::NotificationDetails& details) OVERRIDE; | 213 const content::NotificationDetails& details) OVERRIDE; |
| 214 // ExtensionRegistryObserver implementation. |
| 215 virtual void OnExtensionLoaded(content::BrowserContext* browser_context, |
| 216 const Extension* extension) OVERRIDE; |
| 217 virtual void OnExtensionUnloaded( |
| 218 content::BrowserContext* browser_context, |
| 219 const Extension* extension, |
| 220 UnloadedExtensionInfo::Reason reason) OVERRIDE; |
| 210 | 221 |
| 211 // Returns true if the given listener map contains a event listeners for | 222 // Returns true if the given listener map contains a event listeners for |
| 212 // the given event. If |extension_id| is non-empty, we also check that that | 223 // the given event. If |extension_id| is non-empty, we also check that that |
| 213 // extension is one of the listeners. | 224 // extension is one of the listeners. |
| 214 bool HasEventListenerImpl(const ListenerMap& listeners, | 225 bool HasEventListenerImpl(const ListenerMap& listeners, |
| 215 const std::string& extension_id, | 226 const std::string& extension_id, |
| 216 const std::string& event_name); | 227 const std::string& event_name); |
| 217 | 228 |
| 218 // Shared by DispatchEvent*. If |restrict_to_extension_id| is empty, the | 229 // Shared by DispatchEvent*. If |restrict_to_extension_id| is empty, the |
| 219 // event is broadcast. | 230 // event is broadcast. |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 virtual void OnListenerRemoved(const EventListener* listener) OVERRIDE; | 296 virtual void OnListenerRemoved(const EventListener* listener) OVERRIDE; |
| 286 | 297 |
| 287 content::BrowserContext* browser_context_; | 298 content::BrowserContext* browser_context_; |
| 288 | 299 |
| 289 // The ExtensionPrefs associated with |browser_context_|. May be NULL in | 300 // The ExtensionPrefs associated with |browser_context_|. May be NULL in |
| 290 // tests. | 301 // tests. |
| 291 ExtensionPrefs* extension_prefs_; | 302 ExtensionPrefs* extension_prefs_; |
| 292 | 303 |
| 293 content::NotificationRegistrar registrar_; | 304 content::NotificationRegistrar registrar_; |
| 294 | 305 |
| 306 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> |
| 307 extension_registry_observer_; |
| 308 |
| 295 EventListenerMap listeners_; | 309 EventListenerMap listeners_; |
| 296 | 310 |
| 297 // Map from base event name to observer. | 311 // Map from base event name to observer. |
| 298 typedef base::hash_map<std::string, Observer*> ObserverMap; | 312 typedef base::hash_map<std::string, Observer*> ObserverMap; |
| 299 ObserverMap observers_; | 313 ObserverMap observers_; |
| 300 | 314 |
| 301 DISALLOW_COPY_AND_ASSIGN(EventRouter); | 315 DISALLOW_COPY_AND_ASSIGN(EventRouter); |
| 302 }; | 316 }; |
| 303 | 317 |
| 304 struct Event { | 318 struct Event { |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 374 const std::string event_name; | 388 const std::string event_name; |
| 375 | 389 |
| 376 const std::string extension_id; | 390 const std::string extension_id; |
| 377 const GURL listener_url; | 391 const GURL listener_url; |
| 378 content::BrowserContext* browser_context; | 392 content::BrowserContext* browser_context; |
| 379 }; | 393 }; |
| 380 | 394 |
| 381 } // namespace extensions | 395 } // namespace extensions |
| 382 | 396 |
| 383 #endif // EXTENSIONS_BROWSER_EVENT_ROUTER_H_ | 397 #endif // EXTENSIONS_BROWSER_EVENT_ROUTER_H_ |
| OLD | NEW |