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 24 matching lines...) Expand all Loading... | |
35 public: | 35 public: |
36 // These constants convey the state of our knowledge of whether we're in | 36 // These constants convey the state of our knowledge of whether we're in |
37 // a user-caused gesture as part of DispatchEvent. | 37 // a user-caused gesture as part of DispatchEvent. |
38 enum UserGestureState { | 38 enum UserGestureState { |
39 USER_GESTURE_UNKNOWN = 0, | 39 USER_GESTURE_UNKNOWN = 0, |
40 USER_GESTURE_ENABLED = 1, | 40 USER_GESTURE_ENABLED = 1, |
41 USER_GESTURE_NOT_ENABLED = 2, | 41 USER_GESTURE_NOT_ENABLED = 2, |
42 }; | 42 }; |
43 | 43 |
44 // Sends an event via ipc_sender to the given extension. Can be called on | 44 // Sends an event via ipc_sender to the given extension. Can be called on |
45 // any thread. | 45 // any thread. |
bryeung
2012/07/09 15:12:08
It would be nice to update the comments here (and
Garret Kelly
2012/07/09 15:32:29
Done.
| |
46 static void DispatchEvent(IPC::Sender* ipc_sender, | 46 static void DispatchEvent(IPC::Sender* ipc_sender, |
47 const std::string& extension_id, | 47 const std::string& extension_id, |
48 const std::string& event_name, | 48 const std::string& event_name, |
49 const base::Value& event_args, | 49 base::ListValue* event_args, |
50 const GURL& event_url, | 50 const GURL& event_url, |
51 UserGestureState user_gesture); | 51 UserGestureState user_gesture); |
52 | 52 |
53 // This invocation is deprecated. All future consumers of this API should be | |
54 // sending Values as event arguments, using the above version. | |
55 static void DispatchEvent(IPC::Sender* ipc_sender, | |
56 const std::string& extension_id, | |
57 const std::string& event_name, | |
58 const std::string& event_args, | |
59 const GURL& event_url, | |
60 UserGestureState user_gesture); | |
61 | |
62 explicit ExtensionEventRouter(Profile* profile); | 53 explicit ExtensionEventRouter(Profile* profile); |
63 virtual ~ExtensionEventRouter(); | 54 virtual ~ExtensionEventRouter(); |
64 | 55 |
65 // Add or remove the process/extension pair as a listener for |event_name|. | 56 // Add or remove the process/extension pair as a listener for |event_name|. |
66 // Note that multiple extensions can share a process due to process | 57 // Note that multiple extensions can share a process due to process |
67 // collapsing. Also, a single extension can have 2 processes if it is a split | 58 // collapsing. Also, a single extension can have 2 processes if it is a split |
68 // mode extension. | 59 // mode extension. |
69 void AddEventListener(const std::string& event_name, | 60 void AddEventListener(const std::string& event_name, |
70 content::RenderProcessHost* process, | 61 content::RenderProcessHost* process, |
71 const std::string& extension_id); | 62 const std::string& extension_id); |
(...skipping 18 matching lines...) Expand all Loading... | |
90 const std::string& event_name); | 81 const std::string& event_name); |
91 | 82 |
92 // Send an event to every registered extension renderer. If | 83 // Send an event to every registered extension renderer. If |
93 // |restrict_to_profile| is non-NULL, then the event will not be sent to other | 84 // |restrict_to_profile| is non-NULL, then the event will not be sent to other |
94 // profiles unless the extension has permission (e.g. incognito tab update -> | 85 // profiles unless the extension has permission (e.g. incognito tab update -> |
95 // normal profile only works if extension is allowed incognito access). If | 86 // normal profile only works if extension is allowed incognito access). If |
96 // |event_url| is not empty, the event is only sent to extension with host | 87 // |event_url| is not empty, the event is only sent to extension with host |
97 // permissions for this url. | 88 // permissions for this url. |
98 void DispatchEventToRenderers( | 89 void DispatchEventToRenderers( |
99 const std::string& event_name, | 90 const std::string& event_name, |
100 const std::string& event_args, | 91 base::ListValue* event_args, |
101 Profile* restrict_to_profile, | 92 Profile* restrict_to_profile, |
102 const GURL& event_url); | 93 const GURL& event_url); |
103 | 94 |
104 // Same as above, except only send the event to the given extension. | 95 // Same as above, except only send the event to the given extension. |
105 virtual void DispatchEventToExtension( | 96 virtual void DispatchEventToExtension( |
106 const std::string& extension_id, | 97 const std::string& extension_id, |
107 const std::string& event_name, | 98 const std::string& event_name, |
108 const base::Value& event_args, | 99 base::ListValue* event_args, |
109 Profile* restrict_to_profile, | 100 Profile* restrict_to_profile, |
110 const GURL& event_url); | 101 const GURL& event_url); |
111 | 102 |
112 // This invocation is deprecated. The above variant which uses a Value for | |
113 // event_args is to be used instead. | |
114 virtual void DispatchEventToExtension( | |
115 const std::string& extension_id, | |
116 const std::string& event_name, | |
117 const std::string& event_args, | |
118 Profile* restrict_to_profile, | |
119 const GURL& event_url); | |
120 | |
121 // Dispatch an event to particular extension. Also include an | 103 // Dispatch an event to particular extension. Also include an |
122 // explicit user gesture indicator. | 104 // explicit user gesture indicator. |
123 virtual void DispatchEventToExtension( | 105 virtual void DispatchEventToExtension( |
124 const std::string& extension_id, | 106 const std::string& extension_id, |
125 const std::string& event_name, | 107 const std::string& event_name, |
126 const std::string& event_args, | 108 base::ListValue* event_args, |
127 Profile* restrict_to_profile, | 109 Profile* restrict_to_profile, |
128 const GURL& event_url, | 110 const GURL& event_url, |
129 UserGestureState user_gesture); | 111 UserGestureState user_gesture); |
130 | 112 |
131 // Send different versions of an event to extensions in different profiles. | 113 // Send different versions of an event to extensions in different profiles. |
132 // This is used in the case of sending one event to extensions that have | 114 // This is used in the case of sending one event to extensions that have |
133 // incognito access, and another event to extensions that don't (here), | 115 // incognito access, and another event to extensions that don't (here), |
134 // in order to avoid sending 2 events to "spanning" extensions. | 116 // in order to avoid sending 2 events to "spanning" extensions. |
135 // If |cross_incognito_profile| is non-NULL and different from | 117 // If |cross_incognito_profile| is non-NULL and different from |
136 // restrict_to_profile, send the event with cross_incognito_args to the | 118 // restrict_to_profile, send the event with cross_incognito_args to the |
137 // extensions in that profile that can't cross incognito. | 119 // extensions in that profile that can't cross incognito. |
138 void DispatchEventsToRenderersAcrossIncognito( | 120 void DispatchEventsToRenderersAcrossIncognito( |
139 const std::string& event_name, | 121 const std::string& event_name, |
140 const std::string& event_args, | 122 base::ListValue* event_args, |
141 Profile* restrict_to_profile, | 123 Profile* restrict_to_profile, |
142 const std::string& cross_incognito_args, | 124 base::ListValue* cross_incognito_args, |
143 const GURL& event_url); | 125 const GURL& event_url); |
144 | 126 |
145 // Record the Event Ack from the renderer. (One less event in-flight.) | 127 // Record the Event Ack from the renderer. (One less event in-flight.) |
146 void OnEventAck(Profile* profile, const std::string& extension_id); | 128 void OnEventAck(Profile* profile, const std::string& extension_id); |
147 | 129 |
148 private: | 130 private: |
149 // The details of an event to be dispatched. | 131 // The details of an event to be dispatched. |
150 struct ExtensionEvent; | 132 struct ExtensionEvent; |
151 | 133 |
152 // The extension and process that contains the event listener for a given | 134 // The extension and process that contains the event listener for a given |
(...skipping 27 matching lines...) Expand all Loading... | |
180 const linked_ptr<ExtensionEvent>& event); | 162 const linked_ptr<ExtensionEvent>& event); |
181 | 163 |
182 // Returns false when the event is scoped to a profile and the listening | 164 // Returns false when the event is scoped to a profile and the listening |
183 // extension does not have access to events from that profile. Also fills | 165 // extension does not have access to events from that profile. Also fills |
184 // |event_args| with the proper arguments to send, which may differ if | 166 // |event_args| with the proper arguments to send, which may differ if |
185 // the event crosses the incognito boundary. | 167 // the event crosses the incognito boundary. |
186 bool CanDispatchEventToProfile( | 168 bool CanDispatchEventToProfile( |
187 Profile* profile, | 169 Profile* profile, |
188 const extensions::Extension* extension, | 170 const extensions::Extension* extension, |
189 const linked_ptr<ExtensionEvent>& event, | 171 const linked_ptr<ExtensionEvent>& event, |
190 const base::Value** event_args); | 172 base::ListValue** event_args); |
191 | 173 |
192 // Ensures that all lazy background pages that are interested in the given | 174 // Ensures that all lazy background pages that are interested in the given |
193 // event are loaded, and queues the event if the page is not ready yet. | 175 // event are loaded, and queues the event if the page is not ready yet. |
194 // If |extension_id| is non-empty, we load only that extension's page | 176 // If |extension_id| is non-empty, we load only that extension's page |
195 // (assuming it is interested in the event). | 177 // (assuming it is interested in the event). |
196 void LoadLazyBackgroundPagesForEvent( | 178 void LoadLazyBackgroundPagesForEvent( |
197 const std::string& extension_id, | 179 const std::string& extension_id, |
198 const linked_ptr<ExtensionEvent>& event); | 180 const linked_ptr<ExtensionEvent>& event); |
199 | 181 |
200 // Possibly loads given extension's background page in preparation to | 182 // Possibly loads given extension's background page in preparation to |
(...skipping 22 matching lines...) Expand all Loading... | |
223 | 205 |
224 // The list of all the lazy (non-persistent) background pages that are | 206 // The list of all the lazy (non-persistent) background pages that are |
225 // listening to events. This is just a cache of the real list, which is | 207 // listening to events. This is just a cache of the real list, which is |
226 // stored on disk in the extension prefs. | 208 // stored on disk in the extension prefs. |
227 ListenerMap lazy_listeners_; | 209 ListenerMap lazy_listeners_; |
228 | 210 |
229 DISALLOW_COPY_AND_ASSIGN(ExtensionEventRouter); | 211 DISALLOW_COPY_AND_ASSIGN(ExtensionEventRouter); |
230 }; | 212 }; |
231 | 213 |
232 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_EVENT_ROUTER_H_ | 214 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_EVENT_ROUTER_H_ |
OLD | NEW |