OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_WEBREQUEST_API_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_WEBREQUEST_API_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_WEBREQUEST_API_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_WEBREQUEST_API_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <map> | 9 #include <map> |
10 #include <set> | 10 #include <set> |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 }; | 108 }; |
109 | 109 |
110 // Used in testing to allow chrome-extension URLs to be intercepted. | 110 // Used in testing to allow chrome-extension URLs to be intercepted. |
111 static void SetAllowChromeExtensionScheme(); | 111 static void SetAllowChromeExtensionScheme(); |
112 | 112 |
113 static ExtensionWebRequestEventRouter* GetInstance(); | 113 static ExtensionWebRequestEventRouter* GetInstance(); |
114 | 114 |
115 // Dispatches the OnBeforeRequest event to any extensions whose filters match | 115 // Dispatches the OnBeforeRequest event to any extensions whose filters match |
116 // the given request. Returns net::ERR_IO_PENDING if an extension is | 116 // the given request. Returns net::ERR_IO_PENDING if an extension is |
117 // intercepting the request, OK otherwise. | 117 // intercepting the request, OK otherwise. |
118 int OnBeforeRequest(ProfileId profile_id, | 118 int OnBeforeRequest(void* profile, |
119 ExtensionInfoMap* extension_info_map, | 119 ExtensionInfoMap* extension_info_map, |
120 net::URLRequest* request, | 120 net::URLRequest* request, |
121 net::CompletionCallback* callback, | 121 net::CompletionCallback* callback, |
122 GURL* new_url); | 122 GURL* new_url); |
123 | 123 |
124 // Dispatches the onBeforeSendHeaders event. This is fired for HTTP(s) | 124 // Dispatches the onBeforeSendHeaders event. This is fired for HTTP(s) |
125 // requests only, and allows modification of the outgoing request headers. | 125 // requests only, and allows modification of the outgoing request headers. |
126 // Returns net::ERR_IO_PENDING if an extension is intercepting the request, OK | 126 // Returns net::ERR_IO_PENDING if an extension is intercepting the request, OK |
127 // otherwise. | 127 // otherwise. |
128 int OnBeforeSendHeaders(ProfileId profile_id, | 128 int OnBeforeSendHeaders(void* profile, |
129 ExtensionInfoMap* extension_info_map, | 129 ExtensionInfoMap* extension_info_map, |
130 net::URLRequest* request, | 130 net::URLRequest* request, |
131 net::CompletionCallback* callback, | 131 net::CompletionCallback* callback, |
132 net::HttpRequestHeaders* headers); | 132 net::HttpRequestHeaders* headers); |
133 | 133 |
134 // Dispatches the onRequestSent event. This is fired for HTTP(s) requests | 134 // Dispatches the onRequestSent event. This is fired for HTTP(s) requests |
135 // only. | 135 // only. |
136 void OnRequestSent(ProfileId profile_id, | 136 void OnRequestSent(void* profile, |
137 ExtensionInfoMap* extension_info_map, | 137 ExtensionInfoMap* extension_info_map, |
138 uint64 request_id, | 138 uint64 request_id, |
139 const net::HostPortPair& socket_address, | 139 const net::HostPortPair& socket_address, |
140 const net::HttpRequestHeaders& headers); | 140 const net::HttpRequestHeaders& headers); |
141 | 141 |
142 // Dispatches the onBeforeRedirect event. This is fired for HTTP(s) requests | 142 // Dispatches the onBeforeRedirect event. This is fired for HTTP(s) requests |
143 // only. | 143 // only. |
144 void OnBeforeRedirect(ProfileId profile_id, | 144 void OnBeforeRedirect(void* profile, |
145 ExtensionInfoMap* extension_info_map, | 145 ExtensionInfoMap* extension_info_map, |
146 net::URLRequest* request, | 146 net::URLRequest* request, |
147 const GURL& new_location); | 147 const GURL& new_location); |
148 | 148 |
149 // Dispatches the onResponseStarted event indicating that the first bytes of | 149 // Dispatches the onResponseStarted event indicating that the first bytes of |
150 // the response have arrived. | 150 // the response have arrived. |
151 void OnResponseStarted(ProfileId profile_id, | 151 void OnResponseStarted(void* profile, |
152 ExtensionInfoMap* extension_info_map, | 152 ExtensionInfoMap* extension_info_map, |
153 net::URLRequest* request); | 153 net::URLRequest* request); |
154 | 154 |
155 // Dispatches the onComplete event. | 155 // Dispatches the onComplete event. |
156 void OnCompleted(ProfileId profile_id, | 156 void OnCompleted(void* profile, |
157 ExtensionInfoMap* extension_info_map, | 157 ExtensionInfoMap* extension_info_map, |
158 net::URLRequest* request); | 158 net::URLRequest* request); |
159 | 159 |
160 // Dispatches an onErrorOccurred event. | 160 // Dispatches an onErrorOccurred event. |
161 void OnErrorOccurred(ProfileId profile_id, | 161 void OnErrorOccurred(void* profile, |
162 ExtensionInfoMap* extension_info_map, | 162 ExtensionInfoMap* extension_info_map, |
163 net::URLRequest* request); | 163 net::URLRequest* request); |
164 | 164 |
165 // Notifications when objects are going away. | 165 // Notifications when objects are going away. |
166 void OnURLRequestDestroyed(ProfileId profile_id, net::URLRequest* request); | 166 void OnURLRequestDestroyed(void* profile, net::URLRequest* request); |
167 void OnHttpTransactionDestroyed(ProfileId profile_id, uint64 request_id); | 167 void OnHttpTransactionDestroyed(void* profile, uint64 request_id); |
168 | 168 |
169 // Called when an event listener handles a blocking event and responds. | 169 // Called when an event listener handles a blocking event and responds. |
170 void OnEventHandled( | 170 void OnEventHandled( |
171 ProfileId profile_id, | 171 void* profile, |
172 const std::string& extension_id, | 172 const std::string& extension_id, |
173 const std::string& event_name, | 173 const std::string& event_name, |
174 const std::string& sub_event_name, | 174 const std::string& sub_event_name, |
175 uint64 request_id, | 175 uint64 request_id, |
176 EventResponse* response); | 176 EventResponse* response); |
177 | 177 |
178 // Adds a listener to the given event. |event_name| specifies the event being | 178 // Adds a listener to the given event. |event_name| specifies the event being |
179 // listened to. |sub_event_name| is an internal event uniquely generated in | 179 // listened to. |sub_event_name| is an internal event uniquely generated in |
180 // the extension process to correspond to the given filter and | 180 // the extension process to correspond to the given filter and |
181 // extra_info_spec. | 181 // extra_info_spec. |
182 void AddEventListener( | 182 void AddEventListener( |
183 ProfileId profile_id, | 183 void* profile, |
184 const std::string& extension_id, | 184 const std::string& extension_id, |
185 const std::string& event_name, | 185 const std::string& event_name, |
186 const std::string& sub_event_name, | 186 const std::string& sub_event_name, |
187 const RequestFilter& filter, | 187 const RequestFilter& filter, |
188 int extra_info_spec, | 188 int extra_info_spec, |
189 base::WeakPtr<IPC::Message::Sender> ipc_sender); | 189 base::WeakPtr<IPC::Message::Sender> ipc_sender); |
190 | 190 |
191 // Removes the listener for the given sub-event. | 191 // Removes the listener for the given sub-event. |
192 void RemoveEventListener( | 192 void RemoveEventListener( |
193 ProfileId profile_id, | 193 void* profile, |
194 const std::string& extension_id, | 194 const std::string& extension_id, |
195 const std::string& sub_event_name); | 195 const std::string& sub_event_name); |
196 | 196 |
197 // Called when an incognito profile is created or destroyed. | 197 // Called when an incognito profile is created or destroyed. |
198 void OnOTRProfileCreated(ProfileId original_profile_id, | 198 void OnOTRProfileCreated(void* original_profile, |
199 ProfileId otr_profile_id); | 199 void* otr_profile); |
200 void OnOTRProfileDestroyed(ProfileId original_profile_id, | 200 void OnOTRProfileDestroyed(void* original_profile, |
201 ProfileId otr_profile_id); | 201 void* otr_profile); |
202 | 202 |
203 private: | 203 private: |
204 friend struct DefaultSingletonTraits<ExtensionWebRequestEventRouter>; | 204 friend struct DefaultSingletonTraits<ExtensionWebRequestEventRouter>; |
205 struct EventListener; | 205 struct EventListener; |
206 struct BlockedRequest; | 206 struct BlockedRequest; |
207 typedef std::map<std::string, std::set<EventListener> > ListenerMapForProfile; | 207 typedef std::map<std::string, std::set<EventListener> > ListenerMapForProfile; |
208 typedef std::map<ProfileId, ListenerMapForProfile> ListenerMap; | 208 typedef std::map<void*, ListenerMapForProfile> ListenerMap; |
209 typedef std::map<uint64, BlockedRequest> BlockedRequestMap; | 209 typedef std::map<uint64, BlockedRequest> BlockedRequestMap; |
210 typedef std::map<uint64, net::URLRequest*> HttpRequestMap; | 210 typedef std::map<uint64, net::URLRequest*> HttpRequestMap; |
211 // Map of request_id -> bit vector of EventTypes already signaled | 211 // Map of request_id -> bit vector of EventTypes already signaled |
212 typedef std::map<uint64, int> SignaledRequestMap; | 212 typedef std::map<uint64, int> SignaledRequestMap; |
213 typedef std::map<ProfileId, ProfileId> CrossProfileMap; | 213 typedef std::map<void*, void*> CrossProfileMap; |
214 | 214 |
215 ExtensionWebRequestEventRouter(); | 215 ExtensionWebRequestEventRouter(); |
216 ~ExtensionWebRequestEventRouter(); | 216 ~ExtensionWebRequestEventRouter(); |
217 | 217 |
218 bool DispatchEvent( | 218 bool DispatchEvent( |
219 ProfileId profile_id, | 219 void* profile, |
220 net::URLRequest* request, | 220 net::URLRequest* request, |
221 const std::vector<const EventListener*>& listeners, | 221 const std::vector<const EventListener*>& listeners, |
222 const base::ListValue& args); | 222 const base::ListValue& args); |
223 | 223 |
224 // Returns a list of event listeners that care about the given event, based | 224 // Returns a list of event listeners that care about the given event, based |
225 // on their filter parameters. |extra_info_spec| will contain the combined | 225 // on their filter parameters. |extra_info_spec| will contain the combined |
226 // set of extra_info_spec flags that every matching listener asked for. | 226 // set of extra_info_spec flags that every matching listener asked for. |
227 std::vector<const EventListener*> GetMatchingListeners( | 227 std::vector<const EventListener*> GetMatchingListeners( |
228 ProfileId profile_id, | 228 void* profile, |
229 ExtensionInfoMap* extension_info_map, | 229 ExtensionInfoMap* extension_info_map, |
230 const std::string& event_name, | 230 const std::string& event_name, |
231 const GURL& url, | 231 const GURL& url, |
232 int tab_id, | 232 int tab_id, |
233 int window_id, | 233 int window_id, |
234 ResourceType::Type resource_type, | 234 ResourceType::Type resource_type, |
235 int* extra_info_spec); | 235 int* extra_info_spec); |
236 | 236 |
237 // Same as above, but retrieves the filter parameters from the request. | 237 // Same as above, but retrieves the filter parameters from the request. |
238 std::vector<const EventListener*> GetMatchingListeners( | 238 std::vector<const EventListener*> GetMatchingListeners( |
239 ProfileId profile_id, | 239 void* profile, |
240 ExtensionInfoMap* extension_info_map, | 240 ExtensionInfoMap* extension_info_map, |
241 const std::string& event_name, | 241 const std::string& event_name, |
242 net::URLRequest* request, | 242 net::URLRequest* request, |
243 int* extra_info_spec); | 243 int* extra_info_spec); |
244 | 244 |
245 // Helper for the above functions. This is called twice: once for the profile | 245 // Helper for the above functions. This is called twice: once for the profile |
246 // of the event, the next time for the "cross" profile (i.e. the incognito | 246 // of the event, the next time for the "cross" profile (i.e. the incognito |
247 // profile if the event is originally for the normal profile, or vice versa). | 247 // profile if the event is originally for the normal profile, or vice versa). |
248 void GetMatchingListenersImpl( | 248 void GetMatchingListenersImpl( |
249 ProfileId profile_id, | 249 void* profile, |
250 ExtensionInfoMap* extension_info_map, | 250 ExtensionInfoMap* extension_info_map, |
251 bool crosses_incognito, | 251 bool crosses_incognito, |
252 const std::string& event_name, | 252 const std::string& event_name, |
253 const GURL& url, | 253 const GURL& url, |
254 int tab_id, | 254 int tab_id, |
255 int window_id, | 255 int window_id, |
256 ResourceType::Type resource_type, | 256 ResourceType::Type resource_type, |
257 int* extra_info_spec, | 257 int* extra_info_spec, |
258 std::vector<const ExtensionWebRequestEventRouter::EventListener*>* | 258 std::vector<const ExtensionWebRequestEventRouter::EventListener*>* |
259 matching_listeners); | 259 matching_listeners); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
301 DECLARE_EXTENSION_FUNCTION_NAME("experimental.webRequest.addEventListener"); | 301 DECLARE_EXTENSION_FUNCTION_NAME("experimental.webRequest.addEventListener"); |
302 }; | 302 }; |
303 | 303 |
304 class WebRequestEventHandled : public SyncIOThreadExtensionFunction { | 304 class WebRequestEventHandled : public SyncIOThreadExtensionFunction { |
305 public: | 305 public: |
306 virtual bool RunImpl(); | 306 virtual bool RunImpl(); |
307 DECLARE_EXTENSION_FUNCTION_NAME("experimental.webRequest.eventHandled"); | 307 DECLARE_EXTENSION_FUNCTION_NAME("experimental.webRequest.eventHandled"); |
308 }; | 308 }; |
309 | 309 |
310 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_WEBREQUEST_API_H_ | 310 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_WEBREQUEST_API_H_ |
OLD | NEW |