<!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>[197518] 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/197518">197518</a></dd>
<dt>Author</dt> <dd>aestes@apple.com</dd>
<dt>Date</dt> <dd>2016-03-03 13:46:07 -0800 (Thu, 03 Mar 2016)</dd>
</dl>

<h3>Log Message</h3>
<pre>Adopt CFNetwork storage partitioning SPI
https://bugs.webkit.org/show_bug.cgi?id=154957
rdar://problem/23614620

Reviewed by Darin Adler.

Source/WebCore:

Adopt CFNetwork SPI for creating storage partitions. If Settings::cookieStoragePartitioningEnabled() is true,
create cookie storage partitions for third-party contexts. This feature is disabled by default.

No new tests. Test support is tracked by &lt;https://webkit.org/b/154958&gt;.

* page/Settings.cpp:
(WebCore::Settings::setCookieStoragePartitioningEnabled): Controls whether storage partitioning for cookies is enabled.
* page/Settings.h:
(WebCore::Settings::cookieStoragePartitioningEnabled):
* platform/network/NetworkStorageSession.h:
* platform/network/cf/NetworkStorageSessionCFNet.cpp:
(WebCore::cookieStoragePartition): Computes a storage partition identifier by determining the top
privately-controlled domain of the cookie's first-party (main frame document) URL, then determining whether the
cookie's document hostname is a subdomain of it. If is is not, the first-party top domain is the partition name.
Otherwise, there is no partition name.
* platform/network/mac/CookieJarMac.mm:
(WebCore::applyPartitionToCookies): Returns a deep copy of the given cookie array after adding a storage
partition property to each copied cookie.
(WebCore::cookiesInPartitionForURL): Returns cookies for the partition computed by the given URLs. If no
partition can be determined, nil is returned.
(WebCore::cookiesForURL): Returns cookiesInPartitionForURL() if non-nil, otherwise returns wkHTTPCookiesForURL().
(WebCore::cookiesForSession): Started calling cookiesForURL().
(WebCore::setCookiesFromDOM): Called applyPartitionToCookies() if a partition can be computed from the given URLs.
(WebCore::getRawCookies): Started calling cookiesForURL().
* platform/network/mac/ResourceHandleMac.mm:
(WebCore::ResourceHandle::createNSURLConnection): Computed the storage partition identifier for the new request.
If non-empty, set it as a property on the NSURLRequest where CFNetwork knows to find it.
* platform/spi/cf/CFNetworkSPI.h: Declare new SPI for building with the public SDK.

Source/WebKit2:

* NetworkProcess/cocoa/NetworkDataTaskCocoa.mm:
(WebKit::NetworkDataTask::NetworkDataTask): Computed the storage partition identifier for the new session task.
If non-empty, set it using a NSURLSessionTask SPI.

Source/WTF:

