| 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 CHROME_BROWSER_EXTENSIONS_EVENT_ROUTER_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_EVENT_ROUTER_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_EVENT_ROUTER_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_EVENT_ROUTER_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 #include "ipc/ipc_sender.h" | 24 #include "ipc/ipc_sender.h" |
| 25 | 25 |
| 26 class GURL; | 26 class GURL; |
| 27 class Profile; | 27 class Profile; |
| 28 | 28 |
| 29 namespace content { | 29 namespace content { |
| 30 class RenderProcessHost; | 30 class RenderProcessHost; |
| 31 } | 31 } |
| 32 | 32 |
| 33 namespace extensions { | 33 namespace extensions { |
| 34 class ActivityLog; |
| 34 class Extension; | 35 class Extension; |
| 35 class ExtensionHost; | 36 class ExtensionHost; |
| 36 class ExtensionPrefs; | 37 class ExtensionPrefs; |
| 37 | 38 |
| 38 struct Event; | 39 struct Event; |
| 39 struct EventListenerInfo; | 40 struct EventListenerInfo; |
| 40 | 41 |
| 41 class EventRouter : public content::NotificationObserver, | 42 class EventRouter : public content::NotificationObserver, |
| 42 public EventListenerMap::Delegate { | 43 public EventListenerMap::Delegate { |
| 43 public: | 44 public: |
| (...skipping 11 matching lines...) Expand all Loading... |
| 55 public: | 56 public: |
| 56 // Called when a listener is added. | 57 // Called when a listener is added. |
| 57 virtual void OnListenerAdded(const EventListenerInfo& details) {} | 58 virtual void OnListenerAdded(const EventListenerInfo& details) {} |
| 58 // Called when a listener is removed. | 59 // Called when a listener is removed. |
| 59 virtual void OnListenerRemoved(const EventListenerInfo& details) {} | 60 virtual void OnListenerRemoved(const EventListenerInfo& details) {} |
| 60 }; | 61 }; |
| 61 | 62 |
| 62 // Sends an event via ipc_sender to the given extension. Can be called on any | 63 // Sends an event via ipc_sender to the given extension. Can be called on any |
| 63 // thread. | 64 // thread. |
| 64 static void DispatchEvent(IPC::Sender* ipc_sender, | 65 static void DispatchEvent(IPC::Sender* ipc_sender, |
| 66 void* profile_id, |
| 65 const std::string& extension_id, | 67 const std::string& extension_id, |
| 66 const std::string& event_name, | 68 const std::string& event_name, |
| 67 scoped_ptr<base::ListValue> event_args, | 69 scoped_ptr<base::ListValue> event_args, |
| 68 const GURL& event_url, | 70 const GURL& event_url, |
| 69 UserGestureState user_gesture, | 71 UserGestureState user_gesture, |
| 70 const EventFilteringInfo& info); | 72 const EventFilteringInfo& info); |
| 71 | 73 |
| 72 EventRouter(Profile* profile, ExtensionPrefs* extension_prefs); | 74 EventRouter(Profile* profile, ExtensionPrefs* extension_prefs); |
| 73 virtual ~EventRouter(); | 75 virtual ~EventRouter(); |
| 74 | 76 |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 | 144 |
| 143 // A map between an event name and a set of extensions that are listening | 145 // A map between an event name and a set of extensions that are listening |
| 144 // to that event. | 146 // to that event. |
| 145 typedef std::map<std::string, std::set<ListenerProcess> > ListenerMap; | 147 typedef std::map<std::string, std::set<ListenerProcess> > ListenerMap; |
| 146 | 148 |
| 147 // An identifier for an event dispatch that is used to prevent double dispatch | 149 // An identifier for an event dispatch that is used to prevent double dispatch |
| 148 // due to race conditions between the direct and lazy dispatch paths. | 150 // due to race conditions between the direct and lazy dispatch paths. |
| 149 typedef std::pair<const content::BrowserContext*, std::string> | 151 typedef std::pair<const content::BrowserContext*, std::string> |
| 150 EventDispatchIdentifier; | 152 EventDispatchIdentifier; |
| 151 | 153 |
| 154 // Records an event notification in the extension activity log. Can be |
| 155 // called from any thread. |
| 156 static void LogExtensionEventMessage(void* profile_id, |
| 157 const std::string& extension_id, |
| 158 const std::string& event_name, |
| 159 scoped_ptr<ListValue> event_args); |
| 160 |
| 152 // TODO(gdk): Document this. | 161 // TODO(gdk): Document this. |
| 153 static void DispatchExtensionMessage( | 162 static void DispatchExtensionMessage( |
| 154 IPC::Sender* ipc_sender, | 163 IPC::Sender* ipc_sender, |
| 164 void* profile_id, |
| 155 const std::string& extension_id, | 165 const std::string& extension_id, |
| 156 const std::string& event_name, | 166 const std::string& event_name, |
| 157 base::ListValue* event_args, | 167 base::ListValue* event_args, |
| 158 const GURL& event_url, | 168 const GURL& event_url, |
| 159 UserGestureState user_gesture, | 169 UserGestureState user_gesture, |
| 160 const extensions::EventFilteringInfo& info); | 170 const extensions::EventFilteringInfo& info); |
| 161 | 171 |
| 162 virtual void Observe(int type, | 172 virtual void Observe(int type, |
| 163 const content::NotificationSource& source, | 173 const content::NotificationSource& source, |
| 164 const content::NotificationDetails& details) OVERRIDE; | 174 const content::NotificationDetails& details) OVERRIDE; |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 | 229 |
| 220 Profile* profile_; | 230 Profile* profile_; |
| 221 | 231 |
| 222 content::NotificationRegistrar registrar_; | 232 content::NotificationRegistrar registrar_; |
| 223 | 233 |
| 224 EventListenerMap listeners_; | 234 EventListenerMap listeners_; |
| 225 | 235 |
| 226 typedef base::hash_map<std::string, Observer*> ObserverMap; | 236 typedef base::hash_map<std::string, Observer*> ObserverMap; |
| 227 ObserverMap observers_; | 237 ObserverMap observers_; |
| 228 | 238 |
| 239 ActivityLog* activity_log_; |
| 240 |
| 229 // True if we should dispatch the event signalling that Chrome was updated | 241 // True if we should dispatch the event signalling that Chrome was updated |
| 230 // upon loading an extension. | 242 // upon loading an extension. |
| 231 bool dispatch_chrome_updated_event_; | 243 bool dispatch_chrome_updated_event_; |
| 232 | 244 |
| 233 DISALLOW_COPY_AND_ASSIGN(EventRouter); | 245 DISALLOW_COPY_AND_ASSIGN(EventRouter); |
| 234 }; | 246 }; |
| 235 | 247 |
| 236 struct Event { | 248 struct Event { |
| 237 typedef base::Callback< | 249 typedef base::Callback< |
| 238 void(Profile*, const Extension*, base::ListValue*)> WillDispatchCallback; | 250 void(Profile*, const Extension*, base::ListValue*)> WillDispatchCallback; |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 290 EventListenerInfo(const std::string& event_name, | 302 EventListenerInfo(const std::string& event_name, |
| 291 const std::string& extension_id); | 303 const std::string& extension_id); |
| 292 | 304 |
| 293 const std::string event_name; | 305 const std::string event_name; |
| 294 const std::string extension_id; | 306 const std::string extension_id; |
| 295 }; | 307 }; |
| 296 | 308 |
| 297 } // namespace extensions | 309 } // namespace extensions |
| 298 | 310 |
| 299 #endif // CHROME_BROWSER_EXTENSIONS_EVENT_ROUTER_H_ | 311 #endif // CHROME_BROWSER_EXTENSIONS_EVENT_ROUTER_H_ |
| OLD | NEW |