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 void RegisterInterceptor(const std::string& http_header, |
| 111 const std::string& starts_with, |
| 112 const InterceptorCallback& interceptor) override; |
110 | 113 |
111 // Puts the resource dispatcher host in an inactive state (unable to begin | 114 // Puts the resource dispatcher host in an inactive state (unable to begin |
112 // new requests). Cancels all pending requests. | 115 // new requests). Cancels all pending requests. |
113 void Shutdown(); | 116 void Shutdown(); |
114 | 117 |
115 // Force cancels any pending requests for the given |context|. This is | 118 // Force cancels any pending requests for the given |context|. This is |
116 // necessary to ensure that before |context| goes away, all requests | 119 // necessary to ensure that before |context| goes away, all requests |
117 // for it are dead. | 120 // for it are dead. |
118 void CancelRequestsForContext(ResourceContext* context); | 121 void CancelRequestsForContext(ResourceContext* context); |
119 | 122 |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
318 struct LoadInfo { | 321 struct LoadInfo { |
319 GURL url; | 322 GURL url; |
320 net::LoadStateWithParam load_state; | 323 net::LoadStateWithParam load_state; |
321 uint64_t upload_position; | 324 uint64_t upload_position; |
322 uint64_t upload_size; | 325 uint64_t upload_size; |
323 }; | 326 }; |
324 | 327 |
325 // Map from ProcessID+RouteID pair to the "most interesting" LoadState. | 328 // Map from ProcessID+RouteID pair to the "most interesting" LoadState. |
326 typedef std::map<GlobalRoutingID, LoadInfo> LoadInfoMap; | 329 typedef std::map<GlobalRoutingID, LoadInfo> LoadInfoMap; |
327 | 330 |
| 331 // Information about a HTTP header interceptor. |
| 332 struct HeaderInterceptorInfo { |
| 333 // Structure is sufficiently complicated to require the constructor |
| 334 // destructor definitions in the cc file. |
| 335 HeaderInterceptorInfo(); |
| 336 ~HeaderInterceptorInfo(); |
| 337 HeaderInterceptorInfo(const HeaderInterceptorInfo& other); |
| 338 |
| 339 // Used to prefix match the value of the http header. |
| 340 std::string starts_with; |
| 341 // The interceptor. |
| 342 InterceptorCallback interceptor; |
| 343 }; |
| 344 |
| 345 // Map from HTTP header to its information HeaderInterceptorInfo. |
| 346 typedef std::map<std::string, HeaderInterceptorInfo> HeaderInterceptorMap; |
| 347 |
328 // ResourceLoaderDelegate implementation: | 348 // ResourceLoaderDelegate implementation: |
329 ResourceDispatcherHostLoginDelegate* CreateLoginDelegate( | 349 ResourceDispatcherHostLoginDelegate* CreateLoginDelegate( |
330 ResourceLoader* loader, | 350 ResourceLoader* loader, |
331 net::AuthChallengeInfo* auth_info) override; | 351 net::AuthChallengeInfo* auth_info) override; |
332 bool HandleExternalProtocol(ResourceLoader* loader, const GURL& url) override; | 352 bool HandleExternalProtocol(ResourceLoader* loader, const GURL& url) override; |
333 void DidStartRequest(ResourceLoader* loader) override; | 353 void DidStartRequest(ResourceLoader* loader) override; |
334 void DidReceiveRedirect(ResourceLoader* loader, const GURL& new_url) override; | 354 void DidReceiveRedirect(ResourceLoader* loader, const GURL& new_url) override; |
335 void DidReceiveResponse(ResourceLoader* loader) override; | 355 void DidReceiveResponse(ResourceLoader* loader) override; |
336 void DidFinishLoading(ResourceLoader* loader) override; | 356 void DidFinishLoading(ResourceLoader* loader) override; |
337 std::unique_ptr<net::ClientCertStore> CreateClientCertStore( | 357 std::unique_ptr<net::ClientCertStore> CreateClientCertStore( |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
447 int route_id, | 467 int route_id, |
448 int request_id, | 468 int request_id, |
449 const ResourceRequest& request_data, | 469 const ResourceRequest& request_data, |
450 LoaderMap::iterator iter); | 470 LoaderMap::iterator iter); |
451 | 471 |
452 void BeginRequest(int request_id, | 472 void BeginRequest(int request_id, |
453 const ResourceRequest& request_data, | 473 const ResourceRequest& request_data, |
454 IPC::Message* sync_result, // only valid for sync | 474 IPC::Message* sync_result, // only valid for sync |
455 int route_id); // only valid for async | 475 int route_id); // only valid for async |
456 | 476 |
| 477 // There are requests which need decisions to be made like the following: |
| 478 // Whether the presence of certain HTTP headers like the Origin header are |
| 479 // valid, etc. These requests may need to be aborted based on these |
| 480 // decisions which could be time consuming. We allow for these decisions |
| 481 // to be made asynchronously. The request proceeds when we hear back from |
| 482 // the interceptors about whether to continue or not. |
| 483 // The |continue_request| parameter in the function indicates whether the |
| 484 // request should be continued or aborted. The |error_code| parameter is set |
| 485 // if |continue_request| is false. |
| 486 void ContinuePendingBeginRequest( |
| 487 int request_id, |
| 488 const ResourceRequest& request_data, |
| 489 IPC::Message* sync_result, // only valid for sync |
| 490 int route_id, |
| 491 const net::HttpRequestHeaders& headers, |
| 492 bool continue_request, |
| 493 int error_code); |
| 494 |
457 // Creates a ResourceHandler to be used by BeginRequest() for normal resource | 495 // Creates a ResourceHandler to be used by BeginRequest() for normal resource |
458 // loading. | 496 // loading. |
459 std::unique_ptr<ResourceHandler> CreateResourceHandler( | 497 std::unique_ptr<ResourceHandler> CreateResourceHandler( |
460 net::URLRequest* request, | 498 net::URLRequest* request, |
461 const ResourceRequest& request_data, | 499 const ResourceRequest& request_data, |
462 IPC::Message* sync_result, | 500 IPC::Message* sync_result, |
463 int route_id, | 501 int route_id, |
464 int process_type, | 502 int process_type, |
465 int child_id, | 503 int child_id, |
466 ResourceContext* resource_context); | 504 ResourceContext* resource_context); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
530 // The certificate on a ResourceResponse is associated with a | 568 // The certificate on a ResourceResponse is associated with a |
531 // particular renderer process. As a transfer to a new process | 569 // particular renderer process. As a transfer to a new process |
532 // completes, the stored certificate has to be updated to reflect the | 570 // completes, the stored certificate has to be updated to reflect the |
533 // new renderer process. | 571 // new renderer process. |
534 void UpdateResponseCertificateForTransfer(ResourceResponse* response, | 572 void UpdateResponseCertificateForTransfer(ResourceResponse* response, |
535 const net::SSLInfo& ssl_info, | 573 const net::SSLInfo& ssl_info, |
536 int child_id); | 574 int child_id); |
537 | 575 |
538 CertStore* GetCertStore(); | 576 CertStore* GetCertStore(); |
539 | 577 |
| 578 // This enum holds values which indicate how we want to proceed with a |
| 579 // request that is about to be started. |
| 580 enum BeginRequestStatus { |
| 581 CONTINUE = 0, // Continue with the request. |
| 582 ABORT = 1, // Abort. |
| 583 PENDING = 2, // Wait for the decision to come back. |
| 584 LAST_SERVICE_REQUEST_STATUS = PENDING, |
| 585 }; |
| 586 |
| 587 // Consults the RendererSecurity policy to determine whether the |
| 588 // ResourceDispatcherHostImpl should service this request. A request might |
| 589 // be disallowed if the renderer is not authorized to retrieve the request |
| 590 // URL or if the renderer is attempting to upload an unauthorized file. |
| 591 BeginRequestStatus ShouldServiceRequest( |
| 592 int process_type, |
| 593 int child_id, |
| 594 const ResourceRequest& request_data, |
| 595 const net::HttpRequestHeaders& headers, |
| 596 ResourceMessageFilter* filter, |
| 597 ResourceContext* resource_context, |
| 598 OnHeaderProcessedCallback callback); |
| 599 |
540 LoaderMap pending_loaders_; | 600 LoaderMap pending_loaders_; |
541 | 601 |
542 // Collection of temp files downloaded for child processes via | 602 // Collection of temp files downloaded for child processes via |
543 // the download_to_file mechanism. We avoid deleting them until | 603 // the download_to_file mechanism. We avoid deleting them until |
544 // the client no longer needs them. | 604 // the client no longer needs them. |
545 typedef std::map<int, scoped_refptr<storage::ShareableFileReference> > | 605 typedef std::map<int, scoped_refptr<storage::ShareableFileReference> > |
546 DeletableFilesMap; // key is request id | 606 DeletableFilesMap; // key is request id |
547 typedef std::map<int, DeletableFilesMap> | 607 typedef std::map<int, DeletableFilesMap> |
548 RegisteredTempFiles; // key is child process id | 608 RegisteredTempFiles; // key is child process id |
549 RegisteredTempFiles registered_temp_files_; | 609 RegisteredTempFiles registered_temp_files_; |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
624 typedef std::map<GlobalRequestID, | 684 typedef std::map<GlobalRequestID, |
625 base::ObserverList<ResourceMessageDelegate>*> DelegateMap; | 685 base::ObserverList<ResourceMessageDelegate>*> DelegateMap; |
626 DelegateMap delegate_map_; | 686 DelegateMap delegate_map_; |
627 | 687 |
628 std::unique_ptr<ResourceScheduler> scheduler_; | 688 std::unique_ptr<ResourceScheduler> scheduler_; |
629 | 689 |
630 // Allows tests to use a mock CertStore. If set, the CertStore must | 690 // Allows tests to use a mock CertStore. If set, the CertStore must |
631 // outlive this ResourceDispatcherHostImpl. | 691 // outlive this ResourceDispatcherHostImpl. |
632 CertStore* cert_store_for_testing_; | 692 CertStore* cert_store_for_testing_; |
633 | 693 |
| 694 // Used to invoke an interceptor for the HTTP header. |
| 695 HeaderInterceptorMap http_header_interceptor_map_; |
| 696 |
634 DISALLOW_COPY_AND_ASSIGN(ResourceDispatcherHostImpl); | 697 DISALLOW_COPY_AND_ASSIGN(ResourceDispatcherHostImpl); |
635 }; | 698 }; |
636 | 699 |
637 } // namespace content | 700 } // namespace content |
638 | 701 |
639 #endif // CONTENT_BROWSER_LOADER_RESOURCE_DISPATCHER_HOST_IMPL_H_ | 702 #endif // CONTENT_BROWSER_LOADER_RESOURCE_DISPATCHER_HOST_IMPL_H_ |
OLD | NEW |