| 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/renderer_host/resource_dispatcher_host_impl.h" | 7 #include "content/browser/renderer_host/resource_dispatcher_host_impl.h" |
| 8 | 8 |
| 9 #include <set> | 9 #include <set> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 506 return CallbackAndReturn(started_callback, net::ERR_INSUFFICIENT_RESOURCES); | 506 return CallbackAndReturn(started_callback, net::ERR_INSUFFICIENT_RESOURCES); |
| 507 | 507 |
| 508 const GURL& url = request->original_url(); | 508 const GURL& url = request->original_url(); |
| 509 | 509 |
| 510 // http://crbug.com/90971 | 510 // http://crbug.com/90971 |
| 511 char url_buf[128]; | 511 char url_buf[128]; |
| 512 base::strlcpy(url_buf, url.spec().c_str(), arraysize(url_buf)); | 512 base::strlcpy(url_buf, url.spec().c_str(), arraysize(url_buf)); |
| 513 base::debug::Alias(url_buf); | 513 base::debug::Alias(url_buf); |
| 514 CHECK(ContainsKey(active_resource_contexts_, context)); | 514 CHECK(ContainsKey(active_resource_contexts_, context)); |
| 515 | 515 |
| 516 const net::URLRequestContext* request_context = context->GetRequestContext(); | |
| 517 request->set_referrer(MaybeStripReferrer(GURL(request->referrer())).spec()); | 516 request->set_referrer(MaybeStripReferrer(GURL(request->referrer())).spec()); |
| 518 request->set_context(request_context); | |
| 519 int extra_load_flags = net::LOAD_IS_DOWNLOAD; | 517 int extra_load_flags = net::LOAD_IS_DOWNLOAD; |
| 520 if (prefer_cache) { | 518 if (prefer_cache) { |
| 521 // If there is upload data attached, only retrieve from cache because there | 519 // If there is upload data attached, only retrieve from cache because there |
| 522 // is no current mechanism to prompt the user for their consent for a | 520 // is no current mechanism to prompt the user for their consent for a |
| 523 // re-post. For GETs, try to retrieve data from the cache and skip | 521 // re-post. For GETs, try to retrieve data from the cache and skip |
| 524 // validating the entry if present. | 522 // validating the entry if present. |
| 525 if (request->get_upload() != NULL) | 523 if (request->get_upload() != NULL) |
| 526 extra_load_flags |= net::LOAD_ONLY_FROM_CACHE; | 524 extra_load_flags |= net::LOAD_ONLY_FROM_CACHE; |
| 527 else | 525 else |
| 528 extra_load_flags |= net::LOAD_PREFERRING_CACHE; | 526 extra_load_flags |= net::LOAD_PREFERRING_CACHE; |
| 529 } else { | 527 } else { |
| 530 extra_load_flags |= net::LOAD_DISABLE_CACHE; | 528 extra_load_flags |= net::LOAD_DISABLE_CACHE; |
| 531 } | 529 } |
| 532 request->set_load_flags(request->load_flags() | extra_load_flags); | 530 request->set_load_flags(request->load_flags() | extra_load_flags); |
| 533 // Check if the renderer is permitted to request the requested URL. | 531 // Check if the renderer is permitted to request the requested URL. |
| 534 if (!ChildProcessSecurityPolicyImpl::GetInstance()-> | 532 if (!ChildProcessSecurityPolicyImpl::GetInstance()-> |
| 535 CanRequestURL(child_id, url)) { | 533 CanRequestURL(child_id, url)) { |
| 536 VLOG(1) << "Denied unauthorized download request for " | 534 VLOG(1) << "Denied unauthorized download request for " |
| 537 << url.possibly_invalid_spec(); | 535 << url.possibly_invalid_spec(); |
| 538 return CallbackAndReturn(started_callback, net::ERR_ACCESS_DENIED); | 536 return CallbackAndReturn(started_callback, net::ERR_ACCESS_DENIED); |
| 539 } | 537 } |
| 540 | 538 |
| 541 request_id_--; | 539 request_id_--; |
| 542 | 540 |
| 541 const net::URLRequestContext* request_context = context->GetRequestContext(); |
| 543 if (!request_context->job_factory()->IsHandledURL(url)) { | 542 if (!request_context->job_factory()->IsHandledURL(url)) { |
| 544 VLOG(1) << "Download request for unsupported protocol: " | 543 VLOG(1) << "Download request for unsupported protocol: " |
| 545 << url.possibly_invalid_spec(); | 544 << url.possibly_invalid_spec(); |
| 546 return CallbackAndReturn(started_callback, net::ERR_ACCESS_DENIED); | 545 return CallbackAndReturn(started_callback, net::ERR_ACCESS_DENIED); |
| 547 } | 546 } |
| 548 | 547 |
| 549 ResourceRequestInfoImpl* extra_info = | 548 ResourceRequestInfoImpl* extra_info = |
| 550 CreateRequestInfo(child_id, route_id, true, context); | 549 CreateRequestInfo(child_id, route_id, true, context); |
| 551 extra_info->AssociateWithRequest(request.get()); // Request takes ownership. | 550 extra_info->AssociateWithRequest(request.get()); // Request takes ownership. |
| 552 | 551 |
| (...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 929 | 928 |
| 930 int load_flags = | 929 int load_flags = |
| 931 BuildLoadFlagsForRequest(request_data, child_id, sync_result != NULL); | 930 BuildLoadFlagsForRequest(request_data, child_id, sync_result != NULL); |
| 932 | 931 |
| 933 // Construct the request. | 932 // Construct the request. |
| 934 scoped_ptr<net::URLRequest> new_request; | 933 scoped_ptr<net::URLRequest> new_request; |
| 935 net::URLRequest* request; | 934 net::URLRequest* request; |
| 936 if (deferred_loader.get()) { | 935 if (deferred_loader.get()) { |
| 937 request = deferred_loader->request(); | 936 request = deferred_loader->request(); |
| 938 } else { | 937 } else { |
| 939 new_request.reset(new net::URLRequest(request_data.url, NULL)); | 938 new_request.reset(new net::URLRequest( |
| 939 request_data.url, |
| 940 NULL, |
| 941 filter_->GetURLRequestContext(request_data.resource_type))); |
| 940 request = new_request.get(); | 942 request = new_request.get(); |
| 941 | 943 |
| 942 request->set_method(request_data.method); | 944 request->set_method(request_data.method); |
| 943 request->set_first_party_for_cookies(request_data.first_party_for_cookies); | 945 request->set_first_party_for_cookies(request_data.first_party_for_cookies); |
| 944 request->set_referrer(referrer.url.spec()); | 946 request->set_referrer(referrer.url.spec()); |
| 945 webkit_glue::ConfigureURLRequestForReferrerPolicy(request, | 947 webkit_glue::ConfigureURLRequestForReferrerPolicy(request, |
| 946 referrer.policy); | 948 referrer.policy); |
| 947 net::HttpRequestHeaders headers; | 949 net::HttpRequestHeaders headers; |
| 948 headers.AddHeadersFromString(request_data.headers); | 950 headers.AddHeadersFromString(request_data.headers); |
| 949 request->SetExtraRequestHeaders(headers); | 951 request->SetExtraRequestHeaders(headers); |
| 950 } | 952 } |
| 951 | 953 |
| 952 // TODO(darin): Do we really need all of these URLRequest setters in the | 954 // TODO(darin): Do we really need all of these URLRequest setters in the |
| 953 // transferred navigation case? | 955 // transferred navigation case? |
| 954 | 956 |
| 955 request->set_load_flags(load_flags); | 957 request->set_load_flags(load_flags); |
| 956 | 958 |
| 957 request->set_context( | |
| 958 filter_->GetURLRequestContext(request_data.resource_type)); | |
| 959 request->set_priority(DetermineRequestPriority(request_data.resource_type)); | 959 request->set_priority(DetermineRequestPriority(request_data.resource_type)); |
| 960 | 960 |
| 961 // Set upload data. | 961 // Set upload data. |
| 962 uint64 upload_size = 0; | 962 uint64 upload_size = 0; |
| 963 if (request_data.upload_data) { | 963 if (request_data.upload_data) { |
| 964 request->set_upload(request_data.upload_data); | 964 request->set_upload(request_data.upload_data); |
| 965 // This results in performing file IO. crbug.com/112607. | 965 // This results in performing file IO. crbug.com/112607. |
| 966 base::ThreadRestrictions::ScopedAllowIO allow_io; | 966 base::ThreadRestrictions::ScopedAllowIO allow_io; |
| 967 upload_size = request_data.upload_data->GetContentLengthSync(); | 967 upload_size = request_data.upload_data->GetContentLengthSync(); |
| 968 } | 968 } |
| (...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1243 bool known_proto = | 1243 bool known_proto = |
| 1244 request_context->job_factory()->IsHandledURL(url); | 1244 request_context->job_factory()->IsHandledURL(url); |
| 1245 if (!known_proto) { | 1245 if (!known_proto) { |
| 1246 // Since any URLs which have non-standard scheme have been filtered | 1246 // Since any URLs which have non-standard scheme have been filtered |
| 1247 // by save manager(see GURL::SchemeIsStandard). This situation | 1247 // by save manager(see GURL::SchemeIsStandard). This situation |
| 1248 // should not happen. | 1248 // should not happen. |
| 1249 NOTREACHED(); | 1249 NOTREACHED(); |
| 1250 return; | 1250 return; |
| 1251 } | 1251 } |
| 1252 | 1252 |
| 1253 scoped_ptr<net::URLRequest> request(new net::URLRequest(url, NULL)); | 1253 scoped_ptr<net::URLRequest> request( |
| 1254 new net::URLRequest(url, NULL, request_context)); |
| 1254 request->set_method("GET"); | 1255 request->set_method("GET"); |
| 1255 request->set_referrer(MaybeStripReferrer(referrer.url).spec()); | 1256 request->set_referrer(MaybeStripReferrer(referrer.url).spec()); |
| 1256 webkit_glue::ConfigureURLRequestForReferrerPolicy(request.get(), | 1257 webkit_glue::ConfigureURLRequestForReferrerPolicy(request.get(), |
| 1257 referrer.policy); | 1258 referrer.policy); |
| 1258 // So far, for saving page, we need fetch content from cache, in the | 1259 // So far, for saving page, we need fetch content from cache, in the |
| 1259 // future, maybe we can use a configuration to configure this behavior. | 1260 // future, maybe we can use a configuration to configure this behavior. |
| 1260 request->set_load_flags(net::LOAD_PREFERRING_CACHE); | 1261 request->set_load_flags(net::LOAD_PREFERRING_CACHE); |
| 1261 request->set_context(context->GetRequestContext()); | |
| 1262 | 1262 |
| 1263 // Since we're just saving some resources we need, disallow downloading. | 1263 // Since we're just saving some resources we need, disallow downloading. |
| 1264 ResourceRequestInfoImpl* extra_info = | 1264 ResourceRequestInfoImpl* extra_info = |
| 1265 CreateRequestInfo(child_id, route_id, false, context); | 1265 CreateRequestInfo(child_id, route_id, false, context); |
| 1266 extra_info->AssociateWithRequest(request.get()); // Request takes ownership. | 1266 extra_info->AssociateWithRequest(request.get()); // Request takes ownership. |
| 1267 | 1267 |
| 1268 BeginRequestInternal(request.Pass(), handler.Pass()); | 1268 BeginRequestInternal(request.Pass(), handler.Pass()); |
| 1269 } | 1269 } |
| 1270 | 1270 |
| 1271 void ResourceDispatcherHostImpl::MarkAsTransferredNavigation( | 1271 void ResourceDispatcherHostImpl::MarkAsTransferredNavigation( |
| (...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1712 | 1712 |
| 1713 return i->second.get(); | 1713 return i->second.get(); |
| 1714 } | 1714 } |
| 1715 | 1715 |
| 1716 ResourceLoader* ResourceDispatcherHostImpl::GetLoader(int child_id, | 1716 ResourceLoader* ResourceDispatcherHostImpl::GetLoader(int child_id, |
| 1717 int request_id) const { | 1717 int request_id) const { |
| 1718 return GetLoader(GlobalRequestID(child_id, request_id)); | 1718 return GetLoader(GlobalRequestID(child_id, request_id)); |
| 1719 } | 1719 } |
| 1720 | 1720 |
| 1721 } // namespace content | 1721 } // namespace content |
| OLD | NEW |