| 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 499 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 510 return CallbackAndReturn(started_callback, net::ERR_INSUFFICIENT_RESOURCES); | 510 return CallbackAndReturn(started_callback, net::ERR_INSUFFICIENT_RESOURCES); |
| 511 | 511 |
| 512 const GURL& url = request->original_url(); | 512 const GURL& url = request->original_url(); |
| 513 | 513 |
| 514 // http://crbug.com/90971 | 514 // http://crbug.com/90971 |
| 515 char url_buf[128]; | 515 char url_buf[128]; |
| 516 base::strlcpy(url_buf, url.spec().c_str(), arraysize(url_buf)); | 516 base::strlcpy(url_buf, url.spec().c_str(), arraysize(url_buf)); |
| 517 base::debug::Alias(url_buf); | 517 base::debug::Alias(url_buf); |
| 518 CHECK(ContainsKey(active_resource_contexts_, context)); | 518 CHECK(ContainsKey(active_resource_contexts_, context)); |
| 519 | 519 |
| 520 const net::URLRequestContext* request_context = context->GetRequestContext(); | |
| 521 request->set_referrer(MaybeStripReferrer(GURL(request->referrer())).spec()); | 520 request->set_referrer(MaybeStripReferrer(GURL(request->referrer())).spec()); |
| 522 request->set_context(request_context); | |
| 523 int extra_load_flags = net::LOAD_IS_DOWNLOAD; | 521 int extra_load_flags = net::LOAD_IS_DOWNLOAD; |
| 524 if (prefer_cache) { | 522 if (prefer_cache) { |
| 525 // If there is upload data attached, only retrieve from cache because there | 523 // If there is upload data attached, only retrieve from cache because there |
| 526 // is no current mechanism to prompt the user for their consent for a | 524 // is no current mechanism to prompt the user for their consent for a |
| 527 // re-post. For GETs, try to retrieve data from the cache and skip | 525 // re-post. For GETs, try to retrieve data from the cache and skip |
| 528 // validating the entry if present. | 526 // validating the entry if present. |
| 529 if (request->get_upload() != NULL) | 527 if (request->get_upload() != NULL) |
| 530 extra_load_flags |= net::LOAD_ONLY_FROM_CACHE; | 528 extra_load_flags |= net::LOAD_ONLY_FROM_CACHE; |
| 531 else | 529 else |
| 532 extra_load_flags |= net::LOAD_PREFERRING_CACHE; | 530 extra_load_flags |= net::LOAD_PREFERRING_CACHE; |
| 533 } else { | 531 } else { |
| 534 extra_load_flags |= net::LOAD_DISABLE_CACHE; | 532 extra_load_flags |= net::LOAD_DISABLE_CACHE; |
| 535 } | 533 } |
| 536 request->set_load_flags(request->load_flags() | extra_load_flags); | 534 request->set_load_flags(request->load_flags() | extra_load_flags); |
| 537 // Check if the renderer is permitted to request the requested URL. | 535 // Check if the renderer is permitted to request the requested URL. |
| 538 if (!ChildProcessSecurityPolicyImpl::GetInstance()-> | 536 if (!ChildProcessSecurityPolicyImpl::GetInstance()-> |
| 539 CanRequestURL(child_id, url)) { | 537 CanRequestURL(child_id, url)) { |
| 540 VLOG(1) << "Denied unauthorized download request for " | 538 VLOG(1) << "Denied unauthorized download request for " |
| 541 << url.possibly_invalid_spec(); | 539 << url.possibly_invalid_spec(); |
| 542 return CallbackAndReturn(started_callback, net::ERR_ACCESS_DENIED); | 540 return CallbackAndReturn(started_callback, net::ERR_ACCESS_DENIED); |
| 543 } | 541 } |
| 544 | 542 |
| 545 request_id_--; | 543 request_id_--; |
| 546 | 544 |
| 545 const net::URLRequestContext* request_context = context->GetRequestContext(); |
| 547 if (!request_context->job_factory()->IsHandledURL(url)) { | 546 if (!request_context->job_factory()->IsHandledURL(url)) { |
| 548 VLOG(1) << "Download request for unsupported protocol: " | 547 VLOG(1) << "Download request for unsupported protocol: " |
| 549 << url.possibly_invalid_spec(); | 548 << url.possibly_invalid_spec(); |
| 550 return CallbackAndReturn(started_callback, net::ERR_ACCESS_DENIED); | 549 return CallbackAndReturn(started_callback, net::ERR_ACCESS_DENIED); |
| 551 } | 550 } |
| 552 | 551 |
| 553 ResourceRequestInfoImpl* extra_info = | 552 ResourceRequestInfoImpl* extra_info = |
| 554 CreateRequestInfo(child_id, route_id, true, context); | 553 CreateRequestInfo(child_id, route_id, true, context); |
| 555 extra_info->AssociateWithRequest(request.get()); // Request takes ownership. | 554 extra_info->AssociateWithRequest(request.get()); // Request takes ownership. |
| 556 | 555 |
| (...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 949 | 948 |
| 950 int load_flags = | 949 int load_flags = |
| 951 BuildLoadFlagsForRequest(request_data, child_id, sync_result != NULL); | 950 BuildLoadFlagsForRequest(request_data, child_id, sync_result != NULL); |
| 952 | 951 |
| 953 // Construct the request. | 952 // Construct the request. |
| 954 scoped_ptr<net::URLRequest> new_request; | 953 scoped_ptr<net::URLRequest> new_request; |
| 955 net::URLRequest* request; | 954 net::URLRequest* request; |
| 956 if (deferred_loader.get()) { | 955 if (deferred_loader.get()) { |
| 957 request = deferred_loader->request(); | 956 request = deferred_loader->request(); |
| 958 } else { | 957 } else { |
| 959 new_request.reset(new net::URLRequest(request_data.url, NULL)); | 958 new_request.reset(new net::URLRequest( |
| 959 request_data.url, |
| 960 NULL, |
| 961 filter_->GetURLRequestContext(request_data.resource_type))); |
| 960 request = new_request.get(); | 962 request = new_request.get(); |
| 961 | 963 |
| 962 request->set_method(request_data.method); | 964 request->set_method(request_data.method); |
| 963 request->set_first_party_for_cookies(request_data.first_party_for_cookies); | 965 request->set_first_party_for_cookies(request_data.first_party_for_cookies); |
| 964 request->set_referrer(referrer.url.spec()); | 966 request->set_referrer(referrer.url.spec()); |
| 965 webkit_glue::ConfigureURLRequestForReferrerPolicy(request, | 967 webkit_glue::ConfigureURLRequestForReferrerPolicy(request, |
| 966 referrer.policy); | 968 referrer.policy); |
| 967 net::HttpRequestHeaders headers; | 969 net::HttpRequestHeaders headers; |
| 968 headers.AddHeadersFromString(request_data.headers); | 970 headers.AddHeadersFromString(request_data.headers); |
| 969 request->SetExtraRequestHeaders(headers); | 971 request->SetExtraRequestHeaders(headers); |
| 970 } | 972 } |
| 971 | 973 |
| 972 // TODO(darin): Do we really need all of these URLRequest setters in the | 974 // TODO(darin): Do we really need all of these URLRequest setters in the |
| 973 // transferred navigation case? | 975 // transferred navigation case? |
| 974 | 976 |
| 975 request->set_load_flags(load_flags); | 977 request->set_load_flags(load_flags); |
| 976 | 978 |
| 977 request->set_context( | |
| 978 filter_->GetURLRequestContext(request_data.resource_type)); | |
| 979 request->set_priority(DetermineRequestPriority(request_data.resource_type)); | 979 request->set_priority(DetermineRequestPriority(request_data.resource_type)); |
| 980 | 980 |
| 981 // Set upload data. | 981 // Set upload data. |
| 982 uint64 upload_size = 0; | 982 uint64 upload_size = 0; |
| 983 if (request_data.upload_data) { | 983 if (request_data.upload_data) { |
| 984 request->set_upload(request_data.upload_data); | 984 request->set_upload(request_data.upload_data); |
| 985 // This results in performing file IO. crbug.com/112607. | 985 // This results in performing file IO. crbug.com/112607. |
| 986 base::ThreadRestrictions::ScopedAllowIO allow_io; | 986 base::ThreadRestrictions::ScopedAllowIO allow_io; |
| 987 upload_size = request_data.upload_data->GetContentLengthSync(); | 987 upload_size = request_data.upload_data->GetContentLengthSync(); |
| 988 } | 988 } |
| (...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1263 bool known_proto = | 1263 bool known_proto = |
| 1264 request_context->job_factory()->IsHandledURL(url); | 1264 request_context->job_factory()->IsHandledURL(url); |
| 1265 if (!known_proto) { | 1265 if (!known_proto) { |
| 1266 // Since any URLs which have non-standard scheme have been filtered | 1266 // Since any URLs which have non-standard scheme have been filtered |
| 1267 // by save manager(see GURL::SchemeIsStandard). This situation | 1267 // by save manager(see GURL::SchemeIsStandard). This situation |
| 1268 // should not happen. | 1268 // should not happen. |
| 1269 NOTREACHED(); | 1269 NOTREACHED(); |
| 1270 return; | 1270 return; |
| 1271 } | 1271 } |
| 1272 | 1272 |
| 1273 scoped_ptr<net::URLRequest> request(new net::URLRequest(url, NULL)); | 1273 scoped_ptr<net::URLRequest> request( |
| 1274 new net::URLRequest(url, NULL, request_context)); |
| 1274 request->set_method("GET"); | 1275 request->set_method("GET"); |
| 1275 request->set_referrer(MaybeStripReferrer(referrer.url).spec()); | 1276 request->set_referrer(MaybeStripReferrer(referrer.url).spec()); |
| 1276 webkit_glue::ConfigureURLRequestForReferrerPolicy(request.get(), | 1277 webkit_glue::ConfigureURLRequestForReferrerPolicy(request.get(), |
| 1277 referrer.policy); | 1278 referrer.policy); |
| 1278 // So far, for saving page, we need fetch content from cache, in the | 1279 // So far, for saving page, we need fetch content from cache, in the |
| 1279 // future, maybe we can use a configuration to configure this behavior. | 1280 // future, maybe we can use a configuration to configure this behavior. |
| 1280 request->set_load_flags(net::LOAD_PREFERRING_CACHE); | 1281 request->set_load_flags(net::LOAD_PREFERRING_CACHE); |
| 1281 request->set_context(context->GetRequestContext()); | |
| 1282 | 1282 |
| 1283 // Since we're just saving some resources we need, disallow downloading. | 1283 // Since we're just saving some resources we need, disallow downloading. |
| 1284 ResourceRequestInfoImpl* extra_info = | 1284 ResourceRequestInfoImpl* extra_info = |
| 1285 CreateRequestInfo(child_id, route_id, false, context); | 1285 CreateRequestInfo(child_id, route_id, false, context); |
| 1286 extra_info->AssociateWithRequest(request.get()); // Request takes ownership. | 1286 extra_info->AssociateWithRequest(request.get()); // Request takes ownership. |
| 1287 | 1287 |
| 1288 BeginRequestInternal(request.Pass(), handler.Pass()); | 1288 BeginRequestInternal(request.Pass(), handler.Pass()); |
| 1289 } | 1289 } |
| 1290 | 1290 |
| 1291 bool ResourceDispatcherHostImpl::WillSendData(int child_id, int request_id, | 1291 bool ResourceDispatcherHostImpl::WillSendData(int child_id, int request_id, |
| (...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1754 | 1754 |
| 1755 return i->second.get(); | 1755 return i->second.get(); |
| 1756 } | 1756 } |
| 1757 | 1757 |
| 1758 ResourceLoader* ResourceDispatcherHostImpl::GetLoader(int child_id, | 1758 ResourceLoader* ResourceDispatcherHostImpl::GetLoader(int child_id, |
| 1759 int request_id) const { | 1759 int request_id) const { |
| 1760 return GetLoader(GlobalRequestID(child_id, request_id)); | 1760 return GetLoader(GlobalRequestID(child_id, request_id)); |
| 1761 } | 1761 } |
| 1762 | 1762 |
| 1763 } // namespace content | 1763 } // namespace content |
| OLD | NEW |