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 14 matching lines...) Expand all Loading... | |
25 class ExtensionWebRequestTimeTracker; | 25 class ExtensionWebRequestTimeTracker; |
26 class GURL; | 26 class GURL; |
27 | 27 |
28 namespace base { | 28 namespace base { |
29 class DictionaryValue; | 29 class DictionaryValue; |
30 class ListValue; | 30 class ListValue; |
31 class StringValue; | 31 class StringValue; |
32 } | 32 } |
33 | 33 |
34 namespace net { | 34 namespace net { |
35 class AuthCredentials; | |
35 class AuthChallengeInfo; | 36 class AuthChallengeInfo; |
36 class HostPortPair; | 37 class HostPortPair; |
37 class HttpRequestHeaders; | 38 class HttpRequestHeaders; |
38 class HttpResponseHeaders; | 39 class HttpResponseHeaders; |
39 class URLRequest; | 40 class URLRequest; |
40 } | 41 } |
41 | 42 |
42 // This class observes network events and routes them to the appropriate | 43 // This class observes network events and routes them to the appropriate |
43 // extensions listening to those events. All methods must be called on the IO | 44 // extensions listening to those events. All methods must be called on the IO |
44 // thread unless otherwise specified. | 45 // thread unless otherwise specified. |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
96 | 97 |
97 // The time that the extension was installed. Used for deciding order of | 98 // The time that the extension was installed. Used for deciding order of |
98 // precedence in case multiple extensions respond with conflicting | 99 // precedence in case multiple extensions respond with conflicting |
99 // decisions. | 100 // decisions. |
100 base::Time extension_install_time; | 101 base::Time extension_install_time; |
101 | 102 |
102 // Response values. These are mutually exclusive. | 103 // Response values. These are mutually exclusive. |
103 bool cancel; | 104 bool cancel; |
104 GURL new_url; | 105 GURL new_url; |
105 scoped_ptr<net::HttpRequestHeaders> request_headers; | 106 scoped_ptr<net::HttpRequestHeaders> request_headers; |
107 scoped_ptr<net::AuthCredentials> auth_credentials; | |
106 | 108 |
107 EventResponse(const std::string& extension_id, | 109 EventResponse(const std::string& extension_id, |
108 const base::Time& extension_install_time); | 110 const base::Time& extension_install_time); |
109 ~EventResponse(); | 111 ~EventResponse(); |
110 | 112 |
111 DISALLOW_COPY_AND_ASSIGN(EventResponse); | 113 DISALLOW_COPY_AND_ASSIGN(EventResponse); |
112 }; | 114 }; |
113 | 115 |
114 // Contains the modification an extension wants to perform on an event. | 116 // Contains the modification an extension wants to perform on an event. |
115 struct EventResponseDelta { | 117 struct EventResponseDelta { |
116 // ID of the extension that sent this response. | 118 // ID of the extension that sent this response. |
117 std::string extension_id; | 119 std::string extension_id; |
118 | 120 |
119 // The time that the extension was installed. Used for deciding order of | 121 // The time that the extension was installed. Used for deciding order of |
120 // precedence in case multiple extensions respond with conflicting | 122 // precedence in case multiple extensions respond with conflicting |
121 // decisions. | 123 // decisions. |
122 base::Time extension_install_time; | 124 base::Time extension_install_time; |
123 | 125 |
124 // Response values. These are mutually exclusive. | 126 // Response values. These are mutually exclusive. |
125 bool cancel; | 127 bool cancel; |
126 GURL new_url; | 128 GURL new_url; |
127 | 129 |
128 // Newly introduced or overridden request headers. | 130 // Newly introduced or overridden request headers. |
129 net::HttpRequestHeaders modified_request_headers; | 131 net::HttpRequestHeaders modified_request_headers; |
130 | 132 |
131 // Keys of request headers to be deleted. | 133 // Keys of request headers to be deleted. |
132 std::vector<std::string> deleted_request_headers; | 134 std::vector<std::string> deleted_request_headers; |
133 | 135 |
136 // Authentication Credentials to use. | |
137 scoped_ptr<net::AuthCredentials> auth_credentials; | |
138 | |
134 EventResponseDelta(const std::string& extension_id, | 139 EventResponseDelta(const std::string& extension_id, |
135 const base::Time& extension_install_time); | 140 const base::Time& extension_install_time); |
136 ~EventResponseDelta(); | 141 ~EventResponseDelta(); |
137 | 142 |
138 DISALLOW_COPY_AND_ASSIGN(EventResponseDelta); | 143 DISALLOW_COPY_AND_ASSIGN(EventResponseDelta); |
139 }; | 144 }; |
140 | 145 |
141 typedef std::list<linked_ptr<EventResponseDelta> > EventResponseDeltas; | 146 typedef std::list<linked_ptr<EventResponseDelta> > EventResponseDeltas; |
142 | 147 |
143 // Used in testing to allow chrome-extension URLs to be intercepted. | 148 // Used in testing to allow chrome-extension URLs to be intercepted. |
(...skipping 20 matching lines...) Expand all Loading... | |
164 net::CompletionCallback* callback, | 169 net::CompletionCallback* callback, |
165 net::HttpRequestHeaders* headers); | 170 net::HttpRequestHeaders* headers); |
166 | 171 |
167 // Dispatches the onSendHeaders event. This is fired for HTTP(s) requests | 172 // Dispatches the onSendHeaders event. This is fired for HTTP(s) requests |
168 // only. | 173 // only. |
169 void OnSendHeaders(void* profile, | 174 void OnSendHeaders(void* profile, |
170 ExtensionInfoMap* extension_info_map, | 175 ExtensionInfoMap* extension_info_map, |
171 net::URLRequest* request, | 176 net::URLRequest* request, |
172 const net::HttpRequestHeaders& headers); | 177 const net::HttpRequestHeaders& headers); |
173 | 178 |
174 // Dispatches the onAuthRequired event. | 179 // Dispatches the OnAuthRequired event to any extensions whose filters match |
175 void OnAuthRequired(void* profile, | 180 // the given request. Returns net::ERR_IO_PENDING if an extension is |
181 // intercepting the request, OK otherwise. | |
182 int OnAuthRequired(void* profile, | |
176 ExtensionInfoMap* extension_info_map, | 183 ExtensionInfoMap* extension_info_map, |
177 net::URLRequest* request, | 184 net::URLRequest* request, |
178 const net::AuthChallengeInfo& auth_info); | 185 const net::AuthChallengeInfo& auth_info, |
186 net::CompletionCallback* callback, | |
187 net::AuthCredentials* credentials); | |
179 | 188 |
180 // Dispatches the onBeforeRedirect event. This is fired for HTTP(s) requests | 189 // Dispatches the onBeforeRedirect event. This is fired for HTTP(s) requests |
181 // only. | 190 // only. |
182 void OnBeforeRedirect(void* profile, | 191 void OnBeforeRedirect(void* profile, |
183 ExtensionInfoMap* extension_info_map, | 192 ExtensionInfoMap* extension_info_map, |
184 net::URLRequest* request, | 193 net::URLRequest* request, |
185 const GURL& new_location); | 194 const GURL& new_location); |
186 | 195 |
187 // Dispatches the onResponseStarted event indicating that the first bytes of | 196 // Dispatches the onResponseStarted event indicating that the first bytes of |
188 // the response have arrived. | 197 // the response have arrived. |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
328 // The functions update the target url or the request headers in |request| | 337 // The functions update the target url or the request headers in |request| |
329 // and reports extension IDs of extensions whose wishes could not be honored | 338 // and reports extension IDs of extensions whose wishes could not be honored |
330 // in |conflicting_extensions|. | 339 // in |conflicting_extensions|. |
331 void MergeOnBeforeRequestResponses( | 340 void MergeOnBeforeRequestResponses( |
332 BlockedRequest* request, | 341 BlockedRequest* request, |
333 std::list<std::string>* conflicting_extensions) const; | 342 std::list<std::string>* conflicting_extensions) const; |
334 void MergeOnBeforeSendHeadersResponses( | 343 void MergeOnBeforeSendHeadersResponses( |
335 BlockedRequest* request, | 344 BlockedRequest* request, |
336 std::list<std::string>* conflicting_extensions) const; | 345 std::list<std::string>* conflicting_extensions) const; |
337 | 346 |
347 // Merge the responses of blocked onAuthRequired handlers. The first | |
348 // registered listener that supplies authentication credentials in a response, | |
Matt Perry
2011/09/26 21:19:45
This comment is inaccurate. Since the |deltas| are
| |
349 // if any, will have its authentication credentials used. |request| must be | |
350 // non-NULL, and contain |deltas| that are sorted in decreasing order of | |
351 // precedence. | |
352 void MergeOnAuthRequiredResponses( | |
353 BlockedRequest* request, | |
354 std::list<std::string>* conflicting_extensions) const; | |
355 | |
338 // A map for each profile that maps an event name to a set of extensions that | 356 // A map for each profile that maps an event name to a set of extensions that |
339 // are listening to that event. | 357 // are listening to that event. |
340 ListenerMap listeners_; | 358 ListenerMap listeners_; |
341 | 359 |
342 // A map of network requests that are waiting for at least one event handler | 360 // A map of network requests that are waiting for at least one event handler |
343 // to respond. | 361 // to respond. |
344 BlockedRequestMap blocked_requests_; | 362 BlockedRequestMap blocked_requests_; |
345 | 363 |
346 // A map of request ids to a bitvector indicating which events have been | 364 // A map of request ids to a bitvector indicating which events have been |
347 // signaled and should not be sent again. | 365 // signaled and should not be sent again. |
(...skipping 16 matching lines...) Expand all Loading... | |
364 DECLARE_EXTENSION_FUNCTION_NAME("experimental.webRequest.addEventListener"); | 382 DECLARE_EXTENSION_FUNCTION_NAME("experimental.webRequest.addEventListener"); |
365 }; | 383 }; |
366 | 384 |
367 class WebRequestEventHandled : public SyncIOThreadExtensionFunction { | 385 class WebRequestEventHandled : public SyncIOThreadExtensionFunction { |
368 public: | 386 public: |
369 virtual bool RunImpl(); | 387 virtual bool RunImpl(); |
370 DECLARE_EXTENSION_FUNCTION_NAME("experimental.webRequest.eventHandled"); | 388 DECLARE_EXTENSION_FUNCTION_NAME("experimental.webRequest.eventHandled"); |
371 }; | 389 }; |
372 | 390 |
373 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_WEBREQUEST_API_H_ | 391 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_WEBREQUEST_API_H_ |
OLD | NEW |