<!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>[205269] 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/205269">205269</a></dd>
<dt>Author</dt> <dd>yoav@yoav.ws</dd>
<dt>Date</dt> <dd>2016-08-31 15:41:44 -0700 (Wed, 31 Aug 2016)</dd>
</dl>

<h3>Log Message</h3>
<pre>Add event support for link preload.
https://bugs.webkit.org/show_bug.cgi?id=158466

Reviewed by Alex Christensen.

Source/WebCore:

Add onload/onerror support for link rel preload to align it with the spec
and enable various resource loading use-cases.
This patch also fixes XHR matching issues by replacing LinkPreload with RawResource.

Tests: http/tests/misc/script_onload_delays_window_onload.html
       http/tests/preload/delaying_onload_link_preload_after_discovery.html
       http/tests/preload/delaying_onload_link_preload_after_discovery_image.html
       http/tests/preload/not_delaying_window_onload_before_discovery.html
       http/tests/preload/onerror_event.html
       http/tests/preload/onload_event.html

* CMakeLists.txt: Add LinkPreloadResourceClients.{h,cpp}
* WebCore.xcodeproj/project.pbxproj: Add LinkPreloadResourceClients.{h,cpp}.
* html/HTMlLinkElement.cpp:
(WebCore::linkErrorEventSender): Add an eventSender for the error event.
(WebCore::HTMLLinkElement::HTMLLinkElement): s/m_loadedSheet/m_loadedResource/
(WebCore::HTMLLinkElement::~HTMLLinkElement): Cancel the error event when the element gets destructed.
(WebCore::HTMLLinkElement::linkLoaded): dispatch the event in an async manner.
(WebCore::HTMLLinkElement::linkLoadingErrored): dispatch the event in an async manner.
(WebCore::HTMLLinkElement::dispatchPendingEvent): Call dispatchEvent directly.
(WebCore::HTMLLinkElement::notifyLoadedSheetAndAllCriticalSubresources): s/m_loadedSheet/m_loadedResource/
* html/HTMLLinkElement.h: s/m_loadedSheet/m_loadedResource/
* html/parser/HTMLResourcePreloader.cpp:
(WebCore::HTMLResourcePreloader::preload): Call preload as ImplicitPreload, to distinguish it from declarative preload.
* loader/LinkLoader.cpp:
(WebCore::LinkLoader::LinkLoader): Get rid of unnecessary event timers and add a weakPtrFactory.
(WebCore::LinkLoader::triggerEvents): Add a triggerEvents function that can be called from notifyFinished as well as the
LinkPreloadResourceClients.
(WebCore::LinkLoader::notifyFinished): Call the triggerEvents function.
(WebCore::LinkLoader::resourceTypeFromAsAttribute): Replace LinkPreload with RawResource to avoid XHR resource matching issues.
(WebCore::createLinkPreloadResourceClient): Create a resource client for link preload.
(WebCore::LinkLoader::preloadIfNeeded): Trigger an error when `as` is unknown. Make sure that preload resources don't delay window.onload
before discovery. Get the resource back from calling preload and create a client for that resource.
(WebCore::LinkLoader::linkLoadTimerFired): Deleted.
(WebCore::LinkLoader::linkLoadingErrorTimerFired): Deleted.
(WebCore::preloadIfNeeded): Deleted.
* loader/LinkLoader.h:
(WebCore::LinkLoader::createWeakPtr):
* loader/LinkPreloadResourceClients.cpp: Added.
(WebCore::LinkPreloadResourceClient::LinkPreloadResourceClient): Create a LinkPreloadResourceClient and assign with with a weakPtr of
LinkLoader.
(WebCore::LinkPreloadResourceClient::triggerEvents): Call LinkLoader's triggerEvents.
* loader/LinkPreloadResourceClients.h: Added.
(WebCore::LinkPreloadResourceClient::~LinkPreloadResourceClient):
(WebCore::LinkPreloadResourceClient::addResource): Add as resource's client.
(WebCore::LinkPreloadResourceClient::clearResource): Remove as resource's client and clear ref to resource.
(WebCore::LinkPreloadResourceClient::ownedResource): Return ref to resource.
* loader/ResourceLoadInfo.cpp:
(WebCore::toResourceType): Removed LinkPreload.
* loader/SubresourceLoader.cpp:
(WebCore::logResourceLoaded): Removed LinkPreload.
* loader/cache/CachedResource.cpp:
(WebCore::CachedResource::defaultPriorityForResourceType): Removed LinkPreload.
* loader/cache/CachedResource.h: Removed LinkPreload.
(WebCore::CachedResource::ignoreForRequestCount): Don't delay window.onload for requests that opted out of that.
* loader/cache/CachedResourceLoader.cpp:
(WebCore::CachedResourceLoader::checkInsecureContent): Removed LinkPreload.
(WebCore::CachedResourceLoader::requestResource): Make sure that discovered preload resources do block window.onload.
(WebCore::CachedResourceLoader::preload): Make sure that explicitly preloaded subresources can be fetched even if there are parser
blocking resources still in flight. Return the preloaded resource.
(WebCore::CachedResourceLoader::requestPreload): Make sure that preloaded fonts get requested. Return preloaded resource.
(WebCore::createResource): Removed LinkPreload.
(WebCore::contentTypeFromResourceType): Removed LinkPreload.
(WebCore::CachedResourceLoader::canRequest): Removed LinkPreload.
* loader/cache/CachedResourceLoader.h:
* platform/network/ResourceRequestBase.h:
(WebCore::ResourceRequestBase::ignoreForRequestCount): Get the flag saying if a resource should block window.onload.
(WebCore::ResourceRequestBase::setIgnoreForRequestCount): Set the flag saying if a resource should block window.onload.

Source/WebKit2:

* WebProcess/Network/WebLoaderStrategy.cpp:
(WebKit::maximumBufferingTime): Removed LinkPreload.

LayoutTests:

Add tests that make sure that event handling with regarding to link preload
is working as it should.

