Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 | 5 Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All |
| 6 rights reserved. | 6 rights reserved. |
| 7 Copyright (C) 2009 Torch Mobile Inc. http://www.torchmobile.com/ | 7 Copyright (C) 2009 Torch Mobile Inc. http://www.torchmobile.com/ |
| 8 | 8 |
| 9 This library is free software; you can redistribute it and/or | 9 This library is free software; you can redistribute it and/or |
| 10 modify it under the terms of the GNU Library General Public | 10 modify it under the terms of the GNU Library General Public |
| (...skipping 734 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 745 | 745 |
| 746 // - Don't add main resource to cache to prevent reuse. | 746 // - Don't add main resource to cache to prevent reuse. |
| 747 // - Don't add the resource if its body will not be stored. | 747 // - Don't add the resource if its body will not be stored. |
| 748 if (factory.type() != Resource::MainResource && | 748 if (factory.type() != Resource::MainResource && |
| 749 request.options().dataBufferingPolicy != DoNotBufferData) { | 749 request.options().dataBufferingPolicy != DoNotBufferData) { |
| 750 memoryCache()->add(resource); | 750 memoryCache()->add(resource); |
| 751 } | 751 } |
| 752 return resource; | 752 return resource; |
| 753 } | 753 } |
| 754 | 754 |
| 755 void ResourceFetcher::storeResourceTimingInitiatorInformation( | 755 void ResourceFetcher::storePerformanceTimingInitiatorInformation( |
| 756 Resource* resource) { | 756 Resource* resource) { |
| 757 const AtomicString& fetchInitiator = resource->options().initiatorInfo.name; | 757 const AtomicString& fetchInitiator = resource->options().initiatorInfo.name; |
| 758 if (fetchInitiator == FetchInitiatorTypeNames::internal) | 758 if (fetchInitiator == FetchInitiatorTypeNames::internal) |
| 759 return; | 759 return; |
| 760 | 760 |
| 761 bool isMainResource = resource->getType() == Resource::MainResource; | 761 bool isMainResource = resource->getType() == Resource::MainResource; |
| 762 | 762 |
| 763 // The request can already be fetched in a previous navigation. Thus | 763 // The request can already be fetched in a previous navigation. Thus |
| 764 // startTime must be set accordingly. | 764 // startTime must be set accordingly. |
| 765 double startTime = resource->resourceRequest().navigationStartTime() | 765 double startTime = resource->resourceRequest().navigationStartTime() |
| 766 ? resource->resourceRequest().navigationStartTime() | 766 ? resource->resourceRequest().navigationStartTime() |
| 767 : monotonicallyIncreasingTime(); | 767 : monotonicallyIncreasingTime(); |
| 768 | 768 |
| 769 std::unique_ptr<ResourceTimingInfo> info = | 769 std::unique_ptr<ResourceTimingInfo> info = |
| 770 ResourceTimingInfo::create(fetchInitiator, startTime, isMainResource); | 770 ResourceTimingInfo::create(fetchInitiator, startTime, isMainResource); |
| 771 | 771 |
| 772 if (resource->isCacheValidator()) { | 772 if (resource->isCacheValidator()) { |
| 773 const AtomicString& timingAllowOrigin = | 773 const AtomicString& timingAllowOrigin = |
| 774 resource->response().httpHeaderField(HTTPNames::Timing_Allow_Origin); | 774 resource->response().httpHeaderField(HTTPNames::Timing_Allow_Origin); |
| 775 if (!timingAllowOrigin.isEmpty()) | 775 if (!timingAllowOrigin.isEmpty()) |
| 776 info->setOriginalTimingAllowOrigin(timingAllowOrigin); | 776 info->setOriginalTimingAllowOrigin(timingAllowOrigin); |
| 777 } | 777 } |
| 778 | 778 |
| 779 if (!isMainResource || | 779 if (!isMainResource || |
| 780 context().updateTimingInfoForIFrameNavigation(info.get())) | 780 context().updateTimingInfoForIFrameNavigation(info.get())) |
| 781 m_resourceTimingInfoMap.add(resource, std::move(info)); | 781 m_resourceTimingInfoMap.add(resource, std::move(info)); |
| 782 else | |
| 783 m_mainResourceTimingInfoMap.add(resource->identifier(), std::move(info)); | |
| 782 } | 784 } |
| 783 | 785 |
| 784 ResourceFetcher::RevalidationPolicy | 786 ResourceFetcher::RevalidationPolicy |
| 785 ResourceFetcher::determineRevalidationPolicy(Resource::Type type, | 787 ResourceFetcher::determineRevalidationPolicy(Resource::Type type, |
| 786 const FetchRequest& fetchRequest, | 788 const FetchRequest& fetchRequest, |
| 787 Resource* existingResource, | 789 Resource* existingResource, |
| 788 bool isStaticData) const { | 790 bool isStaticData) const { |
| 789 const ResourceRequest& request = fetchRequest.resourceRequest(); | 791 const ResourceRequest& request = fetchRequest.resourceRequest(); |
| 790 | 792 |
| 791 if (!existingResource) | 793 if (!existingResource) |
| (...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1113 } | 1115 } |
| 1114 | 1116 |
| 1115 ArchiveResource* ResourceFetcher::createArchive(Resource* resource) { | 1117 ArchiveResource* ResourceFetcher::createArchive(Resource* resource) { |
| 1116 // Only the top-frame can load MHTML. | 1118 // Only the top-frame can load MHTML. |
| 1117 if (!context().isMainFrame()) | 1119 if (!context().isMainFrame()) |
| 1118 return nullptr; | 1120 return nullptr; |
| 1119 m_archive = MHTMLArchive::create(resource->url(), resource->resourceBuffer()); | 1121 m_archive = MHTMLArchive::create(resource->url(), resource->resourceBuffer()); |
| 1120 return m_archive ? m_archive->mainResource() : nullptr; | 1122 return m_archive ? m_archive->mainResource() : nullptr; |
| 1121 } | 1123 } |
| 1122 | 1124 |
| 1125 ResourceTimingInfo* ResourceFetcher::getMainResourceTimingInfo( | |
| 1126 unsigned long identifier) { | |
| 1127 MainResourceTimingInfoMap::iterator it = | |
| 1128 m_mainResourceTimingInfoMap.find(identifier); | |
| 1129 if (it != m_mainResourceTimingInfoMap.end()) { | |
| 1130 return it->value.get(); | |
| 1131 } | |
| 1132 return nullptr; | |
| 1133 } | |
| 1134 | |
| 1123 void ResourceFetcher::didFinishLoading(Resource* resource, | 1135 void ResourceFetcher::didFinishLoading(Resource* resource, |
| 1124 double finishTime, | 1136 double finishTime, |
| 1125 int64_t encodedDataLength, | 1137 int64_t encodedDataLength, |
| 1126 DidFinishLoadingReason finishReason) { | 1138 DidFinishLoadingReason finishReason) { |
| 1127 network_instrumentation::endResourceLoad( | 1139 network_instrumentation::endResourceLoad( |
| 1128 resource->identifier(), network_instrumentation::RequestOutcome::Success); | 1140 resource->identifier(), network_instrumentation::RequestOutcome::Success); |
| 1129 DCHECK(resource); | 1141 DCHECK(resource); |
| 1130 | 1142 |
| 1131 // When loading a multipart resource, make the loader non-block when finishing | 1143 // When loading a multipart resource, make the loader non-block when finishing |
| 1132 // loading the first part. | 1144 // loading the first part. |
| 1133 if (finishReason == DidFinishFirstPartInMultipart) | 1145 if (finishReason == DidFinishFirstPartInMultipart) |
| 1134 moveResourceLoaderToNonBlocking(resource->loader()); | 1146 moveResourceLoaderToNonBlocking(resource->loader()); |
| 1135 else | 1147 else |
| 1136 removeResourceLoader(resource->loader()); | 1148 removeResourceLoader(resource->loader()); |
| 1137 DCHECK(!m_loaders.contains(resource->loader())); | 1149 DCHECK(!m_loaders.contains(resource->loader())); |
| 1138 DCHECK(finishReason == DidFinishFirstPartInMultipart || | 1150 DCHECK(finishReason == DidFinishFirstPartInMultipart || |
| 1139 !m_nonBlockingLoaders.contains(resource->loader())); | 1151 !m_nonBlockingLoaders.contains(resource->loader())); |
| 1140 | 1152 |
| 1153 MainResourceTimingInfoMap::iterator it = | |
| 1154 m_mainResourceTimingInfoMap.find(resource->identifier()); | |
| 1155 if (it != m_mainResourceTimingInfoMap.end()) { | |
| 1156 // Store redirect responses that were packed inside the final response. | |
|
kinuko
2016/11/30 07:34:54
We seem to be duplicating the almost same code her
sunjian
2016/12/01 21:21:59
Done.
| |
| 1157 const Vector<ResourceResponse>& responses = | |
| 1158 resource->response().redirectResponses(); | |
| 1159 for (size_t i = 0; i < responses.size(); ++i) { | |
| 1160 const KURL& newURL = i + 1 < responses.size() | |
| 1161 ? KURL(responses[i + 1].url()) | |
| 1162 : resource->resourceRequest().url(); | |
| 1163 bool crossOrigin = IsCrossOrigin(responses[i].url(), newURL); | |
| 1164 it->value->addRedirect(responses[i], crossOrigin); | |
| 1165 } | |
| 1166 it->value->addFinalTransferSize( | |
| 1167 encodedDataLength == -1 ? 0 : encodedDataLength); | |
| 1168 } | |
| 1141 if (std::unique_ptr<ResourceTimingInfo> info = | 1169 if (std::unique_ptr<ResourceTimingInfo> info = |
| 1142 m_resourceTimingInfoMap.take(resource)) { | 1170 m_resourceTimingInfoMap.take(resource)) { |
| 1143 // Store redirect responses that were packed inside the final response. | 1171 // Store redirect responses that were packed inside the final response. |
| 1144 const Vector<ResourceResponse>& responses = | 1172 const Vector<ResourceResponse>& responses = |
| 1145 resource->response().redirectResponses(); | 1173 resource->response().redirectResponses(); |
| 1146 for (size_t i = 0; i < responses.size(); ++i) { | 1174 for (size_t i = 0; i < responses.size(); ++i) { |
| 1147 const KURL& newURL = i + 1 < responses.size() | 1175 const KURL& newURL = i + 1 < responses.size() |
| 1148 ? KURL(responses[i + 1].url()) | 1176 ? KURL(responses[i + 1].url()) |
| 1149 : resource->resourceRequest().url(); | 1177 : resource->resourceRequest().url(); |
| 1150 bool crossOrigin = IsCrossOrigin(responses[i].url(), newURL); | 1178 bool crossOrigin = IsCrossOrigin(responses[i].url(), newURL); |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1307 SecurityOrigin* sourceOrigin = context().getSecurityOrigin(); | 1335 SecurityOrigin* sourceOrigin = context().getSecurityOrigin(); |
| 1308 if (sourceOrigin && sourceOrigin->hasSuborigin()) | 1336 if (sourceOrigin && sourceOrigin->hasSuborigin()) |
| 1309 request.setSkipServiceWorker(WebURLRequest::SkipServiceWorker::All); | 1337 request.setSkipServiceWorker(WebURLRequest::SkipServiceWorker::All); |
| 1310 | 1338 |
| 1311 ResourceLoader* loader = ResourceLoader::create(this, resource); | 1339 ResourceLoader* loader = ResourceLoader::create(this, resource); |
| 1312 if (resource->shouldBlockLoadEvent()) | 1340 if (resource->shouldBlockLoadEvent()) |
| 1313 m_loaders.add(loader); | 1341 m_loaders.add(loader); |
| 1314 else | 1342 else |
| 1315 m_nonBlockingLoaders.add(loader); | 1343 m_nonBlockingLoaders.add(loader); |
| 1316 | 1344 |
| 1317 storeResourceTimingInitiatorInformation(resource); | 1345 storePerformanceTimingInitiatorInformation(resource); |
| 1318 resource->setFetcherSecurityOrigin(sourceOrigin); | 1346 resource->setFetcherSecurityOrigin(sourceOrigin); |
| 1319 | 1347 |
| 1320 loader->activateCacheAwareLoadingIfNeeded(request); | 1348 loader->activateCacheAwareLoadingIfNeeded(request); |
| 1321 loader->start(request, context().loadingTaskRunner(), | 1349 loader->start(request, context().loadingTaskRunner(), |
| 1322 context().defersLoading()); | 1350 context().defersLoading()); |
| 1323 return true; | 1351 return true; |
| 1324 } | 1352 } |
| 1325 | 1353 |
| 1326 void ResourceFetcher::removeResourceLoader(ResourceLoader* loader) { | 1354 void ResourceFetcher::removeResourceLoader(ResourceLoader* loader) { |
| 1327 if (m_loaders.contains(loader)) | 1355 if (m_loaders.contains(loader)) |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1396 if (resource->getType() == Resource::Image && | 1424 if (resource->getType() == Resource::Image && |
| 1397 shouldDeferImageLoad(newRequest.url())) | 1425 shouldDeferImageLoad(newRequest.url())) |
| 1398 return false; | 1426 return false; |
| 1399 } | 1427 } |
| 1400 | 1428 |
| 1401 ResourceTimingInfoMap::iterator it = m_resourceTimingInfoMap.find(resource); | 1429 ResourceTimingInfoMap::iterator it = m_resourceTimingInfoMap.find(resource); |
| 1402 if (it != m_resourceTimingInfoMap.end()) { | 1430 if (it != m_resourceTimingInfoMap.end()) { |
| 1403 bool crossOrigin = IsCrossOrigin(redirectResponse.url(), newRequest.url()); | 1431 bool crossOrigin = IsCrossOrigin(redirectResponse.url(), newRequest.url()); |
| 1404 it->value->addRedirect(redirectResponse, crossOrigin); | 1432 it->value->addRedirect(redirectResponse, crossOrigin); |
| 1405 } | 1433 } |
| 1434 MainResourceTimingInfoMap::iterator itt = | |
| 1435 m_mainResourceTimingInfoMap.find(resource->identifier()); | |
| 1436 if (itt != m_mainResourceTimingInfoMap.end()) { | |
| 1437 bool crossOrigin = IsCrossOrigin(redirectResponse.url(), newRequest.url()); | |
| 1438 itt->value->addRedirect(redirectResponse, crossOrigin); | |
| 1439 } | |
| 1440 | |
| 1406 newRequest.setAllowStoredCredentials(resource->options().allowCredentials == | 1441 newRequest.setAllowStoredCredentials(resource->options().allowCredentials == |
| 1407 AllowStoredCredentials); | 1442 AllowStoredCredentials); |
| 1408 willSendRequest(resource->identifier(), newRequest, redirectResponse, | 1443 willSendRequest(resource->identifier(), newRequest, redirectResponse, |
| 1409 resource->options()); | 1444 resource->options()); |
| 1410 return true; | 1445 return true; |
| 1411 } | 1446 } |
| 1412 | 1447 |
| 1413 void ResourceFetcher::willSendRequest(unsigned long identifier, | 1448 void ResourceFetcher::willSendRequest(unsigned long identifier, |
| 1414 ResourceRequest& newRequest, | 1449 ResourceRequest& newRequest, |
| 1415 const ResourceResponse& redirectResponse, | 1450 const ResourceResponse& redirectResponse, |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1641 visitor->trace(m_context); | 1676 visitor->trace(m_context); |
| 1642 visitor->trace(m_archive); | 1677 visitor->trace(m_archive); |
| 1643 visitor->trace(m_loaders); | 1678 visitor->trace(m_loaders); |
| 1644 visitor->trace(m_nonBlockingLoaders); | 1679 visitor->trace(m_nonBlockingLoaders); |
| 1645 visitor->trace(m_documentResources); | 1680 visitor->trace(m_documentResources); |
| 1646 visitor->trace(m_preloads); | 1681 visitor->trace(m_preloads); |
| 1647 visitor->trace(m_resourceTimingInfoMap); | 1682 visitor->trace(m_resourceTimingInfoMap); |
| 1648 } | 1683 } |
| 1649 | 1684 |
| 1650 } // namespace blink | 1685 } // namespace blink |
| OLD | NEW |