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

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

Issue 2316573002: PlzNavigate: Support ResourceTiming API (Closed)
Patch Set: Support resourceLoadInfo (encodedDataLength) Created 4 years, 3 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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 DEFINE_SINGLE_RESOURCE_HISTOGRAM(prefix, MainResource) \ 85 DEFINE_SINGLE_RESOURCE_HISTOGRAM(prefix, MainResource) \
86 DEFINE_SINGLE_RESOURCE_HISTOGRAM(prefix, Manifest) \ 86 DEFINE_SINGLE_RESOURCE_HISTOGRAM(prefix, Manifest) \
87 DEFINE_SINGLE_RESOURCE_HISTOGRAM(prefix, Media) \ 87 DEFINE_SINGLE_RESOURCE_HISTOGRAM(prefix, Media) \
88 DEFINE_SINGLE_RESOURCE_HISTOGRAM(prefix, Raw) \ 88 DEFINE_SINGLE_RESOURCE_HISTOGRAM(prefix, Raw) \
89 DEFINE_SINGLE_RESOURCE_HISTOGRAM(prefix, Script) \ 89 DEFINE_SINGLE_RESOURCE_HISTOGRAM(prefix, Script) \
90 DEFINE_SINGLE_RESOURCE_HISTOGRAM(prefix, SVGDocument) \ 90 DEFINE_SINGLE_RESOURCE_HISTOGRAM(prefix, SVGDocument) \
91 DEFINE_SINGLE_RESOURCE_HISTOGRAM(prefix, TextTrack) \ 91 DEFINE_SINGLE_RESOURCE_HISTOGRAM(prefix, TextTrack) \
92 DEFINE_SINGLE_RESOURCE_HISTOGRAM(prefix, XSLStyleSheet) \ 92 DEFINE_SINGLE_RESOURCE_HISTOGRAM(prefix, XSLStyleSheet) \
93 } 93 }
94 94
95 bool IsCrossOrigin(const KURL& a, const KURL& b)
96 {
97 RefPtr<SecurityOrigin> originA = SecurityOrigin::create(a);
98 RefPtr<SecurityOrigin> originB = SecurityOrigin::create(b);
99 return !originB->isSameSchemeHostPort(originA.get());
100 }
101
95 } // namespace 102 } // namespace
96 103
97 static void RecordSriResourceIntegrityMismatchEvent(SriResourceIntegrityMismatch Event event) 104 static void RecordSriResourceIntegrityMismatchEvent(SriResourceIntegrityMismatch Event event)
98 { 105 {
99 DEFINE_THREAD_SAFE_STATIC_LOCAL(EnumerationHistogram, integrityHistogram, ne w EnumerationHistogram("sri.resource_integrity_mismatch_event", SriResourceInteg rityMismatchEventCount)); 106 DEFINE_THREAD_SAFE_STATIC_LOCAL(EnumerationHistogram, integrityHistogram, ne w EnumerationHistogram("sri.resource_integrity_mismatch_event", SriResourceInteg rityMismatchEventCount));
100 integrityHistogram.count(event); 107 integrityHistogram.count(event);
101 } 108 }
102 109
103 static ResourceLoadPriority typeToPriority(Resource::Type type) 110 static ResourceLoadPriority typeToPriority(Resource::Type type)
104 { 111 {
(...skipping 496 matching lines...) Expand 10 before | Expand all | Expand 10 after
601 return resource; 608 return resource;
602 } 609 }
603 610
604 void ResourceFetcher::storeResourceTimingInitiatorInformation(Resource* resource ) 611 void ResourceFetcher::storeResourceTimingInitiatorInformation(Resource* resource )
605 { 612 {
606 const AtomicString& fetchInitiator = resource->options().initiatorInfo.name; 613 const AtomicString& fetchInitiator = resource->options().initiatorInfo.name;
607 if (fetchInitiator == FetchInitiatorTypeNames::internal) 614 if (fetchInitiator == FetchInitiatorTypeNames::internal)
608 return; 615 return;
609 616
610 bool isMainResource = resource->getType() == Resource::MainResource; 617 bool isMainResource = resource->getType() == Resource::MainResource;
611 std::unique_ptr<ResourceTimingInfo> info = ResourceTimingInfo::create(fetchI nitiator, monotonicallyIncreasingTime(), isMainResource); 618 double startTime = monotonicallyIncreasingTime();
619
620 // The request can already be fetched in a previous navigation. Thus
621 // startTime must be set accordingly.
622 if (resource->resourceRequest().previousNavigationStart())
623 startTime = resource->resourceRequest().previousNavigationStart();
624
625 std::unique_ptr<ResourceTimingInfo> info = ResourceTimingInfo::create(fetchI nitiator, startTime, isMainResource);
612 626
613 if (resource->isCacheValidator()) { 627 if (resource->isCacheValidator()) {
614 const AtomicString& timingAllowOrigin = resource->response().httpHeaderF ield(HTTPNames::Timing_Allow_Origin); 628 const AtomicString& timingAllowOrigin = resource->response().httpHeaderF ield(HTTPNames::Timing_Allow_Origin);
615 if (!timingAllowOrigin.isEmpty()) 629 if (!timingAllowOrigin.isEmpty())
616 info->setOriginalTimingAllowOrigin(timingAllowOrigin); 630 info->setOriginalTimingAllowOrigin(timingAllowOrigin);
617 } 631 }
618 632
619 if (!isMainResource || context().updateTimingInfoForIFrameNavigation(info.ge t())) 633 if (!isMainResource || context().updateTimingInfoForIFrameNavigation(info.ge t()))
620 m_resourceTimingInfoMap.add(resource, std::move(info)); 634 m_resourceTimingInfoMap.add(resource, std::move(info));
621 } 635 }
622 636
637 void ResourceFetcher::storeResourceTimingPreviousRedirects(Resource* resource)
638 {
639 ResourceTimingInfoMap::iterator it = m_resourceTimingInfoMap.find(resource);
640 if (it == m_resourceTimingInfoMap.end())
641 return;
642
643 const WebVector<WebURLResponse>& responses = resource->resourceRequest().pre viousResponses();
644 for (size_t i = 0; i < responses.size(); ++i) {
645 const ResourceResponse& response = responses[i].toResourceResponse();
646 const KURL& newURL = i + 1 < responses.size() ? KURL(responses[i + 1].ur l()) : resource->resourceRequest().url();
647 bool crossOrigin = IsCrossOrigin(response.url(), newURL);
648 it->value->addRedirect(response, crossOrigin);
649 }
650 }
651
623 ResourceFetcher::RevalidationPolicy ResourceFetcher::determineRevalidationPolicy (Resource::Type type, const FetchRequest& fetchRequest, Resource* existingResour ce, bool isStaticData) const 652 ResourceFetcher::RevalidationPolicy ResourceFetcher::determineRevalidationPolicy (Resource::Type type, const FetchRequest& fetchRequest, Resource* existingResour ce, bool isStaticData) const
624 { 653 {
625 const ResourceRequest& request = fetchRequest.resourceRequest(); 654 const ResourceRequest& request = fetchRequest.resourceRequest();
626 655
627 if (!existingResource) 656 if (!existingResource)
628 return Load; 657 return Load;
629 658
630 // Checks if the resource has an explicit policy about integrity metadata. 659 // Checks if the resource has an explicit policy about integrity metadata.
631 // Currently only applies to ScriptResources. 660 // Currently only applies to ScriptResources.
632 // 661 //
(...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after
1033 ResourceRequest request(resource->resourceRequest()); 1062 ResourceRequest request(resource->resourceRequest());
1034 willSendRequest(resource->identifier(), request, ResourceResponse(), resourc e->options()); 1063 willSendRequest(resource->identifier(), request, ResourceResponse(), resourc e->options());
1035 1064
1036 ResourceLoader* loader = ResourceLoader::create(this, resource); 1065 ResourceLoader* loader = ResourceLoader::create(this, resource);
1037 if (resource->shouldBlockLoadEvent()) 1066 if (resource->shouldBlockLoadEvent())
1038 m_loaders.add(loader); 1067 m_loaders.add(loader);
1039 else 1068 else
1040 m_nonBlockingLoaders.add(loader); 1069 m_nonBlockingLoaders.add(loader);
1041 1070
1042 storeResourceTimingInitiatorInformation(resource); 1071 storeResourceTimingInitiatorInformation(resource);
1072 storeResourceTimingPreviousRedirects(resource);
1043 resource->setFetcherSecurityOrigin(context().getSecurityOrigin()); 1073 resource->setFetcherSecurityOrigin(context().getSecurityOrigin());
1044 loader->start(request, context().loadingTaskRunner(), context().defersLoadin g()); 1074 loader->start(request, context().loadingTaskRunner(), context().defersLoadin g());
1045 return true; 1075 return true;
1046 } 1076 }
1047 1077
1048 void ResourceFetcher::removeResourceLoader(ResourceLoader* loader) 1078 void ResourceFetcher::removeResourceLoader(ResourceLoader* loader)
1049 { 1079 {
1050 if (m_loaders.contains(loader)) 1080 if (m_loaders.contains(loader))
1051 m_loaders.remove(loader); 1081 m_loaders.remove(loader);
1052 else if (m_nonBlockingLoaders.contains(loader)) 1082 else if (m_nonBlockingLoaders.contains(loader))
(...skipping 22 matching lines...) Expand all
1075 bool ResourceFetcher::defersLoading() const 1105 bool ResourceFetcher::defersLoading() const
1076 { 1106 {
1077 return context().defersLoading(); 1107 return context().defersLoading();
1078 } 1108 }
1079 1109
1080 static bool isManualRedirectFetchRequest(const ResourceRequest& request) 1110 static bool isManualRedirectFetchRequest(const ResourceRequest& request)
1081 { 1111 {
1082 return request.fetchRedirectMode() == WebURLRequest::FetchRedirectModeManual && request.requestContext() == WebURLRequest::RequestContextFetch; 1112 return request.fetchRedirectMode() == WebURLRequest::FetchRedirectModeManual && request.requestContext() == WebURLRequest::RequestContextFetch;
1083 } 1113 }
1084 1114
1085 bool ResourceFetcher::willFollowRedirect(Resource* resource, ResourceRequest& ne wRequest, const ResourceResponse& redirectResponse, int64_t encodedDataLength) 1115 bool ResourceFetcher::willFollowRedirect(Resource* resource, ResourceRequest& ne wRequest, const ResourceResponse& redirectResponse)
1086 { 1116 {
1087 if (!isManualRedirectFetchRequest(resource->resourceRequest())) { 1117 if (!isManualRedirectFetchRequest(resource->resourceRequest())) {
1088 if (!context().canRequest(resource->getType(), newRequest, newRequest.ur l(), resource->options(), resource->isUnusedPreload(), FetchRequest::UseDefaultO riginRestrictionForType)) 1118 if (!context().canRequest(resource->getType(), newRequest, newRequest.ur l(), resource->options(), resource->isUnusedPreload(), FetchRequest::UseDefaultO riginRestrictionForType))
1089 return false; 1119 return false;
1090 if (resource->options().corsEnabled == IsCORSEnabled) { 1120 if (resource->options().corsEnabled == IsCORSEnabled) {
1091 RefPtr<SecurityOrigin> sourceOrigin = resource->options().securityOr igin; 1121 RefPtr<SecurityOrigin> sourceOrigin = resource->options().securityOr igin;
1092 if (!sourceOrigin.get()) 1122 if (!sourceOrigin.get())
1093 sourceOrigin = context().getSecurityOrigin(); 1123 sourceOrigin = context().getSecurityOrigin();
1094 1124
1095 String errorMessage; 1125 String errorMessage;
1096 StoredCredentials withCredentials = resource->lastResourceRequest(). allowStoredCredentials() ? AllowStoredCredentials : DoNotAllowStoredCredentials; 1126 StoredCredentials withCredentials = resource->lastResourceRequest(). allowStoredCredentials() ? AllowStoredCredentials : DoNotAllowStoredCredentials;
1097 if (!CrossOriginAccessControl::handleRedirect(sourceOrigin, newReque st, redirectResponse, withCredentials, resource->mutableOptions(), errorMessage) ) { 1127 if (!CrossOriginAccessControl::handleRedirect(sourceOrigin, newReque st, redirectResponse, withCredentials, resource->mutableOptions(), errorMessage) ) {
1098 resource->setCORSFailed(); 1128 resource->setCORSFailed();
1099 context().addConsoleMessage(errorMessage); 1129 context().addConsoleMessage(errorMessage);
1100 return false; 1130 return false;
1101 } 1131 }
1102 } 1132 }
1103 if (resource->getType() == Resource::Image && shouldDeferImageLoad(newRe quest.url())) 1133 if (resource->getType() == Resource::Image && shouldDeferImageLoad(newRe quest.url()))
1104 return false; 1134 return false;
1105 } 1135 }
1106 1136
1107 ResourceTimingInfoMap::iterator it = m_resourceTimingInfoMap.find(resource); 1137 ResourceTimingInfoMap::iterator it = m_resourceTimingInfoMap.find(resource);
1108 if (it != m_resourceTimingInfoMap.end()) { 1138 if (it != m_resourceTimingInfoMap.end()) {
1109 RefPtr<SecurityOrigin> originalSecurityOrigin = SecurityOrigin::create(r edirectResponse.url()); 1139 bool crossOrigin = IsCrossOrigin(redirectResponse.url(), newRequest.url( ));
1110 RefPtr<SecurityOrigin> redirectedSecurityOrigin = SecurityOrigin::create (newRequest.url()); 1140 it->value->addRedirect(redirectResponse, crossOrigin);
1111 bool crossOrigin = !redirectedSecurityOrigin->isSameSchemeHostPort(origi nalSecurityOrigin.get());
1112 it->value->addRedirect(redirectResponse, encodedDataLength, crossOrigin) ;
1113 } 1141 }
1114 newRequest.setAllowStoredCredentials(resource->options().allowCredentials == AllowStoredCredentials); 1142 newRequest.setAllowStoredCredentials(resource->options().allowCredentials == AllowStoredCredentials);
1115 willSendRequest(resource->identifier(), newRequest, redirectResponse, resour ce->options()); 1143 willSendRequest(resource->identifier(), newRequest, redirectResponse, resour ce->options());
1116 return true; 1144 return true;
1117 } 1145 }
1118 1146
1119 void ResourceFetcher::willSendRequest(unsigned long identifier, ResourceRequest& newRequest, const ResourceResponse& redirectResponse, const ResourceLoaderOptio ns& options) 1147 void ResourceFetcher::willSendRequest(unsigned long identifier, ResourceRequest& newRequest, const ResourceResponse& redirectResponse, const ResourceLoaderOptio ns& options)
1120 { 1148 {
1121 context().dispatchWillSendRequest(identifier, newRequest, redirectResponse, options.initiatorInfo); 1149 context().dispatchWillSendRequest(identifier, newRequest, redirectResponse, options.initiatorInfo);
1122 } 1150 }
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
1314 visitor->trace(m_context); 1342 visitor->trace(m_context);
1315 visitor->trace(m_archive); 1343 visitor->trace(m_archive);
1316 visitor->trace(m_loaders); 1344 visitor->trace(m_loaders);
1317 visitor->trace(m_nonBlockingLoaders); 1345 visitor->trace(m_nonBlockingLoaders);
1318 visitor->trace(m_documentResources); 1346 visitor->trace(m_documentResources);
1319 visitor->trace(m_preloads); 1347 visitor->trace(m_preloads);
1320 visitor->trace(m_resourceTimingInfoMap); 1348 visitor->trace(m_resourceTimingInfoMap);
1321 } 1349 }
1322 1350
1323 } // namespace blink 1351 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698