<!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>[237535] branches/safari-606-branch</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/237535">237535</a></dd>
<dt>Author</dt> <dd>bshafiei@apple.com</dd>
<dt>Date</dt> <dd>2018-10-28 17:03:25 -0700 (Sun, 28 Oct 2018)</dd>
</dl>

<h3>Log Message</h3>
<pre>Cherry-pick <a href="http://trac.webkit.org/projects/webkit/changeset/237060">r237060</a>. rdar://problem/45435468

    IOS 12 - Service worker cache not shared when added to homescreen
    https://bugs.webkit.org/show_bug.cgi?id=190269
    <rdar://problem/45009961>

    Reviewed by Alex Christensen.

    Source/WebCore:

    Expose Cache Storage API when Service Worker API is exposed.
    This is used for API tests.

    * dom/ScriptExecutionContext.h: Make hasServiceWorkerScheme
    available outside SERVICE_WORKER compilation flag since used by DOMWindowCaches.
    * dom/ScriptExecutionContext.cpp: Ditto.
    * Modules/cache/DOMWindowCaches.idl:

    Source/WebKit:

    NetworkProcessProxy does not always have all its stores in its hash map.
    Make sure to check for the default web process pool store when grabbing cache storage parameters from a given session ID.

    Add a way to remove the default website data for testing.
    This is used in the new API test.

    * UIProcess/API/APIWebsiteDataStore.cpp:
    (API::WebsiteDataStore::deleteDefaultDataStoreForTesting):
    * UIProcess/API/APIWebsiteDataStore.h:
    * UIProcess/API/Cocoa/WKWebsiteDataStore.mm:
    (+[WKWebsiteDataStore _deleteDefaultDataStoreForTesting]):
    * UIProcess/API/Cocoa/WKWebsiteDataStorePrivate.h:
    * UIProcess/Network/NetworkProcessProxy.cpp:
    (WebKit::NetworkProcessProxy::retrieveCacheStorageParameters):

    Tools:

    * TestWebKitAPI/Tests/WebKitCocoa/ServiceWorkerBasic.mm:
    Add test to ensure that CacheStorage use the default website data store parameters.

    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@237060 268f45cc-cd09-0410-ab3c-d52691b4dbfc</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#branchessafari606branchSourceWebCoreChangeLog">branches/safari-606-branch/Source/WebCore/ChangeLog</a></li>
