| 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 EXTENSIONS_BROWSER_API_WEB_REQUEST_WEB_REQUEST_API_H_ | 5 #ifndef EXTENSIONS_BROWSER_API_WEB_REQUEST_WEB_REQUEST_API_H_ |
| 6 #define EXTENSIONS_BROWSER_API_WEB_REQUEST_WEB_REQUEST_API_H_ | 6 #define EXTENSIONS_BROWSER_API_WEB_REQUEST_WEB_REQUEST_API_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <list> | 10 #include <list> |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 namespace net { | 50 namespace net { |
| 51 class AuthChallengeInfo; | 51 class AuthChallengeInfo; |
| 52 class AuthCredentials; | 52 class AuthCredentials; |
| 53 class HttpRequestHeaders; | 53 class HttpRequestHeaders; |
| 54 class HttpResponseHeaders; | 54 class HttpResponseHeaders; |
| 55 class URLRequest; | 55 class URLRequest; |
| 56 } | 56 } |
| 57 | 57 |
| 58 namespace extensions { | 58 namespace extensions { |
| 59 | 59 |
| 60 class ExtensionNavigationUIData; |
| 60 class InfoMap; | 61 class InfoMap; |
| 61 class WebRequestEventDetails; | 62 class WebRequestEventDetails; |
| 62 class WebRequestRulesRegistry; | 63 class WebRequestRulesRegistry; |
| 63 class WebRequestEventRouterDelegate; | 64 class WebRequestEventRouterDelegate; |
| 64 | 65 |
| 65 // Support class for the WebRequest API. Lives on the UI thread. Most of the | 66 // Support class for the WebRequest API. Lives on the UI thread. Most of the |
| 66 // work is done by ExtensionWebRequestEventRouter below. This class observes | 67 // work is done by ExtensionWebRequestEventRouter below. This class observes |
| 67 // extensions::EventRouter to deal with event listeners. There is one instance | 68 // extensions::EventRouter to deal with event listeners. There is one instance |
| 68 // per BrowserContext which is shared with incognito. | 69 // per BrowserContext which is shared with incognito. |
| 69 class WebRequestAPI : public BrowserContextKeyedAPI, | 70 class WebRequestAPI : public BrowserContextKeyedAPI, |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 void RegisterRulesRegistry( | 165 void RegisterRulesRegistry( |
| 165 void* browser_context, | 166 void* browser_context, |
| 166 int rules_registry_id, | 167 int rules_registry_id, |
| 167 scoped_refptr<extensions::WebRequestRulesRegistry> rules_registry); | 168 scoped_refptr<extensions::WebRequestRulesRegistry> rules_registry); |
| 168 | 169 |
| 169 // Dispatches the OnBeforeRequest event to any extensions whose filters match | 170 // Dispatches the OnBeforeRequest event to any extensions whose filters match |
| 170 // the given request. Returns net::ERR_IO_PENDING if an extension is | 171 // the given request. Returns net::ERR_IO_PENDING if an extension is |
| 171 // intercepting the request, OK otherwise. | 172 // intercepting the request, OK otherwise. |
| 172 int OnBeforeRequest(void* browser_context, | 173 int OnBeforeRequest(void* browser_context, |
| 173 const extensions::InfoMap* extension_info_map, | 174 const extensions::InfoMap* extension_info_map, |
| 175 ExtensionNavigationUIData* navigation_ui_data, |
| 174 net::URLRequest* request, | 176 net::URLRequest* request, |
| 175 const net::CompletionCallback& callback, | 177 const net::CompletionCallback& callback, |
| 176 GURL* new_url); | 178 GURL* new_url); |
| 177 | 179 |
| 178 // Dispatches the onBeforeSendHeaders event. This is fired for HTTP(s) | 180 // Dispatches the onBeforeSendHeaders event. This is fired for HTTP(s) |
| 179 // requests only, and allows modification of the outgoing request headers. | 181 // requests only, and allows modification of the outgoing request headers. |
| 180 // Returns net::ERR_IO_PENDING if an extension is intercepting the request, OK | 182 // Returns net::ERR_IO_PENDING if an extension is intercepting the request, OK |
| 181 // otherwise. | 183 // otherwise. |
| 182 int OnBeforeSendHeaders(void* browser_context, | 184 int OnBeforeSendHeaders(void* browser_context, |
| 183 const extensions::InfoMap* extension_info_map, | 185 const extensions::InfoMap* extension_info_map, |
| 186 ExtensionNavigationUIData* navigation_ui_data, |
| 184 net::URLRequest* request, | 187 net::URLRequest* request, |
| 185 const net::CompletionCallback& callback, | 188 const net::CompletionCallback& callback, |
| 186 net::HttpRequestHeaders* headers); | 189 net::HttpRequestHeaders* headers); |
| 187 | 190 |
| 188 // Dispatches the onSendHeaders event. This is fired for HTTP(s) requests | 191 // Dispatches the onSendHeaders event. This is fired for HTTP(s) requests |
| 189 // only. | 192 // only. |
| 190 void OnSendHeaders(void* browser_context, | 193 void OnSendHeaders(void* browser_context, |
| 191 const extensions::InfoMap* extension_info_map, | 194 const extensions::InfoMap* extension_info_map, |
| 195 ExtensionNavigationUIData* navigation_ui_data, |
| 192 net::URLRequest* request, | 196 net::URLRequest* request, |
| 193 const net::HttpRequestHeaders& headers); | 197 const net::HttpRequestHeaders& headers); |
| 194 | 198 |
| 195 // Dispatches the onHeadersReceived event. This is fired for HTTP(s) | 199 // Dispatches the onHeadersReceived event. This is fired for HTTP(s) |
| 196 // requests only, and allows modification of incoming response headers. | 200 // requests only, and allows modification of incoming response headers. |
| 197 // Returns net::ERR_IO_PENDING if an extension is intercepting the request, | 201 // Returns net::ERR_IO_PENDING if an extension is intercepting the request, |
| 198 // OK otherwise. |original_response_headers| is reference counted. |callback| | 202 // OK otherwise. |original_response_headers| is reference counted. |callback| |
| 199 // |override_response_headers| and |allowed_unsafe_redirect_url| are owned by | 203 // |override_response_headers| and |allowed_unsafe_redirect_url| are owned by |
| 200 // a URLRequestJob. They are guaranteed to be valid until |callback| is called | 204 // a URLRequestJob. They are guaranteed to be valid until |callback| is called |
| 201 // or OnURLRequestDestroyed is called (whatever comes first). | 205 // or OnURLRequestDestroyed is called (whatever comes first). |
| 202 // Do not modify |original_response_headers| directly but write new ones | 206 // Do not modify |original_response_headers| directly but write new ones |
| 203 // into |override_response_headers|. | 207 // into |override_response_headers|. |
| 204 int OnHeadersReceived( | 208 int OnHeadersReceived( |
| 205 void* browser_context, | 209 void* browser_context, |
| 206 const extensions::InfoMap* extension_info_map, | 210 const extensions::InfoMap* extension_info_map, |
| 211 ExtensionNavigationUIData* navigation_ui_data, |
| 207 net::URLRequest* request, | 212 net::URLRequest* request, |
| 208 const net::CompletionCallback& callback, | 213 const net::CompletionCallback& callback, |
| 209 const net::HttpResponseHeaders* original_response_headers, | 214 const net::HttpResponseHeaders* original_response_headers, |
| 210 scoped_refptr<net::HttpResponseHeaders>* override_response_headers, | 215 scoped_refptr<net::HttpResponseHeaders>* override_response_headers, |
| 211 GURL* allowed_unsafe_redirect_url); | 216 GURL* allowed_unsafe_redirect_url); |
| 212 | 217 |
| 213 // Dispatches the OnAuthRequired event to any extensions whose filters match | 218 // Dispatches the OnAuthRequired event to any extensions whose filters match |
| 214 // the given request. If the listener is not registered as "blocking", then | 219 // the given request. If the listener is not registered as "blocking", then |
| 215 // AUTH_REQUIRED_RESPONSE_OK is returned. Otherwise, | 220 // AUTH_REQUIRED_RESPONSE_OK is returned. Otherwise, |
| 216 // AUTH_REQUIRED_RESPONSE_IO_PENDING is returned and |callback| will be | 221 // AUTH_REQUIRED_RESPONSE_IO_PENDING is returned and |callback| will be |
| 217 // invoked later. | 222 // invoked later. |
| 218 net::NetworkDelegate::AuthRequiredResponse OnAuthRequired( | 223 net::NetworkDelegate::AuthRequiredResponse OnAuthRequired( |
| 219 void* browser_context, | 224 void* browser_context, |
| 220 const extensions::InfoMap* extension_info_map, | 225 const extensions::InfoMap* extension_info_map, |
| 226 ExtensionNavigationUIData* navigation_ui_data, |
| 221 net::URLRequest* request, | 227 net::URLRequest* request, |
| 222 const net::AuthChallengeInfo& auth_info, | 228 const net::AuthChallengeInfo& auth_info, |
| 223 const net::NetworkDelegate::AuthCallback& callback, | 229 const net::NetworkDelegate::AuthCallback& callback, |
| 224 net::AuthCredentials* credentials); | 230 net::AuthCredentials* credentials); |
| 225 | 231 |
| 226 // Dispatches the onBeforeRedirect event. This is fired for HTTP(s) requests | 232 // Dispatches the onBeforeRedirect event. This is fired for HTTP(s) requests |
| 227 // only. | 233 // only. |
| 228 void OnBeforeRedirect(void* browser_context, | 234 void OnBeforeRedirect(void* browser_context, |
| 229 const extensions::InfoMap* extension_info_map, | 235 const extensions::InfoMap* extension_info_map, |
| 236 ExtensionNavigationUIData* navigation_ui_data, |
| 230 net::URLRequest* request, | 237 net::URLRequest* request, |
| 231 const GURL& new_location); | 238 const GURL& new_location); |
| 232 | 239 |
| 233 // Dispatches the onResponseStarted event indicating that the first bytes of | 240 // Dispatches the onResponseStarted event indicating that the first bytes of |
| 234 // the response have arrived. | 241 // the response have arrived. |
| 235 void OnResponseStarted(void* browser_context, | 242 void OnResponseStarted(void* browser_context, |
| 236 const extensions::InfoMap* extension_info_map, | 243 const extensions::InfoMap* extension_info_map, |
| 244 ExtensionNavigationUIData* navigation_ui_data, |
| 237 net::URLRequest* request, | 245 net::URLRequest* request, |
| 238 int net_error); | 246 int net_error); |
| 239 // Deprecated. | 247 // Deprecated. |
| 240 // TODO(maksims): Remove this. | 248 // TODO(maksims): Remove this. |
| 241 void OnResponseStarted(void* browser_context, | 249 void OnResponseStarted(void* browser_context, |
| 242 const extensions::InfoMap* extension_info_map, | 250 const extensions::InfoMap* extension_info_map, |
| 251 ExtensionNavigationUIData* navigation_ui_data, |
| 243 net::URLRequest* request); | 252 net::URLRequest* request); |
| 244 | 253 |
| 245 // Dispatches the onComplete event. | 254 // Dispatches the onComplete event. |
| 246 void OnCompleted(void* browser_context, | 255 void OnCompleted(void* browser_context, |
| 247 const extensions::InfoMap* extension_info_map, | 256 const extensions::InfoMap* extension_info_map, |
| 257 ExtensionNavigationUIData* navigation_ui_data, |
| 248 net::URLRequest* request, | 258 net::URLRequest* request, |
| 249 int net_error); | 259 int net_error); |
| 250 // Deprecated. | 260 // Deprecated. |
| 251 // TODO(maksims): Remove this. | 261 // TODO(maksims): Remove this. |
| 252 void OnCompleted(void* browser_context, | 262 void OnCompleted(void* browser_context, |
| 253 const extensions::InfoMap* extension_info_map, | 263 const extensions::InfoMap* extension_info_map, |
| 264 ExtensionNavigationUIData* navigation_ui_data, |
| 254 net::URLRequest* request); | 265 net::URLRequest* request); |
| 255 | 266 |
| 256 // Dispatches an onErrorOccurred event. | 267 // Dispatches an onErrorOccurred event. |
| 257 void OnErrorOccurred(void* browser_context, | 268 void OnErrorOccurred(void* browser_context, |
| 258 const extensions::InfoMap* extension_info_map, | 269 const extensions::InfoMap* extension_info_map, |
| 270 ExtensionNavigationUIData* navigation_ui_data, |
| 259 net::URLRequest* request, | 271 net::URLRequest* request, |
| 260 bool started, | 272 bool started, |
| 261 int net_error); | 273 int net_error); |
| 262 // Deprecated. | 274 // Deprecated. |
| 263 // TODO(maksims): Remove this. | 275 // TODO(maksims): Remove this. |
| 264 void OnErrorOccurred(void* browser_context, | 276 void OnErrorOccurred(void* browser_context, |
| 265 const extensions::InfoMap* extension_info_map, | 277 const extensions::InfoMap* extension_info_map, |
| 278 ExtensionNavigationUIData* navigation_ui_data, |
| 266 net::URLRequest* request, | 279 net::URLRequest* request, |
| 267 bool started); | 280 bool started); |
| 268 | 281 |
| 269 // Notifications when objects are going away. | 282 // Notifications when objects are going away. |
| 270 void OnURLRequestDestroyed(void* browser_context, | 283 void OnURLRequestDestroyed(void* browser_context, |
| 271 const net::URLRequest* request); | 284 const net::URLRequest* request); |
| 272 | 285 |
| 273 // Called when an event listener handles a blocking event and responds. | 286 // Called when an event listener handles a blocking event and responds. |
| 274 void OnEventHandled(void* browser_context, | 287 void OnEventHandled(void* browser_context, |
| 275 const std::string& extension_id, | 288 const std::string& extension_id, |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 402 // thread. | 415 // thread. |
| 403 void RemoveEventListener(const EventListener::ID& id, bool strict); | 416 void RemoveEventListener(const EventListener::ID& id, bool strict); |
| 404 | 417 |
| 405 // Ensures that future callbacks for |request| are ignored so that it can be | 418 // Ensures that future callbacks for |request| are ignored so that it can be |
| 406 // destroyed safely. | 419 // destroyed safely. |
| 407 void ClearPendingCallbacks(const net::URLRequest* request); | 420 void ClearPendingCallbacks(const net::URLRequest* request); |
| 408 | 421 |
| 409 bool DispatchEvent(void* browser_context, | 422 bool DispatchEvent(void* browser_context, |
| 410 net::URLRequest* request, | 423 net::URLRequest* request, |
| 411 const RawListeners& listener_ids, | 424 const RawListeners& listener_ids, |
| 425 ExtensionNavigationUIData* navigation_ui_data, |
| 412 std::unique_ptr<WebRequestEventDetails> event_details); | 426 std::unique_ptr<WebRequestEventDetails> event_details); |
| 413 | 427 |
| 414 void DispatchEventToListeners( | 428 void DispatchEventToListeners( |
| 415 void* browser_context, | 429 void* browser_context, |
| 416 std::unique_ptr<ListenerIDs> listener_ids, | 430 std::unique_ptr<ListenerIDs> listener_ids, |
| 417 std::unique_ptr<WebRequestEventDetails> event_details); | 431 std::unique_ptr<WebRequestEventDetails> event_details); |
| 418 | 432 |
| 419 // Returns a list of event listeners that care about the given event, based | 433 // Returns a list of event listeners that care about the given event, based |
| 420 // on their filter parameters. |extra_info_spec| will contain the combined | 434 // on their filter parameters. |extra_info_spec| will contain the combined |
| 421 // set of extra_info_spec flags that every matching listener asked for. | 435 // set of extra_info_spec flags that every matching listener asked for. |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 621 extensions::QuotaLimitHeuristics* heuristics) const override; | 635 extensions::QuotaLimitHeuristics* heuristics) const override; |
| 622 // Handle quota exceeded gracefully: Only warn the user but still execute the | 636 // Handle quota exceeded gracefully: Only warn the user but still execute the |
| 623 // function. | 637 // function. |
| 624 void OnQuotaExceeded(const std::string& error) override; | 638 void OnQuotaExceeded(const std::string& error) override; |
| 625 ResponseAction Run() override; | 639 ResponseAction Run() override; |
| 626 }; | 640 }; |
| 627 | 641 |
| 628 } // namespace extensions | 642 } // namespace extensions |
| 629 | 643 |
| 630 #endif // EXTENSIONS_BROWSER_API_WEB_REQUEST_WEB_REQUEST_API_H_ | 644 #endif // EXTENSIONS_BROWSER_API_WEB_REQUEST_WEB_REQUEST_API_H_ |
| OLD | NEW |