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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 #include "content/browser/ssl/ssl_client_auth_handler.h" | 51 #include "content/browser/ssl/ssl_client_auth_handler.h" |
52 #include "content/browser/ssl/ssl_manager.h" | 52 #include "content/browser/ssl/ssl_manager.h" |
53 #include "content/browser/worker_host/worker_service.h" | 53 #include "content/browser/worker_host/worker_service.h" |
54 #include "content/common/resource_messages.h" | 54 #include "content/common/resource_messages.h" |
55 #include "content/common/view_messages.h" | 55 #include "content/common/view_messages.h" |
56 #include "content/public/browser/browser_thread.h" | 56 #include "content/public/browser/browser_thread.h" |
57 #include "content/public/browser/content_browser_client.h" | 57 #include "content/public/browser/content_browser_client.h" |
58 #include "content/public/browser/notification_service.h" | 58 #include "content/public/browser/notification_service.h" |
59 #include "content/public/browser/resource_dispatcher_host_delegate.h" | 59 #include "content/public/browser/resource_dispatcher_host_delegate.h" |
60 #include "content/public/common/content_switches.h" | 60 #include "content/public/common/content_switches.h" |
| 61 #include "content/public/common/process_type.h" |
61 #include "content/public/common/url_constants.h" | 62 #include "content/public/common/url_constants.h" |
62 #include "net/base/auth.h" | 63 #include "net/base/auth.h" |
63 #include "net/base/cert_status_flags.h" | 64 #include "net/base/cert_status_flags.h" |
64 #include "net/base/cookie_monster.h" | 65 #include "net/base/cookie_monster.h" |
65 #include "net/base/load_flags.h" | 66 #include "net/base/load_flags.h" |
66 #include "net/base/mime_util.h" | 67 #include "net/base/mime_util.h" |
67 #include "net/base/net_errors.h" | 68 #include "net/base/net_errors.h" |
68 #include "net/base/registry_controlled_domain.h" | 69 #include "net/base/registry_controlled_domain.h" |
69 #include "net/base/request_priority.h" | 70 #include "net/base/request_priority.h" |
70 #include "net/base/ssl_cert_request_info.h" | 71 #include "net/base/ssl_cert_request_info.h" |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 GURL MaybeStripReferrer(const GURL& possible_referrer) { | 146 GURL MaybeStripReferrer(const GURL& possible_referrer) { |
146 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kNoReferrers)) | 147 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kNoReferrers)) |
147 return GURL(); | 148 return GURL(); |
148 return possible_referrer; | 149 return possible_referrer; |
149 } | 150 } |
150 | 151 |
151 // Consults the RendererSecurity policy to determine whether the | 152 // Consults the RendererSecurity policy to determine whether the |
152 // ResourceDispatcherHost should service this request. A request might be | 153 // ResourceDispatcherHost should service this request. A request might be |
153 // disallowed if the renderer is not authorized to retrieve the request URL or | 154 // disallowed if the renderer is not authorized to retrieve the request URL or |
154 // if the renderer is attempting to upload an unauthorized file. | 155 // if the renderer is attempting to upload an unauthorized file. |
155 bool ShouldServiceRequest(ChildProcessInfo::ProcessType process_type, | 156 bool ShouldServiceRequest(content::ProcessType process_type, |
156 int child_id, | 157 int child_id, |
157 const ResourceHostMsg_Request& request_data) { | 158 const ResourceHostMsg_Request& request_data) { |
158 if (process_type == ChildProcessInfo::PLUGIN_PROCESS) | 159 if (process_type == content::PROCESS_TYPE_PLUGIN) |
159 return true; | 160 return true; |
160 | 161 |
161 ChildProcessSecurityPolicy* policy = | 162 ChildProcessSecurityPolicy* policy = |
162 ChildProcessSecurityPolicy::GetInstance(); | 163 ChildProcessSecurityPolicy::GetInstance(); |
163 | 164 |
164 // Check if the renderer is permitted to request the requested URL. | 165 // Check if the renderer is permitted to request the requested URL. |
165 if (!policy->CanRequestURL(child_id, request_data.url)) { | 166 if (!policy->CanRequestURL(child_id, request_data.url)) { |
166 VLOG(1) << "Denied unauthorized request for " | 167 VLOG(1) << "Denied unauthorized request for " |
167 << request_data.url.possibly_invalid_spec(); | 168 << request_data.url.possibly_invalid_spec(); |
168 return false; | 169 return false; |
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
443 IPC::Message* sync_result) { | 444 IPC::Message* sync_result) { |
444 BeginRequest(request_id, request_data, sync_result, | 445 BeginRequest(request_id, request_data, sync_result, |
445 sync_result->routing_id()); | 446 sync_result->routing_id()); |
446 } | 447 } |
447 | 448 |
448 void ResourceDispatcherHost::BeginRequest( | 449 void ResourceDispatcherHost::BeginRequest( |
449 int request_id, | 450 int request_id, |
450 const ResourceHostMsg_Request& request_data, | 451 const ResourceHostMsg_Request& request_data, |
451 IPC::Message* sync_result, // only valid for sync | 452 IPC::Message* sync_result, // only valid for sync |
452 int route_id) { | 453 int route_id) { |
453 ChildProcessInfo::ProcessType process_type = filter_->process_type(); | 454 content::ProcessType process_type = filter_->process_type(); |
454 int child_id = filter_->child_id(); | 455 int child_id = filter_->child_id(); |
455 | 456 |
456 // If we crash here, figure out what URL the renderer was requesting. | 457 // If we crash here, figure out what URL the renderer was requesting. |
457 // http://crbug.com/91398 | 458 // http://crbug.com/91398 |
458 char url_buf[128]; | 459 char url_buf[128]; |
459 base::strlcpy(url_buf, request_data.url.spec().c_str(), arraysize(url_buf)); | 460 base::strlcpy(url_buf, request_data.url.spec().c_str(), arraysize(url_buf)); |
460 base::debug::Alias(url_buf); | 461 base::debug::Alias(url_buf); |
461 | 462 |
462 const content::ResourceContext& resource_context = | 463 const content::ResourceContext& resource_context = |
463 filter_->resource_context(); | 464 filter_->resource_context(); |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
563 if (request_data.upload_data) { | 564 if (request_data.upload_data) { |
564 request->set_upload(request_data.upload_data); | 565 request->set_upload(request_data.upload_data); |
565 upload_size = request_data.upload_data->GetContentLength(); | 566 upload_size = request_data.upload_data->GetContentLength(); |
566 } | 567 } |
567 | 568 |
568 // Install a CrossSiteResourceHandler if this request is coming from a | 569 // Install a CrossSiteResourceHandler if this request is coming from a |
569 // RenderViewHost with a pending cross-site request. We only check this for | 570 // RenderViewHost with a pending cross-site request. We only check this for |
570 // MAIN_FRAME requests. Unblock requests only come from a blocked page, do | 571 // MAIN_FRAME requests. Unblock requests only come from a blocked page, do |
571 // not count as cross-site, otherwise it gets blocked indefinitely. | 572 // not count as cross-site, otherwise it gets blocked indefinitely. |
572 if (request_data.resource_type == ResourceType::MAIN_FRAME && | 573 if (request_data.resource_type == ResourceType::MAIN_FRAME && |
573 process_type == ChildProcessInfo::RENDER_PROCESS && | 574 process_type == content::PROCESS_TYPE_RENDERER && |
574 CrossSiteRequestManager::GetInstance()-> | 575 CrossSiteRequestManager::GetInstance()-> |
575 HasPendingCrossSiteRequest(child_id, route_id)) { | 576 HasPendingCrossSiteRequest(child_id, route_id)) { |
576 // Wrap the event handler to be sure the current page's onunload handler | 577 // Wrap the event handler to be sure the current page's onunload handler |
577 // has a chance to run before we render the new page. | 578 // has a chance to run before we render the new page. |
578 handler = new CrossSiteResourceHandler(handler, | 579 handler = new CrossSiteResourceHandler(handler, |
579 child_id, | 580 child_id, |
580 route_id, | 581 route_id, |
581 this); | 582 this); |
582 } | 583 } |
583 | 584 |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
747 } | 748 } |
748 | 749 |
749 ResourceDispatcherHostRequestInfo* ResourceDispatcherHost::CreateRequestInfo( | 750 ResourceDispatcherHostRequestInfo* ResourceDispatcherHost::CreateRequestInfo( |
750 ResourceHandler* handler, | 751 ResourceHandler* handler, |
751 int child_id, | 752 int child_id, |
752 int route_id, | 753 int route_id, |
753 bool download, | 754 bool download, |
754 const content::ResourceContext& context) { | 755 const content::ResourceContext& context) { |
755 return new ResourceDispatcherHostRequestInfo( | 756 return new ResourceDispatcherHostRequestInfo( |
756 handler, | 757 handler, |
757 ChildProcessInfo::RENDER_PROCESS, | 758 content::PROCESS_TYPE_RENDERER, |
758 child_id, | 759 child_id, |
759 route_id, | 760 route_id, |
760 0, | 761 0, |
761 request_id_, | 762 request_id_, |
762 false, // is_main_frame | 763 false, // is_main_frame |
763 -1, // frame_id | 764 -1, // frame_id |
764 false, // parent_is_main_frame | 765 false, // parent_is_main_frame |
765 -1, // parent_frame_id | 766 -1, // parent_frame_id |
766 ResourceType::SUB_RESOURCE, | 767 ResourceType::SUB_RESOURCE, |
767 content::PAGE_TRANSITION_LINK, | 768 content::PAGE_TRANSITION_LINK, |
(...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1211 // net::URLRequest::Delegate --------------------------------------------------- | 1212 // net::URLRequest::Delegate --------------------------------------------------- |
1212 | 1213 |
1213 void ResourceDispatcherHost::OnReceivedRedirect(net::URLRequest* request, | 1214 void ResourceDispatcherHost::OnReceivedRedirect(net::URLRequest* request, |
1214 const GURL& new_url, | 1215 const GURL& new_url, |
1215 bool* defer_redirect) { | 1216 bool* defer_redirect) { |
1216 VLOG(1) << "OnReceivedRedirect: " << request->url().spec(); | 1217 VLOG(1) << "OnReceivedRedirect: " << request->url().spec(); |
1217 ResourceDispatcherHostRequestInfo* info = InfoForRequest(request); | 1218 ResourceDispatcherHostRequestInfo* info = InfoForRequest(request); |
1218 | 1219 |
1219 DCHECK(request->status().is_success()); | 1220 DCHECK(request->status().is_success()); |
1220 | 1221 |
1221 if (info->process_type() != ChildProcessInfo::PLUGIN_PROCESS && | 1222 if (info->process_type() != content::PROCESS_TYPE_PLUGIN && |
1222 !ChildProcessSecurityPolicy::GetInstance()-> | 1223 !ChildProcessSecurityPolicy::GetInstance()-> |
1223 CanRequestURL(info->child_id(), new_url)) { | 1224 CanRequestURL(info->child_id(), new_url)) { |
1224 VLOG(1) << "Denied unauthorized request for " | 1225 VLOG(1) << "Denied unauthorized request for " |
1225 << new_url.possibly_invalid_spec(); | 1226 << new_url.possibly_invalid_spec(); |
1226 | 1227 |
1227 // Tell the renderer that this request was disallowed. | 1228 // Tell the renderer that this request was disallowed. |
1228 CancelRequestInternal(request, false); | 1229 CancelRequestInternal(request, false); |
1229 return; | 1230 return; |
1230 } | 1231 } |
1231 | 1232 |
(...skipping 599 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1831 int* render_process_host_id, | 1832 int* render_process_host_id, |
1832 int* render_view_host_id) { | 1833 int* render_view_host_id) { |
1833 const ResourceDispatcherHostRequestInfo* info = InfoForRequest(request); | 1834 const ResourceDispatcherHostRequestInfo* info = InfoForRequest(request); |
1834 if (!info) { | 1835 if (!info) { |
1835 *render_process_host_id = -1; | 1836 *render_process_host_id = -1; |
1836 *render_view_host_id = -1; | 1837 *render_view_host_id = -1; |
1837 return false; | 1838 return false; |
1838 } | 1839 } |
1839 | 1840 |
1840 // If the request is from the worker process, find a tab that owns the worker. | 1841 // If the request is from the worker process, find a tab that owns the worker. |
1841 if (info->process_type() == ChildProcessInfo::WORKER_PROCESS) { | 1842 if (info->process_type() == content::PROCESS_TYPE_WORKER) { |
1842 // Need to display some related UI for this network request - pick an | 1843 // Need to display some related UI for this network request - pick an |
1843 // arbitrary parent to do so. | 1844 // arbitrary parent to do so. |
1844 if (!WorkerService::GetInstance()->GetRendererForWorker( | 1845 if (!WorkerService::GetInstance()->GetRendererForWorker( |
1845 info->child_id(), render_process_host_id, render_view_host_id)) { | 1846 info->child_id(), render_process_host_id, render_view_host_id)) { |
1846 *render_process_host_id = -1; | 1847 *render_process_host_id = -1; |
1847 *render_view_host_id = -1; | 1848 *render_view_host_id = -1; |
1848 return false; | 1849 return false; |
1849 } | 1850 } |
1850 } else { | 1851 } else { |
1851 *render_process_host_id = info->child_id(); | 1852 *render_process_host_id = info->child_id(); |
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2165 return HTTP_AUTH_RESOURCE_BLOCKED_CROSS; | 2166 return HTTP_AUTH_RESOURCE_BLOCKED_CROSS; |
2166 } | 2167 } |
2167 | 2168 |
2168 bool ResourceDispatcherHost::allow_cross_origin_auth_prompt() { | 2169 bool ResourceDispatcherHost::allow_cross_origin_auth_prompt() { |
2169 return allow_cross_origin_auth_prompt_; | 2170 return allow_cross_origin_auth_prompt_; |
2170 } | 2171 } |
2171 | 2172 |
2172 void ResourceDispatcherHost::set_allow_cross_origin_auth_prompt(bool value) { | 2173 void ResourceDispatcherHost::set_allow_cross_origin_auth_prompt(bool value) { |
2173 allow_cross_origin_auth_prompt_ = value; | 2174 allow_cross_origin_auth_prompt_ = value; |
2174 } | 2175 } |
OLD | NEW |