| 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 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 305 request.resourceRequest().requestContext()); | 305 request.resourceRequest().requestContext()); |
| 306 } | 306 } |
| 307 | 307 |
| 308 if (isStaticData) | 308 if (isStaticData) |
| 309 return; | 309 return; |
| 310 | 310 |
| 311 if (type == ResourceLoadingFromCache && !resource->stillNeedsLoad() && | 311 if (type == ResourceLoadingFromCache && !resource->stillNeedsLoad() && |
| 312 !m_validatedURLs.contains(request.resourceRequest().url())) { | 312 !m_validatedURLs.contains(request.resourceRequest().url())) { |
| 313 // Resources loaded from memory cache should be reported the first time | 313 // Resources loaded from memory cache should be reported the first time |
| 314 // they're used. | 314 // they're used. |
| 315 std::unique_ptr<ResourceTimingInfo> info = ResourceTimingInfo::create( | 315 RefPtr<ResourceTimingInfo> info = ResourceTimingInfo::create( |
| 316 request.options().initiatorInfo.name, monotonicallyIncreasingTime(), | 316 request.options().initiatorInfo.name, monotonicallyIncreasingTime(), |
| 317 resource->getType() == Resource::MainResource); | 317 resource->getType() == Resource::MainResource); |
| 318 populateTimingInfo(info.get(), resource); | 318 populateTimingInfo(info.get(), resource); |
| 319 info->clearLoadTimings(); | 319 info->clearLoadTimings(); |
| 320 info->setLoadFinishTime(info->initialTime()); | 320 info->setLoadFinishTime(info->initialTime()); |
| 321 m_scheduledResourceTimingReports.push_back(std::move(info)); | 321 m_scheduledResourceTimingReports.push_back(info.release()); |
| 322 if (!m_resourceTimingReportTimer.isActive()) | 322 if (!m_resourceTimingReportTimer.isActive()) |
| 323 m_resourceTimingReportTimer.startOneShot(0, BLINK_FROM_HERE); | 323 m_resourceTimingReportTimer.startOneShot(0, BLINK_FROM_HERE); |
| 324 } | 324 } |
| 325 | 325 |
| 326 if (m_validatedURLs.size() >= kMaxValidatedURLsSize) { | 326 if (m_validatedURLs.size() >= kMaxValidatedURLsSize) { |
| 327 m_validatedURLs.clear(); | 327 m_validatedURLs.clear(); |
| 328 } | 328 } |
| 329 m_validatedURLs.insert(request.resourceRequest().url()); | 329 m_validatedURLs.insert(request.resourceRequest().url()); |
| 330 } | 330 } |
| 331 | 331 |
| (...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 624 return nullptr; | 624 return nullptr; |
| 625 scopedResourceLoadTracker.resourceLoadContinuesBeyondScope(); | 625 scopedResourceLoadTracker.resourceLoadContinuesBeyondScope(); |
| 626 | 626 |
| 627 DCHECK(!resource->errorOccurred() || | 627 DCHECK(!resource->errorOccurred() || |
| 628 request.options().synchronousPolicy == RequestSynchronously); | 628 request.options().synchronousPolicy == RequestSynchronously); |
| 629 return resource; | 629 return resource; |
| 630 } | 630 } |
| 631 | 631 |
| 632 void ResourceFetcher::resourceTimingReportTimerFired(TimerBase* timer) { | 632 void ResourceFetcher::resourceTimingReportTimerFired(TimerBase* timer) { |
| 633 DCHECK_EQ(timer, &m_resourceTimingReportTimer); | 633 DCHECK_EQ(timer, &m_resourceTimingReportTimer); |
| 634 Vector<std::unique_ptr<ResourceTimingInfo>> timingReports; | 634 Vector<RefPtr<ResourceTimingInfo>> timingReports; |
| 635 timingReports.swap(m_scheduledResourceTimingReports); | 635 timingReports.swap(m_scheduledResourceTimingReports); |
| 636 for (const auto& timingInfo : timingReports) | 636 for (const auto& timingInfo : timingReports) |
| 637 context().addResourceTiming(*timingInfo); | 637 context().addResourceTiming(*timingInfo); |
| 638 } | 638 } |
| 639 | 639 |
| 640 void ResourceFetcher::determineRequestContext(ResourceRequest& request, | 640 void ResourceFetcher::determineRequestContext(ResourceRequest& request, |
| 641 Resource::Type type, | 641 Resource::Type type, |
| 642 bool isMainFrame) { | 642 bool isMainFrame) { |
| 643 WebURLRequest::RequestContext requestContext = | 643 WebURLRequest::RequestContext requestContext = |
| 644 requestContextFromType(isMainFrame, type); | 644 requestContextFromType(isMainFrame, type); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 661 if (request.requestContext() == WebURLRequest::RequestContextUnspecified) | 661 if (request.requestContext() == WebURLRequest::RequestContextUnspecified) |
| 662 determineRequestContext(request, type); | 662 determineRequestContext(request, type); |
| 663 if (type == Resource::LinkPrefetch) | 663 if (type == Resource::LinkPrefetch) |
| 664 request.setHTTPHeaderField(HTTPNames::Purpose, "prefetch"); | 664 request.setHTTPHeaderField(HTTPNames::Purpose, "prefetch"); |
| 665 | 665 |
| 666 context().addAdditionalRequestHeaders( | 666 context().addAdditionalRequestHeaders( |
| 667 request, | 667 request, |
| 668 (type == Resource::MainResource) ? FetchMainResource : FetchSubresource); | 668 (type == Resource::MainResource) ? FetchMainResource : FetchSubresource); |
| 669 } | 669 } |
| 670 | 670 |
| 671 ResourceTimingInfo* ResourceFetcher::getNavigationTimingInfo() { |
| 672 return m_navigationTimingInfo.get(); |
| 673 } |
| 674 |
| 671 void ResourceFetcher::initializeRevalidation( | 675 void ResourceFetcher::initializeRevalidation( |
| 672 ResourceRequest& revalidatingRequest, | 676 ResourceRequest& revalidatingRequest, |
| 673 Resource* resource) { | 677 Resource* resource) { |
| 674 DCHECK(resource); | 678 DCHECK(resource); |
| 675 DCHECK(memoryCache()->contains(resource)); | 679 DCHECK(memoryCache()->contains(resource)); |
| 676 DCHECK(resource->isLoaded()); | 680 DCHECK(resource->isLoaded()); |
| 677 DCHECK(resource->canUseCacheValidator()); | 681 DCHECK(resource->canUseCacheValidator()); |
| 678 DCHECK(!resource->isCacheValidator()); | 682 DCHECK(!resource->isCacheValidator()); |
| 679 DCHECK(!context().isControlledByServiceWorker()); | 683 DCHECK(!context().isControlledByServiceWorker()); |
| 680 | 684 |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 752 : monotonicallyIncreasingTime(); | 756 : monotonicallyIncreasingTime(); |
| 753 | 757 |
| 754 // This buffer is created and populated for providing transferSize | 758 // This buffer is created and populated for providing transferSize |
| 755 // and redirect timing opt-in information. | 759 // and redirect timing opt-in information. |
| 756 if (isMainResource) { | 760 if (isMainResource) { |
| 757 DCHECK(!m_navigationTimingInfo); | 761 DCHECK(!m_navigationTimingInfo); |
| 758 m_navigationTimingInfo = | 762 m_navigationTimingInfo = |
| 759 ResourceTimingInfo::create(fetchInitiator, startTime, isMainResource); | 763 ResourceTimingInfo::create(fetchInitiator, startTime, isMainResource); |
| 760 } | 764 } |
| 761 | 765 |
| 762 std::unique_ptr<ResourceTimingInfo> info = | 766 RefPtr<ResourceTimingInfo> info = |
| 763 ResourceTimingInfo::create(fetchInitiator, startTime, isMainResource); | 767 ResourceTimingInfo::create(fetchInitiator, startTime, isMainResource); |
| 764 | 768 |
| 765 if (resource->isCacheValidator()) { | 769 if (resource->isCacheValidator()) { |
| 766 const AtomicString& timingAllowOrigin = | 770 const AtomicString& timingAllowOrigin = |
| 767 resource->response().httpHeaderField(HTTPNames::Timing_Allow_Origin); | 771 resource->response().httpHeaderField(HTTPNames::Timing_Allow_Origin); |
| 768 if (!timingAllowOrigin.isEmpty()) | 772 if (!timingAllowOrigin.isEmpty()) |
| 769 info->setOriginalTimingAllowOrigin(timingAllowOrigin); | 773 info->setOriginalTimingAllowOrigin(timingAllowOrigin); |
| 770 } | 774 } |
| 771 | 775 |
| 772 if (!isMainResource || | 776 if (!isMainResource || |
| (...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1121 } | 1125 } |
| 1122 | 1126 |
| 1123 ArchiveResource* ResourceFetcher::createArchive(Resource* resource) { | 1127 ArchiveResource* ResourceFetcher::createArchive(Resource* resource) { |
| 1124 // Only the top-frame can load MHTML. | 1128 // Only the top-frame can load MHTML. |
| 1125 if (!context().isMainFrame()) | 1129 if (!context().isMainFrame()) |
| 1126 return nullptr; | 1130 return nullptr; |
| 1127 m_archive = MHTMLArchive::create(resource->url(), resource->resourceBuffer()); | 1131 m_archive = MHTMLArchive::create(resource->url(), resource->resourceBuffer()); |
| 1128 return m_archive ? m_archive->mainResource() : nullptr; | 1132 return m_archive ? m_archive->mainResource() : nullptr; |
| 1129 } | 1133 } |
| 1130 | 1134 |
| 1131 ResourceTimingInfo* ResourceFetcher::getNavigationTimingInfo() { | |
| 1132 return m_navigationTimingInfo.get(); | |
| 1133 } | |
| 1134 | |
| 1135 void ResourceFetcher::handleLoadCompletion(Resource* resource) { | 1135 void ResourceFetcher::handleLoadCompletion(Resource* resource) { |
| 1136 context().didLoadResource(resource); | 1136 context().didLoadResource(resource); |
| 1137 | 1137 |
| 1138 resource->reloadIfLoFiOrPlaceholderImage(this, Resource::kReloadIfNeeded); | 1138 resource->reloadIfLoFiOrPlaceholderImage(this, Resource::kReloadIfNeeded); |
| 1139 } | 1139 } |
| 1140 | 1140 |
| 1141 void ResourceFetcher::handleLoaderFinish(Resource* resource, | 1141 void ResourceFetcher::handleLoaderFinish(Resource* resource, |
| 1142 double finishTime, | 1142 double finishTime, |
| 1143 LoaderFinishType type) { | 1143 LoaderFinishType type) { |
| 1144 DCHECK(resource); | 1144 DCHECK(resource); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1159 if (resource->getType() == Resource::MainResource) { | 1159 if (resource->getType() == Resource::MainResource) { |
| 1160 DCHECK(m_navigationTimingInfo); | 1160 DCHECK(m_navigationTimingInfo); |
| 1161 // Store redirect responses that were packed inside the final response. | 1161 // Store redirect responses that were packed inside the final response. |
| 1162 addRedirectsToTimingInfo(resource, m_navigationTimingInfo.get()); | 1162 addRedirectsToTimingInfo(resource, m_navigationTimingInfo.get()); |
| 1163 if (resource->response().isHTTP()) { | 1163 if (resource->response().isHTTP()) { |
| 1164 populateTimingInfo(m_navigationTimingInfo.get(), resource); | 1164 populateTimingInfo(m_navigationTimingInfo.get(), resource); |
| 1165 m_navigationTimingInfo->addFinalTransferSize( | 1165 m_navigationTimingInfo->addFinalTransferSize( |
| 1166 encodedDataLength == -1 ? 0 : encodedDataLength); | 1166 encodedDataLength == -1 ? 0 : encodedDataLength); |
| 1167 } | 1167 } |
| 1168 } | 1168 } |
| 1169 if (std::unique_ptr<ResourceTimingInfo> info = | 1169 if (RefPtr<ResourceTimingInfo> info = |
| 1170 m_resourceTimingInfoMap.take(resource)) { | 1170 m_resourceTimingInfoMap.take(resource)) { |
| 1171 // Store redirect responses that were packed inside the final response. | 1171 // Store redirect responses that were packed inside the final response. |
| 1172 addRedirectsToTimingInfo(resource, info.get()); | 1172 addRedirectsToTimingInfo(resource, info.get()); |
| 1173 | 1173 |
| 1174 if (resource->response().isHTTP() && | 1174 if (resource->response().isHTTP() && |
| 1175 resource->response().httpStatusCode() < 400) { | 1175 resource->response().httpStatusCode() < 400) { |
| 1176 populateTimingInfo(info.get(), resource); | 1176 populateTimingInfo(info.get(), resource); |
| 1177 info->setLoadFinishTime(finishTime); | 1177 info->setLoadFinishTime(finishTime); |
| 1178 // encodedDataLength == -1 means "not available". | 1178 // encodedDataLength == -1 means "not available". |
| 1179 // TODO(ricea): Find cases where it is not available but the | 1179 // TODO(ricea): Find cases where it is not available but the |
| (...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1540 visitor->trace(m_context); | 1540 visitor->trace(m_context); |
| 1541 visitor->trace(m_archive); | 1541 visitor->trace(m_archive); |
| 1542 visitor->trace(m_loaders); | 1542 visitor->trace(m_loaders); |
| 1543 visitor->trace(m_nonBlockingLoaders); | 1543 visitor->trace(m_nonBlockingLoaders); |
| 1544 visitor->trace(m_documentResources); | 1544 visitor->trace(m_documentResources); |
| 1545 visitor->trace(m_preloads); | 1545 visitor->trace(m_preloads); |
| 1546 visitor->trace(m_resourceTimingInfoMap); | 1546 visitor->trace(m_resourceTimingInfoMap); |
| 1547 } | 1547 } |
| 1548 | 1548 |
| 1549 } // namespace blink | 1549 } // namespace blink |
| OLD | NEW |