| 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_EXTENSION_EVENT_ROUTER_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_EVENT_ROUTER_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_EVENT_ROUTER_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_EVENT_ROUTER_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <map> | 9 #include <map> |
| 10 #include <set> | 10 #include <set> |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 class Extension; | 21 class Extension; |
| 22 class ExtensionDevToolsManager; | 22 class ExtensionDevToolsManager; |
| 23 class Profile; | 23 class Profile; |
| 24 | 24 |
| 25 namespace content { | 25 namespace content { |
| 26 class RenderProcessHost; | 26 class RenderProcessHost; |
| 27 } | 27 } |
| 28 | 28 |
| 29 class ExtensionEventRouter : public content::NotificationObserver { | 29 class ExtensionEventRouter : public content::NotificationObserver { |
| 30 public: | 30 public: |
| 31 // These constants convey the state of our knowledge of whether we're in |
| 32 // a user-caused gesture as part of DispatchEvent. |
| 33 enum UserGestureState { |
| 34 USER_GESTURE_UNKNOWN = 0, |
| 35 USER_GESTURE_ENABLED = 1, |
| 36 USER_GESTURE_NOT_ENABLED = 2, |
| 37 }; |
| 38 |
| 31 // Sends an event via ipc_sender to the given extension. Can be called on | 39 // Sends an event via ipc_sender to the given extension. Can be called on |
| 32 // any thread. | 40 // any thread. |
| 33 static void DispatchEvent(IPC::Message::Sender* ipc_sender, | 41 static void DispatchEvent(IPC::Message::Sender* ipc_sender, |
| 34 const std::string& extension_id, | 42 const std::string& extension_id, |
| 35 const std::string& event_name, | 43 const std::string& event_name, |
| 36 const std::string& event_args, | 44 const std::string& event_args, |
| 37 const GURL& event_url); | 45 const GURL& event_url, |
| 46 UserGestureState user_gesture); |
| 38 | 47 |
| 39 explicit ExtensionEventRouter(Profile* profile); | 48 explicit ExtensionEventRouter(Profile* profile); |
| 40 virtual ~ExtensionEventRouter(); | 49 virtual ~ExtensionEventRouter(); |
| 41 | 50 |
| 42 // Add or remove the process/extension pair as a listener for |event_name|. | 51 // Add or remove the process/extension pair as a listener for |event_name|. |
| 43 // Note that multiple extensions can share a process due to process | 52 // Note that multiple extensions can share a process due to process |
| 44 // collapsing. Also, a single extension can have 2 processes if it is a split | 53 // collapsing. Also, a single extension can have 2 processes if it is a split |
| 45 // mode extension. | 54 // mode extension. |
| 46 void AddEventListener(const std::string& event_name, | 55 void AddEventListener(const std::string& event_name, |
| 47 content::RenderProcessHost* process, | 56 content::RenderProcessHost* process, |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 const GURL& event_url); | 88 const GURL& event_url); |
| 80 | 89 |
| 81 // Same as above, except only send the event to the given extension. | 90 // Same as above, except only send the event to the given extension. |
| 82 virtual void DispatchEventToExtension( | 91 virtual void DispatchEventToExtension( |
| 83 const std::string& extension_id, | 92 const std::string& extension_id, |
| 84 const std::string& event_name, | 93 const std::string& event_name, |
| 85 const std::string& event_args, | 94 const std::string& event_args, |
| 86 Profile* restrict_to_profile, | 95 Profile* restrict_to_profile, |
| 87 const GURL& event_url); | 96 const GURL& event_url); |
| 88 | 97 |
| 98 // Dispatch an event to particular extension. Also include an |
| 99 // explicit user gesture indicator. |
| 100 virtual void DispatchEventToExtension( |
| 101 const std::string& extension_id, |
| 102 const std::string& event_name, |
| 103 const std::string& event_args, |
| 104 Profile* restrict_to_profile, |
| 105 const GURL& event_url, |
| 106 UserGestureState user_gesture); |
| 107 |
| 89 // Send different versions of an event to extensions in different profiles. | 108 // Send different versions of an event to extensions in different profiles. |
| 90 // This is used in the case of sending one event to extensions that have | 109 // This is used in the case of sending one event to extensions that have |
| 91 // incognito access, and another event to extensions that don't (here), | 110 // incognito access, and another event to extensions that don't (here), |
| 92 // in order to avoid sending 2 events to "spanning" extensions. | 111 // in order to avoid sending 2 events to "spanning" extensions. |
| 93 // If |cross_incognito_profile| is non-NULL and different from | 112 // If |cross_incognito_profile| is non-NULL and different from |
| 94 // restrict_to_profile, send the event with cross_incognito_args to the | 113 // restrict_to_profile, send the event with cross_incognito_args to the |
| 95 // extensions in that profile that can't cross incognito. | 114 // extensions in that profile that can't cross incognito. |
| 96 void DispatchEventsToRenderersAcrossIncognito( | 115 void DispatchEventsToRenderersAcrossIncognito( |
| 97 const std::string& event_name, | 116 const std::string& event_name, |
| 98 const std::string& event_args, | 117 const std::string& event_args, |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 PendingEventsPerExtMap pending_events_; | 192 PendingEventsPerExtMap pending_events_; |
| 174 | 193 |
| 175 // Track of the number of dispatched events that have not yet sent an | 194 // Track of the number of dispatched events that have not yet sent an |
| 176 // ACK from the renderer. | 195 // ACK from the renderer. |
| 177 void IncrementInFlightEvents(const Extension* extension); | 196 void IncrementInFlightEvents(const Extension* extension); |
| 178 | 197 |
| 179 DISALLOW_COPY_AND_ASSIGN(ExtensionEventRouter); | 198 DISALLOW_COPY_AND_ASSIGN(ExtensionEventRouter); |
| 180 }; | 199 }; |
| 181 | 200 |
| 182 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_EVENT_ROUTER_H_ | 201 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_EVENT_ROUTER_H_ |
| OLD | NEW |