* http/tests/misc/script_onload_delays_window_onload-expected.txt: Added.
* http/tests/misc/script_onload_delays_window_onload.html: Added.
* http/tests/preload/delaying_onload_link_preload_after_discovery-expected.txt: Added.
* http/tests/preload/delaying_onload_link_preload_after_discovery.html: Added.
* http/tests/preload/delaying_onload_link_preload_after_discovery_image-expected.txt: Added.
* http/tests/preload/delaying_onload_link_preload_after_discovery_image.html: Added.
* http/tests/preload/dynamic_remove_preload_href-expected.txt:
* http/tests/preload/dynamic_remove_preload_href.html:
* http/tests/preload/not_delaying_window_onload_before_discovery-expected.txt: Added.
* http/tests/preload/not_delaying_window_onload_before_discovery.html: Added.
* http/tests/preload/onerror_event-expected.txt: Added.
* http/tests/preload/onerror_event.html: Added.
* http/tests/preload/onload_event-expected.txt: Added.
* http/tests/preload/onload_event.html: Added.
* http/tests/preload/resources/single_download_preload.html:
* http/tests/resources/dummy.css: Added.
* http/tests/resources/dummy.js: Added.
* http/tests/resources/dummy.xml: Added.
* http/tests/resources/slow-image.php: Added.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkLayoutTestshttptestspreloaddynamic_remove_preload_hrefexpectedtxt">trunk/LayoutTests/http/tests/preload/dynamic_remove_preload_href-expected.txt</a></li>
<li><a href="#trunkLayoutTestshttptestspreloaddynamic_remove_preload_hrefhtml">trunk/LayoutTests/http/tests/preload/dynamic_remove_preload_href.html</a></li>
<li><a href="#trunkLayoutTestshttptestspreloadresourcessingle_download_preloadhtml">trunk/LayoutTests/http/tests/preload/resources/single_download_preload.html</a></li>
<li><a href="#trunkSourceWebCoreCMakeListstxt">trunk/Source/WebCore/CMakeLists.txt</a></li>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreWebCorexcodeprojprojectpbxproj">trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj</a></li>
<li><a href="#trunkSourceWebCorehtmlHTMLLinkElementcpp">trunk/Source/WebCore/html/HTMLLinkElement.cpp</a></li>
<li><a href="#trunkSourceWebCorehtmlHTMLLinkElementh">trunk/Source/WebCore/html/HTMLLinkElement.h</a></li>
<li><a href="#trunkSourceWebCorehtmlparserHTMLResourcePreloadercpp">trunk/Source/WebCore/html/parser/HTMLResourcePreloader.cpp</a></li>
<li><a href="#trunkSourceWebCoreloaderLinkLoadercpp">trunk/Source/WebCore/loader/LinkLoader.cpp</a></li>
<li><a href="#trunkSourceWebCoreloaderLinkLoaderh">trunk/Source/WebCore/loader/LinkLoader.h</a></li>
<li><a href="#trunkSourceWebCoreloaderResourceLoadInfocpp">trunk/Source/WebCore/loader/ResourceLoadInfo.cpp</a></li>
<li><a href="#trunkSourceWebCoreloaderSubresourceLoadercpp">trunk/Source/WebCore/loader/SubresourceLoader.cpp</a></li>
<li><a href="#trunkSourceWebCoreloadercacheCachedResourcecpp">trunk/Source/WebCore/loader/cache/CachedResource.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="#trunkSourceWebCoreloadercacheCachedResourceLoaderh">trunk/Source/WebCore/loader/cache/CachedResourceLoader.h</a></li>
<li><a href="#trunkSourceWebCoreplatformnetworkResourceRequestBaseh">trunk/Source/WebCore/platform/network/ResourceRequestBase.h</a></li>
<li><a href="#trunkSourceWebKit2ChangeLog">trunk/Source/WebKit2/ChangeLog</a></li>
<li><a href="#trunkSourceWebKit2WebProcessNetworkWebLoaderStrategycpp">trunk/Source/WebKit2/WebProcess/Network/WebLoaderStrategy.cpp</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkLayoutTestshttptestsmiscscript_onload_delays_window_onloadexpectedtxt">trunk/LayoutTests/http/tests/misc/script_onload_delays_window_onload-expected.txt</a></li>
<li><a href="#trunkLayoutTestshttptestsmiscscript_onload_delays_window_onloadhtml">trunk/LayoutTests/http/tests/misc/script_onload_delays_window_onload.html</a></li>
<li><a href="#trunkLayoutTestshttptestspreloaddelaying_onload_link_preload_after_discoveryexpectedtxt">trunk/LayoutTests/http/tests/preload/delaying_onload_link_preload_after_discovery-expected.txt</a></li>
<li><a href="#trunkLayoutTestshttptestspreloaddelaying_onload_link_preload_after_discoveryhtml">trunk/LayoutTests/http/tests/preload/delaying_onload_link_preload_after_discovery.html</a></li>
<li><a href="#trunkLayoutTestshttptestspreloaddelaying_onload_link_preload_after_discovery_imageexpectedtxt">trunk/LayoutTests/http/tests/preload/delaying_onload_link_preload_after_discovery_image-expected.txt</a></li>
<li><a href="#trunkLayoutTestshttptestspreloaddelaying_onload_link_preload_after_discovery_imagehtml">trunk/LayoutTests/http/tests/preload/delaying_onload_link_preload_after_discovery_image.html</a></li>
<li><a href="#trunkLayoutTestshttptestspreloadnot_delaying_window_onload_before_discoveryexpectedtxt">trunk/LayoutTests/http/tests/preload/not_delaying_window_onload_before_discovery-expected.txt</a></li>
<li><a href="#trunkLayoutTestshttptestspreloadnot_delaying_window_onload_before_discoveryhtml">trunk/LayoutTests/http/tests/preload/not_delaying_window_onload_before_discovery.html</a></li>
<li><a href="#trunkLayoutTestshttptestspreloadonerror_eventexpectedtxt">trunk/LayoutTests/http/tests/preload/onerror_event-expected.txt</a></li>
<li><a href="#trunkLayoutTestshttptestspreloadonerror_eventhtml">trunk/LayoutTests/http/tests/preload/onerror_event.html</a></li>
<li><a href="#trunkLayoutTestshttptestspreloadonload_eventexpectedtxt">trunk/LayoutTests/http/tests/preload/onload_event-expected.txt</a></li>
<li><a href="#trunkLayoutTestshttptestspreloadonload_eventhtml">trunk/LayoutTests/http/tests/preload/onload_event.html</a></li>
<li><a href="#trunkLayoutTestshttptestsresourcesdummycss">trunk/LayoutTests/http/tests/resources/dummy.css</a></li>
<li><a href="#trunkLayoutTestshttptestsresourcesdummyjs">trunk/LayoutTests/http/tests/resources/dummy.js</a></li>
<li><a href="#trunkLayoutTestshttptestsresourcesslowimagephp">trunk/LayoutTests/http/tests/resources/slow-image.php</a></li>
<li><a href="#trunkSourceWebCoreloaderLinkPreloadResourceClientscpp">trunk/Source/WebCore/loader/LinkPreloadResourceClients.cpp</a></li>
<li><a href="#trunkSourceWebCoreloaderLinkPreloadResourceClientsh">trunk/Source/WebCore/loader/LinkPreloadResourceClients.h</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (205268 => 205269)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2016-08-31 22:16:23 UTC (rev 205268)
+++ trunk/LayoutTests/ChangeLog        2016-08-31 22:41:44 UTC (rev 205269)
</span><span class="lines">@@ -1,3 +1,33 @@
</span><ins>+2016-08-31  Yoav Weiss  &lt;yoav@yoav.ws&gt;
+
+        Add event support for link preload.
+        https://bugs.webkit.org/show_bug.cgi?id=158466
+
+        Reviewed by Alex Christensen.
+
+        Add tests that make sure that event handling with regarding to link preload
+        is working as it should.
+
+        * http/tests/misc/script_onload_delays_window_onload-expected.txt: Added.
+        * http/tests/misc/script_onload_delays_window_onload.html: Added.
+        * http/tests/preload/delaying_onload_link_preload_after_discovery-expected.txt: Added.
+        * http/tests/preload/delaying_onload_link_preload_after_discovery.html: Added.
+        * http/tests/preload/delaying_onload_link_preload_after_discovery_image-expected.txt: Added.
+        * http/tests/preload/delaying_onload_link_preload_after_discovery_image.html: Added.
+        * http/tests/preload/dynamic_remove_preload_href-expected.txt:
+        * http/tests/preload/dynamic_remove_preload_href.html:
+        * http/tests/preload/not_delaying_window_onload_before_discovery-expected.txt: Added.
+        * http/tests/preload/not_delaying_window_onload_before_discovery.html: Added.
+        * http/tests/preload/onerror_event-expected.txt: Added.
+        * http/tests/preload/onerror_event.html: Added.
+        * http/tests/preload/onload_event-expected.txt: Added.
+        * http/tests/preload/onload_event.html: Added.
+        * http/tests/preload/resources/single_download_preload.html:
+        * http/tests/resources/dummy.css: Added.
+        * http/tests/resources/dummy.js: Added.
+        * http/tests/resources/dummy.xml: Added.
+        * http/tests/resources/slow-image.php: Added.
+
</ins><span class="cx"> 2016-08-31  Joseph Pecoraro  &lt;pecoraro@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Web Inspector: XHR with text but responseType = &quot;blob&quot; shows blank content
</span></span></pre></div>
<a id="trunkLayoutTestshttptestsmiscscript_onload_delays_window_onloadexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/http/tests/misc/script_onload_delays_window_onload-expected.txt (0 => 205269)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/http/tests/misc/script_onload_delays_window_onload-expected.txt                                (rev 0)
+++ trunk/LayoutTests/http/tests/misc/script_onload_delays_window_onload-expected.txt        2016-08-31 22:41:44 UTC (rev 205269)
</span><span class="lines">@@ -0,0 +1,5 @@
</span><ins>+PASS scriptLoaded is true
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
</ins></span></pre></div>
<a id="trunkLayoutTestshttptestsmiscscript_onload_delays_window_onloadhtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/http/tests/misc/script_onload_delays_window_onload.html (0 => 205269)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/http/tests/misc/script_onload_delays_window_onload.html                                (rev 0)
+++ trunk/LayoutTests/http/tests/misc/script_onload_delays_window_onload.html        2016-08-31 22:41:44 UTC (rev 205269)
</span><span class="lines">@@ -0,0 +1,12 @@
</span><ins>+&lt;!DOCTYPE html&gt;
+&lt;script src=&quot;/js-test-resources/js-test.js&quot;&gt;&lt;/script&gt;
+&lt;script&gt;
+    var scriptLoaded = false;
+&lt;/script&gt;
+&lt;script src=&quot;../resources/slow-script.pl?delay=200&quot; onload=&quot;scriptLoaded = true;&quot;&gt;&lt;/script&gt;
+&lt;script&gt;
+     addEventListener(&quot;load&quot;, function() {
+         shouldBeTrue(&quot;scriptLoaded&quot;);
+     });
+&lt;/script&gt;
+
</ins></span></pre></div>
<a id="trunkLayoutTestshttptestspreloaddelaying_onload_link_preload_after_discoveryexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/http/tests/preload/delaying_onload_link_preload_after_discovery-expected.txt (0 => 205269)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/http/tests/preload/delaying_onload_link_preload_after_discovery-expected.txt                                (rev 0)
+++ trunk/LayoutTests/http/tests/preload/delaying_onload_link_preload_after_discovery-expected.txt        2016-08-31 22:41:44 UTC (rev 205269)
</span><span class="lines">@@ -0,0 +1,5 @@
</span><ins>+PASS finishedScript is true
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
</ins></span></pre></div>
<a id="trunkLayoutTestshttptestspreloaddelaying_onload_link_preload_after_discoveryhtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/http/tests/preload/delaying_onload_link_preload_after_discovery.html (0 => 205269)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/http/tests/preload/delaying_onload_link_preload_after_discovery.html                                (rev 0)
+++ trunk/LayoutTests/http/tests/preload/delaying_onload_link_preload_after_discovery.html        2016-08-31 22:41:44 UTC (rev 205269)
</span><span class="lines">@@ -0,0 +1,25 @@
</span><ins>+&lt;!DOCTYPE html&gt;
+&lt;script&gt;
+    if (window.internals)
+        window.internals.setLinkPreloadSupport(true);
+    if (window.testRunner) {
+        testRunner.dumpAsText()
+        testRunner.waitUntilDone();
+    }
+    var finishedScript = false;
+&lt;/script&gt;
+&lt;script src=&quot;/js-test-resources/js-test.js&quot;&gt;&lt;/script&gt;
+&lt;link rel=preload href=&quot;../resources/slow-script.pl?delay=400&quot; as=script onload=&quot;finishedScript = true;&quot;&gt;
+&lt;body&gt;
+&lt;script&gt;
+    window.addEventListener(&quot;load&quot;, function() {
+        shouldBeTrue(&quot;finishedScript&quot;);
+        if (window.internals)
+            window.internals.setLinkPreloadSupport(false);
+        setTimeout(function() { testRunner.notifyDone(); }, 0);
+    });
+    var scr = document.createElement(&quot;script&quot;);
+    scr.src = &quot;../resources/slow-script.pl?delay=400&quot;;
+    document.body.appendChild(scr);
+&lt;/script&gt;
+&lt;/body&gt;
</ins></span></pre></div>
<a id="trunkLayoutTestshttptestspreloaddelaying_onload_link_preload_after_discovery_imageexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/http/tests/preload/delaying_onload_link_preload_after_discovery_image-expected.txt (0 => 205269)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/http/tests/preload/delaying_onload_link_preload_after_discovery_image-expected.txt                                (rev 0)
+++ trunk/LayoutTests/http/tests/preload/delaying_onload_link_preload_after_discovery_image-expected.txt        2016-08-31 22:41:44 UTC (rev 205269)
</span><span class="lines">@@ -0,0 +1,5 @@
</span><ins>+PASS finishedImage is true
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
</ins></span></pre></div>
<a id="trunkLayoutTestshttptestspreloaddelaying_onload_link_preload_after_discovery_imagehtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/http/tests/preload/delaying_onload_link_preload_after_discovery_image.html (0 => 205269)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/http/tests/preload/delaying_onload_link_preload_after_discovery_image.html                                (rev 0)
+++ trunk/LayoutTests/http/tests/preload/delaying_onload_link_preload_after_discovery_image.html        2016-08-31 22:41:44 UTC (rev 205269)
</span><span class="lines">@@ -0,0 +1,25 @@
</span><ins>+&lt;!DOCTYPE html&gt;
+&lt;script&gt;
+    if (window.internals)
+        window.internals.setLinkPreloadSupport(true);
+    if (window.testRunner) {
+        testRunner.dumpAsText()
+        testRunner.waitUntilDone();
+    }
+    var finishedImage = false;
+&lt;/script&gt;
+&lt;script src=&quot;/js-test-resources/js-test.js&quot;&gt;&lt;/script&gt;
+&lt;link rel=preload href=&quot;../resources/slow-image.php&quot; as=image onload=&quot;finishedImage = true;&quot;&gt;
+&lt;body&gt;
+&lt;script&gt;
+    window.addEventListener(&quot;load&quot;, function() {
+        shouldBeTrue(&quot;finishedImage&quot;);
+        if (window.internals)
+            window.internals.setLinkPreloadSupport(false);
+        testRunner.notifyDone();
+    });
+    var img = new Image();
+    img.src = &quot;../resources/slow-image.php&quot;;
+    document.body.appendChild(img);
+&lt;/script&gt;
+&lt;/body&gt;
</ins></span></pre></div>
<a id="trunkLayoutTestshttptestspreloaddynamic_remove_preload_hrefexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/http/tests/preload/dynamic_remove_preload_href-expected.txt (205268 => 205269)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/http/tests/preload/dynamic_remove_preload_href-expected.txt        2016-08-31 22:16:23 UTC (rev 205268)
+++ trunk/LayoutTests/http/tests/preload/dynamic_remove_preload_href-expected.txt        2016-08-31 22:41:44 UTC (rev 205269)
</span><span class="lines">@@ -1,5 +1,5 @@
</span><del>-CONSOLE MESSAGE: line 16: &lt;link rel=preload&gt; has an invalid `href` value
-PASS internals.isPreloaded('../resources/dummy.js'); is false
</del><ins>+CONSOLE MESSAGE: line 19: &lt;link rel=preload&gt; has an invalid `href` value
+PASS downloadedImage is false
</ins><span class="cx"> PASS successfullyParsed is true
</span><span class="cx"> 
</span><span class="cx"> TEST COMPLETE
</span></span></pre></div>
<a id="trunkLayoutTestshttptestspreloaddynamic_remove_preload_hrefhtml"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/http/tests/preload/dynamic_remove_preload_href.html (205268 => 205269)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/http/tests/preload/dynamic_remove_preload_href.html        2016-08-31 22:16:23 UTC (rev 205268)
+++ trunk/LayoutTests/http/tests/preload/dynamic_remove_preload_href.html        2016-08-31 22:41:44 UTC (rev 205269)
</span><span class="lines">@@ -2,22 +2,32 @@
</span><span class="cx"> &lt;html&gt;
</span><span class="cx"> &lt;head&gt;
</span><span class="cx"> &lt;script&gt;
</span><del>-    if (window.internals)
</del><ins>+    if (window.internals) {
</ins><span class="cx">         window.internals.setLinkPreloadSupport(true);
</span><ins>+        window.internals.setResourceTimingSupport(true);
+    }
</ins><span class="cx"> &lt;/script&gt;
</span><span class="cx"> &lt;script src=&quot;/js-test-resources/js-test.js&quot;&gt;&lt;/script&gt;
</span><span class="cx"> &lt;body&gt;
</span><span class="cx"> &lt;script&gt;
</span><span class="cx">     var link = document.createElement(&quot;link&quot;);
</span><del>-    link.as = &quot;script&quot;;
</del><ins>+    link.as = &quot;image&quot;;
</ins><span class="cx">     link.rel = &quot;preload&quot;;
</span><del>-    link.href = &quot;../resources/dummy.js&quot;;
</del><ins>+    link.href = &quot;../resources/slow-image.php&quot;;
+    var downloadedImage = false;
</ins><span class="cx">     document.body.appendChild(link);
</span><span class="cx">     link.href = &quot;&quot;;
</span><span class="cx">     window.addEventListener(&quot;load&quot;, function() {
</span><del>-        shouldBeFalse(&quot;internals.isPreloaded('../resources/dummy.js');&quot;);
-        if (window.internals)
</del><ins>+        var entries = performance.getEntriesByType(&quot;resource&quot;);
+        for (var i = 0; i &lt; entries.length; ++i) {
+            if (entries[i].name.indexOf(&quot;slow-image.php&quot;) != -1)
+                downloadedImage = true;
+        }
+        shouldBeFalse(&quot;downloadedImage&quot;);
+        if (window.internals) {
</ins><span class="cx">             window.internals.setLinkPreloadSupport(false);
</span><ins>+            window.internals.setResourceTimingSupport(false);
+        }
</ins><span class="cx">     });
</span><span class="cx"> &lt;/script&gt;
</span><span class="cx"> &lt;/body&gt;
</span></span></pre></div>
<a id="trunkLayoutTestshttptestspreloadnot_delaying_window_onload_before_discoveryexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/http/tests/preload/not_delaying_window_onload_before_discovery-expected.txt (0 => 205269)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/http/tests/preload/not_delaying_window_onload_before_discovery-expected.txt                                (rev 0)
+++ trunk/LayoutTests/http/tests/preload/not_delaying_window_onload_before_discovery-expected.txt        2016-08-31 22:41:44 UTC (rev 205269)
</span><span class="lines">@@ -0,0 +1,8 @@
</span><ins>+PASS finishedScript is false
+PASS finishedImage is false
+PASS successfullyParsed is true
+
+TEST COMPLETE
+PASS windowOnLoad is true
+PASS windowOnLoad is true
+
</ins></span></pre></div>
<a id="trunkLayoutTestshttptestspreloadnot_delaying_window_onload_before_discoveryhtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/http/tests/preload/not_delaying_window_onload_before_discovery.html (0 => 205269)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/http/tests/preload/not_delaying_window_onload_before_discovery.html                                (rev 0)
+++ trunk/LayoutTests/http/tests/preload/not_delaying_window_onload_before_discovery.html        2016-08-31 22:41:44 UTC (rev 205269)
</span><span class="lines">@@ -0,0 +1,36 @@
</span><ins>+&lt;!DOCTYPE html&gt;
+&lt;script&gt;
+    if (window.internals)
+        window.internals.setLinkPreloadSupport(true);
+    if (window.testRunner) {
+        testRunner.dumpAsText()
+        testRunner.waitUntilDone();
+    }
+&lt;/script&gt;
+&lt;script src=&quot;/js-test-resources/js-test.js&quot;&gt;&lt;/script&gt;
+&lt;script&gt;
+    finishedScript = false;
+    finishedImage = false;
+    windowOnLoad = false;
+    function test() {
+        shouldBeTrue(&quot;windowOnLoad&quot;);
+        if (finishedImage &amp;&amp; finishedScript) {
+            if (window.internals)
+                window.internals.setLinkPreloadSupport(false);
+            if (window.testRunner)
+                testRunner.notifyDone();
+        }
+    };
+
+&lt;/script&gt;
+&lt;link rel=preload href=&quot;../resources/slow-script.pl?delay=200&quot; as=script onload=&quot;window.finishedScript = true; test();&quot;&gt;
+&lt;link rel=preload href=&quot;../resources/slow-image.php&quot; as=image onload=&quot;window.finishedImage = true; test();&quot;&gt;
+&lt;body&gt;
+&lt;script&gt;
+    window.addEventListener(&quot;load&quot;, function() {
+        shouldBeFalse(&quot;finishedScript&quot;);
+        shouldBeFalse(&quot;finishedImage&quot;);
+        windowOnLoad = true;
+    });
+&lt;/script&gt;
+&lt;/body&gt;
</ins></span></pre></div>
<a id="trunkLayoutTestshttptestspreloadonerror_eventexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/http/tests/preload/onerror_event-expected.txt (0 => 205269)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/http/tests/preload/onerror_event-expected.txt                                (rev 0)
+++ trunk/LayoutTests/http/tests/preload/onerror_event-expected.txt        2016-08-31 22:41:44 UTC (rev 205269)
</span><span class="lines">@@ -0,0 +1,12 @@
</span><ins>+CONSOLE MESSAGE: line 29: &lt;link rel=preload&gt; must have a valid `as` value
+PASS successfullyParsed is true
+
+TEST COMPLETE
+PASS styleFailed is true
+PASS scriptFailed is true
+PASS imageFailed is true
+PASS fontFailed is true
+PASS trackFailed is true
+PASS gibrishFailed is true
+PASS noTypeFailed is true
+
</ins></span></pre></div>
<a id="trunkLayoutTestshttptestspreloadonerror_eventhtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/http/tests/preload/onerror_event.html (0 => 205269)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/http/tests/preload/onerror_event.html                                (rev 0)
+++ trunk/LayoutTests/http/tests/preload/onerror_event.html        2016-08-31 22:41:44 UTC (rev 205269)
</span><span class="lines">@@ -0,0 +1,50 @@
</span><ins>+&lt;!DOCTYPE html&gt;
+&lt;script&gt;
+    if (window.internals)
+        window.internals.setLinkPreloadSupport(true);
+    if (window.testRunner) {
+        testRunner.dumpAsText()
+        testRunner.waitUntilDone();
+    }
+&lt;/script&gt;
+&lt;script src=&quot;/js-test-resources/js-test.js&quot;&gt;&lt;/script&gt;
+&lt;script&gt;
+    var scriptFailed = false;
+    var styleFailed = false;
+    var imageFailed = false;
+    var fontFailed = false;
+    var trackFailed = false;
+    var gibrishFailed = false;
+    var noTypeFailed = false;
+    var counter = 0;
+    function count() {
+        ++window.counter;
+    };
+&lt;/script&gt;
+&lt;link rel=preload href=&quot;../non-existent/dummy.js&quot; as=script onerror=&quot;count();scriptFailed = true;&quot; onload=&quot;count();&quot;&gt;
+&lt;link rel=preload href=&quot;../non-existent/dummy.css&quot; as=style onerror=&quot;count();styleFailed = true;&quot; onload=&quot;count();&quot;&gt;
+&lt;link rel=preload href=&quot;../non-existent/square.png&quot; as=image onerror=&quot;count();imageFailed = true;&quot; onload=&quot;count();&quot;&gt;
+&lt;link rel=preload href=&quot;../non-existent/Ahem.ttf&quot; as=font crossorigin onerror=&quot;count();fontFailed = true;&quot; onload=&quot;count();&quot;&gt;
+&lt;link rel=preload href=&quot;../non-existent/security/captions.vtt&quot; as=track onerror=&quot;count();trackFailed = true;&quot; onload=&quot;count();&quot;&gt;
+&lt;link rel=preload href=&quot;../non-existent/dummy.xml&quot; as=foobarxmlthing onerror=&quot;count();gibrishFailed = true;&quot; onload=&quot;count();&quot;&gt;
+&lt;link rel=preload href=&quot;http://127.0.0.1:9999/non-existent/dummy.xml&quot; onerror=&quot;count();noTypeFailed = true;&quot; onload=&quot;count();&quot;&gt;
+&lt;script&gt;
+    function test() {
+        shouldBeTrue(&quot;styleFailed&quot;);
+        shouldBeTrue(&quot;scriptFailed&quot;);
+        shouldBeTrue(&quot;imageFailed&quot;);
+        shouldBeTrue(&quot;fontFailed&quot;);
+        shouldBeTrue(&quot;trackFailed&quot;);
+        shouldBeTrue(&quot;gibrishFailed&quot;);
+        shouldBeTrue(&quot;noTypeFailed&quot;);
+        if (window.internals)
+            window.internals.setLinkPreloadSupport(false);
+        if (window.testRunner)
+            testRunner.notifyDone();
+    };
+    setInterval(function() {
+        if (window.counter &gt;= 7)
+            test();
+    }, 100);
+&lt;/script&gt;
+
</ins></span></pre></div>
<a id="trunkLayoutTestshttptestspreloadonload_eventexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/http/tests/preload/onload_event-expected.txt (0 => 205269)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/http/tests/preload/onload_event-expected.txt                                (rev 0)
+++ trunk/LayoutTests/http/tests/preload/onload_event-expected.txt        2016-08-31 22:41:44 UTC (rev 205269)
</span><span class="lines">@@ -0,0 +1,18 @@
</span><ins>+CONSOLE MESSAGE: line 35: &lt;link rel=preload&gt; must have a valid `as` value
+CONSOLE MESSAGE: line 36: &lt;link rel=preload&gt; must have a valid `as` value
+PASS successfullyParsed is true
+
+TEST COMPLETE
+PASS styleLoaded is true
+PASS scriptLoaded is true
+PASS imageLoaded is true
+PASS fontLoaded is true
+PASS mediaLoaded is true
+PASS trackLoaded is true
+PASS gibberishLoaded is false
+PASS gibberishErrored is true
+PASS xsltLoaded is false
+PASS xsltErrored is true
+PASS noTypeLoaded is true
+PASS emptyTypeLoaded is true
+
</ins></span></pre></div>
<a id="trunkLayoutTestshttptestspreloadonload_eventhtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/http/tests/preload/onload_event.html (0 => 205269)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/http/tests/preload/onload_event.html                                (rev 0)
+++ trunk/LayoutTests/http/tests/preload/onload_event.html        2016-08-31 22:41:44 UTC (rev 205269)
</span><span class="lines">@@ -0,0 +1,65 @@
</span><ins>+&lt;!DOCTYPE html&gt;
+&lt;script&gt;
+    if (window.internals)
+        window.internals.setLinkPreloadSupport(true);
+    if (window.testRunner) {
+        testRunner.dumpAsText()
+        testRunner.waitUntilDone();
+    }
+&lt;/script&gt;
+&lt;script src=&quot;/js-test-resources/js-test.js&quot;&gt;&lt;/script&gt;
+&lt;script&gt;
+    var scriptLoaded = false;
+    var styleLoaded = false;
+    var imageLoaded = false;
+    var fontLoaded = false;
+    var mediaLoaded = false;
+    var trackLoaded = false;
+    var gibberishLoaded = false;
+    var gibberishErrored = false;
+    var xsltLoaded = false;
+    var xsltErrored = false;
+    var noTypeLoaded = false;
+    var emptyTypeLoaded = false;
+    var counter = 0;
+    function count() {
+        ++window.counter;
+    };
+&lt;/script&gt;
+&lt;link rel=preload href=&quot;../resources/dummy.js&quot; as=script onload=&quot;count(); scriptLoaded = true;&quot; onerror=&quot;count()&quot;&gt;
+&lt;link rel=preload href=&quot;../resources/dummy.css&quot; as=style onload=&quot;count(); styleLoaded = true;&quot; onerror=&quot;count()&quot;&gt;
+&lt;link rel=preload href=&quot;../resources/square100.png&quot; as=image onload=&quot;count(); imageLoaded = true;&quot; onerror=&quot;count()&quot;&gt;
+&lt;link rel=preload href=&quot;../resources/Ahem.woff&quot; as=font crossorigin onload=&quot;count(); fontLoaded = true;&quot; onerror=&quot;count()&quot;&gt;
+&lt;link rel=preload href=&quot;../resources/test.ogv&quot; as=media onload=&quot;count(); mediaLoaded = true;&quot; onerror=&quot;count()&quot;&gt;
+&lt;link rel=preload href=&quot;../security/resources/captions.vtt&quot; as=track onload=&quot;count(); trackLoaded = true;&quot; onerror=&quot;count()&quot;&gt;
+&lt;link rel=preload href=&quot;../resources/dummy.xml&quot; as=foobarxmlthing onload=&quot;count(); gibberishLoaded = true;&quot; onerror=&quot;count(); gibberishErrored = true;&quot;&gt;
+&lt;link rel=preload href=&quot;../resources/dummy.xslt&quot; as=xslt onload=&quot;count(); xsltLoaded = true;&quot; onerror=&quot;count(); xsltErrored = true;&quot;&gt;
+&lt;link rel=preload href=&quot;../resources/dummy.xml&quot; onload=&quot;count(); noTypeLoaded = true;&quot; onerror=&quot;count()&quot;&gt;
+&lt;link rel=preload href=&quot;../resources/dummy.xml?empty&quot; as onload=&quot;count(); emptyTypeLoaded = true;&quot; onerror=&quot;count()&quot;&gt;
+&lt;script&gt;
+    function test() {
+        shouldBeTrue(&quot;styleLoaded&quot;);
+        shouldBeTrue(&quot;scriptLoaded&quot;);
+        shouldBeTrue(&quot;imageLoaded&quot;);
+        shouldBeTrue(&quot;fontLoaded&quot;);
+        shouldBeTrue(&quot;mediaLoaded&quot;);
+        shouldBeTrue(&quot;trackLoaded&quot;);
+        shouldBeFalse(&quot;gibberishLoaded&quot;);
+        shouldBeTrue(&quot;gibberishErrored&quot;);
+        shouldBeFalse(&quot;xsltLoaded&quot;);
+        shouldBeTrue(&quot;xsltErrored&quot;);
+        shouldBeTrue(&quot;noTypeLoaded&quot;);
+        shouldBeTrue(&quot;emptyTypeLoaded&quot;);
+        if (window.internals)
+            window.internals.setLinkPreloadSupport(false);
+        if (window.testRunner)
+            testRunner.notifyDone();
+    }
+     addEventListener(&quot;load&quot;, function(){
+        setInterval(function() {
+            if (window.counter &gt;= 10)
+                test();
+        }, 100);
+    });
+&lt;/script&gt;
+
</ins></span></pre></div>
<a id="trunkLayoutTestshttptestspreloadresourcessingle_download_preloadhtml"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/http/tests/preload/resources/single_download_preload.html (205268 => 205269)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/http/tests/preload/resources/single_download_preload.html        2016-08-31 22:16:23 UTC (rev 205268)
+++ trunk/LayoutTests/http/tests/preload/resources/single_download_preload.html        2016-08-31 22:41:44 UTC (rev 205269)
</span><span class="lines">@@ -7,7 +7,7 @@
</span><span class="cx"> &lt;link rel=preload href=&quot;../../resources/test.mp4&quot; as=media&gt;
</span><span class="cx"> &lt;link rel=preload href=&quot;../../resources/test.oga&quot; as=media&gt;
</span><span class="cx"> &lt;link rel=preload href=&quot;../../security/resources/captions.vtt&quot; as=track&gt;
</span><del>-&lt;link rel=preload href=&quot;../../resources/dummy.xml&quot; as=foobarxmlthing&gt;
</del><ins>+&lt;link rel=preload href=&quot;../../resources/dummy.xml?foobar&quot; as=foobarxmlthing&gt;
</ins><span class="cx"> &lt;link rel=preload href=&quot;../../resources/dummy.xml&quot;&gt;
</span><span class="cx"> &lt;script src=&quot;../../resources/slow-script.pl?delay=200&quot;&gt;&lt;/script&gt;
</span><span class="cx"> &lt;style&gt;
</span></span></pre></div>
<a id="trunkLayoutTestshttptestsresourcesdummycss"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/http/tests/resources/dummy.css (0 => 205269)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/http/tests/resources/dummy.css                                (rev 0)
+++ trunk/LayoutTests/http/tests/resources/dummy.css        2016-08-31 22:41:44 UTC (rev 205269)
</span><span class="lines">@@ -0,0 +1 @@
</span><ins>+body { line-height: 16px; }
</ins></span></pre></div>
<a id="trunkLayoutTestshttptestsresourcesdummyjs"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/http/tests/resources/dummy.js (0 => 205269)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/http/tests/resources/dummy.js                                (rev 0)
+++ trunk/LayoutTests/http/tests/resources/dummy.js        2016-08-31 22:41:44 UTC (rev 205269)
</span><span class="lines">@@ -0,0 +1 @@
</span><ins>+var x = 5;
</ins></span></pre></div>
<a id="trunkLayoutTestshttptestsresourcesslowimagephp"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/http/tests/resources/slow-image.php (0 => 205269)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/http/tests/resources/slow-image.php                                (rev 0)
+++ trunk/LayoutTests/http/tests/resources/slow-image.php        2016-08-31 22:41:44 UTC (rev 205269)
</span><span class="lines">@@ -0,0 +1,7 @@
</span><ins>+&lt;?php
+usleep(400000);
+header(&quot;Content-Type: image/png&quot;);
+@readfile(&quot;square100.png&quot;);
+?&gt;
+
+
</ins></span></pre></div>
<a id="trunkSourceWebCoreCMakeListstxt"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/CMakeLists.txt (205268 => 205269)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/CMakeLists.txt        2016-08-31 22:16:23 UTC (rev 205268)
+++ trunk/Source/WebCore/CMakeLists.txt        2016-08-31 22:41:44 UTC (rev 205269)
</span><span class="lines">@@ -1944,6 +1944,7 @@
</span><span class="cx">     loader/HistoryController.cpp
</span><span class="cx">     loader/ImageLoader.cpp
</span><span class="cx">     loader/LinkLoader.cpp
</span><ins>+    loader/LinkPreloadResourceClients.cpp
</ins><span class="cx">     loader/LoadTiming.cpp
</span><span class="cx">     loader/LoaderStrategy.cpp
</span><span class="cx">     loader/MediaResourceLoader.cpp
</span></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (205268 => 205269)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2016-08-31 22:16:23 UTC (rev 205268)
+++ trunk/Source/WebCore/ChangeLog        2016-08-31 22:41:44 UTC (rev 205269)
</span><span class="lines">@@ -1,3 +1,79 @@
</span><ins>+2016-08-31  Yoav Weiss  &lt;yoav@yoav.ws&gt;
+
+        Add event support for link preload.
+        https://bugs.webkit.org/show_bug.cgi?id=158466
+
+        Reviewed by Alex Christensen.
+
+        Add onload/onerror support for link rel preload to align it with the spec
+        and enable various resource loading use-cases.
+        This patch also fixes XHR matching issues by replacing LinkPreload with RawResource.
+
+        Tests: http/tests/misc/script_onload_delays_window_onload.html
+               http/tests/preload/delaying_onload_link_preload_after_discovery.html
+               http/tests/preload/delaying_onload_link_preload_after_discovery_image.html
+               http/tests/preload/not_delaying_window_onload_before_discovery.html
+               http/tests/preload/onerror_event.html
+               http/tests/preload/onload_event.html
+
+        * CMakeLists.txt: Add LinkPreloadResourceClients.{h,cpp}
+        * WebCore.xcodeproj/project.pbxproj: Add LinkPreloadResourceClients.{h,cpp}.
+        * html/HTMlLinkElement.cpp:
+        (WebCore::linkErrorEventSender): Add an eventSender for the error event.
+        (WebCore::HTMLLinkElement::HTMLLinkElement): s/m_loadedSheet/m_loadedResource/
+        (WebCore::HTMLLinkElement::~HTMLLinkElement): Cancel the error event when the element gets destructed.
+        (WebCore::HTMLLinkElement::linkLoaded): dispatch the event in an async manner.
+        (WebCore::HTMLLinkElement::linkLoadingErrored): dispatch the event in an async manner.
+        (WebCore::HTMLLinkElement::dispatchPendingEvent): Call dispatchEvent directly.
+        (WebCore::HTMLLinkElement::notifyLoadedSheetAndAllCriticalSubresources): s/m_loadedSheet/m_loadedResource/
+        * html/HTMLLinkElement.h: s/m_loadedSheet/m_loadedResource/
+        * html/parser/HTMLResourcePreloader.cpp:
+        (WebCore::HTMLResourcePreloader::preload): Call preload as ImplicitPreload, to distinguish it from declarative preload.
+        * loader/LinkLoader.cpp:
+        (WebCore::LinkLoader::LinkLoader): Get rid of unnecessary event timers and add a weakPtrFactory.
+        (WebCore::LinkLoader::triggerEvents): Add a triggerEvents function that can be called from notifyFinished as well as the
+        LinkPreloadResourceClients.
+        (WebCore::LinkLoader::notifyFinished): Call the triggerEvents function.
+        (WebCore::LinkLoader::resourceTypeFromAsAttribute): Replace LinkPreload with RawResource to avoid XHR resource matching issues.
+        (WebCore::createLinkPreloadResourceClient): Create a resource client for link preload.
+        (WebCore::LinkLoader::preloadIfNeeded): Trigger an error when `as` is unknown. Make sure that preload resources don't delay window.onload
+        before discovery. Get the resource back from calling preload and create a client for that resource.
+        (WebCore::LinkLoader::linkLoadTimerFired): Deleted.
+        (WebCore::LinkLoader::linkLoadingErrorTimerFired): Deleted.
+        (WebCore::preloadIfNeeded): Deleted.
+        * loader/LinkLoader.h:
+        (WebCore::LinkLoader::createWeakPtr):
+        * loader/LinkPreloadResourceClients.cpp: Added.
+        (WebCore::LinkPreloadResourceClient::LinkPreloadResourceClient): Create a LinkPreloadResourceClient and assign with with a weakPtr of
+        LinkLoader.
+        (WebCore::LinkPreloadResourceClient::triggerEvents): Call LinkLoader's triggerEvents.
+        * loader/LinkPreloadResourceClients.h: Added.
+        (WebCore::LinkPreloadResourceClient::~LinkPreloadResourceClient):
+        (WebCore::LinkPreloadResourceClient::addResource): Add as resource's client.
+        (WebCore::LinkPreloadResourceClient::clearResource): Remove as resource's client and clear ref to resource.
+        (WebCore::LinkPreloadResourceClient::ownedResource): Return ref to resource.
+        * loader/ResourceLoadInfo.cpp:
+        (WebCore::toResourceType): Removed LinkPreload.
+        * loader/SubresourceLoader.cpp:
+        (WebCore::logResourceLoaded): Removed LinkPreload.
+        * loader/cache/CachedResource.cpp:
+        (WebCore::CachedResource::defaultPriorityForResourceType): Removed LinkPreload.
+        * loader/cache/CachedResource.h: Removed LinkPreload.
+        (WebCore::CachedResource::ignoreForRequestCount): Don't delay window.onload for requests that opted out of that.
+        * loader/cache/CachedResourceLoader.cpp:
+        (WebCore::CachedResourceLoader::checkInsecureContent): Removed LinkPreload.
+        (WebCore::CachedResourceLoader::requestResource): Make sure that discovered preload resources do block window.onload.
+        (WebCore::CachedResourceLoader::preload): Make sure that explicitly preloaded subresources can be fetched even if there are parser
+        blocking resources still in flight. Return the preloaded resource.
+        (WebCore::CachedResourceLoader::requestPreload): Make sure that preloaded fonts get requested. Return preloaded resource.
+        (WebCore::createResource): Removed LinkPreload.
+        (WebCore::contentTypeFromResourceType): Removed LinkPreload.
+        (WebCore::CachedResourceLoader::canRequest): Removed LinkPreload.
+        * loader/cache/CachedResourceLoader.h:
+        * platform/network/ResourceRequestBase.h:
+        (WebCore::ResourceRequestBase::ignoreForRequestCount): Get the flag saying if a resource should block window.onload.
+        (WebCore::ResourceRequestBase::setIgnoreForRequestCount): Set the flag saying if a resource should block window.onload.
+
</ins><span class="cx"> 2016-08-31  Joseph Pecoraro  &lt;pecoraro@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Web Inspector: XHR with text but responseType = &quot;blob&quot; shows blank content
</span></span></pre></div>
<a id="trunkSourceWebCoreWebCorexcodeprojprojectpbxproj"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (205268 => 205269)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj        2016-08-31 22:16:23 UTC (rev 205268)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj        2016-08-31 22:41:44 UTC (rev 205269)
</span><span class="lines">@@ -5530,7 +5530,9 @@
</span><span class="cx">                 CB38FD571CD21E2A00592A3F /* JSPerformanceEntryCustom.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CB38FD551CD21D5B00592A3F /* JSPerformanceEntryCustom.cpp */; };
</span><span class="cx">                 CB38FD5A1CD2325800592A3F /* JSPerformanceResourceTiming.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CB38FD581CD2314500592A3F /* JSPerformanceResourceTiming.cpp */; };
</span><span class="cx">                 CB38FD5B1CD2325B00592A3F /* JSPerformanceResourceTiming.h in Headers */ = {isa = PBXBuildFile; fileRef = CB38FD591CD2314500592A3F /* JSPerformanceResourceTiming.h */; };
</span><ins>+                CB61C7931D755207001ADC7D /* LinkPreloadResourceClients.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CBB6B2D11CB7ADC6009EDE1A /* LinkPreloadResourceClients.cpp */; };
</ins><span class="cx">                 CB8CF0181A9358D4000D510B /* Microtasks.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CB8CF0151A934B43000D510B /* Microtasks.cpp */; };
</span><ins>+                CBB6B2D41CB7AE51009EDE1A /* LinkPreloadResourceClients.h in Headers */ = {isa = PBXBuildFile; fileRef = CBB6B2D21CB7ADD0009EDE1A /* LinkPreloadResourceClients.h */; settings = {ATTRIBUTES = (Private, ); }; };
</ins><span class="cx">                 CBC2D22F1CE5B89D00D1880B /* ResourceTimingInformation.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CBC2D22D1CE5B77400D1880B /* ResourceTimingInformation.cpp */; };
</span><span class="cx">                 CBC2D2301CE5B8A100D1880B /* ResourceTimingInformation.h in Headers */ = {isa = PBXBuildFile; fileRef = CBC2D22E1CE5B77D00D1880B /* ResourceTimingInformation.h */; settings = {ATTRIBUTES = (Private, ); }; };
</span><span class="cx">                 CCC2B51415F613060048CDD6 /* DeviceClient.h in Headers */ = {isa = PBXBuildFile; fileRef = CCC2B51015F613060048CDD6 /* DeviceClient.h */; settings = {ATTRIBUTES = (Private, ); }; };
</span><span class="lines">@@ -13007,6 +13009,8 @@
</span><span class="cx">                 CB38FD581CD2314500592A3F /* JSPerformanceResourceTiming.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSPerformanceResourceTiming.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 CB38FD591CD2314500592A3F /* JSPerformanceResourceTiming.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSPerformanceResourceTiming.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 CB8CF0151A934B43000D510B /* Microtasks.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Microtasks.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><ins>+                CBB6B2D11CB7ADC6009EDE1A /* LinkPreloadResourceClients.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = LinkPreloadResourceClients.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
+                CBB6B2D21CB7ADD0009EDE1A /* LinkPreloadResourceClients.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LinkPreloadResourceClients.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</ins><span class="cx">                 CBC2D22D1CE5B77400D1880B /* ResourceTimingInformation.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ResourceTimingInformation.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 CBC2D22E1CE5B77D00D1880B /* ResourceTimingInformation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ResourceTimingInformation.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 CCC2B51015F613060048CDD6 /* DeviceClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DeviceClient.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="lines">@@ -21356,6 +21360,8 @@
</span><span class="cx">                                 089582540E857A7E00F82C83 /* ImageLoader.h */,
</span><span class="cx">                                 98CE4325129E00BD005821DC /* LinkLoader.cpp */,
</span><span class="cx">                                 98CE4329129E00E5005821DC /* LinkLoader.h */,
</span><ins>+                                CBB6B2D11CB7ADC6009EDE1A /* LinkPreloadResourceClients.cpp */,
+                                CBB6B2D21CB7ADD0009EDE1A /* LinkPreloadResourceClients.h */,
</ins><span class="cx">                                 984264EF12D5280A000D88A4 /* LinkLoaderClient.h */,
</span><span class="cx">                                 51ABF64C16392E2800132A7A /* LoaderStrategy.cpp */,
</span><span class="cx">                                 51E6820F16387302003BBF3C /* LoaderStrategy.h */,
</span><span class="lines">@@ -26326,6 +26332,7 @@
</span><span class="cx">                                 1A22464A0CC98DDB00C05240 /* SQLiteDatabase.h in Headers */,
</span><span class="cx">                                 7E474E1F12494DC900235364 /* SQLiteDatabaseTracker.h in Headers */,
</span><span class="cx">                                 7E474E1E12494DC900235364 /* SQLiteDatabaseTrackerClient.h in Headers */,
</span><ins>+                                CBB6B2D41CB7AE51009EDE1A /* LinkPreloadResourceClients.h in Headers */,
</ins><span class="cx">                                 B5A684220FFABE9800D24689 /* SQLiteFileSystem.h in Headers */,
</span><span class="cx">                                 512BDB4B1C456FFA006494DF /* SQLiteIDBBackingStore.h in Headers */,
</span><span class="cx">                                 511EC1301C50ABF50032F983 /* SQLiteIDBCursor.h in Headers */,
</span><span class="lines">@@ -29878,6 +29885,7 @@
</span><span class="cx">                                 FE8A674716CDD19E00930BF8 /* SQLStatement.cpp in Sources */,
</span><span class="cx">                                 97BC6A4F1505F081001B74AC /* SQLTransaction.cpp in Sources */,
</span><span class="cx">                                 FEE1811316C319E800084849 /* SQLTransactionBackend.cpp in Sources */,
</span><ins>+                                CB61C7931D755207001ADC7D /* LinkPreloadResourceClients.cpp in Sources */,
</ins><span class="cx">                                 97BC6A541505F081001B74AC /* SQLTransactionClient.cpp in Sources */,
</span><span class="cx">                                 97BC6A561505F081001B74AC /* SQLTransactionCoordinator.cpp in Sources */,
</span><span class="cx">                                 FE36FD1616C7826500F887C1 /* SQLTransactionStateMachine.cpp in Sources */,
</span></span></pre></div>
<a id="trunkSourceWebCorehtmlHTMLLinkElementcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/html/HTMLLinkElement.cpp (205268 => 205269)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/html/HTMLLinkElement.cpp        2016-08-31 22:16:23 UTC (rev 205268)
+++ trunk/Source/WebCore/html/HTMLLinkElement.cpp        2016-08-31 22:41:44 UTC (rev 205269)
</span><span class="lines">@@ -68,6 +68,12 @@
</span><span class="cx">     return sharedLoadEventSender;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+static LinkEventSender&amp; linkErrorEventSender()
+{
+    static NeverDestroyed&lt;LinkEventSender&gt; sharedErrorEventSender(eventNames().errorEvent);
+    return sharedErrorEventSender;
+}
+
</ins><span class="cx"> inline HTMLLinkElement::HTMLLinkElement(const QualifiedName&amp; tagName, Document&amp; document, bool createdByParser)
</span><span class="cx">     : HTMLElement(tagName, document)
</span><span class="cx">     , m_linkLoader(*this)
</span><span class="lines">@@ -76,7 +82,7 @@
</span><span class="cx">     , m_createdByParser(createdByParser)
</span><span class="cx">     , m_isInShadowTree(false)
</span><span class="cx">     , m_firedLoad(false)
</span><del>-    , m_loadedSheet(false)
</del><ins>+    , m_loadedResource(false)
</ins><span class="cx">     , m_pendingSheetType(Unknown)
</span><span class="cx"> {
</span><span class="cx">     ASSERT(hasTagName(linkTag));
</span><span class="lines">@@ -99,6 +105,7 @@
</span><span class="cx">         document().authorStyleSheets().removeStyleSheetCandidateNode(*this);
</span><span class="cx"> 
</span><span class="cx">     linkLoadEventSender().cancelEvent(*this);
</span><ins>+    linkErrorEventSender().cancelEvent(*this);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void HTMLLinkElement::setDisabledState(bool disabled)
</span><span class="lines">@@ -395,12 +402,13 @@
</span><span class="cx"> 
</span><span class="cx"> void HTMLLinkElement::linkLoaded()
</span><span class="cx"> {
</span><del>-    dispatchEvent(Event::create(eventNames().loadEvent, false, false));
</del><ins>+    m_loadedResource = true;
+    linkLoadEventSender().dispatchEventSoon(*this);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void HTMLLinkElement::linkLoadingErrored()
</span><span class="cx"> {
</span><del>-    dispatchEvent(Event::create(eventNames().errorEvent, false, false));
</del><ins>+    linkErrorEventSender().dispatchEventSoon(*this);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> bool HTMLLinkElement::sheetLoaded()
</span><span class="lines">@@ -419,11 +427,11 @@
</span><span class="cx"> 
</span><span class="cx"> void HTMLLinkElement::dispatchPendingEvent(LinkEventSender* eventSender)
</span><span class="cx"> {
</span><del>-    ASSERT_UNUSED(eventSender, eventSender == &amp;linkLoadEventSender());
-    if (m_loadedSheet)
-        linkLoaded();
</del><ins>+    ASSERT_UNUSED(eventSender, eventSender == &amp;linkLoadEventSender() || eventSender == &amp;linkErrorEventSender());
+    if (m_loadedResource)
+        dispatchEvent(Event::create(eventNames().loadEvent, false, false));
</ins><span class="cx">     else
</span><del>-        linkLoadingErrored();
</del><ins>+        dispatchEvent(Event::create(eventNames().errorEvent, false, false));
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> DOMTokenList&amp; HTMLLinkElement::relList()
</span><span class="lines">@@ -437,7 +445,7 @@
</span><span class="cx"> {
</span><span class="cx">     if (m_firedLoad)
</span><span class="cx">         return;
</span><del>-    m_loadedSheet = !errorOccurred;
</del><ins>+    m_loadedResource = !errorOccurred;
</ins><span class="cx">     linkLoadEventSender().dispatchEventSoon(*this);
</span><span class="cx">     m_firedLoad = true;
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebCorehtmlHTMLLinkElementh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/html/HTMLLinkElement.h (205268 => 205269)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/html/HTMLLinkElement.h        2016-08-31 22:16:23 UTC (rev 205268)
+++ trunk/Source/WebCore/html/HTMLLinkElement.h        2016-08-31 22:41:44 UTC (rev 205269)
</span><span class="lines">@@ -134,7 +134,7 @@
</span><span class="cx">     bool m_createdByParser;
</span><span class="cx">     bool m_isInShadowTree;
</span><span class="cx">     bool m_firedLoad;
</span><del>-    bool m_loadedSheet;
</del><ins>+    bool m_loadedResource;
</ins><span class="cx"> 
</span><span class="cx">     PendingSheetType m_pendingSheetType;
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCorehtmlparserHTMLResourcePreloadercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/html/parser/HTMLResourcePreloader.cpp (205268 => 205269)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/html/parser/HTMLResourcePreloader.cpp        2016-08-31 22:16:23 UTC (rev 205268)
+++ trunk/Source/WebCore/html/parser/HTMLResourcePreloader.cpp        2016-08-31 22:41:44 UTC (rev 205269)
</span><span class="lines">@@ -69,7 +69,7 @@
</span><span class="cx">         return;
</span><span class="cx"> 
</span><span class="cx">     CachedResourceRequest request = preload-&gt;resourceRequest(m_document);
</span><del>-    m_document.cachedResourceLoader().preload(preload-&gt;resourceType(), request, preload-&gt;charset());
</del><ins>+    m_document.cachedResourceLoader().preload(preload-&gt;resourceType(), request, preload-&gt;charset(), CachedResourceLoader::ImplicitPreload);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoreloaderLinkLoadercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/loader/LinkLoader.cpp (205268 => 205269)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/loader/LinkLoader.cpp        2016-08-31 22:16:23 UTC (rev 205268)
+++ trunk/Source/WebCore/loader/LinkLoader.cpp        2016-08-31 22:41:44 UTC (rev 205269)
</span><span class="lines">@@ -43,6 +43,7 @@
</span><span class="cx"> #include &quot;Frame.h&quot;
</span><span class="cx"> #include &quot;FrameLoaderClient.h&quot;
</span><span class="cx"> #include &quot;FrameView.h&quot;
</span><ins>+#include &quot;LinkPreloadResourceClients.h&quot;
</ins><span class="cx"> #include &quot;LinkRelAttribute.h&quot;
</span><span class="cx"> #include &quot;RuntimeEnabledFeatures.h&quot;
</span><span class="cx"> #include &quot;Settings.h&quot;
</span><span class="lines">@@ -52,8 +53,7 @@
</span><span class="cx"> 
</span><span class="cx"> LinkLoader::LinkLoader(LinkLoaderClient&amp; client)
</span><span class="cx">     : m_client(client)
</span><del>-    , m_linkLoadTimer(*this, &amp;LinkLoader::linkLoadTimerFired)
-    , m_linkLoadingErrorTimer(*this, &amp;LinkLoader::linkLoadingErrorTimerFired)
</del><ins>+    , m_weakPtrFactory(this)
</ins><span class="cx"> {
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -61,26 +61,23 @@
</span><span class="cx"> {
</span><span class="cx">     if (m_cachedLinkResource)
</span><span class="cx">         m_cachedLinkResource-&gt;removeClient(this);
</span><ins>+    if (m_preloadResourceClient)
+        m_preloadResourceClient-&gt;clear();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-void LinkLoader::linkLoadTimerFired()
</del><ins>+void LinkLoader::triggerEvents(const CachedResource* resource)
</ins><span class="cx"> {
</span><del>-    m_client.linkLoaded();
</del><ins>+    if (resource-&gt;errorOccurred())
+        m_client.linkLoadingErrored();
+    else
+        m_client.linkLoaded();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-void LinkLoader::linkLoadingErrorTimerFired()
-{
-    m_client.linkLoadingErrored();
-}
-
</del><span class="cx"> void LinkLoader::notifyFinished(CachedResource* resource)
</span><span class="cx"> {
</span><span class="cx">     ASSERT_UNUSED(resource, m_cachedLinkResource.get() == resource);
</span><span class="cx"> 
</span><del>-    if (m_cachedLinkResource-&gt;errorOccurred())
-        m_linkLoadingErrorTimer.startOneShot(0);
-    else 
-        m_linkLoadTimer.startOneShot(0);
</del><ins>+    triggerEvents(m_cachedLinkResource.get());
</ins><span class="cx"> 
</span><span class="cx">     m_cachedLinkResource-&gt;removeClient(this);
</span><span class="cx">     m_cachedLinkResource = nullptr;
</span><span class="lines">@@ -89,7 +86,7 @@
</span><span class="cx"> Optional&lt;CachedResource::Type&gt; LinkLoader::resourceTypeFromAsAttribute(const String&amp; as)
</span><span class="cx"> {
</span><span class="cx">     if (as.isEmpty())
</span><del>-        return CachedResource::LinkPreload;
</del><ins>+        return CachedResource::RawResource;
</ins><span class="cx">     if (equalLettersIgnoringASCIICase(as, &quot;image&quot;))
</span><span class="cx">         return CachedResource::ImageResource;
</span><span class="cx">     if (equalLettersIgnoringASCIICase(as, &quot;script&quot;))
</span><span class="lines">@@ -107,8 +104,39 @@
</span><span class="cx">     return Nullopt;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-static void preloadIfNeeded(const LinkRelAttribute&amp; relAttribute, const URL&amp; href, Document&amp; document, const String&amp; as, const String&amp; crossOriginMode)
</del><ins>+static std::unique_ptr&lt;LinkPreloadResourceClient&gt; createLinkPreloadResourceClient(CachedResource&amp; resource, LinkLoader&amp; loader, CachedResource::Type type)
</ins><span class="cx"> {
</span><ins>+    switch (type) {
+    case CachedResource::ImageResource:
+        return LinkPreloadImageResourceClient::create(loader, static_cast&lt;CachedImage&amp;&gt;(resource));
+    case CachedResource::Script:
+        return LinkPreloadScriptResourceClient::create(loader, static_cast&lt;CachedScript&amp;&gt;(resource));
+    case CachedResource::CSSStyleSheet:
+        return LinkPreloadStyleResourceClient::create(loader, static_cast&lt;CachedCSSStyleSheet&amp;&gt;(resource));
+    case CachedResource::FontResource:
+        return LinkPreloadFontResourceClient::create(loader, static_cast&lt;CachedFont&amp;&gt;(resource));
+    case CachedResource::MediaResource:
+#if ENABLE(VIDEO_TRACK)
+    case CachedResource::TextTrackResource:
+#endif
+    case CachedResource::RawResource:
+        return LinkPreloadRawResourceClient::create(loader, static_cast&lt;CachedRawResource&amp;&gt;(resource));
+    case CachedResource::MainResource:
+    case CachedResource::SVGFontResource:
+    case CachedResource::SVGDocumentResource:
+    case CachedResource::XSLStyleSheet:
+#if ENABLE(LINK_PREFETCH)
+    case CachedResource::LinkSubresource:
+    case CachedResource::LinkPrefetch:
+#endif
+        // None of these values is currently supported as an `as` value.
+        ASSERT_NOT_REACHED();
+    }
+    return nullptr;
+}
+
+void LinkLoader::preloadIfNeeded(const LinkRelAttribute&amp; relAttribute, const URL&amp; href, Document&amp; document, const String&amp; as, const String&amp; crossOriginMode)
+{
</ins><span class="cx">     if (!document.loader() || !relAttribute.isLinkPreload)
</span><span class="cx">         return;
</span><span class="cx"> 
</span><span class="lines">@@ -120,10 +148,12 @@
</span><span class="cx">     auto type = LinkLoader::resourceTypeFromAsAttribute(as);
</span><span class="cx">     if (!type) {
</span><span class="cx">         document.addConsoleMessage(MessageSource::Other, MessageLevel::Error, String(&quot;&lt;link rel=preload&gt; must have a valid `as` value&quot;));
</span><ins>+        m_client.linkLoadingErrored();
</ins><span class="cx">         return;
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     ResourceRequest resourceRequest(document.completeURL(href));
</span><ins>+    resourceRequest.setIgnoreForRequestCount(true);
</ins><span class="cx">     CachedResourceRequest linkRequest(resourceRequest, CachedResource::defaultPriorityForResourceType(type.value()));
</span><span class="cx">     linkRequest.setInitiator(&quot;link&quot;);
</span><span class="cx"> 
</span><span class="lines">@@ -133,7 +163,10 @@
</span><span class="cx">         updateRequestForAccessControl(linkRequest.mutableResourceRequest(), *document.securityOrigin(), allowCredentials);
</span><span class="cx">     }
</span><span class="cx">     linkRequest.setForPreload(true);
</span><del>-    document.cachedResourceLoader().preload(type.value(), linkRequest, emptyString());
</del><ins>+    CachedResourceHandle&lt;CachedResource&gt; cachedLinkResource = document.cachedResourceLoader().preload(type.value(), linkRequest, emptyString(), CachedResourceLoader::ExplicitPreload);
+
+    if (cachedLinkResource)
+        m_preloadResourceClient = createLinkPreloadResourceClient(*cachedLinkResource, *this, type.value());
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> bool LinkLoader::loadLink(const LinkRelAttribute&amp; relAttribute, const URL&amp; href, const String&amp; as, const String&amp; crossOrigin, Document&amp; document)
</span></span></pre></div>
<a id="trunkSourceWebCoreloaderLinkLoaderh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/loader/LinkLoader.h (205268 => 205269)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/loader/LinkLoader.h        2016-08-31 22:16:23 UTC (rev 205268)
+++ trunk/Source/WebCore/loader/LinkLoader.h        2016-08-31 22:41:44 UTC (rev 205269)
</span><span class="lines">@@ -36,12 +36,14 @@
</span><span class="cx"> #include &quot;CachedResourceClient.h&quot;
</span><span class="cx"> #include &quot;CachedResourceHandle.h&quot;
</span><span class="cx"> #include &quot;LinkLoaderClient.h&quot;
</span><del>-#include &quot;Timer.h&quot;
</del><span class="cx"> 
</span><ins>+#include &lt;wtf/WeakPtr.h&gt;
+
</ins><span class="cx"> namespace WebCore {
</span><span class="cx"> 
</span><span class="cx"> class Document;
</span><span class="cx"> class URL;
</span><ins>+class LinkPreloadResourceClient;
</ins><span class="cx"> 
</span><span class="cx"> struct LinkRelAttribute;
</span><span class="cx"> 
</span><span class="lines">@@ -53,16 +55,17 @@
</span><span class="cx">     bool loadLink(const LinkRelAttribute&amp;, const URL&amp;, const String&amp; as, const String&amp; crossOrigin, Document&amp;);
</span><span class="cx">     static Optional&lt;CachedResource::Type&gt; resourceTypeFromAsAttribute(const String&amp; as);
</span><span class="cx"> 
</span><ins>+    WeakPtr&lt;LinkLoader&gt; createWeakPtr() { return m_weakPtrFactory.createWeakPtr(); }
+    void triggerEvents(const CachedResource*);
+
</ins><span class="cx"> private:
</span><span class="cx">     void notifyFinished(CachedResource*) override;
</span><ins>+    void preloadIfNeeded(const LinkRelAttribute&amp;, const URL&amp; href, Document&amp;, const String&amp; as, const String&amp; crossOriginMode);
</ins><span class="cx"> 
</span><del>-    void linkLoadTimerFired();
-    void linkLoadingErrorTimerFired();
-
</del><span class="cx">     LinkLoaderClient&amp; m_client;
</span><span class="cx">     CachedResourceHandle&lt;CachedResource&gt; m_cachedLinkResource;
</span><del>-    Timer m_linkLoadTimer;
-    Timer m_linkLoadingErrorTimer;
</del><ins>+    std::unique_ptr&lt;LinkPreloadResourceClient&gt; m_preloadResourceClient;
+    WeakPtrFactory&lt;LinkLoader&gt; m_weakPtrFactory;
</ins><span class="cx"> };
</span><span class="cx">     
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebCoreloaderLinkPreloadResourceClientscpp"></a>
<div class="addfile"><h4>Added: trunk/Source/WebCore/loader/LinkPreloadResourceClients.cpp (0 => 205269)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/loader/LinkPreloadResourceClients.cpp                                (rev 0)
+++ trunk/Source/WebCore/loader/LinkPreloadResourceClients.cpp        2016-08-31 22:41:44 UTC (rev 205269)
</span><span class="lines">@@ -0,0 +1,46 @@
</span><ins>+/*
+ * Copyright 2016 The Chromium Authors. All rights reserved.
+ * Copyright (C) 2016 Akamai Technologies Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * &quot;AS IS&quot; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include &quot;config.h&quot;
+#include &quot;LinkPreloadResourceClients.h&quot;
+
+#include &quot;LinkLoader.h&quot;
+
+namespace WebCore {
+
+LinkPreloadResourceClient::LinkPreloadResourceClient(LinkLoader&amp; loader, CachedResource&amp; resource)
+{
+    m_loader = loader.createWeakPtr();
+    m_resource = &amp;resource;
+}
+
+void LinkPreloadResourceClient::triggerEvents(const CachedResource* resource)
+{
+    if (m_loader)
+        m_loader-&gt;triggerEvents(resource);
+}
+
+}
</ins></span></pre></div>
<a id="trunkSourceWebCoreloaderLinkPreloadResourceClientsh"></a>
<div class="addfile"><h4>Added: trunk/Source/WebCore/loader/LinkPreloadResourceClients.h (0 => 205269)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/loader/LinkPreloadResourceClients.h                                (rev 0)
+++ trunk/Source/WebCore/loader/LinkPreloadResourceClients.h        2016-08-31 22:41:44 UTC (rev 205269)
</span><span class="lines">@@ -0,0 +1,202 @@
</span><ins>+/*
+ * Copyright 2016 The Chromium Authors. All rights reserved.
+ * Copyright (C) 2016 Akamai Technologies Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * &quot;AS IS&quot; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include &quot;CachedCSSStyleSheet.h&quot;
+#include &quot;CachedFont.h&quot;
+#include &quot;CachedFontClient.h&quot;
+#include &quot;CachedImage.h&quot;
+#include &quot;CachedImageClient.h&quot;
+#include &quot;CachedRawResource.h&quot;
+#include &quot;CachedResourceLoader.h&quot;
+#include &quot;CachedScript.h&quot;
+#include &quot;CachedStyleSheetClient.h&quot;
+
+#include &lt;wtf/WeakPtr.h&gt;
+
+namespace WebCore {
+
+class LinkLoader;
+
+class LinkPreloadResourceClient {
+public:
+    virtual ~LinkPreloadResourceClient() { }
+
+    void triggerEvents(const CachedResource*);
+
+    virtual void clear() = 0;
+
+protected:
+
+    LinkPreloadResourceClient(LinkLoader&amp;, CachedResource&amp;);
+
+    void addResource(CachedResourceClient* client)
+    {
+        m_resource-&gt;addClient(client);
+    }
+
+    void clearResource(CachedResourceClient* client)
+    {
+        if (m_resource)
+            m_resource-&gt;removeClient(client);
+        m_resource = nullptr;
+    }
+
+    CachedResource* ownedResource() { return m_resource.get(); }
+
+private:
+    WeakPtr&lt;LinkLoader&gt; m_loader;
+    CachedResourceHandle&lt;CachedResource&gt; m_resource;
+};
+
+class LinkPreloadScriptResourceClient: public LinkPreloadResourceClient, CachedResourceClient {
+public:
+    static std::unique_ptr&lt;LinkPreloadScriptResourceClient&gt; create(LinkLoader&amp; loader, CachedScript&amp; resource)
+    {
+        return std::unique_ptr&lt;LinkPreloadScriptResourceClient&gt;(new LinkPreloadScriptResourceClient(loader, resource));
+    }
+
+    virtual ~LinkPreloadScriptResourceClient() { }
+
+
+    void notifyFinished(CachedResource* resource) override
+    {
+        ASSERT(ownedResource() == resource);
+        triggerEvents(resource);
+    }
+
+    void clear() override { clearResource(this); }
+
+private:
+    LinkPreloadScriptResourceClient(LinkLoader&amp; loader, CachedScript&amp; resource)
+        : LinkPreloadResourceClient(loader, resource)
+    {
+        addResource(this);
+    }
+};
+
+class LinkPreloadStyleResourceClient: public LinkPreloadResourceClient, public CachedStyleSheetClient {
+public:
+    static std::unique_ptr&lt;LinkPreloadStyleResourceClient&gt; create(LinkLoader&amp; loader, CachedCSSStyleSheet&amp; resource)
+    {
+        return std::unique_ptr&lt;LinkPreloadStyleResourceClient&gt;(new LinkPreloadStyleResourceClient(loader, resource));
+    }
+
+    virtual ~LinkPreloadStyleResourceClient() { }
+
+    void setCSSStyleSheet(const String&amp;, const URL&amp;, const String&amp;, const CachedCSSStyleSheet* resource) override
+    {
+        ASSERT(ownedResource() == resource);
+        triggerEvents(resource);
+    }
+
+    void clear() override { clearResource(this); }
+
+private:
+    LinkPreloadStyleResourceClient(LinkLoader&amp; loader, CachedCSSStyleSheet&amp; resource)
+        : LinkPreloadResourceClient(loader, resource)
+    {
+        addResource(this);
+    }
+};
+
+class LinkPreloadImageResourceClient: public LinkPreloadResourceClient, public CachedImageClient {
+public:
+    static std::unique_ptr&lt;LinkPreloadImageResourceClient&gt; create(LinkLoader&amp; loader, CachedImage&amp; resource)
+    {
+        return std::unique_ptr&lt;LinkPreloadImageResourceClient&gt;(new LinkPreloadImageResourceClient(loader, resource));
+    }
+
+    virtual ~LinkPreloadImageResourceClient() { }
+
+    void notifyFinished(CachedResource* resource) override
+    {
+        ASSERT(ownedResource() == resource);
+        triggerEvents(resource);
+    }
+
+    void clear() override { clearResource(this); }
+
+private:
+    LinkPreloadImageResourceClient(LinkLoader&amp; loader, CachedImage&amp; resource)
+        : LinkPreloadResourceClient(loader, dynamic_cast&lt;CachedResource&amp;&gt;(resource))
+    {
+        addResource(this);
+    }
+};
+
+class LinkPreloadFontResourceClient: public LinkPreloadResourceClient, public CachedFontClient {
+public:
+    static std::unique_ptr&lt;LinkPreloadFontResourceClient&gt; create(LinkLoader&amp; loader, CachedFont&amp; resource)
+    {
+        return std::unique_ptr&lt;LinkPreloadFontResourceClient&gt;(new LinkPreloadFontResourceClient(loader, resource));
+    }
+
+    virtual ~LinkPreloadFontResourceClient() { }
+
+    void fontLoaded(CachedFont&amp; resource) override
+    {
+        ASSERT(ownedResource() == &amp;resource);
+        triggerEvents(&amp;resource);
+    }
+
+    void clear() override { clearResource(this); }
+
+private:
+    LinkPreloadFontResourceClient(LinkLoader&amp; loader, CachedFont&amp; resource)
+        : LinkPreloadResourceClient(loader, resource)
+    {
+        addResource(this);
+    }
+};
+
+class LinkPreloadRawResourceClient: public LinkPreloadResourceClient, public CachedRawResourceClient {
+public:
+    static std::unique_ptr&lt;LinkPreloadRawResourceClient&gt; create(LinkLoader&amp; loader, CachedRawResource&amp; resource)
+    {
+        return std::unique_ptr&lt;LinkPreloadRawResourceClient&gt;(new LinkPreloadRawResourceClient(loader, resource));
+    }
+
+    virtual ~LinkPreloadRawResourceClient() { }
+
+    void notifyFinished(CachedResource* resource) override
+    {
+        ASSERT(ownedResource() == resource);
+        triggerEvents(resource);
+    }
+
+    void clear() override { clearResource(this); }
+
+private:
+    LinkPreloadRawResourceClient(LinkLoader&amp; loader, CachedRawResource&amp; resource)
+        : LinkPreloadResourceClient(loader, resource)
+    {
+        addResource(this);
+    }
+};
+
+}
</ins></span></pre></div>
<a id="trunkSourceWebCoreloaderResourceLoadInfocpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/loader/ResourceLoadInfo.cpp (205268 => 205269)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/loader/ResourceLoadInfo.cpp        2016-08-31 22:16:23 UTC (rev 205268)
+++ trunk/Source/WebCore/loader/ResourceLoadInfo.cpp        2016-08-31 22:41:44 UTC (rev 205269)
</span><span class="lines">@@ -56,7 +56,6 @@
</span><span class="cx">         return ResourceType::Font;
</span><span class="cx"> 
</span><span class="cx">     case CachedResource::MediaResource:
</span><del>-    case CachedResource::LinkPreload:
</del><span class="cx">     case CachedResource::RawResource:
</span><span class="cx">         return ResourceType::Raw;
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoreloaderSubresourceLoadercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/loader/SubresourceLoader.cpp (205268 => 205269)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/loader/SubresourceLoader.cpp        2016-08-31 22:16:23 UTC (rev 205268)
+++ trunk/Source/WebCore/loader/SubresourceLoader.cpp        2016-08-31 22:41:44 UTC (rev 205269)
</span><span class="lines">@@ -390,7 +390,6 @@
</span><span class="cx">     case CachedResource::SVGDocumentResource:
</span><span class="cx">         resourceType = DiagnosticLoggingKeys::svgDocumentKey();
</span><span class="cx">         break;
</span><del>-    case CachedResource::LinkPreload:
</del><span class="cx"> #if ENABLE(LINK_PREFETCH)
</span><span class="cx">     case CachedResource::LinkPrefetch:
</span><span class="cx">     case CachedResource::LinkSubresource:
</span></span></pre></div>
<a id="trunkSourceWebCoreloadercacheCachedResourcecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/loader/cache/CachedResource.cpp (205268 => 205269)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/loader/cache/CachedResource.cpp        2016-08-31 22:16:23 UTC (rev 205268)
+++ trunk/Source/WebCore/loader/cache/CachedResource.cpp        2016-08-31 22:41:44 UTC (rev 205269)
</span><span class="lines">@@ -87,8 +87,6 @@
</span><span class="cx"> #endif
</span><span class="cx">     case CachedResource::SVGDocumentResource:
</span><span class="cx">         return ResourceLoadPriority::Low;
</span><del>-    case CachedResource::LinkPreload:
-        return ResourceLoadPriority::Low;
</del><span class="cx"> #if ENABLE(LINK_PREFETCH)
</span><span class="cx">     case CachedResource::LinkPrefetch:
</span><span class="cx">         return ResourceLoadPriority::VeryLow;
</span></span></pre></div>
<a id="trunkSourceWebCoreloadercacheCachedResourceh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/loader/cache/CachedResource.h (205268 => 205269)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/loader/cache/CachedResource.h        2016-08-31 22:16:23 UTC (rev 205268)
+++ trunk/Source/WebCore/loader/cache/CachedResource.h        2016-08-31 22:41:44 UTC (rev 205269)
</span><span class="lines">@@ -76,7 +76,6 @@
</span><span class="cx"> #if ENABLE(XSLT)
</span><span class="cx">         , XSLStyleSheet
</span><span class="cx"> #endif
</span><del>-        , LinkPreload
</del><span class="cx"> #if ENABLE(LINK_PREFETCH)
</span><span class="cx">         , LinkPrefetch
</span><span class="cx">         , LinkSubresource
</span><span class="lines">@@ -167,7 +166,8 @@
</span><span class="cx">     bool isMainOrMediaOrRawResource() const { return type() == MainResource || type() == MediaResource || type() == RawResource; }
</span><span class="cx">     bool ignoreForRequestCount() const
</span><span class="cx">     {
</span><del>-        return type() == MainResource
</del><ins>+        return m_resourceRequest.ignoreForRequestCount()
+            || type() == MainResource
</ins><span class="cx"> #if ENABLE(LINK_PREFETCH)
</span><span class="cx">             || type() == LinkPrefetch
</span><span class="cx">             || type() == LinkSubresource
</span></span></pre></div>
<a id="trunkSourceWebCoreloadercacheCachedResourceLoadercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/loader/cache/CachedResourceLoader.cpp (205268 => 205269)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/loader/cache/CachedResourceLoader.cpp        2016-08-31 22:16:23 UTC (rev 205268)
+++ trunk/Source/WebCore/loader/cache/CachedResourceLoader.cpp        2016-08-31 22:41:44 UTC (rev 205269)
</span><span class="lines">@@ -107,8 +107,6 @@
</span><span class="cx">     case CachedResource::XSLStyleSheet:
</span><span class="cx">         return new CachedXSLStyleSheet(request, sessionID);
</span><span class="cx"> #endif
</span><del>-    case CachedResource::LinkPreload:
-        return new CachedResource(request, CachedResource::LinkPreload, sessionID);
</del><span class="cx"> #if ENABLE(LINK_PREFETCH)
</span><span class="cx">     case CachedResource::LinkPrefetch:
</span><span class="cx">         return new CachedResource(request, CachedResource::LinkPrefetch, sessionID);
</span><span class="lines">@@ -316,7 +314,6 @@
</span><span class="cx">         return MixedContentChecker::ContentType::Active;
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><del>-    case CachedResource::LinkPreload:
</del><span class="cx"> #if ENABLE(LINK_PREFETCH)
</span><span class="cx">     case CachedResource::LinkPrefetch:
</span><span class="cx">     case CachedResource::LinkSubresource:
</span><span class="lines">@@ -361,8 +358,7 @@
</span><span class="cx"> #if ENABLE(SVG_FONTS)
</span><span class="cx">     case CachedResource::SVGFontResource:
</span><span class="cx"> #endif
</span><del>-    case CachedResource::FontResource:
-    case CachedResource::LinkPreload: {
</del><ins>+    case CachedResource::FontResource: {
</ins><span class="cx">         // These resources can corrupt only the frame's pixels.
</span><span class="cx">         if (Frame* f = frame()) {
</span><span class="cx">             Frame&amp; topFrame = f-&gt;tree().top();
</span><span class="lines">@@ -412,7 +408,6 @@
</span><span class="cx">     case CachedResource::MediaResource:
</span><span class="cx">     case CachedResource::FontResource:
</span><span class="cx">     case CachedResource::RawResource:
</span><del>-    case CachedResource::LinkPreload:
</del><span class="cx"> #if ENABLE(LINK_PREFETCH)
</span><span class="cx">     case CachedResource::LinkPrefetch:
</span><span class="cx">     case CachedResource::LinkSubresource:
</span><span class="lines">@@ -468,8 +463,6 @@
</span><span class="cx">     }
</span><span class="cx">     case CachedResource::MainResource:
</span><span class="cx">     case CachedResource::RawResource:
</span><del>-    // FIXME: Preload should be subject to connect-src.
-    case CachedResource::LinkPreload:
</del><span class="cx"> #if ENABLE(LINK_PREFETCH)
</span><span class="cx">     case CachedResource::LinkPrefetch:
</span><span class="cx">     case CachedResource::LinkSubresource:
</span><span class="lines">@@ -664,6 +657,11 @@
</span><span class="cx">     if (!request.forPreload() || policy != Use)
</span><span class="cx">         resource-&gt;setLoadPriority(request.priority());
</span><span class="cx"> 
</span><ins>+    if (!request.forPreload() &amp;&amp; resource-&gt;loader() &amp;&amp; resource-&gt;resourceRequest().ignoreForRequestCount()) {
+        resource-&gt;resourceRequest().setIgnoreForRequestCount(false);
+        incrementRequestCount(*resource);
+    }
+
</ins><span class="cx">     if ((policy != Use || resource-&gt;stillNeedsLoad()) &amp;&amp; CachedResourceRequest::NoDefer == request.defer()) {
</span><span class="cx">         resource-&gt;load(*this, request.options());
</span><span class="cx"> 
</span><span class="lines">@@ -1063,7 +1061,7 @@
</span><span class="cx">     ASSERT(m_requestCount &gt; -1);
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void CachedResourceLoader::preload(CachedResource::Type type, CachedResourceRequest&amp; request, const String&amp; charset)
</del><ins>+CachedResourceHandle&lt;CachedResource&gt; CachedResourceLoader::preload(CachedResource::Type type, CachedResourceRequest&amp; request, const String&amp; charset, PreloadType preloadType)
</ins><span class="cx"> {
</span><span class="cx">     // We always preload resources on iOS. See &lt;https://bugs.webkit.org/show_bug.cgi?id=91276&gt;.
</span><span class="cx">     // FIXME: We should consider adding a setting to toggle aggressive preloading behavior as opposed
</span><span class="lines">@@ -1071,15 +1069,17 @@
</span><span class="cx"> #if !PLATFORM(IOS)
</span><span class="cx">     bool hasRendering = m_document-&gt;bodyOrFrameset() &amp;&amp; m_document-&gt;renderView();
</span><span class="cx">     bool canBlockParser = type == CachedResource::Script || type == CachedResource::CSSStyleSheet;
</span><del>-    if (!hasRendering &amp;&amp; !canBlockParser) {
</del><ins>+    if (!hasRendering &amp;&amp; !canBlockParser &amp;&amp; preloadType == ImplicitPreload) {
</ins><span class="cx">         // Don't preload subresources that can't block the parser before we have something to draw.
</span><span class="cx">         // This helps prevent preloads from delaying first display when bandwidth is limited.
</span><span class="cx">         PendingPreload pendingPreload = { type, request, charset };
</span><span class="cx">         m_pendingPreloads.append(pendingPreload);
</span><del>-        return;
</del><ins>+        return nullptr;
</ins><span class="cx">     }
</span><ins>+#else
+    UNUSED_PARAM(preloadType);
</ins><span class="cx"> #endif
</span><del>-    requestPreload(type, request, charset);
</del><ins>+    return requestPreload(type, request, charset);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void CachedResourceLoader::checkForPendingPreloads() 
</span><span class="lines">@@ -1104,7 +1104,7 @@
</span><span class="cx">     m_pendingPreloads.clear();
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void CachedResourceLoader::requestPreload(CachedResource::Type type, CachedResourceRequest&amp; request, const String&amp; charset)
</del><ins>+CachedResourceHandle&lt;CachedResource&gt; CachedResourceLoader::requestPreload(CachedResource::Type type, CachedResourceRequest&amp; request, const String&amp; charset)
</ins><span class="cx"> {
</span><span class="cx">     String encoding;
</span><span class="cx">     if (type == CachedResource::Script || type == CachedResource::CSSStyleSheet)
</span><span class="lines">@@ -1115,7 +1115,10 @@
</span><span class="cx"> 
</span><span class="cx">     CachedResourceHandle&lt;CachedResource&gt; resource = requestResource(type, request);
</span><span class="cx">     if (!resource || (m_preloads &amp;&amp; m_preloads-&gt;contains(resource.get())))
</span><del>-        return;
</del><ins>+        return nullptr;
+    // Fonts need special treatment since just creating the resource doesn't trigger a load.
+    if (type == CachedResource::FontResource)
+        downcast&lt;CachedFont&gt;(resource.get())-&gt;beginLoadIfNeeded(*this);
</ins><span class="cx">     resource-&gt;increasePreloadCount();
</span><span class="cx"> 
</span><span class="cx">     if (!m_preloads)
</span><span class="lines">@@ -1125,6 +1128,7 @@
</span><span class="cx"> #if PRELOAD_DEBUG
</span><span class="cx">     printf(&quot;PRELOADING %s\n&quot;,  resource-&gt;url().latin1().data());
</span><span class="cx"> #endif
</span><ins>+    return resource;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> bool CachedResourceLoader::isPreloaded(const String&amp; urlString) const
</span></span></pre></div>
<a id="trunkSourceWebCoreloadercacheCachedResourceLoaderh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/loader/cache/CachedResourceLoader.h (205268 => 205269)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/loader/cache/CachedResourceLoader.h        2016-08-31 22:16:23 UTC (rev 205268)
+++ trunk/Source/WebCore/loader/cache/CachedResourceLoader.h        2016-08-31 22:41:44 UTC (rev 205269)
</span><span class="lines">@@ -130,7 +130,8 @@
</span><span class="cx">     WEBCORE_EXPORT bool isPreloaded(const String&amp; urlString) const;
</span><span class="cx">     void clearPreloads();
</span><span class="cx">     void clearPendingPreloads();
</span><del>-    void preload(CachedResource::Type, CachedResourceRequest&amp;, const String&amp; charset);
</del><ins>+    enum PreloadType { ImplicitPreload, ExplicitPreload };
+    CachedResourceHandle&lt;CachedResource&gt; preload(CachedResource::Type, CachedResourceRequest&amp;, const String&amp; charset, PreloadType);
</ins><span class="cx">     void checkForPendingPreloads();
</span><span class="cx">     void printPreloadStats();
</span><span class="cx"> 
</span><span class="lines">@@ -150,7 +151,7 @@
</span><span class="cx">     CachedResourceHandle&lt;CachedResource&gt; requestResource(CachedResource::Type, CachedResourceRequest&amp;);
</span><span class="cx">     CachedResourceHandle&lt;CachedResource&gt; revalidateResource(const CachedResourceRequest&amp;, CachedResource*);
</span><span class="cx">     CachedResourceHandle&lt;CachedResource&gt; loadResource(CachedResource::Type, CachedResourceRequest&amp;);
</span><del>-    void requestPreload(CachedResource::Type, CachedResourceRequest&amp;, const String&amp; charset);
</del><ins>+    CachedResourceHandle&lt;CachedResource&gt; requestPreload(CachedResource::Type, CachedResourceRequest&amp;, const String&amp; charset);
</ins><span class="cx"> 
</span><span class="cx">     enum RevalidationPolicy { Use, Revalidate, Reload, Load };
</span><span class="cx">     RevalidationPolicy determineRevalidationPolicy(CachedResource::Type, CachedResourceRequest&amp;, CachedResource* existingResource) const;
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformnetworkResourceRequestBaseh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/network/ResourceRequestBase.h (205268 => 205269)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/network/ResourceRequestBase.h        2016-08-31 22:16:23 UTC (rev 205268)
+++ trunk/Source/WebCore/platform/network/ResourceRequestBase.h        2016-08-31 22:41:44 UTC (rev 205269)
</span><span class="lines">@@ -148,6 +148,10 @@
</span><span class="cx">     bool hiddenFromInspector() const { return m_hiddenFromInspector; }
</span><span class="cx">     void setHiddenFromInspector(bool hiddenFromInspector) { m_hiddenFromInspector = hiddenFromInspector; }
</span><span class="cx"> 
</span><ins>+    // Whether this request should impact request counting and delay window.onload.
+    bool ignoreForRequestCount() const { return m_ignoreForRequestCount; }
+    void setIgnoreForRequestCount(bool ignoreForRequestCount) { m_ignoreForRequestCount = ignoreForRequestCount; }
+
</ins><span class="cx">     enum class Requester { Unspecified, Main, XHR, Media };
</span><span class="cx">     Requester requester() const { return m_requester; }
</span><span class="cx">     void setRequester(Requester requester) { m_requester = requester; }
</span><span class="lines">@@ -214,6 +218,7 @@
</span><span class="cx">     bool m_reportLoadTiming { false };
</span><span class="cx">     bool m_reportRawHeaders { false };
</span><span class="cx">     bool m_hiddenFromInspector { false };
</span><ins>+    bool m_ignoreForRequestCount { false };
</ins><span class="cx">     ResourceLoadPriority m_priority { ResourceLoadPriority::Low };
</span><span class="cx">     Requester m_requester { Requester::Unspecified };
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/ChangeLog (205268 => 205269)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/ChangeLog        2016-08-31 22:16:23 UTC (rev 205268)
+++ trunk/Source/WebKit2/ChangeLog        2016-08-31 22:41:44 UTC (rev 205269)
</span><span class="lines">@@ -1,3 +1,13 @@
</span><ins>+2016-08-31  Yoav Weiss  &lt;yoav@yoav.ws&gt;
+
+        Add event support for link preload.
+        https://bugs.webkit.org/show_bug.cgi?id=158466
+
+        Reviewed by Alex Christensen.
+
+        * WebProcess/Network/WebLoaderStrategy.cpp:
+        (WebKit::maximumBufferingTime): Removed LinkPreload.
+
</ins><span class="cx"> 2016-08-31  Alex Christensen  &lt;achristensen@webkit.org&gt;
</span><span class="cx"> 
</span><span class="cx">         Add runtime flag for using URLParser
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessNetworkWebLoaderStrategycpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/Network/WebLoaderStrategy.cpp (205268 => 205269)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/Network/WebLoaderStrategy.cpp        2016-08-31 22:16:23 UTC (rev 205268)
+++ trunk/Source/WebKit2/WebProcess/Network/WebLoaderStrategy.cpp        2016-08-31 22:41:44 UTC (rev 205269)
</span><span class="lines">@@ -110,7 +110,6 @@
</span><span class="cx">     case CachedResource::MainResource:
</span><span class="cx">     case CachedResource::RawResource:
</span><span class="cx">     case CachedResource::SVGDocumentResource:
</span><del>-    case CachedResource::LinkPreload:
</del><span class="cx"> #if ENABLE(LINK_PREFETCH)
</span><span class="cx">     case CachedResource::LinkPrefetch:
</span><span class="cx">     case CachedResource::LinkSubresource:
</span></span></pre>
</div>
</div>

</body>
</html>