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