https://bugs.webkit.org/show_bug.cgi?id=225737
Reviewed by Chris Dumez.
LayoutTests/imported/w3c:
* web-platform-tests/resource-timing/cors-preflight.any-expected.txt:
* web-platform-tests/resource-timing/crossorigin-sandwich-no-TAO.sub-expected.txt:
* web-platform-tests/resource-timing/crossorigin-sandwich-partial-TAO.sub-expected.txt:
* web-platform-tests/resource-timing/resource_timing_cross_origin_redirect_chain-expected.txt:
* web-platform-tests/resource-timing/status-codes-create-entry-expected.txt:
Source/WebCore:
This fixes two problems with our PerformanceResourceTiming implementation:
1. ResourceTimingInformation::shouldAddResourceTiming wasn't adding timing data if CachedResource::errorOccurred returned true,
which includes when the server responds with an HTTP 404. We want loadFailedOrCanceled instead, which only returns true if
there's a network error or if the load is cancelled. This matches the behavior of other browsers.
2. ResourceTiming::fromMemoryCache was assuming that it never had network information to report because we pulled from the cache,
not the network. However, a common case is that HTMLPreloadScanner::scan calls HTMLResourcePreloader::preload which loads the resource
while the HTML parser is blocked on loading scripts or other things, then CachedResourceLoader::requestResource pulls it out of the
memory cache. In this case, use the network metrics that we are already storing if it's the first time we are pulling this resource
out of the memory cache. After that, 0 load time is quite accurate.
Covered by newly passing Web Platform Tests, which Chrome and Firefox already passed.
* loader/ResourceTiming.cpp:
(WebCore::ResourceTiming::fromMemoryCache):
(WebCore::ResourceTiming::ResourceTiming):
(WebCore::ResourceTiming::initServerTiming): Deleted.
* loader/ResourceTiming.h:
(WebCore::ResourceTiming::ResourceTiming):
* loader/ResourceTimingInformation.cpp:
(WebCore::ResourceTimingInformation::shouldAddResourceTiming):
* loader/cache/CachedResource.h:
(WebCore::CachedResource::takeNetworkLoadMetrics):
* loader/cache/CachedResourceLoader.cpp:
(WebCore::CachedResourceLoader::requestResource):
* platform/network/ResourceResponseBase.h:
(WebCore::ResourceResponseBase::deprecatedNetworkLoadMetricsOrNull const):
(WebCore::ResourceResponseBase::takeNetworkLoadMetrics):
Canonical link: https://commits.webkit.org/240569@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@281110 268f45cc-cd09-0410-ab3c-d52691b4dbfc