| 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 // 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/loader/resource_dispatcher_host_impl.h" | 7 #include "content/browser/loader/resource_dispatcher_host_impl.h" |
| 8 | 8 |
| 9 #include <stddef.h> | 9 #include <stddef.h> |
| 10 | 10 |
| (...skipping 1300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1311 ResourceContext* resource_context = NULL; | 1311 ResourceContext* resource_context = NULL; |
| 1312 net::URLRequestContext* request_context = NULL; | 1312 net::URLRequestContext* request_context = NULL; |
| 1313 filter_->GetContexts(request_data.resource_type, &resource_context, | 1313 filter_->GetContexts(request_data.resource_type, &resource_context, |
| 1314 &request_context); | 1314 &request_context); |
| 1315 | 1315 |
| 1316 // Parse the headers before calling ShouldServiceRequest, so that they are | 1316 // Parse the headers before calling ShouldServiceRequest, so that they are |
| 1317 // available to be validated. | 1317 // available to be validated. |
| 1318 net::HttpRequestHeaders headers; | 1318 net::HttpRequestHeaders headers; |
| 1319 headers.AddHeadersFromString(request_data.headers); | 1319 headers.AddHeadersFromString(request_data.headers); |
| 1320 | 1320 |
| 1321 BeginRequestStatus begin_request_status = CONTINUE; | 1321 if (is_shutdown_ || |
| 1322 OnHeaderProcessedCallback callback; | 1322 !ShouldServiceRequest(process_type, child_id, request_data, headers, |
| 1323 if (!is_shutdown_) { | 1323 filter_, resource_context)) { |
| 1324 callback = | |
| 1325 base::Bind(&ResourceDispatcherHostImpl::ContinuePendingBeginRequest, | |
| 1326 base::Unretained(this), request_id, request_data, | |
| 1327 sync_result, route_id, headers); | |
| 1328 begin_request_status = | |
| 1329 ShouldServiceRequest(process_type, child_id, request_data, headers, | |
| 1330 filter_, resource_context, callback); | |
| 1331 } else { | |
| 1332 begin_request_status = ABORT; | |
| 1333 } | |
| 1334 if (begin_request_status == ABORT) { | |
| 1335 AbortRequestBeforeItStarts(filter_, sync_result, request_id); | 1324 AbortRequestBeforeItStarts(filter_, sync_result, request_id); |
| 1336 return; | 1325 return; |
| 1337 } else if (begin_request_status == CONTINUE) { | |
| 1338 callback.Run(true, 0); | |
| 1339 } | 1326 } |
| 1327 // Check if we have a registered interceptor for the headers passed in. If |
| 1328 // yes then we need to mark the current request as pending and wait for the |
| 1329 // interceptor to invoke the callback with a status code indicating whether |
| 1330 // the request needs to be aborted or continued. |
| 1331 for (net::HttpRequestHeaders::Iterator it(headers); it.GetNext();) { |
| 1332 HeaderInterceptorMap::iterator index = |
| 1333 http_header_interceptor_map_.find(it.name()); |
| 1334 if (index != http_header_interceptor_map_.end()) { |
| 1335 HeaderInterceptorInfo& interceptor_info = index->second; |
| 1336 |
| 1337 bool call_interceptor = true; |
| 1338 if (!interceptor_info.starts_with.empty()) { |
| 1339 call_interceptor = |
| 1340 base::StartsWith(it.value(), interceptor_info.starts_with, |
| 1341 base::CompareCase::INSENSITIVE_ASCII); |
| 1342 } |
| 1343 if (call_interceptor) { |
| 1344 interceptor_info.interceptor.Run( |
| 1345 it.name(), it.value(), child_id, resource_context, |
| 1346 base::Bind(&ResourceDispatcherHostImpl::ContinuePendingBeginRequest, |
| 1347 base::Unretained(this), request_id, request_data, |
| 1348 sync_result, route_id, headers)); |
| 1349 return; |
| 1350 } |
| 1351 } |
| 1352 } |
| 1353 ContinuePendingBeginRequest(request_id, request_data, sync_result, route_id, |
| 1354 headers, true, 0); |
| 1340 } | 1355 } |
| 1341 | 1356 |
| 1342 void ResourceDispatcherHostImpl::ContinuePendingBeginRequest( | 1357 void ResourceDispatcherHostImpl::ContinuePendingBeginRequest( |
| 1343 int request_id, | 1358 int request_id, |
| 1344 const ResourceRequest& request_data, | 1359 const ResourceRequest& request_data, |
| 1345 IPC::Message* sync_result, // only valid for sync | 1360 IPC::Message* sync_result, // only valid for sync |
| 1346 int route_id, | 1361 int route_id, |
| 1347 const net::HttpRequestHeaders& headers, | 1362 const net::HttpRequestHeaders& headers, |
| 1348 bool continue_request, | 1363 bool continue_request, |
| 1349 int error_code) { | 1364 int error_code) { |
| (...skipping 1251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2601 DCHECK(deserialized); | 2616 DCHECK(deserialized); |
| 2602 ssl.cert_id = GetCertStore()->StoreCert(ssl_info.cert.get(), child_id); | 2617 ssl.cert_id = GetCertStore()->StoreCert(ssl_info.cert.get(), child_id); |
| 2603 response->head.security_info = SerializeSecurityInfo(ssl); | 2618 response->head.security_info = SerializeSecurityInfo(ssl); |
| 2604 } | 2619 } |
| 2605 | 2620 |
| 2606 CertStore* ResourceDispatcherHostImpl::GetCertStore() { | 2621 CertStore* ResourceDispatcherHostImpl::GetCertStore() { |
| 2607 return cert_store_for_testing_ ? cert_store_for_testing_ | 2622 return cert_store_for_testing_ ? cert_store_for_testing_ |
| 2608 : CertStore::GetInstance(); | 2623 : CertStore::GetInstance(); |
| 2609 } | 2624 } |
| 2610 | 2625 |
| 2611 ResourceDispatcherHostImpl::BeginRequestStatus | 2626 bool ResourceDispatcherHostImpl::ShouldServiceRequest( |
| 2612 ResourceDispatcherHostImpl::ShouldServiceRequest( | |
| 2613 int process_type, | 2627 int process_type, |
| 2614 int child_id, | 2628 int child_id, |
| 2615 const ResourceRequest& request_data, | 2629 const ResourceRequest& request_data, |
| 2616 const net::HttpRequestHeaders& headers, | 2630 const net::HttpRequestHeaders& headers, |
| 2617 ResourceMessageFilter* filter, | 2631 ResourceMessageFilter* filter, |
| 2618 ResourceContext* resource_context, | 2632 ResourceContext* resource_context) { |
| 2619 OnHeaderProcessedCallback callback) { | |
| 2620 ChildProcessSecurityPolicyImpl* policy = | 2633 ChildProcessSecurityPolicyImpl* policy = |
| 2621 ChildProcessSecurityPolicyImpl::GetInstance(); | 2634 ChildProcessSecurityPolicyImpl::GetInstance(); |
| 2622 | 2635 |
| 2623 // Check if the renderer is permitted to request the requested URL. | 2636 // Check if the renderer is permitted to request the requested URL. |
| 2624 if (!policy->CanRequestURL(child_id, request_data.url)) { | 2637 if (!policy->CanRequestURL(child_id, request_data.url)) { |
| 2625 VLOG(1) << "Denied unauthorized request for " | 2638 VLOG(1) << "Denied unauthorized request for " |
| 2626 << request_data.url.possibly_invalid_spec(); | 2639 << request_data.url.possibly_invalid_spec(); |
| 2627 return ABORT; | 2640 return false; |
| 2628 } | 2641 } |
| 2629 | 2642 |
| 2630 // Check if the renderer is using an illegal Origin header. If so, kill it. | 2643 // Check if the renderer is using an illegal Origin header. If so, kill it. |
| 2631 std::string origin_string; | 2644 std::string origin_string; |
| 2632 bool has_origin = | 2645 bool has_origin = |
| 2633 headers.GetHeader("Origin", &origin_string) && origin_string != "null"; | 2646 headers.GetHeader("Origin", &origin_string) && origin_string != "null"; |
| 2634 if (has_origin) { | 2647 if (has_origin) { |
| 2635 GURL origin(origin_string); | 2648 GURL origin(origin_string); |
| 2636 if (!policy->CanCommitURL(child_id, origin)) { | 2649 if (!policy->CanCommitURL(child_id, origin)) { |
| 2637 VLOG(1) << "Killed renderer for illegal origin: " << origin_string; | 2650 VLOG(1) << "Killed renderer for illegal origin: " << origin_string; |
| 2638 bad_message::ReceivedBadMessage(filter, bad_message::RDH_ILLEGAL_ORIGIN); | 2651 bad_message::ReceivedBadMessage(filter, bad_message::RDH_ILLEGAL_ORIGIN); |
| 2639 return ABORT; | 2652 return false; |
| 2640 } | 2653 } |
| 2641 } | 2654 } |
| 2642 | 2655 |
| 2643 // Check if the renderer is permitted to upload the requested files. | 2656 // Check if the renderer is permitted to upload the requested files. |
| 2644 if (request_data.request_body.get()) { | 2657 if (request_data.request_body.get()) { |
| 2645 const std::vector<ResourceRequestBodyImpl::Element>* uploads = | 2658 const std::vector<ResourceRequestBodyImpl::Element>* uploads = |
| 2646 request_data.request_body->elements(); | 2659 request_data.request_body->elements(); |
| 2647 std::vector<ResourceRequestBodyImpl::Element>::const_iterator iter; | 2660 std::vector<ResourceRequestBodyImpl::Element>::const_iterator iter; |
| 2648 for (iter = uploads->begin(); iter != uploads->end(); ++iter) { | 2661 for (iter = uploads->begin(); iter != uploads->end(); ++iter) { |
| 2649 if (iter->type() == ResourceRequestBodyImpl::Element::TYPE_FILE && | 2662 if (iter->type() == ResourceRequestBodyImpl::Element::TYPE_FILE && |
| 2650 !policy->CanReadFile(child_id, iter->path())) { | 2663 !policy->CanReadFile(child_id, iter->path())) { |
| 2651 NOTREACHED() << "Denied unauthorized upload of " | 2664 NOTREACHED() << "Denied unauthorized upload of " |
| 2652 << iter->path().value(); | 2665 << iter->path().value(); |
| 2653 return ABORT; | 2666 return false; |
| 2654 } | 2667 } |
| 2655 if (iter->type() == | 2668 if (iter->type() == |
| 2656 ResourceRequestBodyImpl::Element::TYPE_FILE_FILESYSTEM) { | 2669 ResourceRequestBodyImpl::Element::TYPE_FILE_FILESYSTEM) { |
| 2657 storage::FileSystemURL url = | 2670 storage::FileSystemURL url = |
| 2658 filter->file_system_context()->CrackURL(iter->filesystem_url()); | 2671 filter->file_system_context()->CrackURL(iter->filesystem_url()); |
| 2659 if (!policy->CanReadFileSystemFile(child_id, url)) { | 2672 if (!policy->CanReadFileSystemFile(child_id, url)) { |
| 2660 NOTREACHED() << "Denied unauthorized upload of " | 2673 NOTREACHED() << "Denied unauthorized upload of " |
| 2661 << iter->filesystem_url().spec(); | 2674 << iter->filesystem_url().spec(); |
| 2662 return ABORT; | 2675 return false; |
| 2663 } | 2676 } |
| 2664 } | 2677 } |
| 2665 } | 2678 } |
| 2666 } | 2679 } |
| 2667 | 2680 return true; |
| 2668 // Check if we have a registered interceptor for the headers passed in. If | |
| 2669 // yes then we need to mark the current request as pending and wait for the | |
| 2670 // interceptor to invoke the |callback| with a status code indicating whether | |
| 2671 // the request needs to be aborted or continued. | |
| 2672 for (net::HttpRequestHeaders::Iterator it(headers); it.GetNext();) { | |
| 2673 HeaderInterceptorMap::iterator index = | |
| 2674 http_header_interceptor_map_.find(it.name()); | |
| 2675 if (index != http_header_interceptor_map_.end()) { | |
| 2676 HeaderInterceptorInfo& interceptor_info = index->second; | |
| 2677 | |
| 2678 bool call_interceptor = true; | |
| 2679 if (!interceptor_info.starts_with.empty()) { | |
| 2680 call_interceptor = | |
| 2681 base::StartsWith(it.value(), interceptor_info.starts_with, | |
| 2682 base::CompareCase::INSENSITIVE_ASCII); | |
| 2683 } | |
| 2684 if (call_interceptor) { | |
| 2685 interceptor_info.interceptor.Run(it.name(), it.value(), child_id, | |
| 2686 resource_context, callback); | |
| 2687 return PENDING; | |
| 2688 } | |
| 2689 } | |
| 2690 } | |
| 2691 return CONTINUE; | |
| 2692 } | 2681 } |
| 2693 | 2682 |
| 2694 } // namespace content | 2683 } // namespace content |
| OLD | NEW |