<li><a href="#branchessafari606branchSourceWebCoreModulescacheDOMWindowCachesidl">branches/safari-606-branch/Source/WebCore/Modules/cache/DOMWindowCaches.idl</a></li>
<li><a href="#branchessafari606branchSourceWebCoredomScriptExecutionContextcpp">branches/safari-606-branch/Source/WebCore/dom/ScriptExecutionContext.cpp</a></li>
<li><a href="#branchessafari606branchSourceWebCoredomScriptExecutionContexth">branches/safari-606-branch/Source/WebCore/dom/ScriptExecutionContext.h</a></li>
<li><a href="#branchessafari606branchSourceWebKitChangeLog">branches/safari-606-branch/Source/WebKit/ChangeLog</a></li>
<li><a href="#branchessafari606branchSourceWebKitUIProcessAPIAPIWebsiteDataStorecpp">branches/safari-606-branch/Source/WebKit/UIProcess/API/APIWebsiteDataStore.cpp</a></li>
<li><a href="#branchessafari606branchSourceWebKitUIProcessAPIAPIWebsiteDataStoreh">branches/safari-606-branch/Source/WebKit/UIProcess/API/APIWebsiteDataStore.h</a></li>
<li><a href="#branchessafari606branchSourceWebKitUIProcessAPICocoaWKWebsiteDataStoremm">branches/safari-606-branch/Source/WebKit/UIProcess/API/Cocoa/WKWebsiteDataStore.mm</a></li>
<li><a href="#branchessafari606branchSourceWebKitUIProcessAPICocoaWKWebsiteDataStorePrivateh">branches/safari-606-branch/Source/WebKit/UIProcess/API/Cocoa/WKWebsiteDataStorePrivate.h</a></li>
<li><a href="#branchessafari606branchSourceWebKitUIProcessNetworkNetworkProcessProxycpp">branches/safari-606-branch/Source/WebKit/UIProcess/Network/NetworkProcessProxy.cpp</a></li>
<li><a href="#branchessafari606branchSourceWebKitUIProcessNetworkNetworkProcessProxyh">branches/safari-606-branch/Source/WebKit/UIProcess/Network/NetworkProcessProxy.h</a></li>
<li><a href="#branchessafari606branchToolsChangeLog">branches/safari-606-branch/Tools/ChangeLog</a></li>
<li><a href="#branchessafari606branchToolsTestWebKitAPITestsWebKitCocoaServiceWorkerBasicmm">branches/safari-606-branch/Tools/TestWebKitAPI/Tests/WebKitCocoa/ServiceWorkerBasic.mm</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="branchessafari606branchSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: branches/safari-606-branch/Source/WebCore/ChangeLog (237534 => 237535)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-606-branch/Source/WebCore/ChangeLog      2018-10-28 23:01:57 UTC (rev 237534)
+++ branches/safari-606-branch/Source/WebCore/ChangeLog 2018-10-29 00:03:25 UTC (rev 237535)
</span><span class="lines">@@ -1,5 +1,65 @@
</span><span class="cx"> 2018-10-28  Babak Shafiei  <bshafiei@apple.com>
</span><span class="cx"> 
</span><ins>+        Cherry-pick r237060. rdar://problem/45435468
+
+    IOS 12 - Service worker cache not shared when added to homescreen
+    https://bugs.webkit.org/show_bug.cgi?id=190269
+    <rdar://problem/45009961>
+    
+    Reviewed by Alex Christensen.
+    
+    Source/WebCore:
+    
+    Expose Cache Storage API when Service Worker API is exposed.
+    This is used for API tests.
+    
+    * dom/ScriptExecutionContext.h: Make hasServiceWorkerScheme
+    available outside SERVICE_WORKER compilation flag since used by DOMWindowCaches.
+    * dom/ScriptExecutionContext.cpp: Ditto.
+    * Modules/cache/DOMWindowCaches.idl:
+    
+    Source/WebKit:
+    
+    NetworkProcessProxy does not always have all its stores in its hash map.
+    Make sure to check for the default web process pool store when grabbing cache storage parameters from a given session ID.
+    
+    Add a way to remove the default website data for testing.
+    This is used in the new API test.
+    
+    * UIProcess/API/APIWebsiteDataStore.cpp:
+    (API::WebsiteDataStore::deleteDefaultDataStoreForTesting):
+    * UIProcess/API/APIWebsiteDataStore.h:
+    * UIProcess/API/Cocoa/WKWebsiteDataStore.mm:
+    (+[WKWebsiteDataStore _deleteDefaultDataStoreForTesting]):
+    * UIProcess/API/Cocoa/WKWebsiteDataStorePrivate.h:
+    * UIProcess/Network/NetworkProcessProxy.cpp:
+    (WebKit::NetworkProcessProxy::retrieveCacheStorageParameters):
+    
+    Tools:
+    
+    * TestWebKitAPI/Tests/WebKitCocoa/ServiceWorkerBasic.mm:
+    Add test to ensure that CacheStorage use the default website data store parameters.
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@237060 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2018-10-11  Youenn Fablet  <youenn@apple.com>
+
+            IOS 12 - Service worker cache not shared when added to homescreen
+            https://bugs.webkit.org/show_bug.cgi?id=190269
+            <rdar://problem/45009961>
+
+            Reviewed by Alex Christensen.
+
+            Expose Cache Storage API when Service Worker API is exposed.
+            This is used for API tests.
+
+            * dom/ScriptExecutionContext.h: Make hasServiceWorkerScheme
+            available outside SERVICE_WORKER compilation flag since used by DOMWindowCaches.
+            * dom/ScriptExecutionContext.cpp: Ditto.
+            * Modules/cache/DOMWindowCaches.idl:
+
+2018-10-28  Babak Shafiei  <bshafiei@apple.com>
+
</ins><span class="cx">         Cherry-pick r237395. rdar://problem/45574503
</span><span class="cx"> 
</span><span class="cx">     Only report resource timing to parent frame for the first iframe load
</span></span></pre></div>
<a id="branchessafari606branchSourceWebCoreModulescacheDOMWindowCachesidl"></a>
<div class="modfile"><h4>Modified: branches/safari-606-branch/Source/WebCore/Modules/cache/DOMWindowCaches.idl (237534 => 237535)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-606-branch/Source/WebCore/Modules/cache/DOMWindowCaches.idl      2018-10-28 23:01:57 UTC (rev 237534)
+++ branches/safari-606-branch/Source/WebCore/Modules/cache/DOMWindowCaches.idl 2018-10-29 00:03:25 UTC (rev 237535)
</span><span class="lines">@@ -26,5 +26,5 @@
</span><span class="cx"> [
</span><span class="cx">     EnabledAtRuntime=CacheAPI,
</span><span class="cx"> ] partial interface DOMWindow {
</span><del>-    [CallWith=ScriptExecutionContext, MayThrowException, SecureContext, SameObject] readonly attribute DOMCacheStorage caches;
</del><ins>+    [CallWith=ScriptExecutionContext, MayThrowException, SecureContext, ContextHasServiceWorkerScheme, SameObject] readonly attribute DOMCacheStorage caches;
</ins><span class="cx"> };
</span></span></pre></div>
<a id="branchessafari606branchSourceWebCoredomScriptExecutionContextcpp"></a>
<div class="modfile"><h4>Modified: branches/safari-606-branch/Source/WebCore/dom/ScriptExecutionContext.cpp (237534 => 237535)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-606-branch/Source/WebCore/dom/ScriptExecutionContext.cpp 2018-10-28 23:01:57 UTC (rev 237534)
+++ branches/safari-606-branch/Source/WebCore/dom/ScriptExecutionContext.cpp    2018-10-29 00:03:25 UTC (rev 237535)
</span><span class="lines">@@ -561,8 +561,6 @@
</span><span class="cx">     return m_domainForCachePartition.isNull() ? topOrigin().domainForCachePartition() : m_domainForCachePartition;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-#if ENABLE(SERVICE_WORKER)
-
</del><span class="cx"> bool ScriptExecutionContext::hasServiceWorkerScheme()
</span><span class="cx"> {
</span><span class="cx">     ASSERT(securityOrigin());
</span><span class="lines">@@ -569,6 +567,8 @@
</span><span class="cx">     return SchemeRegistry::isServiceWorkerContainerCustomScheme(securityOrigin()->protocol());
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+#if ENABLE(SERVICE_WORKER)
+
</ins><span class="cx"> ServiceWorker* ScriptExecutionContext::activeServiceWorker() const
</span><span class="cx"> {
</span><span class="cx">     return m_activeServiceWorker.get();
</span></span></pre></div>
<a id="branchessafari606branchSourceWebCoredomScriptExecutionContexth"></a>
<div class="modfile"><h4>Modified: branches/safari-606-branch/Source/WebCore/dom/ScriptExecutionContext.h (237534 => 237535)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-606-branch/Source/WebCore/dom/ScriptExecutionContext.h   2018-10-28 23:01:57 UTC (rev 237534)
+++ branches/safari-606-branch/Source/WebCore/dom/ScriptExecutionContext.h      2018-10-29 00:03:25 UTC (rev 237535)
</span><span class="lines">@@ -244,8 +244,8 @@
</span><span class="cx">     WEBCORE_EXPORT String domainForCachePartition() const;
</span><span class="cx">     void setDomainForCachePartition(String&& domain) { m_domainForCachePartition = WTFMove(domain); }
</span><span class="cx"> 
</span><ins>+    bool hasServiceWorkerScheme();
</ins><span class="cx"> #if ENABLE(SERVICE_WORKER)
</span><del>-    bool hasServiceWorkerScheme();
</del><span class="cx">     ServiceWorker* activeServiceWorker() const;
</span><span class="cx">     void setActiveServiceWorker(RefPtr<ServiceWorker>&&);
</span><span class="cx"> 
</span></span></pre></div>
<a id="branchessafari606branchSourceWebKitChangeLog"></a>
<div class="modfile"><h4>Modified: branches/safari-606-branch/Source/WebKit/ChangeLog (237534 => 237535)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-606-branch/Source/WebKit/ChangeLog       2018-10-28 23:01:57 UTC (rev 237534)
+++ branches/safari-606-branch/Source/WebKit/ChangeLog  2018-10-29 00:03:25 UTC (rev 237535)
</span><span class="lines">@@ -1,5 +1,72 @@
</span><span class="cx"> 2018-10-28  Babak Shafiei  <bshafiei@apple.com>
</span><span class="cx"> 
</span><ins>+        Cherry-pick r237060. rdar://problem/45435468
+
+    IOS 12 - Service worker cache not shared when added to homescreen
+    https://bugs.webkit.org/show_bug.cgi?id=190269
+    <rdar://problem/45009961>
+    
+    Reviewed by Alex Christensen.
+    
+    Source/WebCore:
+    
+    Expose Cache Storage API when Service Worker API is exposed.
+    This is used for API tests.
+    
+    * dom/ScriptExecutionContext.h: Make hasServiceWorkerScheme
+    available outside SERVICE_WORKER compilation flag since used by DOMWindowCaches.
+    * dom/ScriptExecutionContext.cpp: Ditto.
+    * Modules/cache/DOMWindowCaches.idl:
+    
+    Source/WebKit:
+    
+    NetworkProcessProxy does not always have all its stores in its hash map.
+    Make sure to check for the default web process pool store when grabbing cache storage parameters from a given session ID.
+    
+    Add a way to remove the default website data for testing.
+    This is used in the new API test.
+    
+    * UIProcess/API/APIWebsiteDataStore.cpp:
+    (API::WebsiteDataStore::deleteDefaultDataStoreForTesting):
+    * UIProcess/API/APIWebsiteDataStore.h:
+    * UIProcess/API/Cocoa/WKWebsiteDataStore.mm:
+    (+[WKWebsiteDataStore _deleteDefaultDataStoreForTesting]):
+    * UIProcess/API/Cocoa/WKWebsiteDataStorePrivate.h:
+    * UIProcess/Network/NetworkProcessProxy.cpp:
+    (WebKit::NetworkProcessProxy::retrieveCacheStorageParameters):
+    
+    Tools:
+    
+    * TestWebKitAPI/Tests/WebKitCocoa/ServiceWorkerBasic.mm:
+    Add test to ensure that CacheStorage use the default website data store parameters.
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@237060 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2018-10-11  Youenn Fablet  <youenn@apple.com>
+
+            IOS 12 - Service worker cache not shared when added to homescreen
+            https://bugs.webkit.org/show_bug.cgi?id=190269
+            <rdar://problem/45009961>
+
+            Reviewed by Alex Christensen.
+
+            NetworkProcessProxy does not always have all its stores in its hash map.
+            Make sure to check for the default web process pool store when grabbing cache storage parameters from a given session ID.
+
+            Add a way to remove the default website data for testing.
+            This is used in the new API test.
+
+            * UIProcess/API/APIWebsiteDataStore.cpp:
+            (API::WebsiteDataStore::deleteDefaultDataStoreForTesting):
+            * UIProcess/API/APIWebsiteDataStore.h:
+            * UIProcess/API/Cocoa/WKWebsiteDataStore.mm:
+            (+[WKWebsiteDataStore _deleteDefaultDataStoreForTesting]):
+            * UIProcess/API/Cocoa/WKWebsiteDataStorePrivate.h:
+            * UIProcess/Network/NetworkProcessProxy.cpp:
+            (WebKit::NetworkProcessProxy::retrieveCacheStorageParameters):
+
+2018-10-28  Babak Shafiei  <bshafiei@apple.com>
+
</ins><span class="cx">         Apply patch. rdar://problem/45523764
</span><span class="cx"> 
</span><span class="cx">     2018-10-28  John Wilander  <wilander@apple.com>
</span></span></pre></div>
<a id="branchessafari606branchSourceWebKitUIProcessAPIAPIWebsiteDataStorecpp"></a>
<div class="modfile"><h4>Modified: branches/safari-606-branch/Source/WebKit/UIProcess/API/APIWebsiteDataStore.cpp (237534 => 237535)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-606-branch/Source/WebKit/UIProcess/API/APIWebsiteDataStore.cpp   2018-10-28 23:01:57 UTC (rev 237534)
+++ branches/safari-606-branch/Source/WebKit/UIProcess/API/APIWebsiteDataStore.cpp      2018-10-29 00:03:25 UTC (rev 237535)
</span><span class="lines">@@ -31,21 +31,32 @@
</span><span class="cx"> 
</span><span class="cx"> namespace API {
</span><span class="cx"> 
</span><del>-static WebsiteDataStore* globalDefaultDataStore;
</del><ins>+static RefPtr<WebsiteDataStore>& globalDefaultDataStore()
+{
+    static NeverDestroyed<RefPtr<WebsiteDataStore>> globalDefaultDataStore;
+    return globalDefaultDataStore.get();
+}
</ins><span class="cx"> 
</span><ins>+
</ins><span class="cx"> Ref<WebsiteDataStore> WebsiteDataStore::defaultDataStore()
</span><span class="cx"> {
</span><span class="cx">     WebKit::InitializeWebKit2();
</span><span class="cx"> 
</span><del>-    if (!globalDefaultDataStore)
-        globalDefaultDataStore = adoptRef(new WebsiteDataStore(defaultDataStoreConfiguration(), PAL::SessionID::defaultSessionID())).leakRef();
</del><ins>+    auto& store = globalDefaultDataStore();
+    if (!store)
+        store = adoptRef(new WebsiteDataStore(defaultDataStoreConfiguration(), PAL::SessionID::defaultSessionID()));
</ins><span class="cx"> 
</span><del>-    return *globalDefaultDataStore;
</del><ins>+    return *store;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void WebsiteDataStore::deleteDefaultDataStoreForTesting()
+{
+    globalDefaultDataStore() = nullptr;
+}
+
</ins><span class="cx"> bool WebsiteDataStore::defaultDataStoreExists()
</span><span class="cx"> {
</span><del>-    return globalDefaultDataStore;
</del><ins>+    return !!globalDefaultDataStore();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> Ref<WebsiteDataStore> WebsiteDataStore::createNonPersistentDataStore()
</span></span></pre></div>
<a id="branchessafari606branchSourceWebKitUIProcessAPIAPIWebsiteDataStoreh"></a>
<div class="modfile"><h4>Modified: branches/safari-606-branch/Source/WebKit/UIProcess/API/APIWebsiteDataStore.h (237534 => 237535)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-606-branch/Source/WebKit/UIProcess/API/APIWebsiteDataStore.h     2018-10-28 23:01:57 UTC (rev 237534)
+++ branches/safari-606-branch/Source/WebKit/UIProcess/API/APIWebsiteDataStore.h        2018-10-29 00:03:25 UTC (rev 237535)
</span><span class="lines">@@ -36,6 +36,7 @@
</span><span class="cx"> public:
</span><span class="cx">     static Ref<WebsiteDataStore> defaultDataStore();
</span><span class="cx">     static bool defaultDataStoreExists();
</span><ins>+    static void deleteDefaultDataStoreForTesting();
</ins><span class="cx"> 
</span><span class="cx">     static Ref<WebsiteDataStore> createNonPersistentDataStore();
</span><span class="cx">     static Ref<WebsiteDataStore> createLegacy(WebKit::WebsiteDataStore::Configuration);
</span></span></pre></div>
<a id="branchessafari606branchSourceWebKitUIProcessAPICocoaWKWebsiteDataStoremm"></a>
<div class="modfile"><h4>Modified: branches/safari-606-branch/Source/WebKit/UIProcess/API/Cocoa/WKWebsiteDataStore.mm (237534 => 237535)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-606-branch/Source/WebKit/UIProcess/API/Cocoa/WKWebsiteDataStore.mm       2018-10-28 23:01:57 UTC (rev 237534)
+++ branches/safari-606-branch/Source/WebKit/UIProcess/API/Cocoa/WKWebsiteDataStore.mm  2018-10-29 00:03:25 UTC (rev 237535)
</span><span class="lines">@@ -186,6 +186,11 @@
</span><span class="cx">     return API::WebsiteDataStore::defaultDataStoreExists();
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>++ (void)_deleteDefaultDataStoreForTesting
+{
+    return API::WebsiteDataStore::deleteDefaultDataStoreForTesting();
+}
+
</ins><span class="cx"> - (instancetype)_initWithConfiguration:(_WKWebsiteDataStoreConfiguration *)configuration
</span><span class="cx"> {
</span><span class="cx">     if (!(self = [super init]))
</span></span></pre></div>
<a id="branchessafari606branchSourceWebKitUIProcessAPICocoaWKWebsiteDataStorePrivateh"></a>
<div class="modfile"><h4>Modified: branches/safari-606-branch/Source/WebKit/UIProcess/API/Cocoa/WKWebsiteDataStorePrivate.h (237534 => 237535)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-606-branch/Source/WebKit/UIProcess/API/Cocoa/WKWebsiteDataStorePrivate.h 2018-10-28 23:01:57 UTC (rev 237534)
+++ branches/safari-606-branch/Source/WebKit/UIProcess/API/Cocoa/WKWebsiteDataStorePrivate.h    2018-10-29 00:03:25 UTC (rev 237535)
</span><span class="lines">@@ -40,6 +40,7 @@
</span><span class="cx"> 
</span><span class="cx"> + (NSSet<NSString *> *)_allWebsiteDataTypesIncludingPrivate;
</span><span class="cx"> + (BOOL)_defaultDataStoreExists;
</span><ins>++ (void)_deleteDefaultDataStoreForTesting;
</ins><span class="cx"> 
</span><span class="cx"> - (instancetype)_initWithConfiguration:(_WKWebsiteDataStoreConfiguration *)configuration WK_API_AVAILABLE(macosx(10.13), ios(11.0));
</span><span class="cx"> 
</span></span></pre></div>
<a id="branchessafari606branchSourceWebKitUIProcessNetworkNetworkProcessProxycpp"></a>
<div class="modfile"><h4>Modified: branches/safari-606-branch/Source/WebKit/UIProcess/Network/NetworkProcessProxy.cpp (237534 => 237535)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-606-branch/Source/WebKit/UIProcess/Network/NetworkProcessProxy.cpp       2018-10-28 23:01:57 UTC (rev 237534)
+++ branches/safari-606-branch/Source/WebKit/UIProcess/Network/NetworkProcessProxy.cpp  2018-10-29 00:03:25 UTC (rev 237535)
</span><span class="lines">@@ -606,22 +606,40 @@
</span><span class="cx">         m_websiteDataStores.remove(sessionID);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+WebsiteDataStore* NetworkProcessProxy::websiteDataStoreFromSessionID(PAL::SessionID sessionID)
+{
+    auto iterator = m_websiteDataStores.find(sessionID);
+    if (iterator != m_websiteDataStores.end())
+        return iterator->value.get();
+
+    if (auto* websiteDataStore = m_processPool.websiteDataStore()) {
+        if (sessionID == websiteDataStore->websiteDataStore().sessionID())
+            return &websiteDataStore->websiteDataStore();
+    }
+
+    if (sessionID != PAL::SessionID::defaultSessionID())
+        return nullptr;
+
+    return &API::WebsiteDataStore::defaultDataStore()->websiteDataStore();
+}
+
</ins><span class="cx"> void NetworkProcessProxy::retrieveCacheStorageParameters(PAL::SessionID sessionID)
</span><span class="cx"> {
</span><del>-    auto iterator = m_websiteDataStores.find(sessionID);
-    if (iterator == m_websiteDataStores.end()) {
</del><ins>+    auto* store = websiteDataStoreFromSessionID(sessionID);
+
+    if (!store) {
+        RELEASE_LOG_ERROR(CacheStorage, "%p - NetworkProcessProxy is unable to retrieve CacheStorage parameters from the given session ID %" PRIu64, this, sessionID.sessionID());
</ins><span class="cx">         auto quota = m_processPool.websiteDataStore() ? m_processPool.websiteDataStore()->websiteDataStore().cacheStoragePerOriginQuota() : WebsiteDataStore::defaultCacheStoragePerOriginQuota;
</span><span class="cx">         send(Messages::NetworkProcess::SetCacheStorageParameters { sessionID, quota, { }, { } }, 0);
</span><span class="cx">         return;
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    auto& store = *iterator->value;
-    auto& cacheStorageDirectory = store.cacheStorageDirectory();
</del><ins>+    auto& cacheStorageDirectory = store->cacheStorageDirectory();
</ins><span class="cx">     SandboxExtension::Handle cacheStorageDirectoryExtensionHandle;
</span><span class="cx">     if (!cacheStorageDirectory.isEmpty())
</span><span class="cx">         SandboxExtension::createHandleForReadWriteDirectory(cacheStorageDirectory, cacheStorageDirectoryExtensionHandle);
</span><span class="cx"> 
</span><del>-    send(Messages::NetworkProcess::SetCacheStorageParameters { sessionID, store.cacheStoragePerOriginQuota(), cacheStorageDirectory, cacheStorageDirectoryExtensionHandle }, 0);
</del><ins>+    send(Messages::NetworkProcess::SetCacheStorageParameters { sessionID, store->cacheStoragePerOriginQuota(), cacheStorageDirectory, cacheStorageDirectoryExtensionHandle }, 0);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(CONTENT_EXTENSIONS)
</span></span></pre></div>
<a id="branchessafari606branchSourceWebKitUIProcessNetworkNetworkProcessProxyh"></a>
<div class="modfile"><h4>Modified: branches/safari-606-branch/Source/WebKit/UIProcess/Network/NetworkProcessProxy.h (237534 => 237535)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-606-branch/Source/WebKit/UIProcess/Network/NetworkProcessProxy.h 2018-10-28 23:01:57 UTC (rev 237534)
+++ branches/safari-606-branch/Source/WebKit/UIProcess/Network/NetworkProcessProxy.h    2018-10-29 00:03:25 UTC (rev 237535)
</span><span class="lines">@@ -157,6 +157,8 @@
</span><span class="cx">     void contentExtensionRules(UserContentControllerIdentifier);
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><ins>+    WebsiteDataStore* websiteDataStoreFromSessionID(PAL::SessionID);
+
</ins><span class="cx">     // ProcessLauncher::Client
</span><span class="cx">     void didFinishLaunching(ProcessLauncher*, IPC::Connection::Identifier) override;
</span><span class="cx"> 
</span></span></pre></div>
<a id="branchessafari606branchToolsChangeLog"></a>
<div class="modfile"><h4>Modified: branches/safari-606-branch/Tools/ChangeLog (237534 => 237535)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-606-branch/Tools/ChangeLog       2018-10-28 23:01:57 UTC (rev 237534)
+++ branches/safari-606-branch/Tools/ChangeLog  2018-10-29 00:03:25 UTC (rev 237535)
</span><span class="lines">@@ -1,5 +1,60 @@
</span><span class="cx"> 2018-10-28  Babak Shafiei  <bshafiei@apple.com>
</span><span class="cx"> 
</span><ins>+        Cherry-pick r237060. rdar://problem/45435468
+
+    IOS 12 - Service worker cache not shared when added to homescreen
+    https://bugs.webkit.org/show_bug.cgi?id=190269
+    <rdar://problem/45009961>
+    
+    Reviewed by Alex Christensen.
+    
+    Source/WebCore:
+    
+    Expose Cache Storage API when Service Worker API is exposed.
+    This is used for API tests.
+    
+    * dom/ScriptExecutionContext.h: Make hasServiceWorkerScheme
+    available outside SERVICE_WORKER compilation flag since used by DOMWindowCaches.
+    * dom/ScriptExecutionContext.cpp: Ditto.
+    * Modules/cache/DOMWindowCaches.idl:
+    
+    Source/WebKit:
+    
+    NetworkProcessProxy does not always have all its stores in its hash map.
+    Make sure to check for the default web process pool store when grabbing cache storage parameters from a given session ID.
+    
+    Add a way to remove the default website data for testing.
+    This is used in the new API test.
+    
+    * UIProcess/API/APIWebsiteDataStore.cpp:
+    (API::WebsiteDataStore::deleteDefaultDataStoreForTesting):
+    * UIProcess/API/APIWebsiteDataStore.h:
+    * UIProcess/API/Cocoa/WKWebsiteDataStore.mm:
+    (+[WKWebsiteDataStore _deleteDefaultDataStoreForTesting]):
+    * UIProcess/API/Cocoa/WKWebsiteDataStorePrivate.h:
+    * UIProcess/Network/NetworkProcessProxy.cpp:
+    (WebKit::NetworkProcessProxy::retrieveCacheStorageParameters):
+    
+    Tools:
+    
+    * TestWebKitAPI/Tests/WebKitCocoa/ServiceWorkerBasic.mm:
+    Add test to ensure that CacheStorage use the default website data store parameters.
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@237060 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2018-10-11  Youenn Fablet  <youenn@apple.com>
+
+            IOS 12 - Service worker cache not shared when added to homescreen
+            https://bugs.webkit.org/show_bug.cgi?id=190269
+            <rdar://problem/45009961>
+
+            Reviewed by Alex Christensen.
+
+            * TestWebKitAPI/Tests/WebKitCocoa/ServiceWorkerBasic.mm:
+            Add test to ensure that CacheStorage use the default website data store parameters.
+
+2018-10-28  Babak Shafiei  <bshafiei@apple.com>
+
</ins><span class="cx">         Cherry-pick r237135. rdar://problem/45562440
</span><span class="cx"> 
</span><span class="cx">     [iOS] Can't select text after dismissing the keyboard when changing focus
</span></span></pre></div>
<a id="branchessafari606branchToolsTestWebKitAPITestsWebKitCocoaServiceWorkerBasicmm"></a>
<div class="modfile"><h4>Modified: branches/safari-606-branch/Tools/TestWebKitAPI/Tests/WebKitCocoa/ServiceWorkerBasic.mm (237534 => 237535)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-606-branch/Tools/TestWebKitAPI/Tests/WebKitCocoa/ServiceWorkerBasic.mm   2018-10-28 23:01:57 UTC (rev 237534)
+++ branches/safari-606-branch/Tools/TestWebKitAPI/Tests/WebKitCocoa/ServiceWorkerBasic.mm      2018-10-29 00:03:25 UTC (rev 237535)
</span><span class="lines">@@ -194,7 +194,33 @@
</span><span class="cx"> }
</span><span class="cx"> @end
</span><span class="cx"> 
</span><ins>+static const char* mainCacheStorageBytes = R"SWRESOURCE(
+<script>
</ins><span class="cx"> 
</span><ins>+function log(msg)
+{
+    window.webkit.messageHandlers.sw.postMessage(msg);
+}
+
+async function doTest()
+{
+    const keys = await window.caches.keys();
+    if (!keys.length) {
+        const cache = await window.caches.open("my cache");
+        log("No cache storage data");
+        return;
+    }
+    if (keys.length !== 1) {
+        log("Unexpected cache number");
+        return;
+    }
+    log("Some cache storage data: " + keys[0]);
+}
+doTest();
+
+</script>
+)SWRESOURCE";
+
</ins><span class="cx"> static const char* mainBytes = R"SWRESOURCE(
</span><span class="cx"> <script>
</span><span class="cx"> 
</span><span class="lines">@@ -541,6 +567,63 @@
</span><span class="cx">     done = false;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+TEST(ServiceWorkers, CacheStorageRestoreFromDisk)
+{
+    ASSERT(mainCacheStorageBytes);
+    [WKWebsiteDataStore _allowWebsiteDataRecordsForAllOrigins];
+
+    // Start with a clean slate data store
+    [[WKWebsiteDataStore defaultDataStore] removeDataOfTypes:[WKWebsiteDataStore allWebsiteDataTypes] modifiedSince:[NSDate distantPast] completionHandler:^() {
+        done = true;
+    }];
+
+    TestWebKitAPI::Util::run(&done);
+    done = false;
+
+    [WKWebsiteDataStore _deleteDefaultDataStoreForTesting];
+
+    auto handler = adoptNS([[SWSchemes alloc] init]);
+    handler->resources.set("sw://host/main.html", ResourceInfo { @"text/html", mainCacheStorageBytes });
+
+    auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
+    auto messageHandler = adoptNS([[SWMessageHandlerForRestoreFromDiskTest alloc] initWithExpectedMessage:@"No cache storage data"]);
+
+    [[configuration userContentController] addScriptMessageHandler:messageHandler.get() name:@"sw"];
+    [configuration setURLSchemeHandler:handler.get() forURLScheme:@"SW"];
+
+    auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
+    [webView.get().configuration.processPool _registerURLSchemeServiceWorkersCanHandle:@"sw"];
+
+    // Trigger creation of network process.
+    [webView.get().configuration.processPool _syncNetworkProcessCookies];
+
+    auto *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"sw://host/main.html"]];
+    [webView loadRequest:request];
+
+    TestWebKitAPI::Util::run(&done);
+    done = false;
+
+    webView = nullptr;
+    configuration = nullptr;
+    messageHandler = nullptr;
+
+    configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
+    messageHandler = adoptNS([[SWMessageHandlerForRestoreFromDiskTest alloc] initWithExpectedMessage:@"Some cache storage data: my cache"]);
+
+    [[configuration userContentController] addScriptMessageHandler:messageHandler.get() name:@"sw"];
+    [configuration setURLSchemeHandler:handler.get() forURLScheme:@"SW"];
+
+    webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
+    [webView.get().configuration.processPool _registerURLSchemeServiceWorkersCanHandle:@"sw"];
+
+    request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"sw://host/main.html"]];
+    [webView loadRequest:request];
+
+    TestWebKitAPI::Util::run(&done);
+    done = false;
+}
+
+
</ins><span class="cx"> TEST(ServiceWorkers, FetchAfterRestoreFromDisk)
</span><span class="cx"> {
</span><span class="cx">     ASSERT(mainForFetchTestBytes);
</span></span></pre>
</div>
</div>

</body>
</html>