<!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>[197939] trunk/Source</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/197939">197939</a></dd>
<dt>Author</dt> <dd>cdumez@apple.com</dd>
<dt>Date</dt> <dd>2016-03-10 08:57:11 -0800 (Thu, 10 Mar 2016)</dd>
</dl>

<h3>Log Message</h3>
<pre>Speculative revalidation requests do not have their 'first party for cookies' URL set
https://bugs.webkit.org/show_bug.cgi?id=155284
&lt;rdar://problem/25053203&gt;

Reviewed by Antti Koivisto.

Source/WebCore:

Export a few more symbols so they can be used in WebKit2.

* platform/URL.h:
* platform/network/ResourceRequestBase.h:

Source/WebKit2:

Speculative revalidation requests did not have their 'first party for cookies'
URL set. This means the underlying NSURLRequest has a nil mainDocumentURL.
Without a way to determine whether the cookie is in a third-party context,
CFNetwork defaults to accepting all cookies for these resources.

* NetworkProcess/cache/NetworkCacheCoders.cpp:
(WebKit::NetworkCache::Coder&lt;WebCore::URL&gt;::encode):
(WebKit::NetworkCache::Coder&lt;WebCore::URL&gt;::decode):
* NetworkProcess/cache/NetworkCacheCoders.h:
Add template specialization to support encoding / decoding WebCore::URL.

* NetworkProcess/cache/NetworkCacheSpeculativeLoadManager.cpp:
(WebKit::NetworkCache::constructRevalidationRequest):
Set the &quot;first party for cookies&quot; URL on the revalidation request.

(WebKit::NetworkCache::SpeculativeLoadManager::PendingFrameLoad::registerSubresourceLoad):
(WebKit::NetworkCache::SpeculativeLoadManager::PendingFrameLoad::saveToDiskIfReady):
Now keep the subresources' ResourceRequests, in addition to their key, so we can later
extract the 'first party for cookies' URL from the request and save it to disk.

(WebKit::NetworkCache::SpeculativeLoadManager::registerLoad):
Pass the ResourceRequest in addition to the key to
PendingFrameLoad::registerSubresourceLoad().

(WebKit::NetworkCache::SpeculativeLoadManager::revalidateEntry):
Add an extra SubresourceInfo parameter, in addition to the Entry, so we
have access to the first party for cookies URL. Pass this URL to
constructRevalidationRequest().

(WebKit::NetworkCache::SpeculativeLoadManager::preloadEntry):
Add an extra SubresourceInfo parameter, in addition to the Entry, so we
have access to the first party for cookies URL.

(WebKit::NetworkCache::SpeculativeLoadManager::startSpeculativeRevalidation):
Pass the SubresourceInfo to preloadEntry().

* NetworkProcess/cache/NetworkCacheSpeculativeLoadManager.h:

* NetworkProcess/cache/NetworkCacheSubresourcesEntry.cpp:
(WebKit::NetworkCache::SubresourcesEntry::SubresourceInfo::encode):
(WebKit::NetworkCache::SubresourcesEntry::SubresourceInfo::decode):
Encode / Decode new firstPartyForCookies member.

(WebKit::NetworkCache::SubresourcesEntry::SubresourcesEntry):
(WebKit::NetworkCache::SubresourcesEntry::updateSubresourceLoads):
Take SubresourceLoad objects in, instead of simple Key objects so we have
access to the ResourceRequest. We extract the first party for cookies URL
from the request and pass it to the SubresourceInfo constructor.

