<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[281110] trunk</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/281110">281110</a></dd>
<dt>Author</dt> <dd>achristensen@apple.com</dd>
<dt>Date</dt> <dd>2021-08-16 14:43:02 -0700 (Mon, 16 Aug 2021)</dd>
</dl>

<h3>Log Message</h3>
<pre>Resource Timing: Duration is 0 in many cases
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):</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsimportedw3cChangeLog">trunk/LayoutTests/imported/w3c/ChangeLog</a></li>
<li><a href="#trunkLayoutTestsimportedw3cwebplatformtestsresourcetimingcorspreflightanyexpectedtxt">trunk/LayoutTests/imported/w3c/web-platform-tests/resource-timing/cors-preflight.any-expected.txt</a></li>
<li><a href="#trunkLayoutTestsimportedw3cwebplatformtestsresourcetimingcrossoriginsandwichnoTAOsubexpectedtxt">trunk/LayoutTests/imported/w3c/web-platform-tests/resource-timing/crossorigin-sandwich-no-TAO.sub-expected.txt</a></li>
<li><a href="#trunkLayoutTestsimportedw3cwebplatformtestsresourcetimingcrossoriginsandwichpartialTAOsubexpectedtxt">trunk/LayoutTests/imported/w3c/web-platform-tests/resource-timing/crossorigin-sandwich-partial-TAO.sub-expected.txt</a></li>
<li><a href="#trunkLayoutTestsimportedw3cwebplatformtestsresourcetimingresource_timing_cross_origin_redirect_chainexpectedtxt">trunk/LayoutTests/imported/w3c/web-platform-tests/resource-timing/resource_timing_cross_origin_redirect_chain-expected.txt</a></li>
<li><a href="#trunkLayoutTestsimportedw3cwebplatformtestsresourcetimingstatuscodescreateentryexpectedtxt">trunk/LayoutTests/imported/w3c/web-platform-tests/resource-timing/status-codes-create-entry-expected.txt</a></li>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreloaderResourceTimingcpp">trunk/Source/WebCore/loader/ResourceTiming.cpp</a></li>
<li><a href="#trunkSourceWebCoreloaderResourceTimingh">trunk/Source/WebCore/loader/ResourceTiming.h</a></li>
<li><a href="#trunkSourceWebCoreloaderResourceTimingInformationcpp">trunk/Source/WebCore/loader/ResourceTimingInformation.cpp</a></li>
<li><a href="#trunkSourceWebCoreloadercacheCachedResourceh">trunk/Source/WebCore/loader/cache/CachedResource.h</a></li>
<li><a href="#trunkSourceWebCoreloadercacheCachedResourceLoadercpp">trunk/Source/WebCore/loader/cache/CachedResourceLoader.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformnetworkResourceResponseBaseh">trunk/Source/WebCore/platform/network/ResourceResponseBase.h</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsimportedw3cChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/imported/w3c/ChangeLog (281109 => 281110)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/imported/w3c/ChangeLog 2021-08-16 21:39:33 UTC (rev 281109)
+++ trunk/LayoutTests/imported/w3c/ChangeLog    2021-08-16 21:43:02 UTC (rev 281110)
</span><span class="lines">@@ -1,3 +1,16 @@
</span><ins>+2021-08-16  Alex Christensen  <achristensen@webkit.org>
+
+        Resource Timing: Duration is 0 in many cases
+        https://bugs.webkit.org/show_bug.cgi?id=225737
+
+        Reviewed by Chris Dumez.
+
+        * 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:
+
</ins><span class="cx"> 2021-08-16  Brent Fulgham  <bfulgham@apple.com>
</span><span class="cx"> 
</span><span class="cx">         REGRESSION (r281012): WebInspector console no longer shows script integrity information
</span></span></pre></div>
<a id="trunkLayoutTestsimportedw3cwebplatformtestsresourcetimingcorspreflightanyexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/resource-timing/cors-preflight.any-expected.txt (281109 => 281110)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/imported/w3c/web-platform-tests/resource-timing/cors-preflight.any-expected.txt        2021-08-16 21:39:33 UTC (rev 281109)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/resource-timing/cors-preflight.any-expected.txt   2021-08-16 21:43:02 UTC (rev 281110)
</span><span class="lines">@@ -1,3 +1,3 @@
</span><span class="cx"> 
</span><del>-FAIL PerformanceResourceTiming sizes fetch with preflight test assert_greater_than: No-preflight transferSize expected a number greater than 0 but got 0
</del><ins>+PASS PerformanceResourceTiming sizes fetch with preflight test
</ins><span class="cx"> 
</span></span></pre></div>
<a id="trunkLayoutTestsimportedw3cwebplatformtestsresourcetimingcrossoriginsandwichnoTAOsubexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/resource-timing/crossorigin-sandwich-no-TAO.sub-expected.txt (281109 => 281110)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/imported/w3c/web-platform-tests/resource-timing/crossorigin-sandwich-no-TAO.sub-expected.txt   2021-08-16 21:39:33 UTC (rev 281109)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/resource-timing/crossorigin-sandwich-no-TAO.sub-expected.txt      2021-08-16 21:43:02 UTC (rev 281110)
</span><span class="lines">@@ -3,8 +3,8 @@
</span><span class="cx"> PASS window.performance is defined
</span><span class="cx"> PASS window.performance.getEntriesByName is defined
</span><span class="cx"> PASS There should be one entry.
</span><del>-FAIL redirectStart == 0 in cross-origin redirect with failing Timing-Allow-Origin. assert_equals: redirectStart == 0 in cross-origin redirect with failing Timing-Allow-Origin. expected 0 but got 22
-FAIL redirectEnd == 0 in cross-origin redirect with failing Timing-Allow-Origin. assert_equals: redirectEnd == 0 in cross-origin redirect with failing Timing-Allow-Origin. expected 0 but got 34
</del><ins>+PASS redirectStart == 0 in cross-origin redirect with failing Timing-Allow-Origin.
+PASS redirectEnd == 0 in cross-origin redirect with failing Timing-Allow-Origin.
</ins><span class="cx"> PASS fetchStart > 0 in cross-origin redirect with failing Timing-Allow-Origin.
</span><del>-FAIL startTime == fetchStart in cross-origin redirect with failing Timing-Allow-Origin. assert_equals: startTime == fetchStart in cross-origin redirect with failing Timing-Allow-Origin. expected 22 but got 34
</del><ins>+PASS startTime == fetchStart in cross-origin redirect with failing Timing-Allow-Origin.
</ins><span class="cx"> 
</span></span></pre></div>
<a id="trunkLayoutTestsimportedw3cwebplatformtestsresourcetimingcrossoriginsandwichpartialTAOsubexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/resource-timing/crossorigin-sandwich-partial-TAO.sub-expected.txt (281109 => 281110)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/imported/w3c/web-platform-tests/resource-timing/crossorigin-sandwich-partial-TAO.sub-expected.txt      2021-08-16 21:39:33 UTC (rev 281109)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/resource-timing/crossorigin-sandwich-partial-TAO.sub-expected.txt 2021-08-16 21:43:02 UTC (rev 281110)
</span><span class="lines">@@ -3,8 +3,8 @@
</span><span class="cx"> PASS window.performance is defined
</span><span class="cx"> PASS window.performance.getEntriesByName is defined
</span><span class="cx"> PASS There should be one entry.
</span><del>-FAIL redirectStart == 0 in cross-origin redirect with failing Timing-Allow-Origin. assert_equals: redirectStart == 0 in cross-origin redirect with failing Timing-Allow-Origin. expected 0 but got 15
-FAIL redirectEnd == 0 in cross-origin redirect with failing Timing-Allow-Origin. assert_equals: redirectEnd == 0 in cross-origin redirect with failing Timing-Allow-Origin. expected 0 but got 24
</del><ins>+PASS redirectStart == 0 in cross-origin redirect with failing Timing-Allow-Origin.
+PASS redirectEnd == 0 in cross-origin redirect with failing Timing-Allow-Origin.
</ins><span class="cx"> PASS fetchStart > 0 in cross-origin redirect with failing Timing-Allow-Origin.
</span><del>-FAIL startTime == fetchStart in cross-origin redirect with failing Timing-Allow-Origin. assert_equals: startTime == fetchStart in cross-origin redirect with failing Timing-Allow-Origin. expected 15 but got 24
</del><ins>+PASS startTime == fetchStart in cross-origin redirect with failing Timing-Allow-Origin.
</ins><span class="cx"> 
</span></span></pre></div>
<a id="trunkLayoutTestsimportedw3cwebplatformtestsresourcetimingresource_timing_cross_origin_redirect_chainexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/resource-timing/resource_timing_cross_origin_redirect_chain-expected.txt (281109 => 281110)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/imported/w3c/web-platform-tests/resource-timing/resource_timing_cross_origin_redirect_chain-expected.txt       2021-08-16 21:39:33 UTC (rev 281109)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/resource-timing/resource_timing_cross_origin_redirect_chain-expected.txt  2021-08-16 21:43:02 UTC (rev 281110)
</span><span class="lines">@@ -3,8 +3,8 @@
</span><span class="cx"> PASS window.performance is defined
</span><span class="cx"> PASS window.performance.getEntriesByName is defined
</span><span class="cx"> PASS There should be one entry.
</span><del>-FAIL redirectStart == 0 in cross-origin redirect. assert_equals: redirectStart == 0 in cross-origin redirect. expected 0 but got 889
-FAIL redirectEnd == 0 in cross-origin redirect. assert_equals: redirectEnd == 0 in cross-origin redirect. expected 0 but got 955.0000000000001
</del><ins>+PASS redirectStart == 0 in cross-origin redirect.
+PASS redirectEnd == 0 in cross-origin redirect.
</ins><span class="cx"> PASS fetchStart > 0 in cross-origin redirect.
</span><del>-FAIL startTime == fetchStart in cross-origin redirect. assert_equals: startTime == fetchStart in cross-origin redirect. expected 955.0000000000001 but got 889
</del><ins>+PASS startTime == fetchStart in cross-origin redirect.
</ins><span class="cx"> 
</span></span></pre></div>
<a id="trunkLayoutTestsimportedw3cwebplatformtestsresourcetimingstatuscodescreateentryexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/resource-timing/status-codes-create-entry-expected.txt (281109 => 281110)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/imported/w3c/web-platform-tests/resource-timing/status-codes-create-entry-expected.txt 2021-08-16 21:39:33 UTC (rev 281109)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/resource-timing/status-codes-create-entry-expected.txt    2021-08-16 21:43:02 UTC (rev 281110)
</span><span class="lines">@@ -1,4 +1,4 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-FAIL Make sure all status codes are reported assert_greater_than: http://localhost:8800/resource-timing/resources/status-code.py?status=404&script=1 expected a number greater than 0 but got 0
</del><ins>+PASS Make sure all status codes are reported
</ins><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (281109 => 281110)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog   2021-08-16 21:39:33 UTC (rev 281109)
+++ trunk/Source/WebCore/ChangeLog      2021-08-16 21:43:02 UTC (rev 281110)
</span><span class="lines">@@ -1,3 +1,38 @@
</span><ins>+2021-08-16  Alex Christensen  <achristensen@webkit.org>
+
+        Resource Timing: Duration is 0 in many cases
+        https://bugs.webkit.org/show_bug.cgi?id=225737
+
+        Reviewed by Chris Dumez.
+
+        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):
+
</ins><span class="cx"> 2021-08-16  Andres Gonzalez  <andresg_22@apple.com>
</span><span class="cx"> 
</span><span class="cx">         Expose [WebAccessibilityObjectWrapper lineRectsAndText] on MacOS.
</span></span></pre></div>
<a id="trunkSourceWebCoreloaderResourceTimingcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/loader/ResourceTiming.cpp (281109 => 281110)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/loader/ResourceTiming.cpp   2021-08-16 21:39:33 UTC (rev 281109)
+++ trunk/Source/WebCore/loader/ResourceTiming.cpp      2021-08-16 21:43:02 UTC (rev 281110)
</span><span class="lines">@@ -27,6 +27,7 @@
</span><span class="cx"> #include "ResourceTiming.h"
</span><span class="cx"> 
</span><span class="cx"> #include "CachedResource.h"
</span><ins>+#include "DocumentLoadTiming.h"
</ins><span class="cx"> #include "PerformanceServerTiming.h"
</span><span class="cx"> #include "RuntimeEnabledFeatures.h"
</span><span class="cx"> #include "SecurityOrigin.h"
</span><span class="lines">@@ -35,9 +36,9 @@
</span><span class="cx"> 
</span><span class="cx"> namespace WebCore {
</span><span class="cx"> 
</span><del>-ResourceTiming ResourceTiming::fromMemoryCache(const URL& url, const String& initiator, const ResourceLoadTiming& loadTiming, const ResourceResponse& response, const SecurityOrigin& securityOrigin)
</del><ins>+ResourceTiming ResourceTiming::fromMemoryCache(const URL& url, const String& initiator, const ResourceLoadTiming& loadTiming, const ResourceResponse& response, const NetworkLoadMetrics& networkLoadMetrics, const SecurityOrigin& securityOrigin)
</ins><span class="cx"> {
</span><del>-    return ResourceTiming(url, initiator, loadTiming, response, securityOrigin);
</del><ins>+    return ResourceTiming(url, initiator, loadTiming, networkLoadMetrics, response, securityOrigin);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> ResourceTiming ResourceTiming::fromLoad(CachedResource& resource, const URL& url, const String& initiator, const ResourceLoadTiming& loadTiming, const NetworkLoadMetrics& networkLoadMetrics, const SecurityOrigin& securityOrigin)
</span><span class="lines">@@ -50,14 +51,6 @@
</span><span class="cx">     return ResourceTiming(url, initiator, loadTiming, networkLoadMetrics, response, securityOrigin);
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-ResourceTiming::ResourceTiming(const URL& url, const String& initiator, const ResourceLoadTiming& loadTiming, const ResourceResponse& response, const SecurityOrigin&)
-    : m_url(url)
-    , m_initiator(initiator)
-    , m_resourceLoadTiming(loadTiming)
-{
-    initServerTiming(response);
-}
-
</del><span class="cx"> ResourceTiming::ResourceTiming(const URL& url, const String& initiator, const ResourceLoadTiming& timing, const NetworkLoadMetrics& networkLoadMetrics, const ResourceResponse& response, const SecurityOrigin&)
</span><span class="cx">     : m_url(url)
</span><span class="cx">     , m_initiator(initiator)
</span><span class="lines">@@ -64,11 +57,6 @@
</span><span class="cx">     , m_resourceLoadTiming(timing)
</span><span class="cx">     , m_networkLoadMetrics(networkLoadMetrics)
</span><span class="cx"> {
</span><del>-    initServerTiming(response);
-}
-
-void ResourceTiming::initServerTiming(const ResourceResponse& response)
-{
</del><span class="cx">     if (RuntimeEnabledFeatures::sharedFeatures().serverTimingEnabled() && !m_networkLoadMetrics.failsTAOCheck)
</span><span class="cx">         m_serverTiming = ServerTimingParser::parseServerTiming(response.httpHeaderField(HTTPHeaderName::ServerTiming));
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebCoreloaderResourceTimingh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/loader/ResourceTiming.h (281109 => 281110)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/loader/ResourceTiming.h     2021-08-16 21:39:33 UTC (rev 281109)
+++ trunk/Source/WebCore/loader/ResourceTiming.h        2021-08-16 21:43:02 UTC (rev 281110)
</span><span class="lines">@@ -41,7 +41,7 @@
</span><span class="cx"> class ResourceTiming {
</span><span class="cx">     WTF_MAKE_FAST_ALLOCATED;
</span><span class="cx"> public:
</span><del>-    static ResourceTiming fromMemoryCache(const URL&, const String& initiator, const ResourceLoadTiming&, const ResourceResponse&, const SecurityOrigin&);
</del><ins>+    static ResourceTiming fromMemoryCache(const URL&, const String& initiator, const ResourceLoadTiming&, const ResourceResponse&, const NetworkLoadMetrics&, const SecurityOrigin&);
</ins><span class="cx">     static ResourceTiming fromLoad(CachedResource&, const URL&, const String& initiator, const ResourceLoadTiming&, const NetworkLoadMetrics&, const SecurityOrigin&);
</span><span class="cx">     static ResourceTiming fromSynchronousLoad(const URL&, const String& initiator, const ResourceLoadTiming&, const NetworkLoadMetrics&, const ResourceResponse&, const SecurityOrigin&);
</span><span class="cx"> 
</span><span class="lines">@@ -56,7 +56,6 @@
</span><span class="cx"> 
</span><span class="cx"> private:
</span><span class="cx">     ResourceTiming(const URL&, const String& initiator, const ResourceLoadTiming&, const NetworkLoadMetrics&, const ResourceResponse&, const SecurityOrigin&);
</span><del>-    ResourceTiming(const URL&, const String& initiator, const ResourceLoadTiming&, const ResourceResponse&, const SecurityOrigin&);
</del><span class="cx">     ResourceTiming(URL&& url, String&& initiator, const ResourceLoadTiming& resourceLoadTiming, NetworkLoadMetrics&& networkLoadMetrics, Vector<ServerTiming>&& serverTiming)
</span><span class="cx">         : m_url(WTFMove(url))
</span><span class="cx">         , m_initiator(WTFMove(initiator))
</span><span class="lines">@@ -65,7 +64,6 @@
</span><span class="cx">         , m_serverTiming(WTFMove(serverTiming))
</span><span class="cx">     {
</span><span class="cx">     }
</span><del>-    void initServerTiming(const ResourceResponse&);
</del><span class="cx"> 
</span><span class="cx">     URL m_url;
</span><span class="cx">     String m_initiator;
</span></span></pre></div>
<a id="trunkSourceWebCoreloaderResourceTimingInformationcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/loader/ResourceTimingInformation.cpp (281109 => 281110)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/loader/ResourceTimingInformation.cpp        2021-08-16 21:39:33 UTC (rev 281109)
+++ trunk/Source/WebCore/loader/ResourceTimingInformation.cpp   2021-08-16 21:43:02 UTC (rev 281110)
</span><span class="lines">@@ -40,19 +40,9 @@
</span><span class="cx"> 
</span><span class="cx"> bool ResourceTimingInformation::shouldAddResourceTiming(CachedResource& resource)
</span><span class="cx"> {
</span><del>-    // FIXME: We can be less restrictive here.
-    // <https://github.com/w3c/resource-timing/issues/100>
-    if (!resource.resourceRequest().url().protocolIsInHTTPFamily())
-        return false;
-    if (resource.errorOccurred())
-        return false;
-    if (resource.wasCanceled())
-        return false;
-
-    if (resource.options().loadedFromOpaqueSource == LoadedFromOpaqueSource::Yes)
-        return false;
-
-    return true;
</del><ins>+    return resource.resourceRequest().url().protocolIsInHTTPFamily()
+        && !resource.loadFailedOrCanceled()
+        && resource.options().loadedFromOpaqueSource == LoadedFromOpaqueSource::No;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void ResourceTimingInformation::addResourceTiming(CachedResource& resource, Document& document, ResourceTiming&& resourceTiming)
</span></span></pre></div>
<a id="trunkSourceWebCoreloadercacheCachedResourceh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/loader/cache/CachedResource.h (281109 => 281110)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/loader/cache/CachedResource.h       2021-08-16 21:39:33 UTC (rev 281109)
+++ trunk/Source/WebCore/loader/cache/CachedResource.h  2021-08-16 21:43:02 UTC (rev 281110)
</span><span class="lines">@@ -219,6 +219,7 @@
</span><span class="cx">     virtual bool shouldCacheResponse(const ResourceResponse&) { return true; }
</span><span class="cx">     void setResponse(const ResourceResponse&);
</span><span class="cx">     const ResourceResponse& response() const { return m_response; }
</span><ins>+    Box<NetworkLoadMetrics> takeNetworkLoadMetrics() { return m_response.takeNetworkLoadMetrics(); }
</ins><span class="cx"> 
</span><span class="cx">     void setCrossOrigin();
</span><span class="cx">     bool isCrossOrigin() const;
</span></span></pre></div>
<a id="trunkSourceWebCoreloadercacheCachedResourceLoadercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/loader/cache/CachedResourceLoader.cpp (281109 => 281110)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/loader/cache/CachedResourceLoader.cpp       2021-08-16 21:39:33 UTC (rev 281109)
+++ trunk/Source/WebCore/loader/cache/CachedResourceLoader.cpp  2021-08-16 21:43:02 UTC (rev 281110)
</span><span class="lines">@@ -1034,7 +1034,13 @@
</span><span class="cx">             memoryCache.resourceAccessed(*resource);
</span><span class="cx"> 
</span><span class="cx">             if (document() && !resource->isLoading()) {
</span><del>-                auto resourceTiming = ResourceTiming::fromMemoryCache(url, request.initiatorName(), loadTiming, resource->response(), *request.origin());
</del><ins>+                Box<NetworkLoadMetrics> metrics;
+                auto* documentLoader = document()->loader();
+                // Use the actual network load metrics if this is the first time loading this resource and it was loaded
+                // for this document because it may have been speculatively preloaded.
+                if (auto metricsFromResource = resource->takeNetworkLoadMetrics(); metricsFromResource && documentLoader && metricsFromResource->redirectStart >= documentLoader->timing().timeOrigin())
+                    metrics = WTFMove(metricsFromResource);
+                auto resourceTiming = ResourceTiming::fromMemoryCache(url, request.initiatorName(), loadTiming, resource->response(), metrics ? *metrics : NetworkLoadMetrics { }, *request.origin());
</ins><span class="cx">                 if (initiatorContext == InitiatorContext::Worker) {
</span><span class="cx">                     ASSERT(is<CachedRawResource>(resource.get()));
</span><span class="cx">                     downcast<CachedRawResource>(resource.get())->finishedTimingForWorkerLoad(WTFMove(resourceTiming));
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformnetworkResourceResponseBaseh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/network/ResourceResponseBase.h (281109 => 281110)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/network/ResourceResponseBase.h     2021-08-16 21:39:33 UTC (rev 281109)
+++ trunk/Source/WebCore/platform/network/ResourceResponseBase.h        2021-08-16 21:43:02 UTC (rev 281110)
</span><span class="lines">@@ -183,6 +183,10 @@
</span><span class="cx">     {
</span><span class="cx">         m_networkLoadMetrics = WTFMove(metrics);
</span><span class="cx">     }
</span><ins>+    Box<NetworkLoadMetrics> takeNetworkLoadMetrics()
+    {
+        return std::exchange(m_networkLoadMetrics, nullptr);
+    }
</ins><span class="cx"> 
</span><span class="cx">     // The ResourceResponse subclass may "shadow" this method to provide platform-specific memory usage information
</span><span class="cx">     unsigned memoryUsage() const
</span></span></pre>
</div>
</div>

</body>
</html>