Chromium Code Reviews| 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 // This is the browser side of the resource dispatcher, it receives requests | 5 // This is the browser side of the resource dispatcher, it receives requests |
| 6 // from the child process (i.e. [Renderer, Plugin, Worker]ProcessHost), and | 6 // from the child process (i.e. [Renderer, Plugin, Worker]ProcessHost), and |
| 7 // dispatches them to URLRequests. It then forwards the messages from the | 7 // dispatches them to URLRequests. It then forwards the messages from the |
| 8 // URLRequests back to the correct process for handling. | 8 // URLRequests back to the correct process for handling. |
| 9 // | 9 // |
| 10 // See http://dev.chromium.org/developers/design-documents/multi-process-resourc e-loading | 10 // See http://dev.chromium.org/developers/design-documents/multi-process-resourc e-loading |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 100 RenderFrameHost* root_frame_host); | 100 RenderFrameHost* root_frame_host); |
| 101 | 101 |
| 102 // Cancels any blocked request for the frame and its subframes. | 102 // Cancels any blocked request for the frame and its subframes. |
| 103 static void CancelBlockedRequestsForFrameFromUI( | 103 static void CancelBlockedRequestsForFrameFromUI( |
| 104 RenderFrameHostImpl* root_frame_host); | 104 RenderFrameHostImpl* root_frame_host); |
| 105 | 105 |
| 106 // ResourceDispatcherHost implementation: | 106 // ResourceDispatcherHost implementation: |
| 107 void SetDelegate(ResourceDispatcherHostDelegate* delegate) override; | 107 void SetDelegate(ResourceDispatcherHostDelegate* delegate) override; |
| 108 void SetAllowCrossOriginAuthPrompt(bool value) override; | 108 void SetAllowCrossOriginAuthPrompt(bool value) override; |
| 109 void ClearLoginDelegateForRequest(net::URLRequest* request) override; | 109 void ClearLoginDelegateForRequest(net::URLRequest* request) override; |
| 110 | 110 void AddSchemeForAccessCheck(const std::string& scheme) override; |
| 111 void AddProcessForOrigin(const ResourceContext* context, | |
| 112 const std::string& origin, | |
| 113 int process_id) override; | |
| 114 void RemoveProcessForOrigin(const ResourceContext* context, | |
| 115 const std::string& origin, | |
| 116 int process_id) override; | |
| 111 // Puts the resource dispatcher host in an inactive state (unable to begin | 117 // Puts the resource dispatcher host in an inactive state (unable to begin |
| 112 // new requests). Cancels all pending requests. | 118 // new requests). Cancels all pending requests. |
| 113 void Shutdown(); | 119 void Shutdown(); |
| 114 | 120 |
| 115 // Force cancels any pending requests for the given |context|. This is | 121 // Force cancels any pending requests for the given |context|. This is |
| 116 // necessary to ensure that before |context| goes away, all requests | 122 // necessary to ensure that before |context| goes away, all requests |
| 117 // for it are dead. | 123 // for it are dead. |
| 118 void CancelRequestsForContext(ResourceContext* context); | 124 void CancelRequestsForContext(ResourceContext* context); |
| 119 | 125 |
| 120 // Returns true if the message was a resource message that was processed. | 126 // Returns true if the message was a resource message that was processed. |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 285 // Turns on stale-while-revalidate support, regardless of command-line flags | 291 // Turns on stale-while-revalidate support, regardless of command-line flags |
| 286 // or experiment status. For unit tests only. | 292 // or experiment status. For unit tests only. |
| 287 void EnableStaleWhileRevalidateForTesting(); | 293 void EnableStaleWhileRevalidateForTesting(); |
| 288 | 294 |
| 289 // Sets the LoaderDelegate, which must outlive this object. Ownership is not | 295 // Sets the LoaderDelegate, which must outlive this object. Ownership is not |
| 290 // transferred. The LoaderDelegate should be interacted with on the IO thread. | 296 // transferred. The LoaderDelegate should be interacted with on the IO thread. |
| 291 void SetLoaderDelegate(LoaderDelegate* loader_delegate); | 297 void SetLoaderDelegate(LoaderDelegate* loader_delegate); |
| 292 | 298 |
| 293 void OnRenderFrameDeleted(const GlobalFrameRoutingId& global_routing_id); | 299 void OnRenderFrameDeleted(const GlobalFrameRoutingId& global_routing_id); |
| 294 | 300 |
| 301 // Checks whether the child process identified by |child_process_id| is | |
| 302 // allowed to access the |origin| and returns true if not. | |
| 303 bool IsIllegalOrigin(ResourceContext* context, | |
| 304 const GURL& origin, | |
| 305 int child_process_id); | |
| 306 | |
| 295 private: | 307 private: |
| 296 friend class ResourceDispatcherHostTest; | 308 friend class ResourceDispatcherHostTest; |
| 297 | 309 |
| 298 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest, | 310 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest, |
| 299 TestBlockedRequestsProcessDies); | 311 TestBlockedRequestsProcessDies); |
| 300 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest, | 312 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest, |
| 301 CalculateApproximateMemoryCost); | 313 CalculateApproximateMemoryCost); |
| 302 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest, | 314 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest, |
| 303 DetachableResourceTimesOut); | 315 DetachableResourceTimesOut); |
| 304 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest, | 316 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest, |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 318 struct LoadInfo { | 330 struct LoadInfo { |
| 319 GURL url; | 331 GURL url; |
| 320 net::LoadStateWithParam load_state; | 332 net::LoadStateWithParam load_state; |
| 321 uint64_t upload_position; | 333 uint64_t upload_position; |
| 322 uint64_t upload_size; | 334 uint64_t upload_size; |
| 323 }; | 335 }; |
| 324 | 336 |
| 325 // Map from ProcessID+RouteID pair to the "most interesting" LoadState. | 337 // Map from ProcessID+RouteID pair to the "most interesting" LoadState. |
| 326 typedef std::map<GlobalRoutingID, LoadInfo> LoadInfoMap; | 338 typedef std::map<GlobalRoutingID, LoadInfo> LoadInfoMap; |
| 327 | 339 |
| 340 // Information about a web origin. | |
| 341 struct OriginAccessInfo { | |
| 342 // This structure is complicated enough for clang to require the ctors to | |
| 343 // be explicitly defined in the cc file. | |
|
jam
2016/08/02 17:01:46
now that this is just one set, any reason to keep
ananta
2016/08/02 22:28:28
Done.
| |
| 344 OriginAccessInfo(); | |
| 345 ~OriginAccessInfo(); | |
| 346 OriginAccessInfo(const OriginAccessInfo& other); | |
| 347 | |
| 348 std::set<int> allowed_processes; | |
| 349 }; | |
| 350 | |
| 351 // Map from the origin host (std::string) to its information | |
| 352 // (OriginAccessInfo). | |
| 353 // This map is per ResourceContext. | |
| 354 typedef std::map<std::string, OriginAccessInfo> OriginAccessInfoMap; | |
| 355 | |
| 356 typedef std::map<const ResourceContext*, | |
| 357 std::unique_ptr<OriginAccessInfoMap>> | |
| 358 ResourceContextOriginMap; | |
| 359 | |
| 328 // ResourceLoaderDelegate implementation: | 360 // ResourceLoaderDelegate implementation: |
| 329 ResourceDispatcherHostLoginDelegate* CreateLoginDelegate( | 361 ResourceDispatcherHostLoginDelegate* CreateLoginDelegate( |
| 330 ResourceLoader* loader, | 362 ResourceLoader* loader, |
| 331 net::AuthChallengeInfo* auth_info) override; | 363 net::AuthChallengeInfo* auth_info) override; |
| 332 bool HandleExternalProtocol(ResourceLoader* loader, const GURL& url) override; | 364 bool HandleExternalProtocol(ResourceLoader* loader, const GURL& url) override; |
| 333 void DidStartRequest(ResourceLoader* loader) override; | 365 void DidStartRequest(ResourceLoader* loader) override; |
| 334 void DidReceiveRedirect(ResourceLoader* loader, const GURL& new_url) override; | 366 void DidReceiveRedirect(ResourceLoader* loader, const GURL& new_url) override; |
| 335 void DidReceiveResponse(ResourceLoader* loader) override; | 367 void DidReceiveResponse(ResourceLoader* loader) override; |
| 336 void DidFinishLoading(ResourceLoader* loader) override; | 368 void DidFinishLoading(ResourceLoader* loader) override; |
| 337 std::unique_ptr<net::ClientCertStore> CreateClientCertStore( | 369 std::unique_ptr<net::ClientCertStore> CreateClientCertStore( |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 530 // The certificate on a ResourceResponse is associated with a | 562 // The certificate on a ResourceResponse is associated with a |
| 531 // particular renderer process. As a transfer to a new process | 563 // particular renderer process. As a transfer to a new process |
| 532 // completes, the stored certificate has to be updated to reflect the | 564 // completes, the stored certificate has to be updated to reflect the |
| 533 // new renderer process. | 565 // new renderer process. |
| 534 void UpdateResponseCertificateForTransfer(ResourceResponse* response, | 566 void UpdateResponseCertificateForTransfer(ResourceResponse* response, |
| 535 const net::SSLInfo& ssl_info, | 567 const net::SSLInfo& ssl_info, |
| 536 int child_id); | 568 int child_id); |
| 537 | 569 |
| 538 CertStore* GetCertStore(); | 570 CertStore* GetCertStore(); |
| 539 | 571 |
| 572 // Returns the OriginAccessInfoMap instance for the |context| passed in. This | |
| 573 // map is used to enforce access checks on web requests for some origins. | |
| 574 OriginAccessInfoMap* GetOriginAccessMapForResourceContext( | |
| 575 const ResourceContext* context); | |
| 576 | |
| 540 LoaderMap pending_loaders_; | 577 LoaderMap pending_loaders_; |
| 541 | 578 |
| 542 // Collection of temp files downloaded for child processes via | 579 // Collection of temp files downloaded for child processes via |
| 543 // the download_to_file mechanism. We avoid deleting them until | 580 // the download_to_file mechanism. We avoid deleting them until |
| 544 // the client no longer needs them. | 581 // the client no longer needs them. |
| 545 typedef std::map<int, scoped_refptr<storage::ShareableFileReference> > | 582 typedef std::map<int, scoped_refptr<storage::ShareableFileReference> > |
| 546 DeletableFilesMap; // key is request id | 583 DeletableFilesMap; // key is request id |
| 547 typedef std::map<int, DeletableFilesMap> | 584 typedef std::map<int, DeletableFilesMap> |
| 548 RegisteredTempFiles; // key is child process id | 585 RegisteredTempFiles; // key is child process id |
| 549 RegisteredTempFiles registered_temp_files_; | 586 RegisteredTempFiles registered_temp_files_; |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 624 typedef std::map<GlobalRequestID, | 661 typedef std::map<GlobalRequestID, |
| 625 base::ObserverList<ResourceMessageDelegate>*> DelegateMap; | 662 base::ObserverList<ResourceMessageDelegate>*> DelegateMap; |
| 626 DelegateMap delegate_map_; | 663 DelegateMap delegate_map_; |
| 627 | 664 |
| 628 std::unique_ptr<ResourceScheduler> scheduler_; | 665 std::unique_ptr<ResourceScheduler> scheduler_; |
| 629 | 666 |
| 630 // Allows tests to use a mock CertStore. If set, the CertStore must | 667 // Allows tests to use a mock CertStore. If set, the CertStore must |
| 631 // outlive this ResourceDispatcherHostImpl. | 668 // outlive this ResourceDispatcherHostImpl. |
| 632 CertStore* cert_store_for_testing_; | 669 CertStore* cert_store_for_testing_; |
| 633 | 670 |
| 671 // Used to check whether a request to retrieve an origin resource is allowed. | |
| 672 // This is only done for origins which are to be checked for access. | |
| 673 ResourceContextOriginMap context_origin_access_info_map_; | |
| 674 | |
| 675 // This contains the set of origins we need to enforce access checks on. By | |
| 676 // default everything is allowed. | |
| 677 std::set<std::string> origins_for_access_check_; | |
| 678 | |
| 634 DISALLOW_COPY_AND_ASSIGN(ResourceDispatcherHostImpl); | 679 DISALLOW_COPY_AND_ASSIGN(ResourceDispatcherHostImpl); |
| 635 }; | 680 }; |
| 636 | 681 |
| 637 } // namespace content | 682 } // namespace content |
| 638 | 683 |
| 639 #endif // CONTENT_BROWSER_LOADER_RESOURCE_DISPATCHER_HOST_IMPL_H_ | 684 #endif // CONTENT_BROWSER_LOADER_RESOURCE_DISPATCHER_HOST_IMPL_H_ |
| OLD | NEW |