Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(20)

Side by Side Diff: third_party/WebKit/Source/core/fetch/ResourceFetcher.cpp

Issue 1975373002: Clean up response handling in ResourceLoader/ResourceFetcher (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 Copyright (C) 1998 Lars Knoll (knoll@mpi-hd.mpg.de) 2 Copyright (C) 1998 Lars Knoll (knoll@mpi-hd.mpg.de)
3 Copyright (C) 2001 Dirk Mueller (mueller@kde.org) 3 Copyright (C) 2001 Dirk Mueller (mueller@kde.org)
4 Copyright (C) 2002 Waldo Bastian (bastian@kde.org) 4 Copyright (C) 2002 Waldo Bastian (bastian@kde.org)
5 Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserved. 5 Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserved.
6 Copyright (C) 2009 Torch Mobile Inc. http://www.torchmobile.com/ 6 Copyright (C) 2009 Torch Mobile Inc. http://www.torchmobile.com/
7 7
8 This library is free software; you can redistribute it and/or 8 This library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Library General Public 9 modify it under the terms of the GNU Library General Public
10 License as published by the Free Software Foundation; either 10 License as published by the Free Software Foundation; either
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 { 232 {
233 } 233 }
234 234
235 Resource* ResourceFetcher::cachedResource(const KURL& resourceURL) const 235 Resource* ResourceFetcher::cachedResource(const KURL& resourceURL) const
236 { 236 {
237 KURL url = MemoryCache::removeFragmentIdentifierIfNeeded(resourceURL); 237 KURL url = MemoryCache::removeFragmentIdentifierIfNeeded(resourceURL);
238 const WeakMember<Resource>& resource = m_documentResources.get(url); 238 const WeakMember<Resource>& resource = m_documentResources.get(url);
239 return resource.get(); 239 return resource.get();
240 } 240 }
241 241
242 bool ResourceFetcher::canAccessResource(Resource* resource, SecurityOrigin* sour ceOrigin, const KURL& url, AccessControlLoggingDecision logErrorsDecision) const 242 bool ResourceFetcher::canAccessResponse(Resource* resource, const ResourceRespon se& response) const
hiroshige 2016/07/28 09:56:42 This CL removes AccessControlLoggingDecision becau
Nate Chapin 2016/07/28 22:29:35 Ok, will do.
243 { 243 {
244 // Redirects can change the response URL different from one of request. 244 // Redirects can change the response URL different from one of request.
245 bool forPreload = resource->isUnusedPreload(); 245 bool forPreload = resource->isUnusedPreload();
246 if (!context().canRequest(resource->getType(), resource->resourceRequest(), url, resource->options(), forPreload, FetchRequest::UseDefaultOriginRestrictionF orType)) 246 if (!context().canRequest(resource->getType(), resource->resourceRequest(), response.url(), resource->options(), forPreload, FetchRequest::UseDefaultOriginR estrictionForType))
247 return false; 247 return false;
248 248
249 SecurityOrigin* sourceOrigin = resource->options().securityOrigin.get();
249 if (!sourceOrigin) 250 if (!sourceOrigin)
250 sourceOrigin = context().getSecurityOrigin(); 251 sourceOrigin = context().getSecurityOrigin();
251 252
252 if (sourceOrigin->canRequestNoSuborigin(url)) 253 if (sourceOrigin->canRequestNoSuborigin(response.url()))
253 return true; 254 return true;
254 255
256 // Use the original response instead of the 304 response for a successful re valdiation.
257 const ResourceResponse& responseForAccessControl = response.httpStatusCode() == 304 ? resource->response() : response;
hiroshige 2016/07/28 09:56:42 We need to check m_resource->isCacheValidator() he
Nate Chapin 2016/07/28 22:29:35 Oops, I don't remember dropping that. Done.
255 String errorDescription; 258 String errorDescription;
256 if (!resource->passesAccessControlCheck(sourceOrigin, errorDescription)) { 259 if (!passesAccessControlCheck(responseForAccessControl, resource->options(). allowCredentials, sourceOrigin, errorDescription, resource->lastResourceRequest( ).requestContext())) {
hiroshige 2016/07/28 09:56:42 This replaces ResourceRequest::allowStoredCredenti
hiroshige 2016/07/28 09:56:42 Memo: This inlines Resource::passesAccessControlCh
Nate Chapin 2016/07/28 22:29:35 Also, see comment about setReponse() call in Resou
Nate Chapin 2016/07/28 22:29:35 That may make sense, but some places don't use the
257 resource->setCORSFailed(); 260 resource->setCORSFailed();
258 if (!forPreload && (logErrorsDecision == ShouldLogAccessControlErrors)) { 261 if (!forPreload) {
259 String resourceType = Resource::resourceTypeToString(resource->getTy pe(), resource->options().initiatorInfo); 262 String resourceType = Resource::resourceTypeToString(resource->getTy pe(), resource->options().initiatorInfo);
260 context().addConsoleMessage(resourceType + " from origin '" + Securi tyOrigin::create(url)->toString() + "' has been blocked from loading by Cross-Or igin Resource Sharing policy: " + errorDescription); 263 context().addConsoleMessage(resourceType + " from origin '" + Securi tyOrigin::create(response.url())->toString() + "' has been blocked from loading by Cross-Origin Resource Sharing policy: " + errorDescription);
261 } 264 }
262 return false; 265 return false;
263 } 266 }
264 return true; 267 return true;
265 } 268 }
266 269
267 bool ResourceFetcher::isControlledByServiceWorker() const 270 bool ResourceFetcher::isControlledByServiceWorker() const
268 { 271 {
269 return context().isControlledByServiceWorker(); 272 return context().isControlledByServiceWorker();
270 } 273 }
(...skipping 667 matching lines...) Expand 10 before | Expand all | Expand 10 after
938 { 941 {
939 TRACE_EVENT_ASYNC_END0("blink.net", "Resource", resource->identifier()); 942 TRACE_EVENT_ASYNC_END0("blink.net", "Resource", resource->identifier());
940 removeResourceLoader(resource->loader()); 943 removeResourceLoader(resource->loader());
941 m_resourceTimingInfoMap.take(const_cast<Resource*>(resource)); 944 m_resourceTimingInfoMap.take(const_cast<Resource*>(resource));
942 bool isInternalRequest = resource->options().initiatorInfo.name == FetchInit iatorTypeNames::internal; 945 bool isInternalRequest = resource->options().initiatorInfo.name == FetchInit iatorTypeNames::internal;
943 context().dispatchDidFail(resource->identifier(), error, isInternalRequest); 946 context().dispatchDidFail(resource->identifier(), error, isInternalRequest);
944 resource->error(error); 947 resource->error(error);
945 context().didLoadResource(resource); 948 context().didLoadResource(resource);
946 } 949 }
947 950
948 void ResourceFetcher::didReceiveResponse(Resource* resource, const ResourceRespo nse& response) 951 bool ResourceFetcher::didReceiveResponse(Resource* resource, const ResourceRespo nse& response)
949 { 952 {
950 // If the response is fetched via ServiceWorker, the original URL of the res ponse could be different from the URL of the request. 953 context().dispatchDidReceiveResponse(resource->identifier(), response, resou rce->resourceRequest().frameType(), resource->resourceRequest().requestContext() , resource);
951 // We check the URL not to load the resources which are forbidden by the pag e CSP. 954
952 // https://w3c.github.io/webappsec-csp/#should-block-response
953 if (response.wasFetchedViaServiceWorker()) { 955 if (response.wasFetchedViaServiceWorker()) {
956 if (resource->options().corsEnabled == IsCORSEnabled && response.wasFall backRequiredByServiceWorker()) {
hiroshige 2016/07/28 09:56:42 memo for myself: this block is moved from the call
957 ResourceRequest request = resource->lastResourceRequest();
958 DCHECK_EQ(request.skipServiceWorker(), WebURLRequest::SkipServiceWor ker::None);
959 // This code handles the case when a regular controlling service wor ker
960 // doesn't handle a cross origin request. When this happens we still
961 // want to give foreign fetch a chance to handle the request, so
962 // only skip the controlling service worker for the fallback request .
963 // This is currently safe because of http://crbug.com/604084 the
964 // wasFallbackRequiredByServiceWorker flag is never set when foreign fetch
965 // handled a request.
966 request.setSkipServiceWorker(WebURLRequest::SkipServiceWorker::Contr olling);
967 resource->loader()->restart(request);
968 return false;
969 }
970
971 // If the response is fetched via ServiceWorker, the original URL of the response could be different from the URL of the request.
972 // We check the URL not to load the resources which are forbidden by the page CSP.
973 // https://w3c.github.io/webappsec-csp/#should-block-response
954 const KURL& originalURL = response.originalURLViaServiceWorker(); 974 const KURL& originalURL = response.originalURLViaServiceWorker();
955 if (!originalURL.isEmpty() && !context().allowResponse(resource->getType (), resource->resourceRequest(), originalURL, resource->options())) { 975 if (!originalURL.isEmpty() && !context().allowResponse(resource->getType (), resource->resourceRequest(), originalURL, resource->options())) {
956 resource->loader()->cancel(); 976 resource->loader()->didFail(nullptr, ResourceError::cancelledDueToAc cessCheckError(response.url()));
957 bool isInternalRequest = resource->options().initiatorInfo.name == F etchInitiatorTypeNames::internal; 977 return false;
958 context().dispatchDidFail(resource->identifier(), ResourceError(erro rDomainBlinkInternal, 0, originalURL.getString(), "Unsafe attempt to load URL " + originalURL.elidedString() + " fetched by a ServiceWorker."), isInternalReques t);
959 return;
960 } 978 }
979 } else if (resource->options().corsEnabled == IsCORSEnabled && !canAccessRes ponse(resource, response)) {
980 resource->loader()->didFail(nullptr, ResourceError::cancelledDueToAccess CheckError(response.url()));
981 return false;
961 } 982 }
962 context().dispatchDidReceiveResponse(resource->identifier(), response, resou rce->resourceRequest().frameType(), resource->resourceRequest().requestContext() , resource); 983 return true;
963 } 984 }
964 985
965 void ResourceFetcher::didReceiveData(const Resource* resource, const char* data, int dataLength, int encodedDataLength) 986 void ResourceFetcher::didReceiveData(const Resource* resource, const char* data, int dataLength, int encodedDataLength)
966 { 987 {
967 context().dispatchDidReceiveData(resource->identifier(), data, dataLength, e ncodedDataLength); 988 context().dispatchDidReceiveData(resource->identifier(), data, dataLength, e ncodedDataLength);
968 } 989 }
969 990
970 void ResourceFetcher::didDownloadData(const Resource* resource, int dataLength, int encodedDataLength) 991 void ResourceFetcher::didDownloadData(const Resource* resource, int dataLength, int encodedDataLength)
971 { 992 {
972 context().dispatchDidDownloadData(resource->identifier(), dataLength, encode dDataLength); 993 context().dispatchDidDownloadData(resource->identifier(), dataLength, encode dDataLength);
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after
1272 visitor->trace(m_context); 1293 visitor->trace(m_context);
1273 visitor->trace(m_archive); 1294 visitor->trace(m_archive);
1274 visitor->trace(m_loaders); 1295 visitor->trace(m_loaders);
1275 visitor->trace(m_nonBlockingLoaders); 1296 visitor->trace(m_nonBlockingLoaders);
1276 visitor->trace(m_documentResources); 1297 visitor->trace(m_documentResources);
1277 visitor->trace(m_preloads); 1298 visitor->trace(m_preloads);
1278 visitor->trace(m_resourceTimingInfoMap); 1299 visitor->trace(m_resourceTimingInfoMap);
1279 } 1300 }
1280 1301
1281 } // namespace blink 1302 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698