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

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

Issue 1757633005: Don't duplicate ResourceRequests and ResourceLoaderOptions on ResourceLoader (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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 749 matching lines...) Expand 10 before | Expand all | Expand 10 after
760 // it is a font that defers actually loading until the font is required. On the other hand, 760 // it is a font that defers actually loading until the font is required. On the other hand,
761 // a Resource can have a non-null ResourceLoader* but have isLoading() r eturn false in a narrow window 761 // a Resource can have a non-null ResourceLoader* but have isLoading() r eturn false in a narrow window
762 // during completion, because we set loading to false before notifying R esourceClients, but don't 762 // during completion, because we set loading to false before notifying R esourceClients, but don't
763 // clear the ResourceLoader pointer until the stack unwinds. If, inside the ResourceClient callbacks, 763 // clear the ResourceLoader pointer until the stack unwinds. If, inside the ResourceClient callbacks,
764 // an event fires synchronously and an event handler re-requests the res ource, we can reach this point 764 // an event fires synchronously and an event handler re-requests the res ource, we can reach this point
765 // while not loading but having a ResourceLoader. 765 // while not loading but having a ResourceLoader.
766 if (existingResource->isLoading() || existingResource->loader()) 766 if (existingResource->isLoading() || existingResource->loader())
767 return Use; 767 return Use;
768 } 768 }
769 769
770 // Don't try to reuse an in-progress async request for a new sync request.
771 if (fetchRequest.options().synchronousPolicy == RequestSynchronously && exis tingResource->isLoading())
hiroshige 2016/03/10 00:24:38 This doesn't Reload in non-RawResource cases, beca
Nate Chapin 2016/03/10 18:46:01 Bumped priority up so that the only higher priorit
772 return Reload;
773
770 // CachePolicyReload always reloads 774 // CachePolicyReload always reloads
771 if (cachePolicy == CachePolicyReload) { 775 if (cachePolicy == CachePolicyReload) {
772 WTF_LOG(ResourceLoading, "ResourceFetcher::determineRevalidationPolicy r eloading due to CachePolicyReload."); 776 WTF_LOG(ResourceLoading, "ResourceFetcher::determineRevalidationPolicy r eloading due to CachePolicyReload.");
773 return Reload; 777 return Reload;
774 } 778 }
775 779
776 // We'll try to reload the resource if it failed last time. 780 // We'll try to reload the resource if it failed last time.
777 if (existingResource->errorOccurred()) { 781 if (existingResource->errorOccurred()) {
778 WTF_LOG(ResourceLoading, "ResourceFetcher::determineRevalidationPolicye reloading due to resource being in the error state"); 782 WTF_LOG(ResourceLoading, "ResourceFetcher::determineRevalidationPolicye reloading due to resource being in the error state");
779 return Reload; 783 return Reload;
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
851 // TODO(japhet): Once oilpan ships, the const auto& 855 // TODO(japhet): Once oilpan ships, the const auto&
852 // can be replaced with a Resource*. Also, null checking 856 // can be replaced with a Resource*. Also, null checking
853 // the resource probably won't be necesssary. 857 // the resource probably won't be necesssary.
854 for (const auto& documentResource : m_documentResources) { 858 for (const auto& documentResource : m_documentResources) {
855 Resource* resource = documentResource.value.get(); 859 Resource* resource = documentResource.value.get();
856 if (resource && resource->getType() == Resource::Image && resource->stil lNeedsLoad() && !clientDefersImage(resource->url())) 860 if (resource && resource->getType() == Resource::Image && resource->stil lNeedsLoad() && !clientDefersImage(resource->url()))
857 const_cast<Resource*>(resource)->load(this, defaultResourceOptions() ); 861 const_cast<Resource*>(resource)->load(this, defaultResourceOptions() );
858 } 862 }
859 } 863 }
860 864
861 void ResourceFetcher::redirectReceived(Resource* resource, const ResourceRespons e& redirectResponse)
862 {
863 ResourceTimingInfoMap::iterator it = m_resourceTimingInfoMap.find(resource);
864 if (it != m_resourceTimingInfoMap.end())
865 it->value->addRedirect(redirectResponse);
866 }
867
868 void ResourceFetcher::didLoadResource(Resource* resource) 865 void ResourceFetcher::didLoadResource(Resource* resource)
869 { 866 {
870 context().didLoadResource(resource); 867 context().didLoadResource(resource);
871 } 868 }
872 869
873 int ResourceFetcher::requestCount() const 870 int ResourceFetcher::requestCount() const
874 { 871 {
875 return m_loaders ? m_loaders->size() : 0; 872 return m_loaders ? m_loaders->size() : 0;
876 } 873 }
877 874
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
971 } 968 }
972 969
973 void ResourceFetcher::didFailLoading(const Resource* resource, const ResourceErr or& error) 970 void ResourceFetcher::didFailLoading(const Resource* resource, const ResourceErr or& error)
974 { 971 {
975 TRACE_EVENT_ASYNC_END0("blink.net", "Resource", resource); 972 TRACE_EVENT_ASYNC_END0("blink.net", "Resource", resource);
976 willTerminateResourceLoader(resource->loader()); 973 willTerminateResourceLoader(resource->loader());
977 bool isInternalRequest = resource->options().initiatorInfo.name == FetchInit iatorTypeNames::internal; 974 bool isInternalRequest = resource->options().initiatorInfo.name == FetchInit iatorTypeNames::internal;
978 context().dispatchDidFail(resource->identifier(), error, isInternalRequest); 975 context().dispatchDidFail(resource->identifier(), error, isInternalRequest);
979 } 976 }
980 977
981 void ResourceFetcher::willSendRequest(unsigned long identifier, ResourceRequest& request, const ResourceResponse& redirectResponse, const FetchInitiatorInfo& in itiatorInfo)
982 {
983 context().dispatchWillSendRequest(identifier, request, redirectResponse, ini tiatorInfo);
984 }
985
986 void ResourceFetcher::didReceiveResponse(const Resource* resource, const Resourc eResponse& response) 978 void ResourceFetcher::didReceiveResponse(const Resource* resource, const Resourc eResponse& response)
987 { 979 {
988 // If the response is fetched via ServiceWorker, the original URL of the res ponse could be different from the URL of the request. 980 // If the response is fetched via ServiceWorker, the original URL of the res ponse could be different from the URL of the request.
989 // We check the URL not to load the resources which are forbidden by the pag e CSP. 981 // We check the URL not to load the resources which are forbidden by the pag e CSP.
990 // https://w3c.github.io/webappsec-csp/#should-block-response 982 // https://w3c.github.io/webappsec-csp/#should-block-response
991 if (response.wasFetchedViaServiceWorker()) { 983 if (response.wasFetchedViaServiceWorker()) {
992 const KURL& originalURL = response.originalURLViaServiceWorker(); 984 const KURL& originalURL = response.originalURLViaServiceWorker();
993 if (!originalURL.isEmpty() && !context().allowResponse(resource->getType (), resource->resourceRequest(), originalURL, resource->options())) { 985 if (!originalURL.isEmpty() && !context().allowResponse(resource->getType (), resource->resourceRequest(), originalURL, resource->options())) {
994 resource->loader()->cancel(); 986 resource->loader()->cancel();
995 bool isInternalRequest = resource->options().initiatorInfo.name == F etchInitiatorTypeNames::internal; 987 bool isInternalRequest = resource->options().initiatorInfo.name == F etchInitiatorTypeNames::internal;
(...skipping 21 matching lines...) Expand all
1017 1009
1018 void ResourceFetcher::subresourceLoaderFinishedLoadingOnePart(ResourceLoader* lo ader) 1010 void ResourceFetcher::subresourceLoaderFinishedLoadingOnePart(ResourceLoader* lo ader)
1019 { 1011 {
1020 if (!m_nonBlockingLoaders) 1012 if (!m_nonBlockingLoaders)
1021 m_nonBlockingLoaders = ResourceLoaderSet::create(); 1013 m_nonBlockingLoaders = ResourceLoaderSet::create();
1022 m_nonBlockingLoaders->add(loader); 1014 m_nonBlockingLoaders->add(loader);
1023 m_loaders->remove(loader); 1015 m_loaders->remove(loader);
1024 didLoadResource(loader->cachedResource()); 1016 didLoadResource(loader->cachedResource());
1025 } 1017 }
1026 1018
1027 void ResourceFetcher::didInitializeResourceLoader(ResourceLoader* loader) 1019 void ResourceFetcher::willStartLoadingResource(Resource* resource, ResourceLoade r* loader, ResourceRequest& request)
1028 { 1020 {
1029 if (loader->cachedResource()->shouldBlockLoadEvent()) { 1021 if (loader->cachedResource()->shouldBlockLoadEvent()) {
1030 if (!m_loaders) 1022 if (!m_loaders)
1031 m_loaders = ResourceLoaderSet::create(); 1023 m_loaders = ResourceLoaderSet::create();
1032 m_loaders->add(loader); 1024 m_loaders->add(loader);
1033 } else { 1025 } else {
1034 if (!m_nonBlockingLoaders) 1026 if (!m_nonBlockingLoaders)
1035 m_nonBlockingLoaders = ResourceLoaderSet::create(); 1027 m_nonBlockingLoaders = ResourceLoaderSet::create();
1036 m_nonBlockingLoaders->add(loader); 1028 m_nonBlockingLoaders->add(loader);
1037 } 1029 }
1030
1031 context().willStartLoadingResource(request);
1032 storeResourceTimingInitiatorInformation(resource);
1033 TRACE_EVENT_ASYNC_BEGIN2("blink.net", "Resource", resource, "url", resource- >url().getString().ascii(), "priority", resource->resourceRequest().priority());
1034
1035 context().dispatchWillSendRequest(resource->identifier(), request, ResourceR esponse(), resource->options().initiatorInfo);
1038 } 1036 }
1039 1037
1040 void ResourceFetcher::willTerminateResourceLoader(ResourceLoader* loader) 1038 void ResourceFetcher::willTerminateResourceLoader(ResourceLoader* loader)
1041 { 1039 {
1042 if (m_loaders && m_loaders->contains(loader)) 1040 if (m_loaders && m_loaders->contains(loader))
1043 m_loaders->remove(loader); 1041 m_loaders->remove(loader);
1044 else if (m_nonBlockingLoaders && m_nonBlockingLoaders->contains(loader)) 1042 else if (m_nonBlockingLoaders && m_nonBlockingLoaders->contains(loader))
1045 m_nonBlockingLoaders->remove(loader); 1043 m_nonBlockingLoaders->remove(loader);
1046 else 1044 else
1047 ASSERT_NOT_REACHED(); 1045 ASSERT_NOT_REACHED();
1048 } 1046 }
1049 1047
1050 void ResourceFetcher::willStartLoadingResource(Resource* resource, ResourceReque st& request)
1051 {
1052 context().willStartLoadingResource(request);
1053 storeResourceTimingInitiatorInformation(resource);
1054 TRACE_EVENT_ASYNC_BEGIN2("blink.net", "Resource", resource, "url", resource- >url().getString().ascii(), "priority", resource->resourceRequest().priority());
1055 }
1056
1057 void ResourceFetcher::stopFetching() 1048 void ResourceFetcher::stopFetching()
1058 { 1049 {
1059 if (m_nonBlockingLoaders) 1050 if (m_nonBlockingLoaders)
1060 m_nonBlockingLoaders->cancelAll(); 1051 m_nonBlockingLoaders->cancelAll();
1061 if (m_loaders) 1052 if (m_loaders)
1062 m_loaders->cancelAll(); 1053 m_loaders->cancelAll();
1063 } 1054 }
1064 1055
1065 bool ResourceFetcher::isFetching() const 1056 bool ResourceFetcher::isFetching() const
1066 { 1057 {
1067 return m_loaders && !m_loaders->isEmpty(); 1058 return m_loaders && !m_loaders->isEmpty();
1068 } 1059 }
1069 1060
1070 void ResourceFetcher::setDefersLoading(bool defers) 1061 void ResourceFetcher::setDefersLoading(bool defers)
1071 { 1062 {
1072 if (m_loaders) 1063 if (m_loaders)
1073 m_loaders->setAllDefersLoading(defers); 1064 m_loaders->setAllDefersLoading(defers);
1074 if (m_nonBlockingLoaders) 1065 if (m_nonBlockingLoaders)
1075 m_nonBlockingLoaders->setAllDefersLoading(defers); 1066 m_nonBlockingLoaders->setAllDefersLoading(defers);
1076 } 1067 }
1077 1068
1078 bool ResourceFetcher::defersLoading() const 1069 bool ResourceFetcher::defersLoading() const
1079 { 1070 {
1080 return context().defersLoading(); 1071 return context().defersLoading();
1081 } 1072 }
1082 1073
1083 bool ResourceFetcher::canAccessRedirect(Resource* resource, ResourceRequest& new Request, const ResourceResponse& redirectResponse, ResourceLoaderOptions& option s) 1074 static bool isManualRedirectFetchRequest(const ResourceRequest& request)
Nate Chapin 2016/03/09 22:35:54 I'm not sure whether it's better to merge canAcces
1084 { 1075 {
1085 if (!context().canRequest(resource->getType(), newRequest, newRequest.url(), options, resource->isUnusedPreload(), FetchRequest::UseDefaultOriginRestriction ForType)) 1076 return request.fetchRedirectMode() == WebURLRequest::FetchRedirectModeManual && request.requestContext() == WebURLRequest::RequestContextFetch;
1086 return false; 1077 }
1087 if (options.corsEnabled == IsCORSEnabled) {
1088 SecurityOrigin* sourceOrigin = options.securityOrigin.get();
1089 if (!sourceOrigin)
1090 sourceOrigin = context().securityOrigin();
1091 1078
1092 String errorMessage; 1079 bool ResourceFetcher::willFollowRedirect(Resource* resource, ResourceRequest& ne wRequest, const ResourceResponse& redirectResponse)
1093 StoredCredentials withCredentials = resource->lastResourceRequest().allo wStoredCredentials() ? AllowStoredCredentials : DoNotAllowStoredCredentials; 1080 {
1094 if (!CrossOriginAccessControl::handleRedirect(sourceOrigin, newRequest, redirectResponse, withCredentials, options, errorMessage)) { 1081 if (!isManualRedirectFetchRequest(resource->resourceRequest())) {
1095 resource->setCORSFailed(); 1082 if (!context().canRequest(resource->getType(), newRequest, newRequest.ur l(), resource->options(), resource->isUnusedPreload(), FetchRequest::UseDefaultO riginRestrictionForType))
1096 context().addConsoleMessage(errorMessage);
1097 return false; 1083 return false;
1084 if (resource->options().corsEnabled == IsCORSEnabled) {
1085 SecurityOrigin* sourceOrigin = resource->options().securityOrigin.ge t();
1086 if (!sourceOrigin)
1087 sourceOrigin = context().securityOrigin();
1088
1089 String errorMessage;
1090 StoredCredentials withCredentials = resource->lastResourceRequest(). allowStoredCredentials() ? AllowStoredCredentials : DoNotAllowStoredCredentials;
1091 if (!CrossOriginAccessControl::handleRedirect(sourceOrigin, newReque st, redirectResponse, withCredentials, resource->mutableOptions(), errorMessage) ) {
1092 resource->setCORSFailed();
1093 context().addConsoleMessage(errorMessage);
1094 return false;
1095 }
1098 } 1096 }
1097 if (resource->getType() == Resource::Image && shouldDeferImageLoad(newRe quest.url()))
1098 return false;
1099 } 1099 }
1100 if (resource->getType() == Resource::Image && shouldDeferImageLoad(newReques t.url())) 1100
1101 return false; 1101 ResourceTimingInfoMap::iterator it = m_resourceTimingInfoMap.find(resource);
1102 if (it != m_resourceTimingInfoMap.end())
1103 it->value->addRedirect(redirectResponse);
1104 context().dispatchWillSendRequest(resource->identifier(), newRequest, redire ctResponse, resource->options().initiatorInfo);
1102 return true; 1105 return true;
1103 } 1106 }
1104 1107
1105 void ResourceFetcher::updateAllImageResourcePriorities() 1108 void ResourceFetcher::updateAllImageResourcePriorities()
1106 { 1109 {
1107 if (!m_loaders) 1110 if (!m_loaders)
1108 return; 1111 return;
1109 1112
1110 TRACE_EVENT0("blink", "ResourceLoadPriorityOptimizer::updateAllImageResource Priorities"); 1113 TRACE_EVENT0("blink", "ResourceLoadPriorityOptimizer::updateAllImageResource Priorities");
1111 for (const auto& loader : m_loaders->hashSet()) { 1114 for (const auto& loader : m_loaders->hashSet()) {
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
1240 visitor->trace(m_loaders); 1243 visitor->trace(m_loaders);
1241 visitor->trace(m_nonBlockingLoaders); 1244 visitor->trace(m_nonBlockingLoaders);
1242 #if ENABLE(OILPAN) 1245 #if ENABLE(OILPAN)
1243 visitor->trace(m_documentResources); 1246 visitor->trace(m_documentResources);
1244 visitor->trace(m_preloads); 1247 visitor->trace(m_preloads);
1245 visitor->trace(m_resourceTimingInfoMap); 1248 visitor->trace(m_resourceTimingInfoMap);
1246 #endif 1249 #endif
1247 } 1250 }
1248 1251
1249 } // namespace blink 1252 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/fetch/ResourceFetcher.h ('k') | third_party/WebKit/Source/core/fetch/ResourceLoader.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698