* NetworkProcess/cache/NetworkCacheSubresourcesEntry.h:
(WebKit::NetworkCache::SubresourcesEntry::SubresourceInfo::SubresourceInfo):
(WebKit::NetworkCache::SubresourcesEntry::SubresourceLoad::SubresourceLoad):</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreplatformURLh">trunk/Source/WebCore/platform/URL.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="#trunkSourceWebKit2NetworkProcesscacheNetworkCacheCoderscpp">trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheCoders.cpp</a></li>
<li><a href="#trunkSourceWebKit2NetworkProcesscacheNetworkCacheCodersh">trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheCoders.h</a></li>
<li><a href="#trunkSourceWebKit2NetworkProcesscacheNetworkCacheSpeculativeLoadManagercpp">trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheSpeculativeLoadManager.cpp</a></li>
<li><a href="#trunkSourceWebKit2NetworkProcesscacheNetworkCacheSpeculativeLoadManagerh">trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheSpeculativeLoadManager.h</a></li>
<li><a href="#trunkSourceWebKit2NetworkProcesscacheNetworkCacheSubresourcesEntrycpp">trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheSubresourcesEntry.cpp</a></li>
<li><a href="#trunkSourceWebKit2NetworkProcesscacheNetworkCacheSubresourcesEntryh">trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheSubresourcesEntry.h</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (197938 => 197939)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2016-03-10 16:28:52 UTC (rev 197938)
+++ trunk/Source/WebCore/ChangeLog        2016-03-10 16:57:11 UTC (rev 197939)
</span><span class="lines">@@ -1,3 +1,16 @@
</span><ins>+2016-03-10  Chris Dumez  &lt;cdumez@apple.com&gt;
+
+        Speculative revalidation requests do not have their 'first party for cookies' URL set
+        https://bugs.webkit.org/show_bug.cgi?id=155284
+        &lt;rdar://problem/25053203&gt;
+
+        Reviewed by Antti Koivisto.
+
+        Export a few more symbols so they can be used in WebKit2.
+
+        * platform/URL.h:
+        * platform/network/ResourceRequestBase.h:
+
</ins><span class="cx"> 2016-02-22  Jer Noble  &lt;jer.noble@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Enable AVFoundationNSURLSessionEnabled by default
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformURLh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/URL.h (197938 => 197939)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/URL.h        2016-03-10 16:28:52 UTC (rev 197938)
+++ trunk/Source/WebCore/platform/URL.h        2016-03-10 16:57:11 UTC (rev 197939)
</span><span class="lines">@@ -85,7 +85,7 @@
</span><span class="cx">     // Makes a deep copy. Helpful only if you need to use a URL on another
</span><span class="cx">     // thread. Since the underlying StringImpl objects are immutable, there's
</span><span class="cx">     // no other reason to ever prefer isolatedCopy() over plain old assignment.
</span><del>-    URL isolatedCopy() const;
</del><ins>+    WEBCORE_EXPORT URL isolatedCopy() const;
</ins><span class="cx"> 
</span><span class="cx">     bool isNull() const;
</span><span class="cx">     bool isEmpty() const;
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformnetworkResourceRequestBaseh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/network/ResourceRequestBase.h (197938 => 197939)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/network/ResourceRequestBase.h        2016-03-10 16:28:52 UTC (rev 197938)
+++ trunk/Source/WebCore/platform/network/ResourceRequestBase.h        2016-03-10 16:57:11 UTC (rev 197939)
</span><span class="lines">@@ -74,7 +74,7 @@
</span><span class="cx">         void setTimeoutInterval(double timeoutInterval);
</span><span class="cx">         
</span><span class="cx">         WEBCORE_EXPORT const URL&amp; firstPartyForCookies() const;
</span><del>-        void setFirstPartyForCookies(const URL&amp; firstPartyForCookies);
</del><ins>+        WEBCORE_EXPORT void setFirstPartyForCookies(const URL&amp;);
</ins><span class="cx">         
</span><span class="cx">         WEBCORE_EXPORT const String&amp; httpMethod() const;
</span><span class="cx">         WEBCORE_EXPORT void setHTTPMethod(const String&amp; httpMethod);
</span></span></pre></div>
<a id="trunkSourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/ChangeLog (197938 => 197939)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/ChangeLog        2016-03-10 16:28:52 UTC (rev 197938)
+++ trunk/Source/WebKit2/ChangeLog        2016-03-10 16:57:11 UTC (rev 197939)
</span><span class="lines">@@ -1,3 +1,64 @@
</span><ins>+2016-03-10  Chris Dumez  &lt;cdumez@apple.com&gt;
+
+        Speculative revalidation requests do not have their 'first party for cookies' URL set
+        https://bugs.webkit.org/show_bug.cgi?id=155284
+        &lt;rdar://problem/25053203&gt;
+
+        Reviewed by Antti Koivisto.
+
+        Speculative revalidation requests did not have their 'first party for cookies'
+        URL set. This means the underlying NSURLRequest has a nil mainDocumentURL.
+        Without a way to determine whether the cookie is in a third-party context,
+        CFNetwork defaults to accepting all cookies for these resources.
+
+        * NetworkProcess/cache/NetworkCacheCoders.cpp:
+        (WebKit::NetworkCache::Coder&lt;WebCore::URL&gt;::encode):
+        (WebKit::NetworkCache::Coder&lt;WebCore::URL&gt;::decode):
+        * NetworkProcess/cache/NetworkCacheCoders.h:
+        Add template specialization to support encoding / decoding WebCore::URL.
+
+        * NetworkProcess/cache/NetworkCacheSpeculativeLoadManager.cpp:
+        (WebKit::NetworkCache::constructRevalidationRequest):
+        Set the &quot;first party for cookies&quot; URL on the revalidation request.
+
+        (WebKit::NetworkCache::SpeculativeLoadManager::PendingFrameLoad::registerSubresourceLoad):
+        (WebKit::NetworkCache::SpeculativeLoadManager::PendingFrameLoad::saveToDiskIfReady):
+        Now keep the subresources' ResourceRequests, in addition to their key, so we can later
+        extract the 'first party for cookies' URL from the request and save it to disk.
+
+        (WebKit::NetworkCache::SpeculativeLoadManager::registerLoad):
+        Pass the ResourceRequest in addition to the key to
+        PendingFrameLoad::registerSubresourceLoad().
+
+        (WebKit::NetworkCache::SpeculativeLoadManager::revalidateEntry):
+        Add an extra SubresourceInfo parameter, in addition to the Entry, so we
+        have access to the first party for cookies URL. Pass this URL to
+        constructRevalidationRequest().
+
+        (WebKit::NetworkCache::SpeculativeLoadManager::preloadEntry):
+        Add an extra SubresourceInfo parameter, in addition to the Entry, so we
+        have access to the first party for cookies URL.
+
+        (WebKit::NetworkCache::SpeculativeLoadManager::startSpeculativeRevalidation):
+        Pass the SubresourceInfo to preloadEntry().
+
+        * NetworkProcess/cache/NetworkCacheSpeculativeLoadManager.h:
+
+        * NetworkProcess/cache/NetworkCacheSubresourcesEntry.cpp:
+        (WebKit::NetworkCache::SubresourcesEntry::SubresourceInfo::encode):
+        (WebKit::NetworkCache::SubresourcesEntry::SubresourceInfo::decode):
+        Encode / Decode new firstPartyForCookies member.
+
+        (WebKit::NetworkCache::SubresourcesEntry::SubresourcesEntry):
+        (WebKit::NetworkCache::SubresourcesEntry::updateSubresourceLoads):
+        Take SubresourceLoad objects in, instead of simple Key objects so we have
+        access to the ResourceRequest. We extract the first party for cookies URL
+        from the request and pass it to the SubresourceInfo constructor.
+
+        * NetworkProcess/cache/NetworkCacheSubresourcesEntry.h:
+        (WebKit::NetworkCache::SubresourcesEntry::SubresourceInfo::SubresourceInfo):
+        (WebKit::NetworkCache::SubresourcesEntry::SubresourceLoad::SubresourceLoad):
+
</ins><span class="cx"> 2016-02-22  Jer Noble  &lt;jer.noble@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Enable AVFoundationNSURLSessionEnabled by default
</span></span></pre></div>
<a id="trunkSourceWebKit2NetworkProcesscacheNetworkCacheCoderscpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheCoders.cpp (197938 => 197939)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheCoders.cpp        2016-03-10 16:28:52 UTC (rev 197938)
+++ trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheCoders.cpp        2016-03-10 16:57:11 UTC (rev 197939)
</span><span class="lines">@@ -145,6 +145,20 @@
</span><span class="cx">     return decodeStringText&lt;UChar&gt;(decoder, length, result);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void Coder&lt;WebCore::URL&gt;::encode(Encoder&amp; encoder, const WebCore::URL&amp; url)
+{
+    encoder &lt;&lt; url.string();
+}
+
+bool Coder&lt;WebCore::URL&gt;::decode(Decoder&amp; decoder, WebCore::URL&amp; url)
+{
+    String urlAsString;
+    if (!decoder.decode(urlAsString))
+        return false;
+    url = WebCore::URL(WebCore::ParsedURLString, urlAsString);
+    return true;
+}
+
</ins><span class="cx"> void Coder&lt;WebCore::CertificateInfo&gt;::encode(Encoder&amp; encoder, const WebCore::CertificateInfo&amp; certificateInfo)
</span><span class="cx"> {
</span><span class="cx">     // FIXME: Cocoa CertificateInfo is a CF object tree. Generalize CF type coding so we don't need to use ArgumentCoder here.
</span></span></pre></div>
<a id="trunkSourceWebKit2NetworkProcesscacheNetworkCacheCodersh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheCoders.h (197938 => 197939)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheCoders.h        2016-03-10 16:28:52 UTC (rev 197938)
+++ trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheCoders.h        2016-03-10 16:57:11 UTC (rev 197939)
</span><span class="lines">@@ -31,6 +31,7 @@
</span><span class="cx"> #include &quot;NetworkCacheDecoder.h&quot;
</span><span class="cx"> #include &quot;NetworkCacheEncoder.h&quot;
</span><span class="cx"> #include &lt;WebCore/CertificateInfo.h&gt;
</span><ins>+#include &lt;WebCore/URL.h&gt;
</ins><span class="cx"> #include &lt;utility&gt;
</span><span class="cx"> #include &lt;wtf/Forward.h&gt;
</span><span class="cx"> #include &lt;wtf/HashMap.h&gt;
</span><span class="lines">@@ -248,6 +249,11 @@
</span><span class="cx">     static bool decode(Decoder&amp;, String&amp;);
</span><span class="cx"> };
</span><span class="cx"> 
</span><ins>+template&lt;&gt; struct Coder&lt;WebCore::URL&gt; {
+    static void encode(Encoder&amp;, const WebCore::URL&amp;);
+    static bool decode(Decoder&amp;, WebCore::URL&amp;);
+};
+
</ins><span class="cx"> template&lt;&gt; struct Coder&lt;WebCore::CertificateInfo&gt; {
</span><span class="cx">     static void encode(Encoder&amp;, const WebCore::CertificateInfo&amp;);
</span><span class="cx">     static bool decode(Decoder&amp;, WebCore::CertificateInfo&amp;);
</span></span></pre></div>
<a id="trunkSourceWebKit2NetworkProcesscacheNetworkCacheSpeculativeLoadManagercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheSpeculativeLoadManager.cpp (197938 => 197939)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheSpeculativeLoadManager.cpp        2016-03-10 16:28:52 UTC (rev 197938)
+++ trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheSpeculativeLoadManager.cpp        2016-03-10 16:57:11 UTC (rev 197939)
</span><span class="lines">@@ -84,9 +84,10 @@
</span><span class="cx">     return Key(resourceKey.partition(), subresourcesType(), resourceKey.range(), resourceKey.identifier());
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-static inline ResourceRequest constructRevalidationRequest(const Entry&amp; entry)
</del><ins>+static inline ResourceRequest constructRevalidationRequest(const Entry&amp; entry, const URL&amp; firstPartyForCookies)
</ins><span class="cx"> {
</span><span class="cx">     ResourceRequest revalidationRequest(entry.key().identifier());
</span><ins>+    revalidationRequest.setFirstPartyForCookies(firstPartyForCookies);
</ins><span class="cx"> #if ENABLE(CACHE_PARTITIONING)
</span><span class="cx">     if (entry.key().hasPartition())
</span><span class="cx">         revalidationRequest.setCachePartition(entry.key().partition());
</span><span class="lines">@@ -162,10 +163,10 @@
</span><span class="cx">         ASSERT(m_didRetrieveExistingEntry);
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    void registerSubresource(const Key&amp; subresourceKey)
</del><ins>+    void registerSubresourceLoad(const ResourceRequest&amp; request, const Key&amp; subresourceKey)
</ins><span class="cx">     {
</span><span class="cx">         ASSERT(RunLoop::isMain());
</span><del>-        m_subresourceKeys.append(subresourceKey);
</del><ins>+        m_subresourceLoads.append(std::make_unique&lt;SubresourceLoad&gt;(request, subresourceKey));
</ins><span class="cx">         m_loadHysteresisActivity.impulse();
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="lines">@@ -207,27 +208,27 @@
</span><span class="cx">         if (!m_didFinishLoad || !m_didRetrieveExistingEntry)
</span><span class="cx">             return;
</span><span class="cx"> 
</span><del>-        if (m_subresourceKeys.isEmpty())
</del><ins>+        if (m_subresourceLoads.isEmpty())
</ins><span class="cx">             return;
</span><span class="cx"> 
</span><span class="cx"> #if !LOG_DISABLED
</span><span class="cx">         LOG(NetworkCacheSpeculativePreloading, &quot;(NetworkProcess) Saving to disk list of subresources for '%s':&quot;, m_mainResourceKey.identifier().utf8().data());
</span><del>-        for (auto&amp; subresourceKey : m_subresourceKeys)
-            LOG(NetworkCacheSpeculativePreloading, &quot;(NetworkProcess) * Subresource: '%s'.&quot;, subresourceKey.identifier().utf8().data());
</del><ins>+        for (auto&amp; subresourceLoad : m_subresourceLoads)
+            LOG(NetworkCacheSpeculativePreloading, &quot;(NetworkProcess) * Subresource: '%s'.&quot;, subresourceLoad-&gt;key.identifier().utf8().data());
</ins><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx">         if (m_existingEntry) {
</span><del>-            m_existingEntry-&gt;updateSubresourceKeys(m_subresourceKeys);
</del><ins>+            m_existingEntry-&gt;updateSubresourceLoads(m_subresourceLoads);
</ins><span class="cx">             m_storage.store(m_existingEntry-&gt;encodeAsStorageRecord(), [](const Data&amp;) { });
</span><span class="cx">         } else {
</span><del>-            SubresourcesEntry entry(makeSubresourcesKey(m_mainResourceKey), m_subresourceKeys);
</del><ins>+            SubresourcesEntry entry(makeSubresourcesKey(m_mainResourceKey), m_subresourceLoads);
</ins><span class="cx">             m_storage.store(entry.encodeAsStorageRecord(), [](const Data&amp;) { });
</span><span class="cx">         }
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     Storage&amp; m_storage;
</span><span class="cx">     Key m_mainResourceKey;
</span><del>-    Vector&lt;Key&gt; m_subresourceKeys;
</del><ins>+    Vector&lt;std::unique_ptr&lt;SubresourceLoad&gt;&gt; m_subresourceLoads;
</ins><span class="cx">     std::function&lt;void()&gt; m_loadCompletionHandler;
</span><span class="cx">     HysteresisActivity m_loadHysteresisActivity;
</span><span class="cx">     std::unique_ptr&lt;SubresourcesEntry&gt; m_existingEntry;
</span><span class="lines">@@ -311,7 +312,7 @@
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     if (auto* pendingFrameLoad = m_pendingFrameLoads.get(frameID))
</span><del>-        pendingFrameLoad-&gt;registerSubresource(resourceKey);
</del><ins>+        pendingFrameLoad-&gt;registerSubresourceLoad(request, resourceKey);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void SpeculativeLoadManager::addPreloadedEntry(std::unique_ptr&lt;Entry&gt; entry, const GlobalFrameID&amp; frameID, WasRevalidated wasRevalidated)
</span><span class="lines">@@ -368,7 +369,7 @@
</span><span class="cx">     return true;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void SpeculativeLoadManager::revalidateEntry(std::unique_ptr&lt;Entry&gt; entry, const GlobalFrameID&amp; frameID)
</del><ins>+void SpeculativeLoadManager::revalidateEntry(std::unique_ptr&lt;Entry&gt; entry, const SubresourceInfo&amp; subresourceInfo, const GlobalFrameID&amp; frameID)
</ins><span class="cx"> {
</span><span class="cx">     ASSERT(entry);
</span><span class="cx">     ASSERT(entry-&gt;needsValidation());
</span><span class="lines">@@ -379,8 +380,10 @@
</span><span class="cx">     if (!key.range().isEmpty())
</span><span class="cx">         return;
</span><span class="cx"> 
</span><ins>+    ResourceRequest revalidationRequest = constructRevalidationRequest(*entry, subresourceInfo.firstPartyForCookies);
+
</ins><span class="cx">     LOG(NetworkCacheSpeculativePreloading, &quot;(NetworkProcess) Speculatively revalidating '%s':&quot;, key.identifier().utf8().data());
</span><del>-    auto revalidator = std::make_unique&lt;SpeculativeLoad&gt;(frameID, constructRevalidationRequest(*entry), WTFMove(entry), [this, key, frameID](std::unique_ptr&lt;Entry&gt; revalidatedEntry) {
</del><ins>+    auto revalidator = std::make_unique&lt;SpeculativeLoad&gt;(frameID, revalidationRequest, WTFMove(entry), [this, key, frameID](std::unique_ptr&lt;Entry&gt; revalidatedEntry) {
</ins><span class="cx">         ASSERT(!revalidatedEntry || !revalidatedEntry-&gt;needsValidation());
</span><span class="cx">         ASSERT(!revalidatedEntry || revalidatedEntry-&gt;key() == key);
</span><span class="cx"> 
</span><span class="lines">@@ -399,10 +402,11 @@
</span><span class="cx">     m_pendingPreloads.add(key, WTFMove(revalidator));
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void SpeculativeLoadManager::preloadEntry(const Key&amp; key, const GlobalFrameID&amp; frameID)
</del><ins>+void SpeculativeLoadManager::preloadEntry(const Key&amp; key, const SubresourceInfo&amp; subResourceInfo, const GlobalFrameID&amp; frameID)
</ins><span class="cx"> {
</span><span class="cx">     m_pendingPreloads.add(key, nullptr);
</span><del>-    retrieveEntryFromStorage(key, [this, key, frameID](std::unique_ptr&lt;Entry&gt; entry) {
</del><ins>+    URLCapture firstPartyForCookies(subResourceInfo.firstPartyForCookies);
+    retrieveEntryFromStorage(key, [this, key, firstPartyForCookies, frameID](std::unique_ptr&lt;Entry&gt; entry) {
</ins><span class="cx">         m_pendingPreloads.remove(key);
</span><span class="cx"> 
</span><span class="cx">         if (satisfyPendingRequests(key, entry.get())) {
</span><span class="lines">@@ -415,7 +419,7 @@
</span><span class="cx">             return;
</span><span class="cx"> 
</span><span class="cx">         if (entry-&gt;needsValidation())
</span><del>-            revalidateEntry(WTFMove(entry), frameID);
</del><ins>+            revalidateEntry(WTFMove(entry), firstPartyForCookies.url(), frameID);
</ins><span class="cx">         else
</span><span class="cx">             addPreloadedEntry(WTFMove(entry), frameID, WasRevalidated::No);
</span><span class="cx">     });
</span><span class="lines">@@ -423,12 +427,13 @@
</span><span class="cx"> 
</span><span class="cx"> void SpeculativeLoadManager::startSpeculativeRevalidation(const GlobalFrameID&amp; frameID, SubresourcesEntry&amp; entry)
</span><span class="cx"> {
</span><del>-    for (auto&amp; subresource : entry.subresources()) {
-        auto key = subresource.key;
-        if (!subresource.value.isTransient)
-            preloadEntry(key, frameID);
</del><ins>+    for (auto&amp; subresourcePair : entry.subresources()) {
+        auto key = subresourcePair.key;
+        auto subresourceInfo = subresourcePair.value;
+        if (!subresourceInfo.isTransient)
+            preloadEntry(key, subresourceInfo, frameID);
</ins><span class="cx">         else {
</span><del>-            LOG(NetworkCacheSpeculativePreloading, &quot;(NetworkProcess) Not preloading '%s' because it is marked as transient&quot;, subresource.key.identifier().utf8().data());
</del><ins>+            LOG(NetworkCacheSpeculativePreloading, &quot;(NetworkProcess) Not preloading '%s' because it is marked as transient&quot;, key.identifier().utf8().data());
</ins><span class="cx">             m_notPreloadedEntries.add(key, std::make_unique&lt;ExpiringEntry&gt;([this, key, frameID] {
</span><span class="cx">                 logSpeculativeLoadingDiagnosticMessage(frameID, DiagnosticLoggingKeys::entryRightlyNotWarmedUpKey());
</span><span class="cx">                 m_notPreloadedEntries.remove(key);
</span></span></pre></div>
<a id="trunkSourceWebKit2NetworkProcesscacheNetworkCacheSpeculativeLoadManagerh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheSpeculativeLoadManager.h (197938 => 197939)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheSpeculativeLoadManager.h        2016-03-10 16:28:52 UTC (rev 197938)
+++ trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheSpeculativeLoadManager.h        2016-03-10 16:57:11 UTC (rev 197939)
</span><span class="lines">@@ -41,6 +41,7 @@
</span><span class="cx"> class Entry;
</span><span class="cx"> class SpeculativeLoad;
</span><span class="cx"> class SubresourcesEntry;
</span><ins>+struct SubresourceInfo;
</ins><span class="cx"> 
</span><span class="cx"> class SpeculativeLoadManager {
</span><span class="cx"> public:
</span><span class="lines">@@ -55,9 +56,9 @@
</span><span class="cx"> private:
</span><span class="cx">     enum class WasRevalidated { No, Yes };
</span><span class="cx">     void addPreloadedEntry(std::unique_ptr&lt;Entry&gt;, const GlobalFrameID&amp;, WasRevalidated);
</span><del>-    void preloadEntry(const Key&amp;, const GlobalFrameID&amp;);
</del><ins>+    void preloadEntry(const Key&amp;, const SubresourceInfo&amp;, const GlobalFrameID&amp;);
</ins><span class="cx">     void retrieveEntryFromStorage(const Key&amp;, const RetrieveCompletionHandler&amp;);
</span><del>-    void revalidateEntry(std::unique_ptr&lt;Entry&gt;, const GlobalFrameID&amp;);
</del><ins>+    void revalidateEntry(std::unique_ptr&lt;Entry&gt;, const SubresourceInfo&amp;, const GlobalFrameID&amp;);
</ins><span class="cx">     bool satisfyPendingRequests(const Key&amp;, Entry*);
</span><span class="cx">     void retrieveSubresourcesEntry(const Key&amp; storageKey, std::function&lt;void (std::unique_ptr&lt;SubresourcesEntry&gt;)&gt;);
</span><span class="cx">     void startSpeculativeRevalidation(const GlobalFrameID&amp;, SubresourcesEntry&amp;);
</span></span></pre></div>
<a id="trunkSourceWebKit2NetworkProcesscacheNetworkCacheSubresourcesEntrycpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheSubresourcesEntry.cpp (197938 => 197939)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheSubresourcesEntry.cpp        2016-03-10 16:28:52 UTC (rev 197938)
+++ trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheSubresourcesEntry.cpp        2016-03-10 16:57:11 UTC (rev 197939)
</span><span class="lines">@@ -36,6 +36,21 @@
</span><span class="cx"> namespace WebKit {
</span><span class="cx"> namespace NetworkCache {
</span><span class="cx"> 
</span><ins>+void SubresourceInfo::encode(Encoder&amp; encoder) const
+{
+    encoder &lt;&lt; firstPartyForCookies;
+    encoder &lt;&lt; isTransient;
+}
+
+bool SubresourceInfo::decode(Decoder&amp; decoder, SubresourceInfo&amp; info)
+{
+    if (!decoder.decode(info.firstPartyForCookies))
+        return false;
+    if (!decoder.decode(info.isTransient))
+        return false;
+    return true;
+}
+
</ins><span class="cx"> Storage::Record SubresourcesEntry::encodeAsStorageRecord() const
</span><span class="cx"> {
</span><span class="cx">     Encoder encoder;
</span><span class="lines">@@ -69,23 +84,23 @@
</span><span class="cx">     ASSERT(m_key.type() == &quot;subresources&quot;);
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-SubresourcesEntry::SubresourcesEntry(Key&amp;&amp; key, const Vector&lt;Key&gt;&amp; subresourceKeys)
</del><ins>+SubresourcesEntry::SubresourcesEntry(Key&amp;&amp; key, const Vector&lt;std::unique_ptr&lt;SubresourceLoad&gt;&gt;&amp; subresourceLoads)
</ins><span class="cx">     : m_key(WTFMove(key))
</span><span class="cx">     , m_timeStamp(std::chrono::system_clock::now())
</span><span class="cx"> {
</span><span class="cx">     ASSERT(m_key.type() == &quot;subresources&quot;);
</span><del>-    for (auto&amp; key : subresourceKeys)
-        m_subresources.add(key, SubresourceInfo());
</del><ins>+    for (auto&amp; subresourceLoad : subresourceLoads)
+        m_subresources.add(subresourceLoad-&gt;key, SubresourceInfo(subresourceLoad-&gt;request.firstPartyForCookies()));
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-void SubresourcesEntry::updateSubresourceKeys(const Vector&lt;Key&gt;&amp; subresourceKeys)
</del><ins>+void SubresourcesEntry::updateSubresourceLoads(const Vector&lt;std::unique_ptr&lt;SubresourceLoad&gt;&gt;&amp; subresourceLoads)
</ins><span class="cx"> {
</span><span class="cx">     auto oldSubresources = WTFMove(m_subresources);
</span><span class="cx"> 
</span><span class="cx">     // Mark keys that are common with last load as non-Transient.
</span><del>-    for (auto&amp; key : subresourceKeys) {
-        bool isTransient = !oldSubresources.contains(key);
-        m_subresources.add(key, SubresourceInfo(isTransient));
</del><ins>+    for (auto&amp; subresourceLoad : subresourceLoads) {
+        bool isTransient = !oldSubresources.contains(subresourceLoad-&gt;key);
+        m_subresources.add(subresourceLoad-&gt;key, SubresourceInfo(subresourceLoad-&gt;request.firstPartyForCookies(), isTransient));
</ins><span class="cx">     }
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebKit2NetworkProcesscacheNetworkCacheSubresourcesEntryh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheSubresourcesEntry.h (197938 => 197939)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheSubresourcesEntry.h        2016-03-10 16:28:52 UTC (rev 197938)
+++ trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheSubresourcesEntry.h        2016-03-10 16:57:11 UTC (rev 197939)
</span><span class="lines">@@ -31,24 +31,43 @@
</span><span class="cx"> #include &quot;NetworkCacheDecoder.h&quot;
</span><span class="cx"> #include &quot;NetworkCacheEncoder.h&quot;
</span><span class="cx"> #include &quot;NetworkCacheStorage.h&quot;
</span><ins>+#include &lt;WebCore/ResourceRequest.h&gt;
+#include &lt;WebCore/URL.h&gt;
</ins><span class="cx"> #include &lt;wtf/HashMap.h&gt;
</span><span class="cx"> 
</span><span class="cx"> namespace WebKit {
</span><span class="cx"> namespace NetworkCache {
</span><span class="cx"> 
</span><ins>+struct SubresourceInfo {
+    void encode(Encoder&amp;) const;
+    static bool decode(Decoder&amp;, SubresourceInfo&amp;);
+
+    SubresourceInfo() = default;
+    SubresourceInfo(const WebCore::URL&amp; firstPartyForCookies, bool isTransient = false)
+        : firstPartyForCookies(firstPartyForCookies)
+        , isTransient(isTransient)
+    { }
+
+    WebCore::URL firstPartyForCookies;
+    bool isTransient { false };
+};
+
+struct SubresourceLoad {
+    WTF_MAKE_NONCOPYABLE(SubresourceLoad); WTF_MAKE_FAST_ALLOCATED;
+public:
+    SubresourceLoad(const WebCore::ResourceRequest&amp; request, const Key&amp; key)
+        : request(request)
+        , key(key)
+    { }
+
+    WebCore::ResourceRequest request;
+    Key key;
+};
+
</ins><span class="cx"> class SubresourcesEntry {
</span><span class="cx">     WTF_MAKE_NONCOPYABLE(SubresourcesEntry); WTF_MAKE_FAST_ALLOCATED;
</span><span class="cx"> public:
</span><del>-    struct SubresourceInfo {
-        void encode(Encoder&amp; encoder) const { encoder &lt;&lt; isTransient; }
-        static bool decode(Decoder&amp; decoder, SubresourceInfo&amp; info) { return decoder.decode(info.isTransient); }
-
-        SubresourceInfo() = default;
-        SubresourceInfo(bool isTransient) : isTransient(isTransient) { }
-
-        bool isTransient { false };
-    };
-    SubresourcesEntry(Key&amp;&amp;, const Vector&lt;Key&gt;&amp; subresourceKeys);
</del><ins>+    SubresourcesEntry(Key&amp;&amp;, const Vector&lt;std::unique_ptr&lt;SubresourceLoad&gt;&gt;&amp;);
</ins><span class="cx">     explicit SubresourcesEntry(const Storage::Record&amp;);
</span><span class="cx"> 
</span><span class="cx">     Storage::Record encodeAsStorageRecord() const;
</span><span class="lines">@@ -58,7 +77,7 @@
</span><span class="cx">     std::chrono::system_clock::time_point timeStamp() const { return m_timeStamp; }
</span><span class="cx">     const HashMap&lt;Key, SubresourceInfo&gt;&amp; subresources() const { return m_subresources; }
</span><span class="cx"> 
</span><del>-    void updateSubresourceKeys(const Vector&lt;Key&gt;&amp;);
</del><ins>+    void updateSubresourceLoads(const Vector&lt;std::unique_ptr&lt;SubresourceLoad&gt;&gt;&amp;);
</ins><span class="cx"> 
</span><span class="cx"> private:
</span><span class="cx">     Key m_key;
</span></span></pre>
</div>
</div>

</body>
</html>