| 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/gtest_prod_util.h" | 16 #include "base/gtest_prod_util.h" |
| 17 #include "base/memory/linked_ptr.h" | 17 #include "base/memory/linked_ptr.h" |
| 18 #include "base/memory/ref_counted.h" | 18 #include "base/memory/ref_counted.h" |
| 19 #include "base/scoped_observer.h" |
| 19 #include "base/values.h" | 20 #include "base/values.h" |
| 20 #include "content/public/browser/notification_observer.h" | 21 #include "content/public/browser/notification_observer.h" |
| 21 #include "content/public/browser/notification_registrar.h" | 22 #include "content/public/browser/notification_registrar.h" |
| 22 #include "extensions/browser/event_listener_map.h" | 23 #include "extensions/browser/event_listener_map.h" |
| 24 #include "extensions/browser/extension_registry_observer.h" |
| 23 #include "extensions/common/event_filtering_info.h" | 25 #include "extensions/common/event_filtering_info.h" |
| 24 #include "ipc/ipc_sender.h" | 26 #include "ipc/ipc_sender.h" |
| 25 | 27 |
| 26 class GURL; | 28 class GURL; |
| 27 class PrefService; | 29 class PrefService; |
| 28 | 30 |
| 29 namespace content { | 31 namespace content { |
| 30 class BrowserContext; | 32 class BrowserContext; |
| 31 class RenderProcessHost; | 33 class RenderProcessHost; |
| 32 } | 34 } |
| 33 | 35 |
| 34 namespace extensions { | 36 namespace extensions { |
| 35 class ActivityLog; | 37 class ActivityLog; |
| 36 class Extension; | 38 class Extension; |
| 37 class ExtensionHost; | 39 class ExtensionHost; |
| 38 class ExtensionPrefs; | 40 class ExtensionPrefs; |
| 41 class ExtensionRegistry; |
| 39 | 42 |
| 40 struct Event; | 43 struct Event; |
| 41 struct EventDispatchInfo; | 44 struct EventDispatchInfo; |
| 42 struct EventListenerInfo; | 45 struct EventListenerInfo; |
| 43 | 46 |
| 44 class EventRouter : public content::NotificationObserver, | 47 class EventRouter : public content::NotificationObserver, |
| 48 public ExtensionRegistryObserver, |
| 45 public EventListenerMap::Delegate { | 49 public EventListenerMap::Delegate { |
| 46 public: | 50 public: |
| 47 // These constants convey the state of our knowledge of whether we're in | 51 // These constants convey the state of our knowledge of whether we're in |
| 48 // a user-caused gesture as part of DispatchEvent. | 52 // a user-caused gesture as part of DispatchEvent. |
| 49 enum UserGestureState { | 53 enum UserGestureState { |
| 50 USER_GESTURE_UNKNOWN = 0, | 54 USER_GESTURE_UNKNOWN = 0, |
| 51 USER_GESTURE_ENABLED = 1, | 55 USER_GESTURE_ENABLED = 1, |
| 52 USER_GESTURE_NOT_ENABLED = 2, | 56 USER_GESTURE_NOT_ENABLED = 2, |
| 53 }; | 57 }; |
| 54 | 58 |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 // TODO(gdk): Document this. | 193 // TODO(gdk): Document this. |
| 190 static void DispatchExtensionMessage( | 194 static void DispatchExtensionMessage( |
| 191 IPC::Sender* ipc_sender, | 195 IPC::Sender* ipc_sender, |
| 192 void* browser_context_id, | 196 void* browser_context_id, |
| 193 const std::string& extension_id, | 197 const std::string& extension_id, |
| 194 const std::string& event_name, | 198 const std::string& event_name, |
| 195 base::ListValue* event_args, | 199 base::ListValue* event_args, |
| 196 UserGestureState user_gesture, | 200 UserGestureState user_gesture, |
| 197 const extensions::EventFilteringInfo& info); | 201 const extensions::EventFilteringInfo& info); |
| 198 | 202 |
| 203 // content::NotificationObserver implementation. |
| 199 virtual void Observe(int type, | 204 virtual void Observe(int type, |
| 200 const content::NotificationSource& source, | 205 const content::NotificationSource& source, |
| 201 const content::NotificationDetails& details) OVERRIDE; | 206 const content::NotificationDetails& details) OVERRIDE; |
| 202 | 207 |
| 208 // ExtensionRegistryObserver implementation. |
| 209 virtual void OnExtensionLoaded(content::BrowserContext* browser_context, |
| 210 const Extension* extension) OVERRIDE; |
| 211 virtual void OnExtensionUnloaded( |
| 212 content::BrowserContext* browser_context, |
| 213 const Extension* extension, |
| 214 UnloadedExtensionInfo::Reason reason) OVERRIDE; |
| 215 |
| 203 // Returns true if the given listener map contains a event listeners for | 216 // Returns true if the given listener map contains a event listeners for |
| 204 // the given event. If |extension_id| is non-empty, we also check that that | 217 // the given event. If |extension_id| is non-empty, we also check that that |
| 205 // extension is one of the listeners. | 218 // extension is one of the listeners. |
| 206 bool HasEventListenerImpl(const ListenerMap& listeners, | 219 bool HasEventListenerImpl(const ListenerMap& listeners, |
| 207 const std::string& extension_id, | 220 const std::string& extension_id, |
| 208 const std::string& event_name); | 221 const std::string& event_name); |
| 209 | 222 |
| 210 // Shared by DispatchEvent*. If |restrict_to_extension_id| is empty, the | 223 // Shared by DispatchEvent*. If |restrict_to_extension_id| is empty, the |
| 211 // event is broadcast. | 224 // event is broadcast. |
| 212 // An event that just came off the pending list may not be delayed again. | 225 // An event that just came off the pending list may not be delayed again. |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 virtual void OnListenerRemoved(const EventListener* listener) OVERRIDE; | 288 virtual void OnListenerRemoved(const EventListener* listener) OVERRIDE; |
| 276 | 289 |
| 277 content::BrowserContext* browser_context_; | 290 content::BrowserContext* browser_context_; |
| 278 | 291 |
| 279 // The ExtensionPrefs associated with |browser_context_|. May be NULL in | 292 // The ExtensionPrefs associated with |browser_context_|. May be NULL in |
| 280 // tests. | 293 // tests. |
| 281 ExtensionPrefs* extension_prefs_; | 294 ExtensionPrefs* extension_prefs_; |
| 282 | 295 |
| 283 content::NotificationRegistrar registrar_; | 296 content::NotificationRegistrar registrar_; |
| 284 | 297 |
| 298 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> |
| 299 extension_registry_observer_; |
| 300 |
| 285 EventListenerMap listeners_; | 301 EventListenerMap listeners_; |
| 286 | 302 |
| 287 // Map from base event name to observer. | 303 // Map from base event name to observer. |
| 288 typedef base::hash_map<std::string, Observer*> ObserverMap; | 304 typedef base::hash_map<std::string, Observer*> ObserverMap; |
| 289 ObserverMap observers_; | 305 ObserverMap observers_; |
| 290 | 306 |
| 291 DISALLOW_COPY_AND_ASSIGN(EventRouter); | 307 DISALLOW_COPY_AND_ASSIGN(EventRouter); |
| 292 }; | 308 }; |
| 293 | 309 |
| 294 struct Event { | 310 struct Event { |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 359 // "webRequest.onCompleted/123". | 375 // "webRequest.onCompleted/123". |
| 360 const std::string event_name; | 376 const std::string event_name; |
| 361 | 377 |
| 362 const std::string extension_id; | 378 const std::string extension_id; |
| 363 content::BrowserContext* browser_context; | 379 content::BrowserContext* browser_context; |
| 364 }; | 380 }; |
| 365 | 381 |
| 366 } // namespace extensions | 382 } // namespace extensions |
| 367 | 383 |
| 368 #endif // EXTENSIONS_BROWSER_EVENT_ROUTER_H_ | 384 #endif // EXTENSIONS_BROWSER_EVENT_ROUTER_H_ |
| OLD | NEW |