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_API_WEB_REQUEST_WEB_REQUEST_API_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_WEB_REQUEST_WEB_REQUEST_API_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_API_WEB_REQUEST_WEB_REQUEST_API_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_API_WEB_REQUEST_WEB_REQUEST_API_H_ |
7 | 7 |
8 #include <list> | 8 #include <list> |
9 #include <map> | 9 #include <map> |
10 #include <set> | 10 #include <set> |
11 #include <string> | 11 #include <string> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
14 #include "base/memory/singleton.h" | 14 #include "base/memory/singleton.h" |
15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
16 #include "base/time/time.h" | 16 #include "base/time/time.h" |
17 #include "chrome/browser/extensions/api/declarative/rules_registry_service.h" | 17 #include "chrome/browser/extensions/api/declarative/rules_registry_service.h" |
18 #include "chrome/browser/extensions/api/web_request/web_request_api_helpers.h" | 18 #include "chrome/browser/extensions/api/web_request/web_request_api_helpers.h" |
19 #include "chrome/browser/extensions/api/web_request/web_request_permissions.h" | 19 #include "chrome/browser/extensions/api/web_request/web_request_permissions.h" |
20 #include "content/public/common/resource_type.h" | 20 #include "content/public/common/resource_type.h" |
21 #include "extensions/browser/api/declarative_webrequest/request_stage.h" | 21 #include "extensions/browser/api/declarative_webrequest/request_stage.h" |
| 22 #include "extensions/browser/api/web_request/extra_request_params.h" |
22 #include "extensions/browser/browser_context_keyed_api_factory.h" | 23 #include "extensions/browser/browser_context_keyed_api_factory.h" |
23 #include "extensions/browser/event_router.h" | 24 #include "extensions/browser/event_router.h" |
24 #include "extensions/browser/extension_function.h" | 25 #include "extensions/browser/extension_function.h" |
25 #include "extensions/common/url_pattern_set.h" | 26 #include "extensions/common/url_pattern_set.h" |
26 #include "ipc/ipc_sender.h" | 27 #include "ipc/ipc_sender.h" |
27 #include "net/base/completion_callback.h" | 28 #include "net/base/completion_callback.h" |
28 #include "net/base/network_delegate.h" | 29 #include "net/base/network_delegate.h" |
29 #include "net/http/http_request_headers.h" | 30 #include "net/http/http_request_headers.h" |
30 | 31 |
31 class ExtensionWebRequestTimeTracker; | 32 class ExtensionWebRequestTimeTracker; |
32 class GURL; | 33 class GURL; |
| 34 class ExtraRequestParams; |
33 | 35 |
34 namespace base { | 36 namespace base { |
35 class DictionaryValue; | 37 class DictionaryValue; |
36 class ListValue; | 38 class ListValue; |
37 class StringValue; | 39 class StringValue; |
38 } | 40 } |
39 | 41 |
40 namespace content { | 42 namespace content { |
41 class BrowserContext; | 43 class BrowserContext; |
42 class RenderProcessHost; | 44 class RenderProcessHost; |
43 } | 45 } |
44 | 46 |
45 namespace net { | 47 namespace net { |
46 class AuthCredentials; | 48 class AuthCredentials; |
47 class AuthChallengeInfo; | 49 class AuthChallengeInfo; |
48 class HttpRequestHeaders; | 50 class HttpRequestHeaders; |
49 class HttpResponseHeaders; | 51 class HttpResponseHeaders; |
50 class URLRequest; | 52 class URLRequest; |
51 } | 53 } |
52 | 54 |
53 namespace extensions { | 55 namespace extensions { |
54 | 56 |
55 class InfoMap; | 57 class InfoMap; |
56 class WebRequestRulesRegistry; | 58 class WebRequestRulesRegistry; |
| 59 class WebRequestEventRouterDelegate; |
57 | 60 |
58 // Support class for the WebRequest API. Lives on the UI thread. Most of the | 61 // Support class for the WebRequest API. Lives on the UI thread. Most of the |
59 // work is done by ExtensionWebRequestEventRouter below. This class observes | 62 // work is done by ExtensionWebRequestEventRouter below. This class observes |
60 // extensions::EventRouter to deal with event listeners. There is one instance | 63 // extensions::EventRouter to deal with event listeners. There is one instance |
61 // per BrowserContext which is shared with incognito. | 64 // per BrowserContext which is shared with incognito. |
62 class WebRequestAPI : public BrowserContextKeyedAPI, | 65 class WebRequestAPI : public BrowserContextKeyedAPI, |
63 public EventRouter::Observer { | 66 public EventRouter::Observer { |
64 public: | 67 public: |
65 explicit WebRequestAPI(content::BrowserContext* context); | 68 explicit WebRequestAPI(content::BrowserContext* context); |
66 virtual ~WebRequestAPI(); | 69 virtual ~WebRequestAPI(); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 kOnAuthRequired = 1 << 5, | 107 kOnAuthRequired = 1 << 5, |
105 kOnResponseStarted = 1 << 6, | 108 kOnResponseStarted = 1 << 6, |
106 kOnErrorOccurred = 1 << 7, | 109 kOnErrorOccurred = 1 << 7, |
107 kOnCompleted = 1 << 8, | 110 kOnCompleted = 1 << 8, |
108 }; | 111 }; |
109 | 112 |
110 // Internal representation of the webRequest.RequestFilter type, used to | 113 // Internal representation of the webRequest.RequestFilter type, used to |
111 // filter what network events an extension cares about. | 114 // filter what network events an extension cares about. |
112 struct RequestFilter { | 115 struct RequestFilter { |
113 RequestFilter(); | 116 RequestFilter(); |
| 117 RequestFilter(const RequestFilter& filter); |
114 ~RequestFilter(); | 118 ~RequestFilter(); |
115 | 119 |
| 120 RequestFilter& operator=(const RequestFilter& filter); |
116 // Returns false if there was an error initializing. If it is a user error, | 121 // Returns false if there was an error initializing. If it is a user error, |
117 // an error message is provided, otherwise the error is internal (and | 122 // an error message is provided, otherwise the error is internal (and |
118 // unexpected). | 123 // unexpected). |
119 bool InitFromValue(const base::DictionaryValue& value, std::string* error); | 124 bool InitFromValue(const base::DictionaryValue& value, std::string* error); |
120 | 125 |
121 extensions::URLPatternSet urls; | 126 extensions::URLPatternSet urls; |
122 std::vector<content::ResourceType> types; | 127 std::vector<content::ResourceType> types; |
123 int tab_id; | 128 scoped_ptr<ExtraRequestParams> extra_request_params; |
124 int window_id; | |
125 }; | 129 }; |
126 | 130 |
127 // Internal representation of the extraInfoSpec parameter on webRequest | 131 // Internal representation of the extraInfoSpec parameter on webRequest |
128 // events, used to specify extra information to be included with network | 132 // events, used to specify extra information to be included with network |
129 // events. | 133 // events. |
130 struct ExtraInfoSpec { | 134 struct ExtraInfoSpec { |
131 enum Flags { | 135 enum Flags { |
132 REQUEST_HEADERS = 1<<0, | 136 REQUEST_HEADERS = 1<<0, |
133 RESPONSE_HEADERS = 1<<1, | 137 RESPONSE_HEADERS = 1<<1, |
134 BLOCKING = 1<<2, | 138 BLOCKING = 1<<2, |
(...skipping 27 matching lines...) Expand all Loading... |
162 response_headers; | 166 response_headers; |
163 | 167 |
164 scoped_ptr<net::AuthCredentials> auth_credentials; | 168 scoped_ptr<net::AuthCredentials> auth_credentials; |
165 | 169 |
166 DISALLOW_COPY_AND_ASSIGN(EventResponse); | 170 DISALLOW_COPY_AND_ASSIGN(EventResponse); |
167 }; | 171 }; |
168 | 172 |
169 static ExtensionWebRequestEventRouter* GetInstance(); | 173 static ExtensionWebRequestEventRouter* GetInstance(); |
170 | 174 |
171 // Registers a rule registry. Pass null for |rules_registry| to unregister | 175 // Registers a rule registry. Pass null for |rules_registry| to unregister |
172 // the rule registry for |profile|. | 176 // the rule registry for |browser_context|. |
173 void RegisterRulesRegistry( | 177 void RegisterRulesRegistry( |
174 void* profile, | 178 void* browser_context, |
175 const extensions::RulesRegistryService::WebViewKey& webview_key, | 179 const extensions::RulesRegistryService::WebViewKey& webview_key, |
176 scoped_refptr<extensions::WebRequestRulesRegistry> rules_registry); | 180 scoped_refptr<extensions::WebRequestRulesRegistry> rules_registry); |
177 | 181 |
178 // Dispatches the OnBeforeRequest event to any extensions whose filters match | 182 // Dispatches the OnBeforeRequest event to any extensions whose filters match |
179 // the given request. Returns net::ERR_IO_PENDING if an extension is | 183 // the given request. Returns net::ERR_IO_PENDING if an extension is |
180 // intercepting the request, OK otherwise. | 184 // intercepting the request, OK otherwise. |
181 int OnBeforeRequest(void* profile, | 185 int OnBeforeRequest(void* browser_context, |
182 extensions::InfoMap* extension_info_map, | 186 extensions::InfoMap* extension_info_map, |
183 net::URLRequest* request, | 187 net::URLRequest* request, |
184 const net::CompletionCallback& callback, | 188 const net::CompletionCallback& callback, |
185 GURL* new_url); | 189 GURL* new_url); |
186 | 190 |
187 // Dispatches the onBeforeSendHeaders event. This is fired for HTTP(s) | 191 // Dispatches the onBeforeSendHeaders event. This is fired for HTTP(s) |
188 // requests only, and allows modification of the outgoing request headers. | 192 // requests only, and allows modification of the outgoing request headers. |
189 // Returns net::ERR_IO_PENDING if an extension is intercepting the request, OK | 193 // Returns net::ERR_IO_PENDING if an extension is intercepting the request, OK |
190 // otherwise. | 194 // otherwise. |
191 int OnBeforeSendHeaders(void* profile, | 195 int OnBeforeSendHeaders(void* browser_context, |
192 extensions::InfoMap* extension_info_map, | 196 extensions::InfoMap* extension_info_map, |
193 net::URLRequest* request, | 197 net::URLRequest* request, |
194 const net::CompletionCallback& callback, | 198 const net::CompletionCallback& callback, |
195 net::HttpRequestHeaders* headers); | 199 net::HttpRequestHeaders* headers); |
196 | 200 |
197 // Dispatches the onSendHeaders event. This is fired for HTTP(s) requests | 201 // Dispatches the onSendHeaders event. This is fired for HTTP(s) requests |
198 // only. | 202 // only. |
199 void OnSendHeaders(void* profile, | 203 void OnSendHeaders(void* browser_context, |
200 extensions::InfoMap* extension_info_map, | 204 extensions::InfoMap* extension_info_map, |
201 net::URLRequest* request, | 205 net::URLRequest* request, |
202 const net::HttpRequestHeaders& headers); | 206 const net::HttpRequestHeaders& headers); |
203 | 207 |
204 // Dispatches the onHeadersReceived event. This is fired for HTTP(s) | 208 // Dispatches the onHeadersReceived event. This is fired for HTTP(s) |
205 // requests only, and allows modification of incoming response headers. | 209 // requests only, and allows modification of incoming response headers. |
206 // Returns net::ERR_IO_PENDING if an extension is intercepting the request, | 210 // Returns net::ERR_IO_PENDING if an extension is intercepting the request, |
207 // OK otherwise. |original_response_headers| is reference counted. |callback| | 211 // OK otherwise. |original_response_headers| is reference counted. |callback| |
208 // |override_response_headers| and |allowed_unsafe_redirect_url| are owned by | 212 // |override_response_headers| and |allowed_unsafe_redirect_url| are owned by |
209 // a URLRequestJob. They are guaranteed to be valid until |callback| is called | 213 // a URLRequestJob. They are guaranteed to be valid until |callback| is called |
210 // or OnURLRequestDestroyed is called (whatever comes first). | 214 // or OnURLRequestDestroyed is called (whatever comes first). |
211 // Do not modify |original_response_headers| directly but write new ones | 215 // Do not modify |original_response_headers| directly but write new ones |
212 // into |override_response_headers|. | 216 // into |override_response_headers|. |
213 int OnHeadersReceived( | 217 int OnHeadersReceived( |
214 void* profile, | 218 void* browser_context, |
215 extensions::InfoMap* extension_info_map, | 219 extensions::InfoMap* extension_info_map, |
216 net::URLRequest* request, | 220 net::URLRequest* request, |
217 const net::CompletionCallback& callback, | 221 const net::CompletionCallback& callback, |
218 const net::HttpResponseHeaders* original_response_headers, | 222 const net::HttpResponseHeaders* original_response_headers, |
219 scoped_refptr<net::HttpResponseHeaders>* override_response_headers, | 223 scoped_refptr<net::HttpResponseHeaders>* override_response_headers, |
220 GURL* allowed_unsafe_redirect_url); | 224 GURL* allowed_unsafe_redirect_url); |
221 | 225 |
222 // Dispatches the OnAuthRequired event to any extensions whose filters match | 226 // Dispatches the OnAuthRequired event to any extensions whose filters match |
223 // the given request. If the listener is not registered as "blocking", then | 227 // the given request. If the listener is not registered as "blocking", then |
224 // AUTH_REQUIRED_RESPONSE_OK is returned. Otherwise, | 228 // AUTH_REQUIRED_RESPONSE_OK is returned. Otherwise, |
225 // AUTH_REQUIRED_RESPONSE_IO_PENDING is returned and |callback| will be | 229 // AUTH_REQUIRED_RESPONSE_IO_PENDING is returned and |callback| will be |
226 // invoked later. | 230 // invoked later. |
227 net::NetworkDelegate::AuthRequiredResponse OnAuthRequired( | 231 net::NetworkDelegate::AuthRequiredResponse OnAuthRequired( |
228 void* profile, | 232 void* browser_context, |
229 extensions::InfoMap* extension_info_map, | 233 extensions::InfoMap* extension_info_map, |
230 net::URLRequest* request, | 234 net::URLRequest* request, |
231 const net::AuthChallengeInfo& auth_info, | 235 const net::AuthChallengeInfo& auth_info, |
232 const net::NetworkDelegate::AuthCallback& callback, | 236 const net::NetworkDelegate::AuthCallback& callback, |
233 net::AuthCredentials* credentials); | 237 net::AuthCredentials* credentials); |
234 | 238 |
235 // Dispatches the onBeforeRedirect event. This is fired for HTTP(s) requests | 239 // Dispatches the onBeforeRedirect event. This is fired for HTTP(s) requests |
236 // only. | 240 // only. |
237 void OnBeforeRedirect(void* profile, | 241 void OnBeforeRedirect(void* browser_context, |
238 extensions::InfoMap* extension_info_map, | 242 extensions::InfoMap* extension_info_map, |
239 net::URLRequest* request, | 243 net::URLRequest* request, |
240 const GURL& new_location); | 244 const GURL& new_location); |
241 | 245 |
242 // Dispatches the onResponseStarted event indicating that the first bytes of | 246 // Dispatches the onResponseStarted event indicating that the first bytes of |
243 // the response have arrived. | 247 // the response have arrived. |
244 void OnResponseStarted(void* profile, | 248 void OnResponseStarted(void* browser_context, |
245 extensions::InfoMap* extension_info_map, | 249 extensions::InfoMap* extension_info_map, |
246 net::URLRequest* request); | 250 net::URLRequest* request); |
247 | 251 |
248 // Dispatches the onComplete event. | 252 // Dispatches the onComplete event. |
249 void OnCompleted(void* profile, | 253 void OnCompleted(void* browser_context, |
250 extensions::InfoMap* extension_info_map, | 254 extensions::InfoMap* extension_info_map, |
251 net::URLRequest* request); | 255 net::URLRequest* request); |
252 | 256 |
253 // Dispatches an onErrorOccurred event. | 257 // Dispatches an onErrorOccurred event. |
254 void OnErrorOccurred(void* profile, | 258 void OnErrorOccurred(void* browser_context, |
255 extensions::InfoMap* extension_info_map, | 259 extensions::InfoMap* extension_info_map, |
256 net::URLRequest* request, | 260 net::URLRequest* request, |
257 bool started); | 261 bool started); |
258 | 262 |
259 // Notifications when objects are going away. | 263 // Notifications when objects are going away. |
260 void OnURLRequestDestroyed(void* profile, net::URLRequest* request); | 264 void OnURLRequestDestroyed(void* browser_context, net::URLRequest* request); |
261 | 265 |
262 // Called when an event listener handles a blocking event and responds. | 266 // Called when an event listener handles a blocking event and responds. |
263 void OnEventHandled( | 267 void OnEventHandled( |
264 void* profile, | 268 void* browser_context, |
265 const std::string& extension_id, | 269 const std::string& extension_id, |
266 const std::string& event_name, | 270 const std::string& event_name, |
267 const std::string& sub_event_name, | 271 const std::string& sub_event_name, |
268 uint64 request_id, | 272 uint64 request_id, |
269 EventResponse* response); | 273 EventResponse* response); |
270 | 274 |
271 // Adds a listener to the given event. |event_name| specifies the event being | 275 // Adds a listener to the given event. |event_name| specifies the event being |
272 // listened to. |sub_event_name| is an internal event uniquely generated in | 276 // listened to. |sub_event_name| is an internal event uniquely generated in |
273 // the extension process to correspond to the given filter and | 277 // the extension process to correspond to the given filter and |
274 // extra_info_spec. It returns true on success, false on failure. | 278 // extra_info_spec. It returns true on success, false on failure. |
275 bool AddEventListener( | 279 bool AddEventListener( |
276 void* profile, | 280 void* browser_context, |
277 const std::string& extension_id, | 281 const std::string& extension_id, |
278 const std::string& extension_name, | 282 const std::string& extension_name, |
279 const std::string& event_name, | 283 const std::string& event_name, |
280 const std::string& sub_event_name, | 284 const std::string& sub_event_name, |
281 const RequestFilter& filter, | 285 const RequestFilter& filter, |
282 int extra_info_spec, | 286 int extra_info_spec, |
283 int embedder_process_id, | 287 int embedder_process_id, |
284 int web_view_instance_id, | 288 int web_view_instance_id, |
285 base::WeakPtr<IPC::Sender> ipc_sender); | 289 base::WeakPtr<IPC::Sender> ipc_sender); |
286 | 290 |
287 // Removes the listener for the given sub-event. | 291 // Removes the listener for the given sub-event. |
288 void RemoveEventListener( | 292 void RemoveEventListener( |
289 void* profile, | 293 void* browser_context, |
290 const std::string& extension_id, | 294 const std::string& extension_id, |
291 const std::string& sub_event_name); | 295 const std::string& sub_event_name); |
292 | 296 |
293 // Removes the listeners for a given <webview>. | 297 // Removes the listeners for a given <webview>. |
294 void RemoveWebViewEventListeners( | 298 void RemoveWebViewEventListeners( |
295 void* profile, | 299 void* browser_context, |
296 const std::string& extension_id, | 300 const std::string& extension_id, |
297 int embedder_process_id, | 301 int embedder_process_id, |
298 int web_view_instance_id); | 302 int web_view_instance_id); |
299 | 303 |
300 // Called when an incognito profile is created or destroyed. | 304 // Called when an incognito browser_context is created or destroyed. |
301 void OnOTRProfileCreated(void* original_profile, | 305 void OnOTRBrowserContextCreated(void* original_browser_context, |
302 void* otr_profile); | 306 void* otr_browser_context); |
303 void OnOTRProfileDestroyed(void* original_profile, | 307 void OnOTRBrowserContextDestroyed(void* original_browser_context, |
304 void* otr_profile); | 308 void* otr_browser_context); |
305 | 309 |
306 // Registers a |callback| that is executed when the next page load happens. | 310 // Registers a |callback| that is executed when the next page load happens. |
307 // The callback is then deleted. | 311 // The callback is then deleted. |
308 void AddCallbackForPageLoad(const base::Closure& callback); | 312 void AddCallbackForPageLoad(const base::Closure& callback); |
309 | 313 |
310 private: | 314 private: |
311 friend struct DefaultSingletonTraits<ExtensionWebRequestEventRouter>; | 315 friend struct DefaultSingletonTraits<ExtensionWebRequestEventRouter>; |
312 | 316 |
313 struct EventListener; | 317 struct EventListener; |
314 typedef std::map<std::string, std::set<EventListener> > ListenerMapForProfile; | 318 typedef std::map<std::string, std::set<EventListener> > |
315 typedef std::map<void*, ListenerMapForProfile> ListenerMap; | 319 ListenerMapForBrowserContext; |
| 320 typedef std::map<void*, ListenerMapForBrowserContext> ListenerMap; |
316 typedef std::map<uint64, BlockedRequest> BlockedRequestMap; | 321 typedef std::map<uint64, BlockedRequest> BlockedRequestMap; |
317 // Map of request_id -> bit vector of EventTypes already signaled | 322 // Map of request_id -> bit vector of EventTypes already signaled |
318 typedef std::map<uint64, int> SignaledRequestMap; | 323 typedef std::map<uint64, int> SignaledRequestMap; |
319 // For each profile: a bool indicating whether it is an incognito profile, | 324 // For each browser_context: a bool indicating whether it is an incognito |
320 // and a pointer to the corresponding (non-)incognito profile. | 325 // browser_context, and a pointer to the corresponding (non-)incognito |
321 typedef std::map<void*, std::pair<bool, void*> > CrossProfileMap; | 326 // browser_context. |
| 327 typedef std::map<void*, std::pair<bool, void*> > CrossBrowserContextMap; |
322 typedef std::list<base::Closure> CallbacksForPageLoad; | 328 typedef std::list<base::Closure> CallbacksForPageLoad; |
323 | 329 |
324 ExtensionWebRequestEventRouter(); | 330 ExtensionWebRequestEventRouter(); |
325 ~ExtensionWebRequestEventRouter(); | 331 ~ExtensionWebRequestEventRouter(); |
326 | 332 |
327 // Ensures that future callbacks for |request| are ignored so that it can be | 333 // Ensures that future callbacks for |request| are ignored so that it can be |
328 // destroyed safely. | 334 // destroyed safely. |
329 void ClearPendingCallbacks(net::URLRequest* request); | 335 void ClearPendingCallbacks(net::URLRequest* request); |
330 | 336 |
331 bool DispatchEvent( | 337 bool DispatchEvent( |
332 void* profile, | 338 void* browser_context, |
333 net::URLRequest* request, | 339 net::URLRequest* request, |
334 const std::vector<const EventListener*>& listeners, | 340 const std::vector<const EventListener*>& listeners, |
335 const base::ListValue& args); | 341 const base::ListValue& args); |
336 | 342 |
337 // Returns a list of event listeners that care about the given event, based | 343 // Returns a list of event listeners that care about the given event, based |
338 // on their filter parameters. |extra_info_spec| will contain the combined | 344 // on their filter parameters. |extra_info_spec| will contain the combined |
339 // set of extra_info_spec flags that every matching listener asked for. | 345 // set of extra_info_spec flags that every matching listener asked for. |
340 std::vector<const EventListener*> GetMatchingListeners( | 346 std::vector<const EventListener*> GetMatchingListeners( |
341 void* profile, | 347 void* browser_context, |
342 extensions::InfoMap* extension_info_map, | 348 extensions::InfoMap* extension_info_map, |
343 const std::string& event_name, | 349 const std::string& event_name, |
344 net::URLRequest* request, | 350 net::URLRequest* request, |
345 int* extra_info_spec); | 351 int* extra_info_spec); |
346 | 352 |
347 // Helper for the above functions. This is called twice: once for the profile | 353 // Helper for the above functions. This is called twice: once for the |
348 // of the event, the next time for the "cross" profile (i.e. the incognito | 354 // browser_context of the event, the next time for the "cross" browser_context |
349 // profile if the event is originally for the normal profile, or vice versa). | 355 // (i.e. the incognito browser_context if the event is originally for the |
| 356 // normal browser_context, or vice versa). |
350 void GetMatchingListenersImpl( | 357 void GetMatchingListenersImpl( |
351 void* profile, | 358 void* browser_context, |
| 359 net::URLRequest* request, |
352 extensions::InfoMap* extension_info_map, | 360 extensions::InfoMap* extension_info_map, |
353 bool crosses_incognito, | 361 bool crosses_incognito, |
354 const std::string& event_name, | 362 const std::string& event_name, |
355 const GURL& url, | 363 const GURL& url, |
356 int tab_id, | |
357 int window_id, | |
358 int render_process_host_id, | 364 int render_process_host_id, |
359 int routing_id, | 365 int routing_id, |
360 content::ResourceType resource_type, | 366 content::ResourceType resource_type, |
361 bool is_async_request, | 367 bool is_async_request, |
362 bool is_request_from_extension, | 368 bool is_request_from_extension, |
363 int* extra_info_spec, | 369 int* extra_info_spec, |
364 std::vector<const ExtensionWebRequestEventRouter::EventListener*>* | 370 std::vector<const ExtensionWebRequestEventRouter::EventListener*>* |
365 matching_listeners); | 371 matching_listeners); |
366 | 372 |
367 // Decrements the count of event handlers blocking the given request. When the | 373 // Decrements the count of event handlers blocking the given request. When the |
368 // count reaches 0, we stop blocking the request and proceed it using the | 374 // count reaches 0, we stop blocking the request and proceed it using the |
369 // method requested by the extension with the highest precedence. Precedence | 375 // method requested by the extension with the highest precedence. Precedence |
370 // is decided by extension install time. If |response| is non-NULL, this | 376 // is decided by extension install time. If |response| is non-NULL, this |
371 // method assumes ownership. | 377 // method assumes ownership. |
372 void DecrementBlockCount( | 378 void DecrementBlockCount( |
373 void* profile, | 379 void* browser_context, |
374 const std::string& extension_id, | 380 const std::string& extension_id, |
375 const std::string& event_name, | 381 const std::string& event_name, |
376 uint64 request_id, | 382 uint64 request_id, |
377 EventResponse* response); | 383 EventResponse* response); |
378 | 384 |
379 // Processes the generated deltas from blocked_requests_ on the specified | 385 // Processes the generated deltas from blocked_requests_ on the specified |
380 // request. If |call_back| is true, the callback registered in | 386 // request. If |call_back| is true, the callback registered in |
381 // |blocked_requests_| is called. | 387 // |blocked_requests_| is called. |
382 // The function returns the error code for the network request. This is | 388 // The function returns the error code for the network request. This is |
383 // mostly relevant in case the caller passes |call_callback| = false | 389 // mostly relevant in case the caller passes |call_callback| = false |
384 // and wants to return the correct network error code himself. | 390 // and wants to return the correct network error code himself. |
385 int ExecuteDeltas(void* profile, uint64 request_id, bool call_callback); | 391 int ExecuteDeltas( |
| 392 void* browser_context, uint64 request_id, bool call_callback); |
386 | 393 |
387 // Evaluates the rules of the declarative webrequest API and stores | 394 // Evaluates the rules of the declarative webrequest API and stores |
388 // modifications to the request that result from WebRequestActions as | 395 // modifications to the request that result from WebRequestActions as |
389 // deltas in |blocked_requests_|. |original_response_headers| should only be | 396 // deltas in |blocked_requests_|. |original_response_headers| should only be |
390 // set for the OnHeadersReceived stage and NULL otherwise. Returns whether any | 397 // set for the OnHeadersReceived stage and NULL otherwise. Returns whether any |
391 // deltas were generated. | 398 // deltas were generated. |
392 bool ProcessDeclarativeRules( | 399 bool ProcessDeclarativeRules( |
393 void* profile, | 400 void* browser_context, |
394 extensions::InfoMap* extension_info_map, | 401 extensions::InfoMap* extension_info_map, |
395 const std::string& event_name, | 402 const std::string& event_name, |
396 net::URLRequest* request, | 403 net::URLRequest* request, |
397 extensions::RequestStage request_stage, | 404 extensions::RequestStage request_stage, |
398 const net::HttpResponseHeaders* original_response_headers); | 405 const net::HttpResponseHeaders* original_response_headers); |
399 | 406 |
400 // If the BlockedRequest contains messages_to_extension entries in the event | 407 // If the BlockedRequest contains messages_to_extension entries in the event |
401 // deltas, we send them to subscribers of | 408 // deltas, we send them to subscribers of |
402 // chrome.declarativeWebRequest.onMessage. | 409 // chrome.declarativeWebRequest.onMessage. |
403 void SendMessages(void* profile, const BlockedRequest& blocked_request); | 410 void SendMessages( |
| 411 void* browser_context, const BlockedRequest& blocked_request); |
404 | 412 |
405 // Called when the RulesRegistry is ready to unblock a request that was | 413 // Called when the RulesRegistry is ready to unblock a request that was |
406 // waiting for said event. | 414 // waiting for said event. |
407 void OnRulesRegistryReady( | 415 void OnRulesRegistryReady( |
408 void* profile, | 416 void* browser_context, |
409 const std::string& event_name, | 417 const std::string& event_name, |
410 uint64 request_id, | 418 uint64 request_id, |
411 extensions::RequestStage request_stage); | 419 extensions::RequestStage request_stage); |
412 | 420 |
| 421 // Extracts from |request| information for the keys requestId, url, method, |
| 422 // frameId, tabId, type, and timeStamp and writes these into |out| to be |
| 423 // passed on to extensions. |
| 424 void ExtractRequestInfo(net::URLRequest* request, base::DictionaryValue* out); |
| 425 |
413 // Sets the flag that |event_type| has been signaled for |request_id|. | 426 // Sets the flag that |event_type| has been signaled for |request_id|. |
414 // Returns the value of the flag before setting it. | 427 // Returns the value of the flag before setting it. |
415 bool GetAndSetSignaled(uint64 request_id, EventTypes event_type); | 428 bool GetAndSetSignaled(uint64 request_id, EventTypes event_type); |
416 | 429 |
417 // Clears the flag that |event_type| has been signaled for |request_id|. | 430 // Clears the flag that |event_type| has been signaled for |request_id|. |
418 void ClearSignaled(uint64 request_id, EventTypes event_type); | 431 void ClearSignaled(uint64 request_id, EventTypes event_type); |
419 | 432 |
420 // Returns whether |request| represents a top level window navigation. | 433 // Returns whether |request| represents a top level window navigation. |
421 bool IsPageLoad(net::URLRequest* request) const; | 434 bool IsPageLoad(net::URLRequest* request) const; |
422 | 435 |
423 // Called on a page load to process all registered callbacks. | 436 // Called on a page load to process all registered callbacks. |
424 void NotifyPageLoad(); | 437 void NotifyPageLoad(); |
425 | 438 |
426 // Returns the matching cross profile (the regular profile if |profile| is | 439 // Returns the matching cross browser_context (the regular browser_context if |
427 // OTR and vice versa). | 440 // |browser_context| is OTR and vice versa). |
428 void* GetCrossProfile(void* profile) const; | 441 void* GetCrossBrowserContext(void* browser_context) const; |
429 | 442 |
430 // Determines whether the specified profile is an incognito profile (based on | 443 // Determines whether the specified browser_context is an incognito |
431 // the contents of the cross-profile table and without dereferencing the | 444 // browser_context (based on the contents of the cross-browser_context table |
432 // profile pointer). | 445 // and without dereferencing the browser_context pointer). |
433 bool IsIncognitoProfile(void* profile) const; | 446 bool IsIncognitoBrowserContext(void* browser_context) const; |
434 | 447 |
435 // Returns true if |request| was already signaled to some event handlers. | 448 // Returns true if |request| was already signaled to some event handlers. |
436 bool WasSignaled(const net::URLRequest& request) const; | 449 bool WasSignaled(const net::URLRequest& request) const; |
437 | 450 |
438 // A map for each profile that maps an event name to a set of extensions that | 451 // A map for each browser_context that maps an event name to a set of |
439 // are listening to that event. | 452 // extensions that are listening to that event. |
440 ListenerMap listeners_; | 453 ListenerMap listeners_; |
441 | 454 |
442 // A map of network requests that are waiting for at least one event handler | 455 // A map of network requests that are waiting for at least one event handler |
443 // to respond. | 456 // to respond. |
444 BlockedRequestMap blocked_requests_; | 457 BlockedRequestMap blocked_requests_; |
445 | 458 |
446 // A map of request ids to a bitvector indicating which events have been | 459 // A map of request ids to a bitvector indicating which events have been |
447 // signaled and should not be sent again. | 460 // signaled and should not be sent again. |
448 SignaledRequestMap signaled_requests_; | 461 SignaledRequestMap signaled_requests_; |
449 | 462 |
450 // A map of original profile -> corresponding incognito profile (and vice | 463 // A map of original browser_context -> corresponding incognito |
451 // versa). | 464 // browser_context (and vice versa). |
452 CrossProfileMap cross_profile_map_; | 465 CrossBrowserContextMap cross_browser_context_map_; |
453 | 466 |
454 // Keeps track of time spent waiting on extensions using the blocking | 467 // Keeps track of time spent waiting on extensions using the blocking |
455 // webRequest API. | 468 // webRequest API. |
456 scoped_ptr<ExtensionWebRequestTimeTracker> request_time_tracker_; | 469 scoped_ptr<ExtensionWebRequestTimeTracker> request_time_tracker_; |
457 | 470 |
458 CallbacksForPageLoad callbacks_for_page_load_; | 471 CallbacksForPageLoad callbacks_for_page_load_; |
459 | 472 |
460 typedef std::pair<void*, extensions::RulesRegistryService::WebViewKey> | 473 typedef std::pair<void*, extensions::RulesRegistryService::WebViewKey> |
461 RulesRegistryKey; | 474 RulesRegistryKey; |
462 // Maps each profile (and OTRProfile) and a webview key to its respective | 475 // Maps each browser_context (and OTRBrowserContext) and a webview key to its |
463 // rules registry. | 476 // respective rules registry. |
464 std::map<RulesRegistryKey, | 477 std::map<RulesRegistryKey, |
465 scoped_refptr<extensions::WebRequestRulesRegistry> > rules_registries_; | 478 scoped_refptr<extensions::WebRequestRulesRegistry> > rules_registries_; |
466 | 479 |
| 480 scoped_ptr<extensions::WebRequestEventRouterDelegate> |
| 481 web_request_event_router_delegate_; |
| 482 |
467 DISALLOW_COPY_AND_ASSIGN(ExtensionWebRequestEventRouter); | 483 DISALLOW_COPY_AND_ASSIGN(ExtensionWebRequestEventRouter); |
468 }; | 484 }; |
469 | 485 |
470 class WebRequestInternalAddEventListenerFunction | 486 class WebRequestInternalAddEventListenerFunction |
471 : public SyncIOThreadExtensionFunction { | 487 : public SyncIOThreadExtensionFunction { |
472 public: | 488 public: |
473 DECLARE_EXTENSION_FUNCTION("webRequestInternal.addEventListener", | 489 DECLARE_EXTENSION_FUNCTION("webRequestInternal.addEventListener", |
474 WEBREQUESTINTERNAL_ADDEVENTLISTENER) | 490 WEBREQUESTINTERNAL_ADDEVENTLISTENER) |
475 | 491 |
476 protected: | 492 protected: |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
520 // function. | 536 // function. |
521 virtual void OnQuotaExceeded(const std::string& error) OVERRIDE; | 537 virtual void OnQuotaExceeded(const std::string& error) OVERRIDE; |
522 virtual bool RunSync() OVERRIDE; | 538 virtual bool RunSync() OVERRIDE; |
523 }; | 539 }; |
524 | 540 |
525 // Send updates to |host| with information about what webRequest-related | 541 // Send updates to |host| with information about what webRequest-related |
526 // extensions are installed. | 542 // extensions are installed. |
527 void SendExtensionWebRequestStatusToHost(content::RenderProcessHost* host); | 543 void SendExtensionWebRequestStatusToHost(content::RenderProcessHost* host); |
528 | 544 |
529 #endif // CHROME_BROWSER_EXTENSIONS_API_WEB_REQUEST_WEB_REQUEST_API_H_ | 545 #endif // CHROME_BROWSER_EXTENSIONS_API_WEB_REQUEST_WEB_REQUEST_API_H_ |
OLD | NEW |