OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 // See http://dev.chromium.org/developers/design-documents/multi-process-resourc
e-loading | 5 // See http://dev.chromium.org/developers/design-documents/multi-process-resourc
e-loading |
6 | 6 |
7 #include "content/browser/renderer_host/resource_dispatcher_host.h" | 7 #include "content/browser/renderer_host/resource_dispatcher_host.h" |
8 | 8 |
9 #include <set> | 9 #include <set> |
10 #include <vector> | 10 #include <vector> |
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
353 | 353 |
354 void ResourceDispatcherHost::BeginRequest( | 354 void ResourceDispatcherHost::BeginRequest( |
355 int request_id, | 355 int request_id, |
356 const ResourceHostMsg_Request& request_data, | 356 const ResourceHostMsg_Request& request_data, |
357 IPC::Message* sync_result, // only valid for sync | 357 IPC::Message* sync_result, // only valid for sync |
358 int route_id) { | 358 int route_id) { |
359 ChildProcessInfo::ProcessType process_type = filter_->process_type(); | 359 ChildProcessInfo::ProcessType process_type = filter_->process_type(); |
360 int child_id = filter_->child_id(); | 360 int child_id = filter_->child_id(); |
361 | 361 |
362 ChromeURLRequestContext* context = filter_->GetURLRequestContext( | 362 ChromeURLRequestContext* context = filter_->GetURLRequestContext( |
363 request_data); | 363 request_data.resource_type); |
364 | 364 |
365 // Might need to resolve the blob references in the upload data. | 365 // Might need to resolve the blob references in the upload data. |
366 if (request_data.upload_data && context) { | 366 if (request_data.upload_data && context) { |
367 context->blob_storage_context()->controller()-> | 367 context->blob_storage_context()->controller()-> |
368 ResolveBlobReferencesInUploadData(request_data.upload_data.get()); | 368 ResolveBlobReferencesInUploadData(request_data.upload_data.get()); |
369 } | 369 } |
370 | 370 |
371 if (is_shutdown_ || | 371 if (is_shutdown_ || |
372 !ShouldServiceRequest(process_type, child_id, request_data)) { | 372 !ShouldServiceRequest(process_type, child_id, request_data)) { |
373 net::URLRequestStatus status(net::URLRequestStatus::FAILED, | 373 net::URLRequestStatus status(net::URLRequestStatus::FAILED, |
374 net::ERR_ABORTED); | 374 net::ERR_ABORTED); |
375 if (sync_result) { | 375 if (sync_result) { |
376 SyncLoadResult result; | 376 SyncLoadResult result; |
377 result.status = status; | 377 result.status = status; |
378 ResourceHostMsg_SyncLoad::WriteReplyParams(sync_result, result); | 378 ResourceHostMsg_SyncLoad::WriteReplyParams(sync_result, result); |
379 filter_->Send(sync_result); | 379 filter_->Send(sync_result); |
380 } else { | 380 } else { |
381 // Tell the renderer that this request was disallowed. | 381 // Tell the renderer that this request was disallowed. |
382 filter_->Send(new ResourceMsg_RequestComplete( | 382 filter_->Send(new ResourceMsg_RequestComplete( |
383 route_id, | 383 route_id, |
384 request_id, | 384 request_id, |
385 status, | 385 status, |
386 std::string(), // No security info needed, connection was not | 386 std::string(), // No security info needed, connection was not |
387 base::Time())); // established. | 387 base::Time())); // established. |
388 } | 388 } |
389 return; | 389 return; |
390 } | 390 } |
391 | 391 |
392 // Ensure the Chrome plugins are loaded, as they may intercept network | |
393 // requests. Does nothing if they are already loaded. | |
394 // TODO(mpcomplete): This takes 200 ms! Investigate parallelizing this by | |
395 // starting the load earlier in a BG thread. | |
396 PluginService::GetInstance()->LoadChromePlugins(this); | |
397 | |
398 // Construct the event handler. | 392 // Construct the event handler. |
399 scoped_refptr<ResourceHandler> handler; | 393 scoped_refptr<ResourceHandler> handler; |
400 if (sync_result) { | 394 if (sync_result) { |
401 handler = new SyncResourceHandler( | 395 handler = new SyncResourceHandler( |
402 filter_, request_data.url, sync_result, this); | 396 filter_, request_data.url, sync_result, this); |
403 } else { | 397 } else { |
404 handler = new AsyncResourceHandler( | 398 handler = new AsyncResourceHandler( |
405 filter_, route_id, request_data.url, this); | 399 filter_, route_id, request_data.url, this); |
406 } | 400 } |
407 | 401 |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
511 new ResourceDispatcherHostRequestInfo( | 505 new ResourceDispatcherHostRequestInfo( |
512 handler, | 506 handler, |
513 process_type, | 507 process_type, |
514 child_id, | 508 child_id, |
515 route_id, | 509 route_id, |
516 request_id, | 510 request_id, |
517 request_data.resource_type, | 511 request_data.resource_type, |
518 upload_size, | 512 upload_size, |
519 false, // is download | 513 false, // is download |
520 ResourceType::IsFrame(request_data.resource_type), // allow_download | 514 ResourceType::IsFrame(request_data.resource_type), // allow_download |
521 request_data.has_user_gesture, | 515 request_data.has_user_gesture); |
522 request_data.host_renderer_id, | |
523 request_data.host_render_view_id); | |
524 SetRequestInfo(request, extra_info); // Request takes ownership. | 516 SetRequestInfo(request, extra_info); // Request takes ownership. |
525 chrome_browser_net::SetOriginPIDForRequest( | 517 chrome_browser_net::SetOriginPIDForRequest( |
526 request_data.origin_pid, request); | 518 request_data.origin_pid, request); |
527 | 519 |
528 if (request->url().SchemeIs(chrome::kBlobScheme) && context) { | 520 if (request->url().SchemeIs(chrome::kBlobScheme) && context) { |
529 // Hang on to a reference to ensure the blob is not released prior | 521 // Hang on to a reference to ensure the blob is not released prior |
530 // to the job being started. | 522 // to the job being started. |
531 webkit_blob::BlobStorageController* controller = | 523 webkit_blob::BlobStorageController* controller = |
532 context->blob_storage_context()->controller(); | 524 context->blob_storage_context()->controller(); |
533 extra_info->set_requested_blob_data( | 525 extra_info->set_requested_blob_data( |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
640 ResourceHandler* handler, int child_id, int route_id, bool download) { | 632 ResourceHandler* handler, int child_id, int route_id, bool download) { |
641 return new ResourceDispatcherHostRequestInfo(handler, | 633 return new ResourceDispatcherHostRequestInfo(handler, |
642 ChildProcessInfo::RENDER_PROCESS, | 634 ChildProcessInfo::RENDER_PROCESS, |
643 child_id, | 635 child_id, |
644 route_id, | 636 route_id, |
645 request_id_, | 637 request_id_, |
646 ResourceType::SUB_RESOURCE, | 638 ResourceType::SUB_RESOURCE, |
647 0, // upload_size | 639 0, // upload_size |
648 download, // is_download | 640 download, // is_download |
649 download, // allow_download | 641 download, // allow_download |
650 false, // has_user_gesture | 642 false); // has_user_gesture |
651 -1, // host renderer id | |
652 -1); // host render view id | |
653 } | 643 } |
654 | 644 |
655 void ResourceDispatcherHost::OnClosePageACK( | 645 void ResourceDispatcherHost::OnClosePageACK( |
656 const ViewMsg_ClosePage_Params& params) { | 646 const ViewMsg_ClosePage_Params& params) { |
657 if (params.for_cross_site_transition) { | 647 if (params.for_cross_site_transition) { |
658 // Closes for cross-site transitions are handled such that the cross-site | 648 // Closes for cross-site transitions are handled such that the cross-site |
659 // transition continues. | 649 // transition continues. |
660 GlobalRequestID global_id(params.new_render_process_host_id, | 650 GlobalRequestID global_id(params.new_render_process_host_id, |
661 params.new_request_id); | 651 params.new_request_id); |
662 PendingRequestList::iterator i = pending_requests_.find(global_id); | 652 PendingRequestList::iterator i = pending_requests_.find(global_id); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
694 VLOG(1) << "Denied unauthorized download request for " | 684 VLOG(1) << "Denied unauthorized download request for " |
695 << url.possibly_invalid_spec(); | 685 << url.possibly_invalid_spec(); |
696 return; | 686 return; |
697 } | 687 } |
698 | 688 |
699 BrowserThread::PostTask( | 689 BrowserThread::PostTask( |
700 BrowserThread::UI, FROM_HERE, | 690 BrowserThread::UI, FROM_HERE, |
701 NewRunnableFunction(&download_util::NotifyDownloadInitiated, | 691 NewRunnableFunction(&download_util::NotifyDownloadInitiated, |
702 child_id, route_id)); | 692 child_id, route_id)); |
703 | 693 |
704 // Ensure the Chrome plugins are loaded, as they may intercept network | |
705 // requests. Does nothing if they are already loaded. | |
706 PluginService::GetInstance()->LoadChromePlugins(this); | |
707 net::URLRequest* request = new net::URLRequest(url, this); | 694 net::URLRequest* request = new net::URLRequest(url, this); |
708 | 695 |
709 request_id_--; | 696 request_id_--; |
710 | 697 |
711 scoped_refptr<ResourceHandler> handler( | 698 scoped_refptr<ResourceHandler> handler( |
712 new DownloadResourceHandler(this, | 699 new DownloadResourceHandler(this, |
713 child_id, | 700 child_id, |
714 route_id, | 701 route_id, |
715 request_id_, | 702 request_id_, |
716 url, | 703 url, |
(...skipping 30 matching lines...) Expand all Loading... |
747 // This function is only used for saving feature. | 734 // This function is only used for saving feature. |
748 void ResourceDispatcherHost::BeginSaveFile( | 735 void ResourceDispatcherHost::BeginSaveFile( |
749 const GURL& url, | 736 const GURL& url, |
750 const GURL& referrer, | 737 const GURL& referrer, |
751 int child_id, | 738 int child_id, |
752 int route_id, | 739 int route_id, |
753 net::URLRequestContext* request_context) { | 740 net::URLRequestContext* request_context) { |
754 if (is_shutdown_) | 741 if (is_shutdown_) |
755 return; | 742 return; |
756 | 743 |
757 // Ensure the Chrome plugins are loaded, as they may intercept network | |
758 // requests. Does nothing if they are already loaded. | |
759 PluginService::GetInstance()->LoadChromePlugins(this); | |
760 | |
761 scoped_refptr<ResourceHandler> handler( | 744 scoped_refptr<ResourceHandler> handler( |
762 new SaveFileResourceHandler(child_id, | 745 new SaveFileResourceHandler(child_id, |
763 route_id, | 746 route_id, |
764 url, | 747 url, |
765 save_file_manager_.get())); | 748 save_file_manager_.get())); |
766 request_id_--; | 749 request_id_--; |
767 | 750 |
768 bool known_proto = net::URLRequest::IsHandledURL(url); | 751 bool known_proto = net::URLRequest::IsHandledURL(url); |
769 if (!known_proto) { | 752 if (!known_proto) { |
770 // Since any URLs which have non-standard scheme have been filtered | 753 // Since any URLs which have non-standard scheme have been filtered |
(...skipping 1187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1958 return is_prefetch_enabled_; | 1941 return is_prefetch_enabled_; |
1959 } | 1942 } |
1960 | 1943 |
1961 // static | 1944 // static |
1962 void ResourceDispatcherHost::set_is_prefetch_enabled(bool value) { | 1945 void ResourceDispatcherHost::set_is_prefetch_enabled(bool value) { |
1963 is_prefetch_enabled_ = value; | 1946 is_prefetch_enabled_ = value; |
1964 } | 1947 } |
1965 | 1948 |
1966 // static | 1949 // static |
1967 bool ResourceDispatcherHost::is_prefetch_enabled_ = false; | 1950 bool ResourceDispatcherHost::is_prefetch_enabled_ = false; |
OLD | NEW |