Chromium Code Reviews| Index: third_party/WebKit/Source/core/fetch/ResourceFetcher.cpp |
| diff --git a/third_party/WebKit/Source/core/fetch/ResourceFetcher.cpp b/third_party/WebKit/Source/core/fetch/ResourceFetcher.cpp |
| index 1c9fd3a59b1b6274383c87e2b2060006e5405300..33fcb40758fc132d7f844dd06bc91ad2af05879e 100644 |
| --- a/third_party/WebKit/Source/core/fetch/ResourceFetcher.cpp |
| +++ b/third_party/WebKit/Source/core/fetch/ResourceFetcher.cpp |
| @@ -103,6 +103,20 @@ bool IsCrossOrigin(const KURL& a, const KURL& b) { |
| return !originB->isSameSchemeHostPort(originA.get()); |
| } |
| +void addRedirectsToResourceTimingInfo(Resource* resource, |
|
Yoav Weiss
2016/12/01 21:53:55
As this is used for both RT and NT2, do you think
sunjian
2016/12/01 23:28:42
I personally think it might be a better idea not t
Yoav Weiss
2016/12/02 07:10:05
I'd have preferred something like "addRedirectsToT
sunjian
2016/12/03 00:16:50
Acknowledged.
|
| + ResourceTimingInfo* info) { |
| + // Store redirect responses that were packed inside the final response. |
| + const Vector<ResourceResponse>& responses = |
| + resource->response().redirectResponses(); |
| + for (size_t i = 0; i < responses.size(); ++i) { |
| + const KURL& newURL = i + 1 < responses.size() |
| + ? KURL(responses[i + 1].url()) |
| + : resource->resourceRequest().url(); |
| + bool crossOrigin = IsCrossOrigin(responses[i].url(), newURL); |
| + info->addRedirect(responses[i], crossOrigin); |
| + } |
| +} |
| + |
| } // namespace |
| static void RecordSriResourceIntegrityMismatchEvent( |
| @@ -752,7 +766,7 @@ Resource* ResourceFetcher::createResourceForLoading( |
| return resource; |
| } |
| -void ResourceFetcher::storeResourceTimingInitiatorInformation( |
| +void ResourceFetcher::storePerformanceTimingInitiatorInformation( |
| Resource* resource) { |
| const AtomicString& fetchInitiator = resource->options().initiatorInfo.name; |
| if (fetchInitiator == FetchInitiatorTypeNames::internal) |
| @@ -777,8 +791,13 @@ void ResourceFetcher::storeResourceTimingInitiatorInformation( |
| } |
| if (!isMainResource || |
| - context().updateTimingInfoForIFrameNavigation(info.get())) |
| + context().updateTimingInfoForIFrameNavigation(info.get())) { |
| m_resourceTimingInfoMap.add(resource, std::move(info)); |
| + } else { |
| + DCHECK(!m_mainResourceTimingInfo); |
| + m_mainResourceTimingInfo = std::move(info); |
| + m_mainResourceIdentifier = resource->identifier(); |
| + } |
| } |
| ResourceFetcher::RevalidationPolicy |
| @@ -1120,6 +1139,15 @@ ArchiveResource* ResourceFetcher::createArchive(Resource* resource) { |
| return m_archive ? m_archive->mainResource() : nullptr; |
| } |
| +ResourceTimingInfo* ResourceFetcher::getMainResourceTimingInfo( |
| + unsigned long identifier) { |
| + if (m_mainResourceTimingInfo) { |
|
Yoav Weiss
2016/12/01 21:53:55
The condition here seems unnecessary other than fo
sunjian
2016/12/01 23:28:41
Agree. But since this is a public method, how i ca
kinuko
2016/12/02 00:44:55
Just document / have a comment to say calling getM
Yoav Weiss
2016/12/02 07:10:05
if callers are invoking it before m_mainResourceTi
sunjian
2016/12/03 00:16:50
This commit is old. I uploaded a new commit and th
|
| + DCHECK(m_mainResourceIdentifier == identifier); |
| + return m_mainResourceTimingInfo.get(); |
| + } |
| + return nullptr; |
| +} |
| + |
| void ResourceFetcher::didFinishLoading(Resource* resource, |
| double finishTime, |
| DidFinishLoadingReason finishReason) { |
| @@ -1138,18 +1166,18 @@ void ResourceFetcher::didFinishLoading(Resource* resource, |
| DCHECK(finishReason == DidFinishFirstPartInMultipart || |
| !m_nonBlockingLoaders.contains(resource->loader())); |
| + if (resource->getType() == Resource::MainResource && |
| + m_mainResourceTimingInfo) { |
| + DCHECK(resource->identifier() == m_mainResourceIdentifier); |
| + // Store redirect responses that were packed inside the final response. |
| + addRedirectsToResourceTimingInfo(resource, m_mainResourceTimingInfo.get()); |
| + m_mainResourceTimingInfo->addFinalTransferSize( |
| + encodedDataLength == -1 ? 0 : encodedDataLength); |
| + } |
| if (std::unique_ptr<ResourceTimingInfo> info = |
| m_resourceTimingInfoMap.take(resource)) { |
| // Store redirect responses that were packed inside the final response. |
| - const Vector<ResourceResponse>& responses = |
| - resource->response().redirectResponses(); |
| - for (size_t i = 0; i < responses.size(); ++i) { |
| - const KURL& newURL = i + 1 < responses.size() |
| - ? KURL(responses[i + 1].url()) |
| - : resource->resourceRequest().url(); |
| - bool crossOrigin = IsCrossOrigin(responses[i].url(), newURL); |
| - info->addRedirect(responses[i], crossOrigin); |
| - } |
| + addRedirectsToResourceTimingInfo(resource, info.get()); |
| if (resource->response().isHTTP() && |
| resource->response().httpStatusCode() < 400) { |
| @@ -1314,7 +1342,7 @@ bool ResourceFetcher::startLoad(Resource* resource) { |
| else |
| m_nonBlockingLoaders.add(loader); |
| - storeResourceTimingInitiatorInformation(resource); |
| + storePerformanceTimingInitiatorInformation(resource); |
| resource->setFetcherSecurityOrigin(sourceOrigin); |
| loader->activateCacheAwareLoadingIfNeeded(request); |
| @@ -1403,6 +1431,14 @@ bool ResourceFetcher::willFollowRedirect( |
| bool crossOrigin = IsCrossOrigin(redirectResponse.url(), newRequest.url()); |
| it->value->addRedirect(redirectResponse, crossOrigin); |
| } |
| + |
| + if (resource->getType() == Resource::MainResource && |
| + m_mainResourceTimingInfo) { |
|
Yoav Weiss
2016/12/01 21:53:55
I think this is true for iframes as well. Would be
sunjian
2016/12/01 23:28:41
Did you mean context().updateTimingInfoForIFrameNa
Yoav Weiss
2016/12/02 07:10:05
What happens when m_mainResourceTimingInfo is fill
sunjian
2016/12/03 00:16:49
I see. So i modified the if condition a little bit
|
| + DCHECK(resource->identifier() == m_mainResourceIdentifier); |
| + bool crossOrigin = IsCrossOrigin(redirectResponse.url(), newRequest.url()); |
| + m_mainResourceTimingInfo->addRedirect(redirectResponse, crossOrigin); |
| + } |
| + |
| newRequest.setAllowStoredCredentials(resource->options().allowCredentials == |
| AllowStoredCredentials); |
| willSendRequest(resource->identifier(), newRequest, redirectResponse, |