* wtf/Platform.h: Defined HAVE_CFNETWORK_STORAGE_PARTITIONING.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWTFChangeLog">trunk/Source/WTF/ChangeLog</a></li>
<li><a href="#trunkSourceWTFwtfPlatformh">trunk/Source/WTF/wtf/Platform.h</a></li>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCorepageSettingscpp">trunk/Source/WebCore/page/Settings.cpp</a></li>
<li><a href="#trunkSourceWebCorepageSettingsh">trunk/Source/WebCore/page/Settings.h</a></li>
<li><a href="#trunkSourceWebCoreplatformnetworkNetworkStorageSessionh">trunk/Source/WebCore/platform/network/NetworkStorageSession.h</a></li>
<li><a href="#trunkSourceWebCoreplatformnetworkcfNetworkStorageSessionCFNetcpp">trunk/Source/WebCore/platform/network/cf/NetworkStorageSessionCFNet.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformnetworkmacCookieJarMacmm">trunk/Source/WebCore/platform/network/mac/CookieJarMac.mm</a></li>
<li><a href="#trunkSourceWebCoreplatformnetworkmacResourceHandleMacmm">trunk/Source/WebCore/platform/network/mac/ResourceHandleMac.mm</a></li>
<li><a href="#trunkSourceWebCoreplatformspicfCFNetworkSPIh">trunk/Source/WebCore/platform/spi/cf/CFNetworkSPI.h</a></li>
<li><a href="#trunkSourceWebKit2ChangeLog">trunk/Source/WebKit2/ChangeLog</a></li>
<li><a href="#trunkSourceWebKit2NetworkProcesscocoaNetworkDataTaskCocoamm">trunk/Source/WebKit2/NetworkProcess/cocoa/NetworkDataTaskCocoa.mm</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWTFChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WTF/ChangeLog (197517 => 197518)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/ChangeLog        2016-03-03 21:43:47 UTC (rev 197517)
+++ trunk/Source/WTF/ChangeLog        2016-03-03 21:46:07 UTC (rev 197518)
</span><span class="lines">@@ -1,3 +1,13 @@
</span><ins>+2016-03-03  Andy Estes  &lt;aestes@apple.com&gt;
+
+        Adopt CFNetwork storage partitioning SPI
+        https://bugs.webkit.org/show_bug.cgi?id=154957
+        rdar://problem/23614620
+
+        Reviewed by Darin Adler.
+
+        * wtf/Platform.h: Defined HAVE_CFNETWORK_STORAGE_PARTITIONING.
+
</ins><span class="cx"> 2016-03-02  Konstantin Tokarev  &lt;annulen@yandex.ru&gt;
</span><span class="cx"> 
</span><span class="cx">         [cmake] Moved PRE/POST_BUILD_COMMAND to WEBKIT_FRAMEWORK.
</span></span></pre></div>
<a id="trunkSourceWTFwtfPlatformh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WTF/wtf/Platform.h (197517 => 197518)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/wtf/Platform.h        2016-03-03 21:43:47 UTC (rev 197517)
+++ trunk/Source/WTF/wtf/Platform.h        2016-03-03 21:46:07 UTC (rev 197518)
</span><span class="lines">@@ -665,6 +665,10 @@
</span><span class="cx"> #define HAVE_VIRTUALALLOC 1
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><ins>+#if (PLATFORM(MAC) &amp;&amp; __MAC_OS_X_VERSION_MIN_REQUIRED &gt;= 101200) || (PLATFORM(IOS) &amp;&amp; __IPHONE_OS_VERSION_MIN_REQUIRED &gt;= 100000)
+#define HAVE_CFNETWORK_STORAGE_PARTITIONING 1
+#endif
+
</ins><span class="cx"> /* ENABLE macro defaults */
</span><span class="cx"> 
</span><span class="cx"> /* FIXME: move out all ENABLE() defines from here to FeatureDefines.h */
</span></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (197517 => 197518)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2016-03-03 21:43:47 UTC (rev 197517)
+++ trunk/Source/WebCore/ChangeLog        2016-03-03 21:46:07 UTC (rev 197518)
</span><span class="lines">@@ -1,3 +1,40 @@
</span><ins>+2016-03-03  Andy Estes  &lt;aestes@apple.com&gt;
+
+        Adopt CFNetwork storage partitioning SPI
+        https://bugs.webkit.org/show_bug.cgi?id=154957
+        rdar://problem/23614620
+
+        Reviewed by Darin Adler.
+
+        Adopt CFNetwork SPI for creating storage partitions. If Settings::cookieStoragePartitioningEnabled() is true,
+        create cookie storage partitions for third-party contexts. This feature is disabled by default.
+
+        No new tests. Test support is tracked by &lt;https://webkit.org/b/154958&gt;.
+
+        * page/Settings.cpp:
+        (WebCore::Settings::setCookieStoragePartitioningEnabled): Controls whether storage partitioning for cookies is enabled.
+        * page/Settings.h:
+        (WebCore::Settings::cookieStoragePartitioningEnabled):
+        * platform/network/NetworkStorageSession.h:
+        * platform/network/cf/NetworkStorageSessionCFNet.cpp:
+        (WebCore::cookieStoragePartition): Computes a storage partition identifier by determining the top
+        privately-controlled domain of the cookie's first-party (main frame document) URL, then determining whether the
+        cookie's document hostname is a subdomain of it. If is is not, the first-party top domain is the partition name.
+        Otherwise, there is no partition name.
+        * platform/network/mac/CookieJarMac.mm:
+        (WebCore::applyPartitionToCookies): Returns a deep copy of the given cookie array after adding a storage
+        partition property to each copied cookie.
+        (WebCore::cookiesInPartitionForURL): Returns cookies for the partition computed by the given URLs. If no
+        partition can be determined, nil is returned.
+        (WebCore::cookiesForURL): Returns cookiesInPartitionForURL() if non-nil, otherwise returns wkHTTPCookiesForURL().
+        (WebCore::cookiesForSession): Started calling cookiesForURL().
+        (WebCore::setCookiesFromDOM): Called applyPartitionToCookies() if a partition can be computed from the given URLs.
+        (WebCore::getRawCookies): Started calling cookiesForURL().
+        * platform/network/mac/ResourceHandleMac.mm:
+        (WebCore::ResourceHandle::createNSURLConnection): Computed the storage partition identifier for the new request.
+        If non-empty, set it as a property on the NSURLRequest where CFNetwork knows to find it.
+        * platform/spi/cf/CFNetworkSPI.h: Declare new SPI for building with the public SDK.
+
</ins><span class="cx"> 2016-03-03  Manuel Rego Casasnovas  &lt;rego@igalia.com&gt;
</span><span class="cx"> 
</span><span class="cx">         [css-grid] Fix order of grid shorthands in CSSPropertyNames.in
</span></span></pre></div>
<a id="trunkSourceWebCorepageSettingscpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/Settings.cpp (197517 => 197518)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/Settings.cpp        2016-03-03 21:43:47 UTC (rev 197517)
+++ trunk/Source/WebCore/page/Settings.cpp        2016-03-03 21:46:07 UTC (rev 197518)
</span><span class="lines">@@ -82,6 +82,7 @@
</span><span class="cx"> 
</span><span class="cx"> #if PLATFORM(COCOA)
</span><span class="cx"> bool Settings::gQTKitEnabled = false;
</span><ins>+bool Settings::gCookieStoragePartitioningEnabled = false;
</ins><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx"> bool Settings::gMockScrollbarsEnabled = false;
</span><span class="lines">@@ -598,6 +599,11 @@
</span><span class="cx">     gQTKitEnabled = enabled;
</span><span class="cx">     HTMLMediaElement::resetMediaEngines();
</span><span class="cx"> }
</span><ins>+    
+void Settings::setCookieStoragePartitioningEnabled(bool enabled)
+{
+    gCookieStoragePartitioningEnabled = enabled;
+}
</ins><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(MEDIA_STREAM)
</span></span></pre></div>
<a id="trunkSourceWebCorepageSettingsh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/Settings.h (197517 => 197518)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/Settings.h        2016-03-03 21:43:47 UTC (rev 197517)
+++ trunk/Source/WebCore/page/Settings.h        2016-03-03 21:46:07 UTC (rev 197518)
</span><span class="lines">@@ -198,6 +198,9 @@
</span><span class="cx"> #if PLATFORM(COCOA)
</span><span class="cx">     WEBCORE_EXPORT static void setQTKitEnabled(bool flag);
</span><span class="cx">     static bool isQTKitEnabled() { return gQTKitEnabled; }
</span><ins>+
+    WEBCORE_EXPORT static void setCookieStoragePartitioningEnabled(bool flag);
+    static bool cookieStoragePartitioningEnabled() { return gCookieStoragePartitioningEnabled; }
</ins><span class="cx"> #else
</span><span class="cx">     static bool isQTKitEnabled() { return false; }
</span><span class="cx"> #endif
</span><span class="lines">@@ -352,6 +355,7 @@
</span><span class="cx"> 
</span><span class="cx"> #if PLATFORM(COCOA)
</span><span class="cx">     WEBCORE_EXPORT static bool gQTKitEnabled;
</span><ins>+    static bool gCookieStoragePartitioningEnabled;
</ins><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx">     static bool gMockScrollbarsEnabled;
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformnetworkNetworkStorageSessionh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/network/NetworkStorageSession.h (197517 => 197518)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/network/NetworkStorageSession.h        2016-03-03 21:43:47 UTC (rev 197517)
+++ trunk/Source/WebCore/platform/network/NetworkStorageSession.h        2016-03-03 21:46:07 UTC (rev 197518)
</span><span class="lines">@@ -38,6 +38,7 @@
</span><span class="cx"> namespace WebCore {
</span><span class="cx"> 
</span><span class="cx"> class NetworkingContext;
</span><ins>+class ResourceRequest;
</ins><span class="cx"> class SoupNetworkSession;
</span><span class="cx"> 
</span><span class="cx"> class NetworkStorageSession {
</span><span class="lines">@@ -79,6 +80,9 @@
</span><span class="cx">     CredentialStorage m_credentialStorage;
</span><span class="cx"> };
</span><span class="cx"> 
</span><ins>+WEBCORE_EXPORT String cookieStoragePartition(const ResourceRequest&amp;);
+String cookieStoragePartition(const URL&amp; firstPartyForCookies, const URL&amp; resource);
+
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> #endif // NetworkStorageSession_h
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformnetworkcfNetworkStorageSessionCFNetcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/network/cf/NetworkStorageSessionCFNet.cpp (197517 => 197518)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/network/cf/NetworkStorageSessionCFNet.cpp        2016-03-03 21:43:47 UTC (rev 197517)
+++ trunk/Source/WebCore/platform/network/cf/NetworkStorageSessionCFNet.cpp        2016-03-03 21:46:07 UTC (rev 197518)
</span><span class="lines">@@ -31,6 +31,9 @@
</span><span class="cx"> #include &lt;wtf/ProcessID.h&gt;
</span><span class="cx"> 
</span><span class="cx"> #if PLATFORM(COCOA)
</span><ins>+#include &quot;PublicSuffix.h&quot;
+#include &quot;ResourceRequest.h&quot;
+#include &quot;Settings.h&quot;
</ins><span class="cx"> #include &quot;WebCoreSystemInterface.h&quot;
</span><span class="cx"> #else
</span><span class="cx"> #include &lt;WebKitSystemInterface/WebKitSystemInterface.h&gt;
</span><span class="lines">@@ -94,4 +97,36 @@
</span><span class="cx"> #endif
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+#if PLATFORM(COCOA)
+
+String cookieStoragePartition(const ResourceRequest&amp; request)
+{
+    return cookieStoragePartition(request.firstPartyForCookies(), request.url());
</ins><span class="cx"> }
</span><ins>+
+static inline bool hostIsInDomain(StringView host, StringView domain)
+{
+    if (!host.endsWithIgnoringASCIICase(domain))
+        return false;
+
+    ASSERT(host.length() &gt;= domain.length());
+    unsigned suffixOffset = host.length() - domain.length();
+    return suffixOffset == 0 || host[suffixOffset - 1] == '.';
+}
+
+String cookieStoragePartition(const URL&amp; firstPartyForCookies, const URL&amp; resource)
+{
+    if (!Settings::cookieStoragePartitioningEnabled())
+        return emptyString();
+
+    String firstPartyDomain = firstPartyForCookies.host();
+#if ENABLE(PUBLIC_SUFFIX_LIST)
+    firstPartyDomain = topPrivatelyControlledDomain(firstPartyDomain);
+#endif
+    
+    return hostIsInDomain(resource.host(), firstPartyDomain) ? emptyString() : firstPartyDomain;
+}
+
+#endif
+
+}
</ins></span></pre></div>
<a id="trunkSourceWebCoreplatformnetworkmacCookieJarMacmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/network/mac/CookieJarMac.mm (197517 => 197518)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/network/mac/CookieJarMac.mm        2016-03-03 21:43:47 UTC (rev 197517)
+++ trunk/Source/WebCore/platform/network/mac/CookieJarMac.mm        2016-03-03 21:46:07 UTC (rev 197518)
</span><span class="lines">@@ -36,6 +36,7 @@
</span><span class="cx"> #import &quot;Cookie.h&quot;
</span><span class="cx"> #import &quot;CookieStorage.h&quot;
</span><span class="cx"> #import &quot;URL.h&quot;
</span><ins>+#import &lt;wtf/Optional.h&gt;
</ins><span class="cx"> #import &lt;wtf/text/StringBuilder.h&gt;
</span><span class="cx"> 
</span><span class="cx"> namespace WebCore {
</span><span class="lines">@@ -64,12 +65,64 @@
</span><span class="cx">     return filteredCookies;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+#if HAVE(CFNETWORK_STORAGE_PARTITIONING)
+
+static NSArray *applyPartitionToCookies(NSString *partition, NSArray *cookies)
+{
+    // FIXME 24747739: CFNetwork should expose this key as SPI
+    static NSString * const partitionKey = @&quot;StoragePartition&quot;;
+
+    NSMutableArray *partitionedCookies = [NSMutableArray arrayWithCapacity:cookies.count];
+    for (NSHTTPCookie *cookie in cookies) {
+        RetainPtr&lt;NSMutableDictionary&gt; properties = adoptNS([cookie.properties mutableCopy]);
+        [properties setObject:partition forKey:partitionKey];
+        [partitionedCookies addObject:[NSHTTPCookie cookieWithProperties:properties.get()]];
+    }
+
+    return partitionedCookies;
+}
+
+static NSArray *cookiesInPartitionForURL(const NetworkStorageSession&amp; session, const URL&amp; firstParty, const URL&amp; url)
+{
+    String partition = cookieStoragePartition(firstParty, url);
+    if (partition.isEmpty())
+        return nil;
+
+    // FIXME: Stop creating a new NSHTTPCookieStorage object each time we want to query the cookie jar.
+    // NetworkStorageSession could instead keep a NSHTTPCookieStorage object for us.
+    RetainPtr&lt;NSHTTPCookieStorage&gt; cookieStorage;
+    if (auto storage = session.cookieStorage())
+        cookieStorage = adoptNS([[NSHTTPCookieStorage alloc] _initWithCFHTTPCookieStorage:storage.get()]);
+    else
+        cookieStorage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
+
+    // The _getCookiesForURL: method calls the completionHandler synchronously.
+    Optional&lt;RetainPtr&lt;NSArray *&gt;&gt; cookiesPtr;
+    [cookieStorage _getCookiesForURL:url mainDocumentURL:firstParty partition:partition completionHandler:[&amp;cookiesPtr](NSArray *cookies) {
+        cookiesPtr = retainPtr(cookies);
+    }];
+    ASSERT(!!cookiesPtr);
+
+    return cookiesPtr-&gt;autorelease();
+}
+
+#endif // HAVE(CFNETWORK_STORAGE_PARTITIONING)
+    
+static NSArray *cookiesForURL(const NetworkStorageSession&amp; session, const URL&amp; firstParty, const URL&amp; url)
+{
+#if HAVE(CFNETWORK_STORAGE_PARTITIONING)
+    if (NSArray *cookies = cookiesInPartitionForURL(session, firstParty, url))
+        return cookies;
+#endif
+    return wkHTTPCookiesForURL(session.cookieStorage().get(), firstParty, url);
+}
+
</ins><span class="cx"> enum IncludeHTTPOnlyOrNot { DoNotIncludeHTTPOnly, IncludeHTTPOnly };
</span><span class="cx"> static String cookiesForSession(const NetworkStorageSession&amp; session, const URL&amp; firstParty, const URL&amp; url, IncludeHTTPOnlyOrNot includeHTTPOnly)
</span><span class="cx"> {
</span><span class="cx">     BEGIN_BLOCK_OBJC_EXCEPTIONS;
</span><span class="cx"> 
</span><del>-    NSArray *cookies = wkHTTPCookiesForURL(session.cookieStorage().get(), firstParty, url);
</del><ins>+    NSArray *cookies = cookiesForURL(session, firstParty, url);
</ins><span class="cx">     if (![cookies count])
</span><span class="cx">         return String(); // Return a null string, not an empty one that StringBuilder would create below.
</span><span class="cx"> 
</span><span class="lines">@@ -129,6 +182,12 @@
</span><span class="cx">     RetainPtr&lt;NSArray&gt; filteredCookies = filterCookies(unfilteredCookies);
</span><span class="cx">     ASSERT([filteredCookies.get() count] &lt;= 1);
</span><span class="cx"> 
</span><ins>+#if HAVE(CFNETWORK_STORAGE_PARTITIONING)
+    String partition = cookieStoragePartition(firstParty, url);
+    if (!partition.isEmpty())
+        filteredCookies = applyPartitionToCookies(partition, filteredCookies.get());
+#endif
+
</ins><span class="cx">     wkSetHTTPCookiesForURL(session.cookieStorage().get(), filteredCookies.get(), cookieURL, firstParty);
</span><span class="cx"> 
</span><span class="cx">     END_BLOCK_OBJC_EXCEPTIONS;
</span><span class="lines">@@ -150,7 +209,7 @@
</span><span class="cx">     rawCookies.clear();
</span><span class="cx">     BEGIN_BLOCK_OBJC_EXCEPTIONS;
</span><span class="cx"> 
</span><del>-    NSArray *cookies = wkHTTPCookiesForURL(session.cookieStorage().get(), firstParty, url);
</del><ins>+    NSArray *cookies = cookiesForURL(session, firstParty, url);
</ins><span class="cx">     NSUInteger count = [cookies count];
</span><span class="cx">     rawCookies.reserveCapacity(count);
</span><span class="cx">     for (NSUInteger i = 0; i &lt; count; ++i) {
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformnetworkmacResourceHandleMacmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/network/mac/ResourceHandleMac.mm (197517 => 197518)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/network/mac/ResourceHandleMac.mm        2016-03-03 21:43:47 UTC (rev 197517)
+++ trunk/Source/WebCore/platform/network/mac/ResourceHandleMac.mm        2016-03-03 21:46:07 UTC (rev 197518)
</span><span class="lines">@@ -40,6 +40,7 @@
</span><span class="cx"> #import &quot;Logging.h&quot;
</span><span class="cx"> #import &quot;MIMETypeRegistry.h&quot;
</span><span class="cx"> #import &quot;NSURLConnectionSPI.h&quot;
</span><ins>+#import &quot;NetworkStorageSession.h&quot;
</ins><span class="cx"> #import &quot;NetworkingContext.h&quot;
</span><span class="cx"> #import &quot;Page.h&quot;
</span><span class="cx"> #import &quot;ResourceError.h&quot;
</span><span class="lines">@@ -172,6 +173,15 @@
</span><span class="cx">         nsRequest = mutableRequest;
</span><span class="cx">     }
</span><span class="cx"> 
</span><ins>+#if HAVE(CFNETWORK_STORAGE_PARTITIONING)
+    String storagePartition = cookieStoragePartition(firstRequest());
+    if (!storagePartition.isEmpty()) {
+        NSMutableURLRequest *mutableRequest = [[nsRequest mutableCopy] autorelease];
+        [mutableRequest _setProperty:storagePartition forKey:@&quot;__STORAGE_PARTITION_IDENTIFIER&quot;];
+        nsRequest = mutableRequest;
+    }
+#endif
+
</ins><span class="cx">     if (d-&gt;m_storageSession)
</span><span class="cx">         nsRequest = [wkCopyRequestWithStorageSession(d-&gt;m_storageSession.get(), nsRequest) autorelease];
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformspicfCFNetworkSPIh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/spi/cf/CFNetworkSPI.h (197517 => 197518)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/spi/cf/CFNetworkSPI.h        2016-03-03 21:43:47 UTC (rev 197517)
+++ trunk/Source/WebCore/platform/spi/cf/CFNetworkSPI.h        2016-03-03 21:46:07 UTC (rev 197518)
</span><span class="lines">@@ -41,7 +41,7 @@
</span><span class="cx"> #include &lt;CFNetwork/CFURLResponsePriv.h&gt;
</span><span class="cx"> #include &lt;CFNetwork/CFURLStorageSession.h&gt;
</span><span class="cx"> 
</span><del>-// FIXME: Remove the defined(__OBJC__)-guard onnce we fix &lt;rdar://problem/19033610&gt;.
</del><ins>+// FIXME: Remove the defined(__OBJC__)-guard once we fix &lt;rdar://problem/19033610&gt;.
</ins><span class="cx"> #if defined(__OBJC__) &amp;&amp; PLATFORM(COCOA)
</span><span class="cx"> // FIXME: As a workaround for &lt;rdar://problem/18337182&gt;, we conditionally enclose the header
</span><span class="cx"> // in an extern &quot;C&quot; linkage block to make it suitable for C++ use.
</span><span class="lines">@@ -103,8 +103,22 @@
</span><span class="cx"> @end
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><ins>+#if (PLATFORM(MAC) &amp;&amp; __MAC_OS_X_VERSION_MIN_REQUIRED &gt;= 101200) || (PLATFORM(IOS) &amp;&amp; __IPHONE_OS_VERSION_MIN_REQUIRED &gt;= 100000)
+@interface NSHTTPCookie ()
+@property (nullable, readonly, copy) NSString *_storagePartition;
+@end
+
+@interface NSHTTPCookieStorage ()
+- (void)_getCookiesForURL:(NSURL *)url mainDocumentURL:(NSURL *)mainDocumentURL partition:(NSString *)partition completionHandler:(void (^)(NSArray *))completionHandler;
+@end
+
+@interface NSURLSessionTask ()
+@property (copy) NSString *_storagePartitionIdentifier;
+@end
</ins><span class="cx"> #endif
</span><span class="cx"> 
</span><ins>+#endif // defined(__OBJC__)
+
</ins><span class="cx"> #endif // PLATFORM(WIN) || USE(APPLE_INTERNAL_SDK)
</span><span class="cx"> 
</span><span class="cx"> EXTERN_C void CFURLRequestSetShouldStartSynchronously(CFURLRequestRef, Boolean);
</span></span></pre></div>
<a id="trunkSourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/ChangeLog (197517 => 197518)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/ChangeLog        2016-03-03 21:43:47 UTC (rev 197517)
+++ trunk/Source/WebKit2/ChangeLog        2016-03-03 21:46:07 UTC (rev 197518)
</span><span class="lines">@@ -1,3 +1,15 @@
</span><ins>+2016-03-03  Andy Estes  &lt;aestes@apple.com&gt;
+
+        Adopt CFNetwork storage partitioning SPI
+        https://bugs.webkit.org/show_bug.cgi?id=154957
+        rdar://problem/23614620
+
+        Reviewed by Darin Adler.
+
+        * NetworkProcess/cocoa/NetworkDataTaskCocoa.mm:
+        (WebKit::NetworkDataTask::NetworkDataTask): Computed the storage partition identifier for the new session task.
+        If non-empty, set it using a NSURLSessionTask SPI.
+
</ins><span class="cx"> 2016-03-03  Alex Christensen  &lt;achristensen@webkit.org&gt;
</span><span class="cx"> 
</span><span class="cx">         [WK2] testRunner.setPrivateBrowsingEnabled doesn't work with NetworkProcess
</span></span></pre></div>
<a id="trunkSourceWebKit2NetworkProcesscocoaNetworkDataTaskCocoamm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/NetworkProcess/cocoa/NetworkDataTaskCocoa.mm (197517 => 197518)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/NetworkProcess/cocoa/NetworkDataTaskCocoa.mm        2016-03-03 21:43:47 UTC (rev 197517)
+++ trunk/Source/WebKit2/NetworkProcess/cocoa/NetworkDataTaskCocoa.mm        2016-03-03 21:46:07 UTC (rev 197518)
</span><span class="lines">@@ -34,6 +34,7 @@
</span><span class="cx"> #import &quot;WebCoreArgumentCoders.h&quot;
</span><span class="cx"> #import &lt;WebCore/AuthenticationChallenge.h&gt;
</span><span class="cx"> #import &lt;WebCore/CFNetworkSPI.h&gt;
</span><ins>+#import &lt;WebCore/NetworkStorageSession.h&gt;
</ins><span class="cx"> #import &lt;WebCore/ResourceRequest.h&gt;
</span><span class="cx"> #import &lt;wtf/MainThread.h&gt;
</span><span class="cx"> 
</span><span class="lines">@@ -85,6 +86,12 @@
</span><span class="cx">         ASSERT(!m_session.m_dataTaskMapWithoutCredentials.contains([m_task taskIdentifier]));
</span><span class="cx">         m_session.m_dataTaskMapWithoutCredentials.add([m_task taskIdentifier], this);
</span><span class="cx">     }
</span><ins>+
+#if HAVE(CFNETWORK_STORAGE_PARTITIONING)
+    String storagePartition = WebCore::cookieStoragePartition(request);
+    if (!storagePartition.isEmpty())
+        m_task.get()._storagePartitionIdentifier = storagePartition;
+#endif
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> NetworkDataTask::~NetworkDataTask()
</span></span></pre>
</div>
</div>

</body>
</html>