| 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 12 matching lines...) Expand all Loading... |
| 23 class ExtensionDevToolsManager; | 23 class ExtensionDevToolsManager; |
| 24 class Profile; | 24 class Profile; |
| 25 | 25 |
| 26 namespace content { | 26 namespace content { |
| 27 class RenderProcessHost; | 27 class RenderProcessHost; |
| 28 } | 28 } |
| 29 | 29 |
| 30 namespace extensions { | 30 namespace extensions { |
| 31 class Extension; | 31 class Extension; |
| 32 class ExtensionHost; | 32 class ExtensionHost; |
| 33 class ExtensionPrefs; |
| 33 | 34 |
| 34 struct Event; | 35 struct Event; |
| 35 | 36 |
| 36 class EventRouter : public content::NotificationObserver, | 37 class EventRouter : public content::NotificationObserver, |
| 37 public EventListenerMap::Delegate { | 38 public EventListenerMap::Delegate { |
| 38 public: | 39 public: |
| 39 // These constants convey the state of our knowledge of whether we're in | 40 // These constants convey the state of our knowledge of whether we're in |
| 40 // a user-caused gesture as part of DispatchEvent. | 41 // a user-caused gesture as part of DispatchEvent. |
| 41 enum UserGestureState { | 42 enum UserGestureState { |
| 42 USER_GESTURE_UNKNOWN = 0, | 43 USER_GESTURE_UNKNOWN = 0, |
| 43 USER_GESTURE_ENABLED = 1, | 44 USER_GESTURE_ENABLED = 1, |
| 44 USER_GESTURE_NOT_ENABLED = 2, | 45 USER_GESTURE_NOT_ENABLED = 2, |
| 45 }; | 46 }; |
| 46 | 47 |
| 47 // Sends an event via ipc_sender to the given extension. Can be called on any | 48 // Sends an event via ipc_sender to the given extension. Can be called on any |
| 48 // thread. | 49 // thread. |
| 49 static void DispatchEvent(IPC::Sender* ipc_sender, | 50 static void DispatchEvent(IPC::Sender* ipc_sender, |
| 50 const std::string& extension_id, | 51 const std::string& extension_id, |
| 51 const std::string& event_name, | 52 const std::string& event_name, |
| 52 scoped_ptr<base::ListValue> event_args, | 53 scoped_ptr<base::ListValue> event_args, |
| 53 const GURL& event_url, | 54 const GURL& event_url, |
| 54 UserGestureState user_gesture, | 55 UserGestureState user_gesture, |
| 55 const EventFilteringInfo& info); | 56 const EventFilteringInfo& info); |
| 56 | 57 |
| 57 explicit EventRouter(Profile* profile); | 58 explicit EventRouter(Profile* profile, |
| 59 ExtensionPrefs* extension_prefs); |
| 58 virtual ~EventRouter(); | 60 virtual ~EventRouter(); |
| 59 | 61 |
| 60 // Add or remove the process/extension pair as a listener for |event_name|. | 62 // Add or remove the process/extension pair as a listener for |event_name|. |
| 61 // Note that multiple extensions can share a process due to process | 63 // Note that multiple extensions can share a process due to process |
| 62 // collapsing. Also, a single extension can have 2 processes if it is a split | 64 // collapsing. Also, a single extension can have 2 processes if it is a split |
| 63 // mode extension. | 65 // mode extension. |
| 64 void AddEventListener(const std::string& event_name, | 66 void AddEventListener(const std::string& event_name, |
| 65 content::RenderProcessHost* process, | 67 content::RenderProcessHost* process, |
| 66 const std::string& extension_id); | 68 const std::string& extension_id); |
| 67 void RemoveEventListener(const std::string& event_name, | 69 void RemoveEventListener(const std::string& event_name, |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 virtual void OnListenerRemoved(const EventListener* listener) OVERRIDE; | 236 virtual void OnListenerRemoved(const EventListener* listener) OVERRIDE; |
| 235 | 237 |
| 236 Profile* profile_; | 238 Profile* profile_; |
| 237 | 239 |
| 238 content::NotificationRegistrar registrar_; | 240 content::NotificationRegistrar registrar_; |
| 239 | 241 |
| 240 scoped_refptr<ExtensionDevToolsManager> extension_devtools_manager_; | 242 scoped_refptr<ExtensionDevToolsManager> extension_devtools_manager_; |
| 241 | 243 |
| 242 EventListenerMap listeners_; | 244 EventListenerMap listeners_; |
| 243 | 245 |
| 246 // True if we should dispatch the event signalling that Chrome was updated |
| 247 // upon loading an extension. |
| 248 bool dispatch_chrome_updated_event_; |
| 249 |
| 244 DISALLOW_COPY_AND_ASSIGN(EventRouter); | 250 DISALLOW_COPY_AND_ASSIGN(EventRouter); |
| 245 }; | 251 }; |
| 246 | 252 |
| 247 struct Event { | 253 struct Event { |
| 248 std::string event_name; | 254 std::string event_name; |
| 249 scoped_ptr<base::ListValue> event_args; | 255 scoped_ptr<base::ListValue> event_args; |
| 250 GURL event_url; | 256 GURL event_url; |
| 251 Profile* restrict_to_profile; | 257 Profile* restrict_to_profile; |
| 252 scoped_ptr<base::ListValue> cross_incognito_args; | 258 scoped_ptr<base::ListValue> cross_incognito_args; |
| 253 EventRouter::UserGestureState user_gesture; | 259 EventRouter::UserGestureState user_gesture; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 267 Profile* restrict_to_profile, | 273 Profile* restrict_to_profile, |
| 268 EventRouter::UserGestureState user_gesture, | 274 EventRouter::UserGestureState user_gesture, |
| 269 const EventFilteringInfo& info); | 275 const EventFilteringInfo& info); |
| 270 | 276 |
| 271 ~Event(); | 277 ~Event(); |
| 272 }; | 278 }; |
| 273 | 279 |
| 274 } // namespace extensions | 280 } // namespace extensions |
| 275 | 281 |
| 276 #endif // CHROME_BROWSER_EXTENSIONS_EVENT_ROUTER_H_ | 282 #endif // CHROME_BROWSER_EXTENSIONS_EVENT_ROUTER_H_ |
| OLD | NEW |