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.h" | 16 #include "base/time.h" |
17 #include "chrome/browser/extensions/api/declarative_webrequest/request_stages.h" | 17 #include "chrome/browser/extensions/api/declarative_webrequest/request_stages.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/extension_function.h" | 20 #include "chrome/browser/extensions/extension_function.h" |
20 #include "chrome/browser/profiles/profile.h" | 21 #include "chrome/browser/profiles/profile.h" |
21 #include "chrome/common/extensions/url_pattern_set.h" | 22 #include "chrome/common/extensions/url_pattern_set.h" |
22 #include "ipc/ipc_sender.h" | 23 #include "ipc/ipc_sender.h" |
23 #include "net/base/completion_callback.h" | 24 #include "net/base/completion_callback.h" |
24 #include "net/base/network_delegate.h" | 25 #include "net/base/network_delegate.h" |
25 #include "net/http/http_request_headers.h" | 26 #include "net/http/http_request_headers.h" |
26 #include "webkit/glue/resource_type.h" | 27 #include "webkit/glue/resource_type.h" |
27 | 28 |
28 class ExtensionInfoMap; | 29 class ExtensionInfoMap; |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 scoped_ptr<extension_web_request_api_helpers::ResponseHeaders> | 126 scoped_ptr<extension_web_request_api_helpers::ResponseHeaders> |
126 response_headers; | 127 response_headers; |
127 | 128 |
128 scoped_ptr<net::AuthCredentials> auth_credentials; | 129 scoped_ptr<net::AuthCredentials> auth_credentials; |
129 | 130 |
130 DISALLOW_COPY_AND_ASSIGN(EventResponse); | 131 DISALLOW_COPY_AND_ASSIGN(EventResponse); |
131 }; | 132 }; |
132 | 133 |
133 static ExtensionWebRequestEventRouter* GetInstance(); | 134 static ExtensionWebRequestEventRouter* GetInstance(); |
134 | 135 |
| 136 // Registers a rule registry. Pass null for |rules_registry| to unregister |
| 137 // the rule registry for |profile|. |
135 void RegisterRulesRegistry( | 138 void RegisterRulesRegistry( |
| 139 void* profile, |
136 scoped_refptr<extensions::WebRequestRulesRegistry> rules_registry); | 140 scoped_refptr<extensions::WebRequestRulesRegistry> rules_registry); |
137 | 141 |
138 // Dispatches the OnBeforeRequest event to any extensions whose filters match | 142 // Dispatches the OnBeforeRequest event to any extensions whose filters match |
139 // the given request. Returns net::ERR_IO_PENDING if an extension is | 143 // the given request. Returns net::ERR_IO_PENDING if an extension is |
140 // intercepting the request, OK otherwise. | 144 // intercepting the request, OK otherwise. |
141 int OnBeforeRequest(void* profile, | 145 int OnBeforeRequest(void* profile, |
142 ExtensionInfoMap* extension_info_map, | 146 ExtensionInfoMap* extension_info_map, |
143 net::URLRequest* request, | 147 net::URLRequest* request, |
144 const net::CompletionCallback& callback, | 148 const net::CompletionCallback& callback, |
145 GURL* new_url); | 149 GURL* new_url); |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
356 | 360 |
357 // Clears the flag that |event_type| has been signaled for |request_id|. | 361 // Clears the flag that |event_type| has been signaled for |request_id|. |
358 void ClearSignaled(uint64 request_id, EventTypes event_type); | 362 void ClearSignaled(uint64 request_id, EventTypes event_type); |
359 | 363 |
360 // Returns whether |request| represents a top level window navigation. | 364 // Returns whether |request| represents a top level window navigation. |
361 bool IsPageLoad(net::URLRequest* request) const; | 365 bool IsPageLoad(net::URLRequest* request) const; |
362 | 366 |
363 // Called on a page load to process all registered callbacks. | 367 // Called on a page load to process all registered callbacks. |
364 void NotifyPageLoad(); | 368 void NotifyPageLoad(); |
365 | 369 |
| 370 // Returns the matching cross profile (the regular profile if |profile| is |
| 371 // OTR and vice versa). |
| 372 void* GetCrossProfile(void* profile) const; |
| 373 |
366 // A map for each profile that maps an event name to a set of extensions that | 374 // A map for each profile that maps an event name to a set of extensions that |
367 // are listening to that event. | 375 // are listening to that event. |
368 ListenerMap listeners_; | 376 ListenerMap listeners_; |
369 | 377 |
370 // A map of network requests that are waiting for at least one event handler | 378 // A map of network requests that are waiting for at least one event handler |
371 // to respond. | 379 // to respond. |
372 BlockedRequestMap blocked_requests_; | 380 BlockedRequestMap blocked_requests_; |
373 | 381 |
374 // A map of request ids to a bitvector indicating which events have been | 382 // A map of request ids to a bitvector indicating which events have been |
375 // signaled and should not be sent again. | 383 // signaled and should not be sent again. |
376 SignaledRequestMap signaled_requests_; | 384 SignaledRequestMap signaled_requests_; |
377 | 385 |
378 // A map of original profile -> corresponding incognito profile (and vice | 386 // A map of original profile -> corresponding incognito profile (and vice |
379 // versa). | 387 // versa). |
380 CrossProfileMap cross_profile_map_; | 388 CrossProfileMap cross_profile_map_; |
381 | 389 |
382 // Keeps track of time spent waiting on extensions using the blocking | 390 // Keeps track of time spent waiting on extensions using the blocking |
383 // webRequest API. | 391 // webRequest API. |
384 scoped_ptr<ExtensionWebRequestTimeTracker> request_time_tracker_; | 392 scoped_ptr<ExtensionWebRequestTimeTracker> request_time_tracker_; |
385 | 393 |
386 CallbacksForPageLoad callbacks_for_page_load_; | 394 CallbacksForPageLoad callbacks_for_page_load_; |
387 | 395 |
388 scoped_refptr<extensions::WebRequestRulesRegistry> rules_registry_; | 396 // Maps each profile (and OTRProfile) to its respective rules registry. |
| 397 std::map<void*, scoped_refptr<extensions::WebRequestRulesRegistry> > |
| 398 rules_registries_; |
389 | 399 |
390 DISALLOW_COPY_AND_ASSIGN(ExtensionWebRequestEventRouter); | 400 DISALLOW_COPY_AND_ASSIGN(ExtensionWebRequestEventRouter); |
391 }; | 401 }; |
392 | 402 |
393 class WebRequestAddEventListener : public SyncIOThreadExtensionFunction { | 403 class WebRequestAddEventListener : public SyncIOThreadExtensionFunction { |
394 public: | 404 public: |
395 DECLARE_EXTENSION_FUNCTION_NAME("webRequestInternal.addEventListener"); | 405 DECLARE_EXTENSION_FUNCTION_NAME("webRequestInternal.addEventListener"); |
396 | 406 |
397 protected: | 407 protected: |
398 virtual ~WebRequestAddEventListener() {} | 408 virtual ~WebRequestAddEventListener() {} |
(...skipping 28 matching lines...) Expand all Loading... |
427 virtual void OnQuotaExceeded() OVERRIDE; | 437 virtual void OnQuotaExceeded() OVERRIDE; |
428 virtual bool RunImpl() OVERRIDE; | 438 virtual bool RunImpl() OVERRIDE; |
429 }; | 439 }; |
430 | 440 |
431 // Send updates to |host| with information about what webRequest-related | 441 // Send updates to |host| with information about what webRequest-related |
432 // extensions are installed. | 442 // extensions are installed. |
433 // TODO(mpcomplete): remove. http://crbug.com/100411 | 443 // TODO(mpcomplete): remove. http://crbug.com/100411 |
434 void SendExtensionWebRequestStatusToHost(content::RenderProcessHost* host); | 444 void SendExtensionWebRequestStatusToHost(content::RenderProcessHost* host); |
435 | 445 |
436 #endif // CHROME_BROWSER_EXTENSIONS_API_WEB_REQUEST_WEB_REQUEST_API_H_ | 446 #endif // CHROME_BROWSER_EXTENSIONS_API_WEB_REQUEST_WEB_REQUEST_API_H_ |
OLD | NEW |