Chromium Code Reviews| 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 <algorithm> | 9 #include <algorithm> |
| 10 #include <set> | 10 #include <set> |
| (...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 486 DOWNLOAD_INTERRUPT_REASON_USER_SHUTDOWN); | 486 DOWNLOAD_INTERRUPT_REASON_USER_SHUTDOWN); |
| 487 | 487 |
| 488 const GURL& url = request->original_url(); | 488 const GURL& url = request->original_url(); |
| 489 | 489 |
| 490 // http://crbug.com/90971 | 490 // http://crbug.com/90971 |
| 491 char url_buf[128]; | 491 char url_buf[128]; |
| 492 base::strlcpy(url_buf, url.spec().c_str(), arraysize(url_buf)); | 492 base::strlcpy(url_buf, url.spec().c_str(), arraysize(url_buf)); |
| 493 base::debug::Alias(url_buf); | 493 base::debug::Alias(url_buf); |
| 494 CHECK(ContainsKey(active_resource_contexts_, context)); | 494 CHECK(ContainsKey(active_resource_contexts_, context)); |
| 495 | 495 |
| 496 SetReferrerForRequest(request.get(), referrer); | 496 // Callers which create programmatic downloads do not necessarily sanitize |
| 497 // the referrer, so do it here in a centralized location. | |
| 498 Referrer sanitized_referrer = SanitizeReferrerForRequest(request->url(), | |
| 499 referrer); | |
| 500 SetReferrerForRequest(request.get(), sanitized_referrer); | |
| 497 | 501 |
| 498 int extra_load_flags = net::LOAD_IS_DOWNLOAD; | 502 int extra_load_flags = net::LOAD_IS_DOWNLOAD; |
| 499 if (prefer_cache) { | 503 if (prefer_cache) { |
| 500 // If there is upload data attached, only retrieve from cache because there | 504 // If there is upload data attached, only retrieve from cache because there |
| 501 // is no current mechanism to prompt the user for their consent for a | 505 // is no current mechanism to prompt the user for their consent for a |
| 502 // re-post. For GETs, try to retrieve data from the cache and skip | 506 // re-post. For GETs, try to retrieve data from the cache and skip |
| 503 // validating the entry if present. | 507 // validating the entry if present. |
| 504 if (request->get_upload() != NULL) | 508 if (request->get_upload() != NULL) |
| 505 extra_load_flags |= net::LOAD_ONLY_FROM_CACHE; | 509 extra_load_flags |= net::LOAD_ONLY_FROM_CACHE; |
| 506 else | 510 else |
| (...skipping 884 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1391 return; | 1395 return; |
| 1392 } | 1396 } |
| 1393 | 1397 |
| 1394 net::CookieStore* cookie_store = | 1398 net::CookieStore* cookie_store = |
| 1395 GetContentClient()->browser()->OverrideCookieStoreForRenderProcess( | 1399 GetContentClient()->browser()->OverrideCookieStoreForRenderProcess( |
| 1396 child_id); | 1400 child_id); |
| 1397 scoped_ptr<net::URLRequest> request( | 1401 scoped_ptr<net::URLRequest> request( |
| 1398 request_context->CreateRequest(url, net::DEFAULT_PRIORITY, NULL, | 1402 request_context->CreateRequest(url, net::DEFAULT_PRIORITY, NULL, |
| 1399 cookie_store)); | 1403 cookie_store)); |
| 1400 | 1404 |
| 1401 request->set_method("GET"); | |
| 1402 SetReferrerForRequest(request.get(), referrer); | 1405 SetReferrerForRequest(request.get(), referrer); |
| 1403 | 1406 |
| 1404 // So far, for saving page, we need fetch content from cache, in the | 1407 // So far, for saving page, we need fetch content from cache, in the |
| 1405 // future, maybe we can use a configuration to configure this behavior. | 1408 // future, maybe we can use a configuration to configure this behavior. |
| 1406 request->SetLoadFlags(net::LOAD_PREFERRING_CACHE); | 1409 request->SetLoadFlags(net::LOAD_PREFERRING_CACHE); |
| 1407 | 1410 |
| 1408 // No need to get offline load flags for save files, but make sure | 1411 // No need to get offline load flags for save files, but make sure |
| 1409 // we have an OfflinePolicy to receive request completions. | 1412 // we have an OfflinePolicy to receive request completions. |
| 1410 GlobalRoutingID id(child_id, route_id); | 1413 GlobalRoutingID id(child_id, route_id); |
| 1411 if (!offline_policy_map_[id]) | 1414 if (!offline_policy_map_[id]) |
| (...skipping 621 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2033 // allow requesting them if requester has ReadRawCookies permission. | 2036 // allow requesting them if requester has ReadRawCookies permission. |
| 2034 if ((load_flags & net::LOAD_REPORT_RAW_HEADERS) | 2037 if ((load_flags & net::LOAD_REPORT_RAW_HEADERS) |
| 2035 && !policy->CanReadRawCookies(child_id)) { | 2038 && !policy->CanReadRawCookies(child_id)) { |
| 2036 VLOG(1) << "Denied unauthorized request for raw headers"; | 2039 VLOG(1) << "Denied unauthorized request for raw headers"; |
| 2037 load_flags &= ~net::LOAD_REPORT_RAW_HEADERS; | 2040 load_flags &= ~net::LOAD_REPORT_RAW_HEADERS; |
| 2038 } | 2041 } |
| 2039 | 2042 |
| 2040 return load_flags; | 2043 return load_flags; |
| 2041 } | 2044 } |
| 2042 | 2045 |
| 2046 Referrer SanitizeReferrerForRequest(const GURL& request, | |
|
jochen (gone - plz use gerrit)
2014/05/14 08:32:19
maybe that should be on content::Referrer (a stati
| |
| 2047 const Referrer& referrer) { | |
| 2048 Referrer sanitized_referrer; | |
| 2049 sanitized_referrer.url = referrer.url.GetAsReferrer(); | |
| 2050 sanitized_referrer.policy = referrer.policy; | |
| 2051 switch (sanitized_referrer.policy) { | |
| 2052 case blink::WebReferrerPolicyDefault: | |
| 2053 if (sanitized_referrer.url.SchemeIsSecure() && | |
| 2054 !request.SchemeIsSecure()) { | |
| 2055 sanitized_referrer.url = GURL(); | |
| 2056 } | |
| 2057 break; | |
| 2058 case blink::WebReferrerPolicyAlways: | |
| 2059 break; | |
| 2060 case blink::WebReferrerPolicyNever: | |
| 2061 sanitized_referrer.url = GURL(); | |
| 2062 break; | |
| 2063 case blink::WebReferrerPolicyOrigin: | |
| 2064 sanitized_referrer.url = sanitized_referrer.url.GetOrigin(); | |
| 2065 break; | |
| 2066 default: | |
| 2067 NOTREACHED(); | |
| 2068 break; | |
| 2069 } | |
| 2070 return sanitized_referrer; | |
| 2071 } | |
| 2072 | |
| 2043 } // namespace content | 2073 } // namespace content |
| OLD | NEW |