| 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 22 matching lines...) Expand all Loading... |
| 33 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 33 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
| 34 #include "chrome/browser/ssl/ssl_client_auth_handler.h" | 34 #include "chrome/browser/ssl/ssl_client_auth_handler.h" |
| 35 #include "chrome/browser/ssl/ssl_manager.h" | 35 #include "chrome/browser/ssl/ssl_manager.h" |
| 36 #include "chrome/browser/ui/login/login_prompt.h" | 36 #include "chrome/browser/ui/login/login_prompt.h" |
| 37 #include "chrome/common/chrome_switches.h" | 37 #include "chrome/common/chrome_switches.h" |
| 38 #include "chrome/common/url_constants.h" | 38 #include "chrome/common/url_constants.h" |
| 39 #include "content/browser/appcache/chrome_appcache_service.h" | 39 #include "content/browser/appcache/chrome_appcache_service.h" |
| 40 #include "content/browser/cert_store.h" | 40 #include "content/browser/cert_store.h" |
| 41 #include "content/browser/child_process_security_policy.h" | 41 #include "content/browser/child_process_security_policy.h" |
| 42 #include "content/browser/chrome_blob_storage_context.h" | 42 #include "content/browser/chrome_blob_storage_context.h" |
| 43 #include "content/browser/content_browser_client.h" |
| 43 #include "content/browser/cross_site_request_manager.h" | 44 #include "content/browser/cross_site_request_manager.h" |
| 44 #include "content/browser/in_process_webkit/webkit_thread.h" | 45 #include "content/browser/in_process_webkit/webkit_thread.h" |
| 45 #include "content/browser/plugin_service.h" | 46 #include "content/browser/plugin_service.h" |
| 46 #include "content/browser/resource_context.h" | 47 #include "content/browser/resource_context.h" |
| 47 #include "content/browser/renderer_host/async_resource_handler.h" | 48 #include "content/browser/renderer_host/async_resource_handler.h" |
| 48 #include "content/browser/renderer_host/buffered_resource_handler.h" | 49 #include "content/browser/renderer_host/buffered_resource_handler.h" |
| 49 #include "content/browser/renderer_host/cross_site_resource_handler.h" | 50 #include "content/browser/renderer_host/cross_site_resource_handler.h" |
| 50 #include "content/browser/renderer_host/global_request_id.h" | 51 #include "content/browser/renderer_host/global_request_id.h" |
| 51 #include "content/browser/renderer_host/redirect_to_file_resource_handler.h" | 52 #include "content/browser/renderer_host/redirect_to_file_resource_handler.h" |
| 52 #include "content/browser/renderer_host/render_view_host.h" | 53 #include "content/browser/renderer_host/render_view_host.h" |
| (...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 560 new ResourceDispatcherHostRequestInfo( | 561 new ResourceDispatcherHostRequestInfo( |
| 561 handler, | 562 handler, |
| 562 process_type, | 563 process_type, |
| 563 child_id, | 564 child_id, |
| 564 route_id, | 565 route_id, |
| 565 request_id, | 566 request_id, |
| 566 request_data.resource_type, | 567 request_data.resource_type, |
| 567 upload_size, | 568 upload_size, |
| 568 false, // is download | 569 false, // is download |
| 569 ResourceType::IsFrame(request_data.resource_type), // allow_download | 570 ResourceType::IsFrame(request_data.resource_type), // allow_download |
| 570 request_data.has_user_gesture); | 571 request_data.has_user_gesture, |
| 572 &resource_context); |
| 571 SetRequestInfo(request, extra_info); // Request takes ownership. | 573 SetRequestInfo(request, extra_info); // Request takes ownership. |
| 572 chrome_browser_net::SetOriginPIDForRequest( | 574 chrome_browser_net::SetOriginPIDForRequest( |
| 573 request_data.origin_pid, request); | 575 request_data.origin_pid, request); |
| 574 | 576 |
| 575 if (request->url().SchemeIs(chrome::kBlobScheme)) { | 577 if (request->url().SchemeIs(chrome::kBlobScheme)) { |
| 576 // Hang on to a reference to ensure the blob is not released prior | 578 // Hang on to a reference to ensure the blob is not released prior |
| 577 // to the job being started. | 579 // to the job being started. |
| 578 webkit_blob::BlobStorageController* controller = | 580 webkit_blob::BlobStorageController* controller = |
| 579 resource_context.blob_storage_context()->controller(); | 581 resource_context.blob_storage_context()->controller(); |
| 580 extra_info->set_requested_blob_data( | 582 extra_info->set_requested_blob_data( |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 690 | 692 |
| 691 ResourceHandler* ResourceDispatcherHost::CreateSafeBrowsingResourceHandler( | 693 ResourceHandler* ResourceDispatcherHost::CreateSafeBrowsingResourceHandler( |
| 692 ResourceHandler* handler, int child_id, int route_id, | 694 ResourceHandler* handler, int child_id, int route_id, |
| 693 ResourceType::Type resource_type) { | 695 ResourceType::Type resource_type) { |
| 694 return SafeBrowsingResourceHandler::Create( | 696 return SafeBrowsingResourceHandler::Create( |
| 695 handler, child_id, route_id, resource_type, safe_browsing_, this); | 697 handler, child_id, route_id, resource_type, safe_browsing_, this); |
| 696 } | 698 } |
| 697 | 699 |
| 698 ResourceDispatcherHostRequestInfo* | 700 ResourceDispatcherHostRequestInfo* |
| 699 ResourceDispatcherHost::CreateRequestInfoForBrowserRequest( | 701 ResourceDispatcherHost::CreateRequestInfoForBrowserRequest( |
| 700 ResourceHandler* handler, int child_id, int route_id, bool download) { | 702 ResourceHandler* handler, |
| 703 int child_id, |
| 704 int route_id, |
| 705 bool download, |
| 706 const content::ResourceContext& context) { |
| 701 return new ResourceDispatcherHostRequestInfo(handler, | 707 return new ResourceDispatcherHostRequestInfo(handler, |
| 702 ChildProcessInfo::RENDER_PROCESS, | 708 ChildProcessInfo::RENDER_PROCESS, |
| 703 child_id, | 709 child_id, |
| 704 route_id, | 710 route_id, |
| 705 request_id_, | 711 request_id_, |
| 706 ResourceType::SUB_RESOURCE, | 712 ResourceType::SUB_RESOURCE, |
| 707 0, // upload_size | 713 0, // upload_size |
| 708 download, // is_download | 714 download, // is_download |
| 709 download, // allow_download | 715 download, // allow_download |
| 710 false); // has_user_gesture | 716 false, // has_user_gesture |
| 717 &context); |
| 711 } | 718 } |
| 712 | 719 |
| 713 void ResourceDispatcherHost::OnClosePageACK( | 720 void ResourceDispatcherHost::OnClosePageACK( |
| 714 const ViewMsg_ClosePage_Params& params) { | 721 const ViewMsg_ClosePage_Params& params) { |
| 715 if (params.for_cross_site_transition) { | 722 if (params.for_cross_site_transition) { |
| 716 // Closes for cross-site transitions are handled such that the cross-site | 723 // Closes for cross-site transitions are handled such that the cross-site |
| 717 // transition continues. | 724 // transition continues. |
| 718 GlobalRequestID global_id(params.new_render_process_host_id, | 725 GlobalRequestID global_id(params.new_render_process_host_id, |
| 719 params.new_request_id); | 726 params.new_request_id); |
| 720 PendingRequestList::iterator i = pending_requests_.find(global_id); | 727 PendingRequestList::iterator i = pending_requests_.find(global_id); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 737 } | 744 } |
| 738 | 745 |
| 739 // We are explicitly forcing the download of 'url'. | 746 // We are explicitly forcing the download of 'url'. |
| 740 void ResourceDispatcherHost::BeginDownload( | 747 void ResourceDispatcherHost::BeginDownload( |
| 741 const GURL& url, | 748 const GURL& url, |
| 742 const GURL& referrer, | 749 const GURL& referrer, |
| 743 const DownloadSaveInfo& save_info, | 750 const DownloadSaveInfo& save_info, |
| 744 bool prompt_for_save_location, | 751 bool prompt_for_save_location, |
| 745 int child_id, | 752 int child_id, |
| 746 int route_id, | 753 int route_id, |
| 747 net::URLRequestContext* request_context) { | 754 const content::ResourceContext& context) { |
| 748 if (is_shutdown_) | 755 if (is_shutdown_) |
| 749 return; | 756 return; |
| 750 | 757 |
| 751 // Check if the renderer is permitted to request the requested URL. | 758 // Check if the renderer is permitted to request the requested URL. |
| 752 if (!ChildProcessSecurityPolicy::GetInstance()-> | 759 if (!ChildProcessSecurityPolicy::GetInstance()-> |
| 753 CanRequestURL(child_id, url)) { | 760 CanRequestURL(child_id, url)) { |
| 754 VLOG(1) << "Denied unauthorized download request for " | 761 VLOG(1) << "Denied unauthorized download request for " |
| 755 << url.possibly_invalid_spec(); | 762 << url.possibly_invalid_spec(); |
| 756 return; | 763 return; |
| 757 } | 764 } |
| (...skipping 24 matching lines...) Expand all Loading... |
| 782 } | 789 } |
| 783 | 790 |
| 784 if (!net::URLRequest::IsHandledURL(url)) { | 791 if (!net::URLRequest::IsHandledURL(url)) { |
| 785 VLOG(1) << "Download request for unsupported protocol: " | 792 VLOG(1) << "Download request for unsupported protocol: " |
| 786 << url.possibly_invalid_spec(); | 793 << url.possibly_invalid_spec(); |
| 787 return; | 794 return; |
| 788 } | 795 } |
| 789 | 796 |
| 790 request->set_method("GET"); | 797 request->set_method("GET"); |
| 791 request->set_referrer(MaybeStripReferrer(referrer).spec()); | 798 request->set_referrer(MaybeStripReferrer(referrer).spec()); |
| 792 request->set_context(request_context); | 799 request->set_context(context.request_context()); |
| 793 request->set_load_flags(request->load_flags() | | 800 request->set_load_flags(request->load_flags() | |
| 794 net::LOAD_IS_DOWNLOAD); | 801 net::LOAD_IS_DOWNLOAD); |
| 795 | 802 |
| 796 ResourceDispatcherHostRequestInfo* extra_info = | 803 ResourceDispatcherHostRequestInfo* extra_info = |
| 797 CreateRequestInfoForBrowserRequest(handler, child_id, route_id, true); | 804 CreateRequestInfoForBrowserRequest( |
| 805 handler, child_id, route_id, true, context); |
| 798 SetRequestInfo(request, extra_info); // Request takes ownership. | 806 SetRequestInfo(request, extra_info); // Request takes ownership. |
| 799 | 807 |
| 800 BeginRequestInternal(request); | 808 BeginRequestInternal(request); |
| 801 } | 809 } |
| 802 | 810 |
| 803 // This function is only used for saving feature. | 811 // This function is only used for saving feature. |
| 804 void ResourceDispatcherHost::BeginSaveFile( | 812 void ResourceDispatcherHost::BeginSaveFile( |
| 805 const GURL& url, | 813 const GURL& url, |
| 806 const GURL& referrer, | 814 const GURL& referrer, |
| 807 int child_id, | 815 int child_id, |
| 808 int route_id, | 816 int route_id, |
| 809 net::URLRequestContext* request_context) { | 817 const content::ResourceContext& context) { |
| 810 if (is_shutdown_) | 818 if (is_shutdown_) |
| 811 return; | 819 return; |
| 812 | 820 |
| 813 scoped_refptr<ResourceHandler> handler( | 821 scoped_refptr<ResourceHandler> handler( |
| 814 new SaveFileResourceHandler(child_id, | 822 new SaveFileResourceHandler(child_id, |
| 815 route_id, | 823 route_id, |
| 816 url, | 824 url, |
| 817 save_file_manager_.get())); | 825 save_file_manager_.get())); |
| 818 request_id_--; | 826 request_id_--; |
| 819 | 827 |
| 820 bool known_proto = net::URLRequest::IsHandledURL(url); | 828 bool known_proto = net::URLRequest::IsHandledURL(url); |
| 821 if (!known_proto) { | 829 if (!known_proto) { |
| 822 // Since any URLs which have non-standard scheme have been filtered | 830 // Since any URLs which have non-standard scheme have been filtered |
| 823 // by save manager(see GURL::SchemeIsStandard). This situation | 831 // by save manager(see GURL::SchemeIsStandard). This situation |
| 824 // should not happen. | 832 // should not happen. |
| 825 NOTREACHED(); | 833 NOTREACHED(); |
| 826 return; | 834 return; |
| 827 } | 835 } |
| 828 | 836 |
| 829 net::URLRequest* request = new net::URLRequest(url, this); | 837 net::URLRequest* request = new net::URLRequest(url, this); |
| 830 request->set_method("GET"); | 838 request->set_method("GET"); |
| 831 request->set_referrer(MaybeStripReferrer(referrer).spec()); | 839 request->set_referrer(MaybeStripReferrer(referrer).spec()); |
| 832 // So far, for saving page, we need fetch content from cache, in the | 840 // So far, for saving page, we need fetch content from cache, in the |
| 833 // future, maybe we can use a configuration to configure this behavior. | 841 // future, maybe we can use a configuration to configure this behavior. |
| 834 request->set_load_flags(net::LOAD_PREFERRING_CACHE); | 842 request->set_load_flags(net::LOAD_PREFERRING_CACHE); |
| 835 request->set_context(request_context); | 843 request->set_context(context.request_context()); |
| 836 | 844 |
| 837 // Since we're just saving some resources we need, disallow downloading. | 845 // Since we're just saving some resources we need, disallow downloading. |
| 838 ResourceDispatcherHostRequestInfo* extra_info = | 846 ResourceDispatcherHostRequestInfo* extra_info = |
| 839 CreateRequestInfoForBrowserRequest(handler, child_id, route_id, false); | 847 CreateRequestInfoForBrowserRequest( |
| 848 handler, child_id, route_id, false, context); |
| 840 SetRequestInfo(request, extra_info); // Request takes ownership. | 849 SetRequestInfo(request, extra_info); // Request takes ownership. |
| 841 | 850 |
| 842 BeginRequestInternal(request); | 851 BeginRequestInternal(request); |
| 843 } | 852 } |
| 844 | 853 |
| 845 void ResourceDispatcherHost::FollowDeferredRedirect( | 854 void ResourceDispatcherHost::FollowDeferredRedirect( |
| 846 int child_id, | 855 int child_id, |
| 847 int request_id, | 856 int request_id, |
| 848 bool has_new_first_party_for_cookies, | 857 bool has_new_first_party_for_cookies, |
| 849 const GURL& new_first_party_for_cookies) { | 858 const GURL& new_first_party_for_cookies) { |
| (...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1121 } | 1130 } |
| 1122 | 1131 |
| 1123 void ResourceDispatcherHost::OnSSLCertificateError( | 1132 void ResourceDispatcherHost::OnSSLCertificateError( |
| 1124 net::URLRequest* request, | 1133 net::URLRequest* request, |
| 1125 int cert_error, | 1134 int cert_error, |
| 1126 net::X509Certificate* cert) { | 1135 net::X509Certificate* cert) { |
| 1127 DCHECK(request); | 1136 DCHECK(request); |
| 1128 SSLManager::OnSSLCertificateError(this, request, cert_error, cert); | 1137 SSLManager::OnSSLCertificateError(this, request, cert_error, cert); |
| 1129 } | 1138 } |
| 1130 | 1139 |
| 1131 void ResourceDispatcherHost::OnGetCookies( | 1140 bool ResourceDispatcherHost::CanGetCookies(net::URLRequest* request) { |
| 1132 net::URLRequest* request, | |
| 1133 bool blocked_by_policy) { | |
| 1134 VLOG(1) << "OnGetCookies: " << request->url().spec(); | 1141 VLOG(1) << "OnGetCookies: " << request->url().spec(); |
| 1135 | |
| 1136 int render_process_id, render_view_id; | 1142 int render_process_id, render_view_id; |
| 1137 if (!RenderViewForRequest(request, &render_process_id, &render_view_id)) | 1143 if (!RenderViewForRequest(request, &render_process_id, &render_view_id)) |
| 1138 return; | 1144 return false; |
| 1139 | 1145 |
| 1140 net::URLRequestContext* context = request->context(); | 1146 net::URLRequestContext* context = request->context(); |
| 1141 | |
| 1142 net::CookieMonster* cookie_monster = | 1147 net::CookieMonster* cookie_monster = |
| 1143 context->cookie_store()->GetCookieMonster(); | 1148 context->cookie_store()->GetCookieMonster(); |
| 1144 net::CookieList cookie_list = | 1149 net::CookieList cookie_list = |
| 1145 cookie_monster->GetAllCookiesForURL(request->url()); | 1150 cookie_monster->GetAllCookiesForURL(request->url()); |
| 1146 CallRenderViewHostContentSettingsDelegate( | 1151 ResourceDispatcherHostRequestInfo* info = InfoForRequest(request); |
| 1147 render_process_id, render_view_id, | 1152 |
| 1148 &RenderViewHostDelegate::ContentSettings::OnCookiesRead, | 1153 return content::GetContentClient()->browser()->AllowGetCookie( |
| 1149 request->url(), cookie_list, blocked_by_policy); | 1154 request->url(), request->first_party_for_cookies(), cookie_list, |
| 1155 *info->context(), render_process_id, render_view_id); |
| 1150 } | 1156 } |
| 1151 | 1157 |
| 1152 void ResourceDispatcherHost::OnSetCookie(net::URLRequest* request, | 1158 bool ResourceDispatcherHost::CanSetCookie(net::URLRequest* request, |
| 1153 const std::string& cookie_line, | 1159 const std::string& cookie_line, |
| 1154 const net::CookieOptions& options, | 1160 net::CookieOptions* options) { |
| 1155 bool blocked_by_policy) { | |
| 1156 VLOG(1) << "OnSetCookie: " << request->url().spec(); | 1161 VLOG(1) << "OnSetCookie: " << request->url().spec(); |
| 1157 | 1162 |
| 1158 int render_process_id, render_view_id; | 1163 int render_process_id, render_view_id; |
| 1159 if (!RenderViewForRequest(request, &render_process_id, &render_view_id)) | 1164 if (!RenderViewForRequest(request, &render_process_id, &render_view_id)) |
| 1160 return; | 1165 return false; |
| 1161 | 1166 |
| 1162 CallRenderViewHostContentSettingsDelegate( | 1167 ResourceDispatcherHostRequestInfo* info = InfoForRequest(request); |
| 1163 render_process_id, render_view_id, | 1168 return content::GetContentClient()->browser()->AllowSetCookie( |
| 1164 &RenderViewHostDelegate::ContentSettings::OnCookieChanged, | 1169 request->url(), request->first_party_for_cookies(), cookie_line, |
| 1165 request->url(), cookie_line, options, blocked_by_policy); | 1170 *info->context(), render_process_id, render_view_id, options); |
| 1166 } | 1171 } |
| 1167 | 1172 |
| 1168 void ResourceDispatcherHost::OnResponseStarted(net::URLRequest* request) { | 1173 void ResourceDispatcherHost::OnResponseStarted(net::URLRequest* request) { |
| 1169 VLOG(1) << "OnResponseStarted: " << request->url().spec(); | 1174 VLOG(1) << "OnResponseStarted: " << request->url().spec(); |
| 1170 ResourceDispatcherHostRequestInfo* info = InfoForRequest(request); | 1175 ResourceDispatcherHostRequestInfo* info = InfoForRequest(request); |
| 1171 if (PauseRequestIfNeeded(info)) { | 1176 if (PauseRequestIfNeeded(info)) { |
| 1172 VLOG(1) << "OnResponseStarted pausing: " << request->url().spec(); | 1177 VLOG(1) << "OnResponseStarted pausing: " << request->url().spec(); |
| 1173 return; | 1178 return; |
| 1174 } | 1179 } |
| 1175 | 1180 |
| (...skipping 826 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2002 return is_prefetch_enabled_; | 2007 return is_prefetch_enabled_; |
| 2003 } | 2008 } |
| 2004 | 2009 |
| 2005 // static | 2010 // static |
| 2006 void ResourceDispatcherHost::set_is_prefetch_enabled(bool value) { | 2011 void ResourceDispatcherHost::set_is_prefetch_enabled(bool value) { |
| 2007 is_prefetch_enabled_ = value; | 2012 is_prefetch_enabled_ = value; |
| 2008 } | 2013 } |
| 2009 | 2014 |
| 2010 // static | 2015 // static |
| 2011 bool ResourceDispatcherHost::is_prefetch_enabled_ = false; | 2016 bool ResourceDispatcherHost::is_prefetch_enabled_ = false; |
| OLD | NEW |