| 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 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 std::string extension_id; | 139 std::string extension_id; |
| 140 | 140 |
| 141 // The time that the extension was installed. Used for deciding order of | 141 // The time that the extension was installed. Used for deciding order of |
| 142 // precedence in case multiple extensions respond with conflicting | 142 // precedence in case multiple extensions respond with conflicting |
| 143 // decisions. | 143 // decisions. |
| 144 base::Time extension_install_time; | 144 base::Time extension_install_time; |
| 145 | 145 |
| 146 // Response values. These are mutually exclusive. | 146 // Response values. These are mutually exclusive. |
| 147 bool cancel; | 147 bool cancel; |
| 148 GURL new_url; | 148 GURL new_url; |
| 149 scoped_ptr<net::HttpRequestHeaders> request_headers; | 149 std::unique_ptr<net::HttpRequestHeaders> request_headers; |
| 150 scoped_ptr<extension_web_request_api_helpers::ResponseHeaders> | 150 std::unique_ptr<extension_web_request_api_helpers::ResponseHeaders> |
| 151 response_headers; | 151 response_headers; |
| 152 | 152 |
| 153 scoped_ptr<net::AuthCredentials> auth_credentials; | 153 std::unique_ptr<net::AuthCredentials> auth_credentials; |
| 154 | 154 |
| 155 private: | 155 private: |
| 156 DISALLOW_COPY_AND_ASSIGN(EventResponse); | 156 DISALLOW_COPY_AND_ASSIGN(EventResponse); |
| 157 }; | 157 }; |
| 158 | 158 |
| 159 static ExtensionWebRequestEventRouter* GetInstance(); | 159 static ExtensionWebRequestEventRouter* GetInstance(); |
| 160 | 160 |
| 161 // Registers a rule registry. Pass null for |rules_registry| to unregister | 161 // Registers a rule registry. Pass null for |rules_registry| to unregister |
| 162 // the rule registry for |browser_context|. | 162 // the rule registry for |browser_context|. |
| 163 void RegisterRulesRegistry( | 163 void RegisterRulesRegistry( |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 318 ExtensionWebRequestEventRouter(); | 318 ExtensionWebRequestEventRouter(); |
| 319 ~ExtensionWebRequestEventRouter(); | 319 ~ExtensionWebRequestEventRouter(); |
| 320 | 320 |
| 321 // Ensures that future callbacks for |request| are ignored so that it can be | 321 // Ensures that future callbacks for |request| are ignored so that it can be |
| 322 // destroyed safely. | 322 // destroyed safely. |
| 323 void ClearPendingCallbacks(const net::URLRequest* request); | 323 void ClearPendingCallbacks(const net::URLRequest* request); |
| 324 | 324 |
| 325 bool DispatchEvent(void* browser_context, | 325 bool DispatchEvent(void* browser_context, |
| 326 net::URLRequest* request, | 326 net::URLRequest* request, |
| 327 const std::vector<const EventListener*>& listeners, | 327 const std::vector<const EventListener*>& listeners, |
| 328 scoped_ptr<WebRequestEventDetails> event_details); | 328 std::unique_ptr<WebRequestEventDetails> event_details); |
| 329 | 329 |
| 330 void DispatchEventToListeners( | 330 void DispatchEventToListeners( |
| 331 void* browser_context, | 331 void* browser_context, |
| 332 scoped_ptr<std::vector<EventListener>> listeners, | 332 std::unique_ptr<std::vector<EventListener>> listeners, |
| 333 scoped_ptr<WebRequestEventDetails> event_details); | 333 std::unique_ptr<WebRequestEventDetails> event_details); |
| 334 | 334 |
| 335 // Returns a list of event listeners that care about the given event, based | 335 // Returns a list of event listeners that care about the given event, based |
| 336 // on their filter parameters. |extra_info_spec| will contain the combined | 336 // on their filter parameters. |extra_info_spec| will contain the combined |
| 337 // set of extra_info_spec flags that every matching listener asked for. | 337 // set of extra_info_spec flags that every matching listener asked for. |
| 338 std::vector<const EventListener*> GetMatchingListeners( | 338 std::vector<const EventListener*> GetMatchingListeners( |
| 339 void* browser_context, | 339 void* browser_context, |
| 340 const extensions::InfoMap* extension_info_map, | 340 const extensions::InfoMap* extension_info_map, |
| 341 const std::string& event_name, | 341 const std::string& event_name, |
| 342 const net::URLRequest* request, | 342 const net::URLRequest* request, |
| 343 int* extra_info_spec); | 343 int* extra_info_spec); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 366 // method requested by the extension with the highest precedence. Precedence | 366 // method requested by the extension with the highest precedence. Precedence |
| 367 // is decided by extension install time. If |response| is non-NULL, this | 367 // is decided by extension install time. If |response| is non-NULL, this |
| 368 // method assumes ownership. | 368 // method assumes ownership. |
| 369 void DecrementBlockCount(void* browser_context, | 369 void DecrementBlockCount(void* browser_context, |
| 370 const std::string& extension_id, | 370 const std::string& extension_id, |
| 371 const std::string& event_name, | 371 const std::string& event_name, |
| 372 uint64_t request_id, | 372 uint64_t request_id, |
| 373 EventResponse* response); | 373 EventResponse* response); |
| 374 | 374 |
| 375 // Logs an extension action. | 375 // Logs an extension action. |
| 376 void LogExtensionActivity( | 376 void LogExtensionActivity(void* browser_context_id, |
| 377 void* browser_context_id, | 377 bool is_incognito, |
| 378 bool is_incognito, | 378 const std::string& extension_id, |
| 379 const std::string& extension_id, | 379 const GURL& url, |
| 380 const GURL& url, | 380 const std::string& api_call, |
| 381 const std::string& api_call, | 381 std::unique_ptr<base::DictionaryValue> details); |
| 382 scoped_ptr<base::DictionaryValue> details); | |
| 383 | 382 |
| 384 // Processes the generated deltas from blocked_requests_ on the specified | 383 // Processes the generated deltas from blocked_requests_ on the specified |
| 385 // request. If |call_back| is true, the callback registered in | 384 // request. If |call_back| is true, the callback registered in |
| 386 // |blocked_requests_| is called. | 385 // |blocked_requests_| is called. |
| 387 // The function returns the error code for the network request. This is | 386 // The function returns the error code for the network request. This is |
| 388 // mostly relevant in case the caller passes |call_callback| = false | 387 // mostly relevant in case the caller passes |call_callback| = false |
| 389 // and wants to return the correct network error code himself. | 388 // and wants to return the correct network error code himself. |
| 390 int ExecuteDeltas(void* browser_context, | 389 int ExecuteDeltas(void* browser_context, |
| 391 uint64_t request_id, | 390 uint64_t request_id, |
| 392 bool call_callback); | 391 bool call_callback); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 411 void* browser_context, const BlockedRequest& blocked_request); | 410 void* browser_context, const BlockedRequest& blocked_request); |
| 412 | 411 |
| 413 // Called when the RulesRegistry is ready to unblock a request that was | 412 // Called when the RulesRegistry is ready to unblock a request that was |
| 414 // waiting for said event. | 413 // waiting for said event. |
| 415 void OnRulesRegistryReady(void* browser_context, | 414 void OnRulesRegistryReady(void* browser_context, |
| 416 const std::string& event_name, | 415 const std::string& event_name, |
| 417 uint64_t request_id, | 416 uint64_t request_id, |
| 418 extensions::RequestStage request_stage); | 417 extensions::RequestStage request_stage); |
| 419 | 418 |
| 420 // Returns event details for a given request. | 419 // Returns event details for a given request. |
| 421 scoped_ptr<WebRequestEventDetails> CreateEventDetails( | 420 std::unique_ptr<WebRequestEventDetails> CreateEventDetails( |
| 422 const net::URLRequest* request, | 421 const net::URLRequest* request, |
| 423 int extra_info_spec); | 422 int extra_info_spec); |
| 424 | 423 |
| 425 // Sets the flag that |event_type| has been signaled for |request_id|. | 424 // Sets the flag that |event_type| has been signaled for |request_id|. |
| 426 // Returns the value of the flag before setting it. | 425 // Returns the value of the flag before setting it. |
| 427 bool GetAndSetSignaled(uint64_t request_id, EventTypes event_type); | 426 bool GetAndSetSignaled(uint64_t request_id, EventTypes event_type); |
| 428 | 427 |
| 429 // Clears the flag that |event_type| has been signaled for |request_id|. | 428 // Clears the flag that |event_type| has been signaled for |request_id|. |
| 430 void ClearSignaled(uint64_t request_id, EventTypes event_type); | 429 void ClearSignaled(uint64_t request_id, EventTypes event_type); |
| 431 | 430 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 458 // A map of request ids to a bitvector indicating which events have been | 457 // A map of request ids to a bitvector indicating which events have been |
| 459 // signaled and should not be sent again. | 458 // signaled and should not be sent again. |
| 460 SignaledRequestMap signaled_requests_; | 459 SignaledRequestMap signaled_requests_; |
| 461 | 460 |
| 462 // A map of original browser_context -> corresponding incognito | 461 // A map of original browser_context -> corresponding incognito |
| 463 // browser_context (and vice versa). | 462 // browser_context (and vice versa). |
| 464 CrossBrowserContextMap cross_browser_context_map_; | 463 CrossBrowserContextMap cross_browser_context_map_; |
| 465 | 464 |
| 466 // Keeps track of time spent waiting on extensions using the blocking | 465 // Keeps track of time spent waiting on extensions using the blocking |
| 467 // webRequest API. | 466 // webRequest API. |
| 468 scoped_ptr<ExtensionWebRequestTimeTracker> request_time_tracker_; | 467 std::unique_ptr<ExtensionWebRequestTimeTracker> request_time_tracker_; |
| 469 | 468 |
| 470 CallbacksForPageLoad callbacks_for_page_load_; | 469 CallbacksForPageLoad callbacks_for_page_load_; |
| 471 | 470 |
| 472 typedef std::pair<void*, int> RulesRegistryKey; | 471 typedef std::pair<void*, int> RulesRegistryKey; |
| 473 // Maps each browser_context (and OTRBrowserContext) and a webview key to its | 472 // Maps each browser_context (and OTRBrowserContext) and a webview key to its |
| 474 // respective rules registry. | 473 // respective rules registry. |
| 475 std::map<RulesRegistryKey, | 474 std::map<RulesRegistryKey, |
| 476 scoped_refptr<extensions::WebRequestRulesRegistry> > rules_registries_; | 475 scoped_refptr<extensions::WebRequestRulesRegistry> > rules_registries_; |
| 477 | 476 |
| 478 scoped_ptr<extensions::WebRequestEventRouterDelegate> | 477 std::unique_ptr<extensions::WebRequestEventRouterDelegate> |
| 479 web_request_event_router_delegate_; | 478 web_request_event_router_delegate_; |
| 480 | 479 |
| 481 DISALLOW_COPY_AND_ASSIGN(ExtensionWebRequestEventRouter); | 480 DISALLOW_COPY_AND_ASSIGN(ExtensionWebRequestEventRouter); |
| 482 }; | 481 }; |
| 483 | 482 |
| 484 class WebRequestInternalFunction : public SyncIOThreadExtensionFunction { | 483 class WebRequestInternalFunction : public SyncIOThreadExtensionFunction { |
| 485 public: | 484 public: |
| 486 WebRequestInternalFunction() {} | 485 WebRequestInternalFunction() {} |
| 487 | 486 |
| 488 protected: | 487 protected: |
| (...skipping 27 matching lines...) Expand all Loading... |
| 516 ~WebRequestInternalEventHandledFunction() override {} | 515 ~WebRequestInternalEventHandledFunction() override {} |
| 517 | 516 |
| 518 // Unblocks the network request and sets |error_| such that the developer | 517 // Unblocks the network request and sets |error_| such that the developer |
| 519 // console will show the respective error message. Use this function to handle | 518 // console will show the respective error message. Use this function to handle |
| 520 // incorrect requests from the extension that cannot be detected by the schema | 519 // incorrect requests from the extension that cannot be detected by the schema |
| 521 // validator. | 520 // validator. |
| 522 void RespondWithError( | 521 void RespondWithError( |
| 523 const std::string& event_name, | 522 const std::string& event_name, |
| 524 const std::string& sub_event_name, | 523 const std::string& sub_event_name, |
| 525 uint64_t request_id, | 524 uint64_t request_id, |
| 526 scoped_ptr<ExtensionWebRequestEventRouter::EventResponse> response, | 525 std::unique_ptr<ExtensionWebRequestEventRouter::EventResponse> response, |
| 527 const std::string& error); | 526 const std::string& error); |
| 528 | 527 |
| 529 // ExtensionFunction: | 528 // ExtensionFunction: |
| 530 bool RunSync() override; | 529 bool RunSync() override; |
| 531 }; | 530 }; |
| 532 | 531 |
| 533 class WebRequestHandlerBehaviorChangedFunction | 532 class WebRequestHandlerBehaviorChangedFunction |
| 534 : public WebRequestInternalFunction { | 533 : public WebRequestInternalFunction { |
| 535 public: | 534 public: |
| 536 DECLARE_EXTENSION_FUNCTION("webRequest.handlerBehaviorChanged", | 535 DECLARE_EXTENSION_FUNCTION("webRequest.handlerBehaviorChanged", |
| 537 WEBREQUEST_HANDLERBEHAVIORCHANGED) | 536 WEBREQUEST_HANDLERBEHAVIORCHANGED) |
| 538 | 537 |
| 539 protected: | 538 protected: |
| 540 ~WebRequestHandlerBehaviorChangedFunction() override {} | 539 ~WebRequestHandlerBehaviorChangedFunction() override {} |
| 541 | 540 |
| 542 // ExtensionFunction: | 541 // ExtensionFunction: |
| 543 void GetQuotaLimitHeuristics( | 542 void GetQuotaLimitHeuristics( |
| 544 extensions::QuotaLimitHeuristics* heuristics) const override; | 543 extensions::QuotaLimitHeuristics* heuristics) const override; |
| 545 // Handle quota exceeded gracefully: Only warn the user but still execute the | 544 // Handle quota exceeded gracefully: Only warn the user but still execute the |
| 546 // function. | 545 // function. |
| 547 void OnQuotaExceeded(const std::string& error) override; | 546 void OnQuotaExceeded(const std::string& error) override; |
| 548 bool RunSync() override; | 547 bool RunSync() override; |
| 549 }; | 548 }; |
| 550 | 549 |
| 551 } // namespace extensions | 550 } // namespace extensions |
| 552 | 551 |
| 553 #endif // EXTENSIONS_BROWSER_API_WEB_REQUEST_WEB_REQUEST_API_H_ | 552 #endif // EXTENSIONS_BROWSER_API_WEB_REQUEST_WEB_REQUEST_API_H_ |
| OLD | NEW |