Title: [223935] trunk
Revision
223935
Author
[email protected]
Date
2017-10-24 15:28:44 -0700 (Tue, 24 Oct 2017)

Log Message

Enable service worker to use cache storage api
https://bugs.webkit.org/show_bug.cgi?id=178684

Patch by Youenn Fablet <[email protected]> on 2017-10-24
Reviewed by Brady Eidson.

Source/WebCore:

Test: http/tests/workers/service/service-worker-cache-api.https.html

Updated WorkerLoaderProxy so that it can create a CacheStorageConnection.
Update WorkerCacheStorageConnection to take benefit of that.
This allows creating a CacheStorageConnection based on the page for regular workers and differently for Service Worker context.

Added ServiceWorkerThreadProxy as a proxy to ServiceWorkerThread.
It is in particular responsible to do proxy for loading tasks.
It implements cache API support for service worker by creating a dedicated CacheStorageConnection.

* Modules/cache/WorkerCacheStorageConnection.cpp:
(WebCore::WorkerCacheStorageConnection::create):
(WebCore::WorkerCacheStorageConnection::~WorkerCacheStorageConnection):
(WebCore::WorkerCacheStorageConnection::doOpen):
(WebCore::WorkerCacheStorageConnection::doRemove):
(WebCore::WorkerCacheStorageConnection::doRetrieveCaches):
(WebCore::WorkerCacheStorageConnection::reference):
(WebCore::WorkerCacheStorageConnection::dereference):
(WebCore::WorkerCacheStorageConnection::doRetrieveRecords):
(WebCore::WorkerCacheStorageConnection::doBatchDeleteOperation):
(WebCore::WorkerCacheStorageConnection::doBatchPutOperation):
* WebCore.xcodeproj/project.pbxproj:
* workers/WorkerLoaderProxy.h:
* workers/WorkerMessagingProxy.cpp:
(WebCore::WorkerMessagingProxy::createCacheStorageConnection):
* workers/WorkerMessagingProxy.h:
* workers/service/context/ServiceWorkerThread.cpp:
(WebCore::ServiceWorkerThread::ServiceWorkerThread):
* workers/service/context/ServiceWorkerThread.h:
* workers/service/context/ServiceWorkerThreadProxy.cpp: Added.
(WebCore::ServiceWorkerThreadProxy::create):
(WebCore::ServiceWorkerThreadProxy::ServiceWorkerThreadProxy):
(WebCore::ServiceWorkerThreadProxy::postTaskForModeToWorkerGlobalScope):
(WebCore::ServiceWorkerThreadProxy::postTaskToLoader):
(WebCore::ServiceWorkerThreadProxy::createCacheStorageConnection):
* workers/service/context/ServiceWorkerThreadProxy.h: Added.

Source/WebKit:

Passing the WebPreferences store of the default page group of the WebProcessPool to its ServiceWorker process.
ServiceWorkerContextManager then uses it to initialize the preferences accordingly.
Patch is covered by new test which is using cache api previously disabled and now enabled through the store.

Made use of the new ServiceWorkerThreadProxy in ServiceWorkerContextManager to enable a cache storage connection.
Fixed the default size of quota in WebsiteDataStore.

* UIProcess/WebProcessPool.cpp:
(WebKit::WebProcessPool::getWorkerContextProcessConnection):
* UIProcess/WebsiteData/WebsiteDataStore.h:
* WebProcess/Storage/ServiceWorkerContextManager.cpp:
(WebKit::ServiceWorkerContextManager::ServiceWorkerContextManager):
(WebKit::ServiceWorkerContextManager::updatePreferences):
(WebKit::ServiceWorkerContextManager::startServiceWorker):
(WebKit::ServiceWorkerContextManager::startFetch):
* WebProcess/Storage/ServiceWorkerContextManager.h:
(WebKit::ServiceWorkerContextManager::ServiceWorkerContextManager): Deleted.
* WebProcess/WebProcess.cpp:
(WebKit::WebProcess::getWorkerContextConnection):
* WebProcess/WebProcess.h:
* WebProcess/WebProcess.messages.in:

LayoutTests:

* http/tests/workers/service/resources/service-worker-cache-api-worker.js: Added.
* http/tests/workers/service/resources/service-worker-cache-api.js: Added.
* http/tests/workers/service/service-worker-cache-api.https-expected.txt: Added.
* http/tests/workers/service/service-worker-cache-api.https.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (223934 => 223935)


--- trunk/LayoutTests/ChangeLog	2017-10-24 22:23:12 UTC (rev 223934)
+++ trunk/LayoutTests/ChangeLog	2017-10-24 22:28:44 UTC (rev 223935)
@@ -1,3 +1,15 @@
+2017-10-24  Youenn Fablet  <[email protected]>
+
+        Enable service worker to use cache storage api
+        https://bugs.webkit.org/show_bug.cgi?id=178684
+
+        Reviewed by Brady Eidson.
+
+        * http/tests/workers/service/resources/service-worker-cache-api-worker.js: Added.
+        * http/tests/workers/service/resources/service-worker-cache-api.js: Added.
+        * http/tests/workers/service/service-worker-cache-api.https-expected.txt: Added.
+        * http/tests/workers/service/service-worker-cache-api.https.html: Added.
+
 2017-10-24  Matt Lewis  <[email protected]>
 
         Skipped imported/w3c/web-platform-tests/html/dom/dynamic-markup-insertion/opening-the-input-stream/011.html on High Sierra Release.

Added: trunk/LayoutTests/http/tests/workers/service/resources/service-worker-cache-api-worker.js (0 => 223935)


--- trunk/LayoutTests/http/tests/workers/service/resources/service-worker-cache-api-worker.js	                        (rev 0)
+++ trunk/LayoutTests/http/tests/workers/service/resources/service-worker-cache-api-worker.js	2017-10-24 22:28:44 UTC (rev 223935)
@@ -0,0 +1,38 @@
+var status = "no status";
+var cache;
+var worker = self;
+
+async function prepareCache()
+{
+    status = "opening cache";
+    cache = await caches.open("test");
+    status = "creating response";
+    var response = new Response(new ArrayBuffer(12940), { status: 200, statusText: "OK"});
+    status = "filling cache";
+    await cache.put("/resources/square100.png", response);
+    status = "cache is ready";
+}
+
+function statusResponse()
+{
+    return new Response(null, {status: 200, statusText: status});
+}
+
+self.addEventListener("fetch", (event) => {
+    if (event.request.url.indexOf("status") !== -1) {
+        event.respondWith(promise.then(statusResponse, statusResponse));
+        return;
+    }
+    if (!event.request.url.endsWith(".fromserviceworker")) {
+        state = "unknown url";
+        event.respondWith(new Response(null, {status: 404, statusText: "Not Found"}));
+        return;
+    }
+    event.respondWith(promise.then(() => {
+        status = event.request.url.substring(0, event.request.url.length - 18);
+        return caches.open("test").then((cache) => {
+            return cache.match(event.request.url.substring(0, event.request.url.length - 18));
+        });
+    }));
+});
+var promise = prepareCache();

Added: trunk/LayoutTests/http/tests/workers/service/resources/service-worker-cache-api.js (0 => 223935)


--- trunk/LayoutTests/http/tests/workers/service/resources/service-worker-cache-api.js	                        (rev 0)
+++ trunk/LayoutTests/http/tests/workers/service/resources/service-worker-cache-api.js	2017-10-24 22:28:44 UTC (rev 223935)
@@ -0,0 +1,31 @@
+function done()
+{
+    finishSWTest();
+}
+
+async function logStatus()
+{
+    var response = await fetch("status");
+    log("Status is " + response.statusText);
+}
+
+async function test()
+{
+    try {
+        await navigator.serviceWorker.register("resources/service-worker-cache-api-worker.js", { });
+
+        await logStatus();
+
+        var response = await fetch("/resources/square100.png.fromserviceworker");
+        var buffer =  await response.arrayBuffer();
+        log("Response buffer byte length is " + buffer.byteLength);
+
+        await logStatus();
+    } catch(e) {
+        await logStatus();
+        log("Got exception: " + e);
+    }
+    finishSWTest();
+}
+
+test();

Added: trunk/LayoutTests/http/tests/workers/service/service-worker-cache-api.https-expected.txt (0 => 223935)


--- trunk/LayoutTests/http/tests/workers/service/service-worker-cache-api.https-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/http/tests/workers/service/service-worker-cache-api.https-expected.txt	2017-10-24 22:28:44 UTC (rev 223935)
@@ -0,0 +1,4 @@
+Status is cache is ready
+Response buffer byte length is 12940
+Status is https://127.0.0.1:8443/resources/square100.png
+

Added: trunk/LayoutTests/http/tests/workers/service/service-worker-cache-api.https.html (0 => 223935)


--- trunk/LayoutTests/http/tests/workers/service/service-worker-cache-api.https.html	                        (rev 0)
+++ trunk/LayoutTests/http/tests/workers/service/service-worker-cache-api.https.html	2017-10-24 22:28:44 UTC (rev 223935)
@@ -0,0 +1,8 @@
+<html>
+<head>
+<script src=""
+</head>
+<body>
+<script src=""
+</body>
+</html>

Modified: trunk/Source/WebCore/ChangeLog (223934 => 223935)


--- trunk/Source/WebCore/ChangeLog	2017-10-24 22:23:12 UTC (rev 223934)
+++ trunk/Source/WebCore/ChangeLog	2017-10-24 22:28:44 UTC (rev 223935)
@@ -1,3 +1,47 @@
+2017-10-24  Youenn Fablet  <[email protected]>
+
+        Enable service worker to use cache storage api
+        https://bugs.webkit.org/show_bug.cgi?id=178684
+
+        Reviewed by Brady Eidson.
+
+        Test: http/tests/workers/service/service-worker-cache-api.https.html
+
+        Updated WorkerLoaderProxy so that it can create a CacheStorageConnection.
+        Update WorkerCacheStorageConnection to take benefit of that.
+        This allows creating a CacheStorageConnection based on the page for regular workers and differently for Service Worker context.
+
+        Added ServiceWorkerThreadProxy as a proxy to ServiceWorkerThread.
+        It is in particular responsible to do proxy for loading tasks.
+        It implements cache API support for service worker by creating a dedicated CacheStorageConnection.
+
+        * Modules/cache/WorkerCacheStorageConnection.cpp:
+        (WebCore::WorkerCacheStorageConnection::create):
+        (WebCore::WorkerCacheStorageConnection::~WorkerCacheStorageConnection):
+        (WebCore::WorkerCacheStorageConnection::doOpen):
+        (WebCore::WorkerCacheStorageConnection::doRemove):
+        (WebCore::WorkerCacheStorageConnection::doRetrieveCaches):
+        (WebCore::WorkerCacheStorageConnection::reference):
+        (WebCore::WorkerCacheStorageConnection::dereference):
+        (WebCore::WorkerCacheStorageConnection::doRetrieveRecords):
+        (WebCore::WorkerCacheStorageConnection::doBatchDeleteOperation):
+        (WebCore::WorkerCacheStorageConnection::doBatchPutOperation):
+        * WebCore.xcodeproj/project.pbxproj:
+        * workers/WorkerLoaderProxy.h:
+        * workers/WorkerMessagingProxy.cpp:
+        (WebCore::WorkerMessagingProxy::createCacheStorageConnection):
+        * workers/WorkerMessagingProxy.h:
+        * workers/service/context/ServiceWorkerThread.cpp:
+        (WebCore::ServiceWorkerThread::ServiceWorkerThread):
+        * workers/service/context/ServiceWorkerThread.h:
+        * workers/service/context/ServiceWorkerThreadProxy.cpp: Added.
+        (WebCore::ServiceWorkerThreadProxy::create):
+        (WebCore::ServiceWorkerThreadProxy::ServiceWorkerThreadProxy):
+        (WebCore::ServiceWorkerThreadProxy::postTaskForModeToWorkerGlobalScope):
+        (WebCore::ServiceWorkerThreadProxy::postTaskToLoader):
+        (WebCore::ServiceWorkerThreadProxy::createCacheStorageConnection):
+        * workers/service/context/ServiceWorkerThreadProxy.h: Added.
+
 2017-10-24  Alex Christensen  <[email protected]>
 
         Optionally store entire ResourceRequest for ping loads

Modified: trunk/Source/WebCore/Modules/cache/WorkerCacheStorageConnection.cpp (223934 => 223935)


--- trunk/Source/WebCore/Modules/cache/WorkerCacheStorageConnection.cpp	2017-10-24 22:23:12 UTC (rev 223934)
+++ trunk/Source/WebCore/Modules/cache/WorkerCacheStorageConnection.cpp	2017-10-24 22:28:44 UTC (rev 223935)
@@ -91,12 +91,9 @@
 Ref<WorkerCacheStorageConnection> WorkerCacheStorageConnection::create(WorkerGlobalScope& scope)
 {
     auto connection = adoptRef(*new WorkerCacheStorageConnection(scope));
-    connection->m_proxy.postTaskToLoader([protectedConnection = makeRef(connection.get())](ScriptExecutionContext& context) mutable {
+    callOnMainThread([protectedConnection = connection.copyRef()]() mutable {
         ASSERT(isMainThread());
-        Document& document = downcast<Document>(context);
-
-        ASSERT(document.page());
-        protectedConnection->m_mainThreadConnection = document.page()->cacheStorageProvider().createCacheStorageConnection(document.page()->sessionID());
+        protectedConnection->m_mainThreadConnection = protectedConnection->m_proxy.createCacheStorageConnection();
     });
     return connection;
 }
@@ -111,12 +108,12 @@
 WorkerCacheStorageConnection::~WorkerCacheStorageConnection()
 {
     if (m_mainThreadConnection)
-        m_proxy.postTaskToLoader([mainThreadConnection = WTFMove(m_mainThreadConnection)](ScriptExecutionContext&) mutable { });
+        callOnMainThread([mainThreadConnection = WTFMove(m_mainThreadConnection)]() mutable { });
 }
 
 void WorkerCacheStorageConnection::doOpen(uint64_t requestIdentifier, const String& origin, const String& cacheName)
 {
-    m_proxy.postTaskToLoader([this, protectedThis = makeRef(*this), requestIdentifier, origin = origin.isolatedCopy(), cacheName = cacheName.isolatedCopy()](ScriptExecutionContext&) mutable {
+    callOnMainThread([this, protectedThis = makeRef(*this), requestIdentifier, origin = origin.isolatedCopy(), cacheName = cacheName.isolatedCopy()]() mutable {
         ASSERT(isMainThread());
         ASSERT(m_mainThreadConnection);
 
@@ -131,7 +128,7 @@
 
 void WorkerCacheStorageConnection::doRemove(uint64_t requestIdentifier, uint64_t cacheIdentifier)
 {
-    m_proxy.postTaskToLoader([this, protectedThis = makeRef(*this), requestIdentifier, cacheIdentifier](ScriptExecutionContext&) mutable {
+    callOnMainThread([this, protectedThis = makeRef(*this), requestIdentifier, cacheIdentifier]() mutable {
         ASSERT(isMainThread());
         ASSERT(m_mainThreadConnection);
 
@@ -147,7 +144,7 @@
 
 void WorkerCacheStorageConnection::doRetrieveCaches(uint64_t requestIdentifier, const String& origin, uint64_t updateCounter)
 {
-    m_proxy.postTaskToLoader([this, protectedThis = makeRef(*this), requestIdentifier, origin = origin.isolatedCopy(), updateCounter](ScriptExecutionContext&) mutable {
+    callOnMainThread([this, protectedThis = makeRef(*this), requestIdentifier, origin = origin.isolatedCopy(), updateCounter]() mutable {
         ASSERT(isMainThread());
         ASSERT(m_mainThreadConnection);
 
@@ -168,7 +165,7 @@
 
 void WorkerCacheStorageConnection::reference(uint64_t cacheIdentifier)
 {
-    m_proxy.postTaskToLoader([this, protectedThis = makeRef(*this), cacheIdentifier](ScriptExecutionContext&) {
+    callOnMainThread([this, protectedThis = makeRef(*this), cacheIdentifier]() {
         ASSERT(isMainThread());
         ASSERT(m_mainThreadConnection);
 
@@ -178,7 +175,7 @@
 
 void WorkerCacheStorageConnection::dereference(uint64_t cacheIdentifier)
 {
-    m_proxy.postTaskToLoader([this, protectedThis = makeRef(*this), cacheIdentifier](ScriptExecutionContext&) {
+    callOnMainThread([this, protectedThis = makeRef(*this), cacheIdentifier]() {
         ASSERT(isMainThread());
         ASSERT(m_mainThreadConnection);
 
@@ -213,7 +210,7 @@
 
 void WorkerCacheStorageConnection::doRetrieveRecords(uint64_t requestIdentifier, uint64_t cacheIdentifier, const URL& url)
 {
-    m_proxy.postTaskToLoader([this, protectedThis = makeRef(*this), requestIdentifier, cacheIdentifier, url = "" mutable {
+    callOnMainThread([this, protectedThis = makeRef(*this), requestIdentifier, cacheIdentifier, url = "" mutable {
         ASSERT(isMainThread());
         ASSERT(m_mainThreadConnection);
 
@@ -228,7 +225,7 @@
 
 void WorkerCacheStorageConnection::doBatchDeleteOperation(uint64_t requestIdentifier, uint64_t cacheIdentifier, const ResourceRequest& request, CacheQueryOptions&& options)
 {
-    m_proxy.postTaskToLoader([this, protectedThis = makeRef(*this), requestIdentifier, cacheIdentifier, request = request.isolatedCopy(), options = options.isolatedCopy()](ScriptExecutionContext&) mutable {
+    callOnMainThread([this, protectedThis = makeRef(*this), requestIdentifier, cacheIdentifier, request = request.isolatedCopy(), options = options.isolatedCopy()]() mutable {
         ASSERT(isMainThread());
         ASSERT(m_mainThreadConnection);
 
@@ -244,7 +241,7 @@
 
 void WorkerCacheStorageConnection::doBatchPutOperation(uint64_t requestIdentifier, uint64_t cacheIdentifier, Vector<Record>&& records)
 {
-    m_proxy.postTaskToLoader([this, protectedThis = makeRef(*this), requestIdentifier, cacheIdentifier, recordsData = recordsDataFromRecords(records)](ScriptExecutionContext&) mutable {
+    callOnMainThread([this, protectedThis = makeRef(*this), requestIdentifier, cacheIdentifier, recordsData = recordsDataFromRecords(records)]() mutable {
         ASSERT(isMainThread());
         ASSERT(m_mainThreadConnection);
 

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (223934 => 223935)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2017-10-24 22:23:12 UTC (rev 223934)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2017-10-24 22:28:44 UTC (rev 223935)
@@ -565,7 +565,7 @@
 		185BCF290F3279CE000EA262 /* ThreadTimers.h in Headers */ = {isa = PBXBuildFile; fileRef = 185BCF270F3279CE000EA262 /* ThreadTimers.h */; };
 		188604B30F2E654A000B6443 /* DOMTimer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 188604B10F2E654A000B6443 /* DOMTimer.cpp */; };
 		188604B40F2E654A000B6443 /* DOMTimer.h in Headers */ = {isa = PBXBuildFile; fileRef = 188604B20F2E654A000B6443 /* DOMTimer.h */; settings = {ATTRIBUTES = (Private, ); }; };
-		18F831B80FD48C7800D8C56B /* WorkerLoaderProxy.h in Headers */ = {isa = PBXBuildFile; fileRef = 18F831B70FD48C7800D8C56B /* WorkerLoaderProxy.h */; };
+		18F831B80FD48C7800D8C56B /* WorkerLoaderProxy.h in Headers */ = {isa = PBXBuildFile; fileRef = 18F831B70FD48C7800D8C56B /* WorkerLoaderProxy.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		1921327411C0E6BB00456238 /* SVGFEConvolveMatrixElement.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1921327111C0E6BB00456238 /* SVGFEConvolveMatrixElement.cpp */; };
 		1921327511C0E6BB00456238 /* SVGFEConvolveMatrixElement.h in Headers */ = {isa = PBXBuildFile; fileRef = 1921327211C0E6BB00456238 /* SVGFEConvolveMatrixElement.h */; };
 		197B180C1506353200E4ADA8 /* SVGRenderingContext.h in Headers */ = {isa = PBXBuildFile; fileRef = 197B180B150634C000E4ADA8 /* SVGRenderingContext.h */; };
@@ -1383,6 +1383,8 @@
 		41103AAD1E39791000769F14 /* RealtimeIncomingAudioSourceCocoa.h in Headers */ = {isa = PBXBuildFile; fileRef = 41103AA91E39790A00769F14 /* RealtimeIncomingAudioSourceCocoa.h */; };
 		41103AAE1E39791000769F03 /* RealtimeIncomingAudioSource.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 41103AAA1E39790A00769F03 /* RealtimeIncomingAudioSource.cpp */; };
 		41103AAE1E39791000769F14 /* RealtimeIncomingAudioSourceCocoa.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 41103AAA1E39790A00769F14 /* RealtimeIncomingAudioSourceCocoa.cpp */; };
+		4112B5421F9F9CA000E67875 /* ServiceWorkerThreadProxy.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4112B5411F9F9C9C00E67875 /* ServiceWorkerThreadProxy.cpp */; };
+		4112B5431F9F9CA000E67875 /* ServiceWorkerThreadProxy.h in Headers */ = {isa = PBXBuildFile; fileRef = 4112B53F1F9F9C9B00E67875 /* ServiceWorkerThreadProxy.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		4123081B138C429700BCCFCA /* WebCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 93F19B1A08245E5A001E9ABC /* WebCore.framework */; };
 		41230913138C42FF00BCCFCA /* _javascript_Core.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F8216299029F4FB501000131 /* _javascript_Core.framework */; };
 		4129C9971F59B963009D7403 /* FetchBodySource.h in Headers */ = {isa = PBXBuildFile; fileRef = 413015D61C7B570400091C6F /* FetchBodySource.h */; settings = {ATTRIBUTES = (Private, ); }; };
@@ -8232,6 +8234,8 @@
 		41103AA91E39790A00769F14 /* RealtimeIncomingAudioSourceCocoa.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RealtimeIncomingAudioSourceCocoa.h; sourceTree = "<group>"; };
 		41103AAA1E39790A00769F03 /* RealtimeIncomingAudioSource.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RealtimeIncomingAudioSource.cpp; sourceTree = "<group>"; };
 		41103AAA1E39790A00769F14 /* RealtimeIncomingAudioSourceCocoa.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RealtimeIncomingAudioSourceCocoa.cpp; sourceTree = "<group>"; };
+		4112B53F1F9F9C9B00E67875 /* ServiceWorkerThreadProxy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ServiceWorkerThreadProxy.h; sourceTree = "<group>"; };
+		4112B5411F9F9C9C00E67875 /* ServiceWorkerThreadProxy.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ServiceWorkerThreadProxy.cpp; sourceTree = "<group>"; };
 		41189EF71AD8232800B90A0D /* ReadableStreamDefaultController.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = ReadableStreamDefaultController.idl; sourceTree = "<group>"; };
 		41189EF71AD8232800B93F64 /* ReadableByteStreamController.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = ReadableByteStreamController.idl; sourceTree = "<group>"; };
 		41189EF71AD8232800B95672 /* ReadableStreamBYOBRequest.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = ReadableStreamBYOBRequest.idl; sourceTree = "<group>"; };
@@ -18178,6 +18182,8 @@
 				419ACF8E1F97E7D5009F1A83 /* ServiceWorkerFetch.h */,
 				517C87111F8EE72F00EB8076 /* ServiceWorkerThread.cpp */,
 				517C87101F8EE72E00EB8076 /* ServiceWorkerThread.h */,
+				4112B5411F9F9C9C00E67875 /* ServiceWorkerThreadProxy.cpp */,
+				4112B53F1F9F9C9B00E67875 /* ServiceWorkerThreadProxy.h */,
 			);
 			path = context;
 			sourceTree = "<group>";
@@ -29580,6 +29586,7 @@
 				517A53291F4B90B900DCDC0A /* ServiceWorkerRegistrationKey.h in Headers */,
 				51F175691F3EBC8300C74950 /* ServiceWorkerRegistrationOptions.h in Headers */,
 				51BCCE301F8F179E006BA0ED /* ServiceWorkerThread.h in Headers */,
+				4112B5431F9F9CA000E67875 /* ServiceWorkerThreadProxy.h in Headers */,
 				51F1756C1F3EBC8300C74950 /* ServiceWorkerUpdateViaCache.h in Headers */,
 				46EF142A1F97B7D800C2A524 /* ServiceWorkerWindowClient.h in Headers */,
 				93309E10099E64920056E581 /* SetNodeAttributeCommand.h in Headers */,
@@ -32108,6 +32115,7 @@
 				517A53281F4B90B900DCDC0A /* ServiceWorkerRegistrationKey.cpp in Sources */,
 				51F645A21F4BF53C00B54DED /* ServiceWorkerRegistrationOptions.cpp in Sources */,
 				51BCCE2F1F8F1795006BA0ED /* ServiceWorkerThread.cpp in Sources */,
+				4112B5421F9F9CA000E67875 /* ServiceWorkerThreadProxy.cpp in Sources */,
 				46EF142E1F97B7D800C2A524 /* ServiceWorkerWindowClient.cpp in Sources */,
 				7CD58DFD1F9565A800112791 /* Settings.cpp in Sources */,
 				7CC660A21F93CB9000D500E9 /* SettingsBase.cpp in Sources */,

Modified: trunk/Source/WebCore/workers/WorkerLoaderProxy.h (223934 => 223935)


--- trunk/Source/WebCore/workers/WorkerLoaderProxy.h	2017-10-24 22:23:12 UTC (rev 223934)
+++ trunk/Source/WebCore/workers/WorkerLoaderProxy.h	2017-10-24 22:28:44 UTC (rev 223935)
@@ -34,22 +34,27 @@
 
 namespace WebCore {
 
-    // A proxy to talk to the loader context. Normally, the document on the main thread
-    // provides loading services for the subordinate workers. This interface provides 2-way
-    // communications to the Document context and back to the worker.
-    // Note that in multi-process browsers, the Worker object context and the Document
-    // context can be distinct.
-    class WorkerLoaderProxy {
-    public:
-        virtual ~WorkerLoaderProxy() = default;
+class CacheStorageConnection;
 
-        // Posts a task to the thread which runs the loading code (normally, the main thread).
-        virtual void postTaskToLoader(ScriptExecutionContext::Task&&) = 0;
+// A proxy to talk to the loader context. Normally, the document on the main thread
+// provides loading services for the subordinate workers. This interface provides 2-way
+// communications to the Document context and back to the worker.
+// Note that in multi-process browsers, the Worker object context and the Document
+// context can be distinct.
+class WorkerLoaderProxy {
+public:
+    virtual ~WorkerLoaderProxy() = default;
 
-        // Posts callbacks from loading code to the WorkerGlobalScope. The 'mode' is used to differentiate
-        // specific synchronous loading requests so they can be 'nested', per spec.
-        // Returns true if the task was posted successfully.
-        virtual bool postTaskForModeToWorkerGlobalScope(ScriptExecutionContext::Task&&, const String& mode) = 0;
-    };
+    // Creates a cache storage connection to be used on the main thread. Method must be called on the main thread.
+    virtual Ref<CacheStorageConnection> createCacheStorageConnection() = 0;
 
+    // Posts a task to the thread which runs the loading code (normally, the main thread).
+    virtual void postTaskToLoader(ScriptExecutionContext::Task&&) = 0;
+
+    // Posts callbacks from loading code to the WorkerGlobalScope. The 'mode' is used to differentiate
+    // specific synchronous loading requests so they can be 'nested', per spec.
+    // Returns true if the task was posted successfully.
+    virtual bool postTaskForModeToWorkerGlobalScope(ScriptExecutionContext::Task&&, const String& mode) = 0;
+};
+
 } // namespace WebCore

Modified: trunk/Source/WebCore/workers/WorkerMessagingProxy.cpp (223934 => 223935)


--- trunk/Source/WebCore/workers/WorkerMessagingProxy.cpp	2017-10-24 22:23:12 UTC (rev 223934)
+++ trunk/Source/WebCore/workers/WorkerMessagingProxy.cpp	2017-10-24 22:28:44 UTC (rev 223935)
@@ -28,6 +28,7 @@
 #include "config.h"
 #include "WorkerMessagingProxy.h"
 
+#include "CacheStorageProvider.h"
 #include "ContentSecurityPolicy.h"
 #include "DOMWindow.h"
 #include "DedicatedWorkerGlobalScope.h"
@@ -36,6 +37,7 @@
 #include "ErrorEvent.h"
 #include "EventNames.h"
 #include "MessageEvent.h"
+#include "Page.h"
 #include "ScriptExecutionContext.h"
 #include "Worker.h"
 #include "WorkerInspectorProxy.h"
@@ -133,6 +135,13 @@
     m_scriptExecutionContext->postTask(WTFMove(task));
 }
 
+Ref<CacheStorageConnection> WorkerMessagingProxy::createCacheStorageConnection()
+{
+    ASSERT(isMainThread());
+    auto& document = downcast<Document>(*m_scriptExecutionContext);
+    return document.page()->cacheStorageProvider().createCacheStorageConnection(document.page()->sessionID());
+}
+
 bool WorkerMessagingProxy::postTaskForModeToWorkerGlobalScope(ScriptExecutionContext::Task&& task, const String& mode)
 {
     if (m_askedToTerminate)

Modified: trunk/Source/WebCore/workers/WorkerMessagingProxy.h (223934 => 223935)


--- trunk/Source/WebCore/workers/WorkerMessagingProxy.h	2017-10-24 22:23:12 UTC (rev 223934)
+++ trunk/Source/WebCore/workers/WorkerMessagingProxy.h	2017-10-24 22:28:44 UTC (rev 223935)
@@ -67,6 +67,7 @@
     // requests and to send callbacks back to WorkerGlobalScope.
     void postTaskToLoader(ScriptExecutionContext::Task&&) final;
     bool postTaskForModeToWorkerGlobalScope(ScriptExecutionContext::Task&&, const String& mode) final;
+    Ref<CacheStorageConnection> createCacheStorageConnection() final;
 
     void workerThreadCreated(DedicatedWorkerThread&);
 

Modified: trunk/Source/WebCore/workers/service/context/ServiceWorkerThread.cpp (223934 => 223935)


--- trunk/Source/WebCore/workers/service/context/ServiceWorkerThread.cpp	2017-10-24 22:23:12 UTC (rev 223934)
+++ trunk/Source/WebCore/workers/service/context/ServiceWorkerThread.cpp	2017-10-24 22:28:44 UTC (rev 223935)
@@ -28,6 +28,7 @@
 
 #if ENABLE(SERVICE_WORKER)
 
+#include "CacheStorageProvider.h"
 #include "ContentSecurityPolicyResponseHeaders.h"
 #include "ExtendableMessageEvent.h"
 #include "SecurityOrigin.h"
@@ -43,17 +44,15 @@
 
 namespace WebCore {
 
-class ServiceWorkerThreadProxy : public WorkerLoaderProxy, public WorkerObjectProxy {
+class DummyServiceWorkerThreadProxy : public WorkerObjectProxy {
 public:
-    static ServiceWorkerThreadProxy& sharedDummyProxy()
+    static DummyServiceWorkerThreadProxy& shared()
     {
-        static NeverDestroyed<ServiceWorkerThreadProxy> proxy;
+        static NeverDestroyed<DummyServiceWorkerThreadProxy> proxy;
         return proxy;
     }
 
 private:
-    void postTaskToLoader(ScriptExecutionContext::Task&&) final { };
-    bool postTaskForModeToWorkerGlobalScope(ScriptExecutionContext::Task&&, const String&) final { return false; };
     void postExceptionToWorkerObject(const String&, int, int, const String&) final { };
     void postMessageToPageInspector(const String&) final { };
     void workerGlobalScopeDestroyed() final { };
@@ -70,11 +69,11 @@
 // FIXME: Use a valid user agent
 // FIXME: Use valid runtime flags
 
-ServiceWorkerThread::ServiceWorkerThread(uint64_t serverConnectionIdentifier, const ServiceWorkerContextData& data, PAL::SessionID)
-    : WorkerThread(data.scriptURL, data.workerID, ASCIILiteral("WorkerUserAgent"), data.script, ServiceWorkerThreadProxy::sharedDummyProxy(), ServiceWorkerThreadProxy::sharedDummyProxy(), WorkerThreadStartMode::Normal, ContentSecurityPolicyResponseHeaders { }, false, SecurityOrigin::create(data.scriptURL).get(), MonotonicTime::now(), nullptr, nullptr, JSC::RuntimeFlags::createAllEnabled(), SessionID::defaultSessionID())
+ServiceWorkerThread::ServiceWorkerThread(uint64_t serverConnectionIdentifier, const ServiceWorkerContextData& data, PAL::SessionID, WorkerLoaderProxy& loaderProxy)
+    : WorkerThread(data.scriptURL, data.workerID, ASCIILiteral("WorkerUserAgent"), data.script, loaderProxy, DummyServiceWorkerThreadProxy::shared(), WorkerThreadStartMode::Normal, ContentSecurityPolicyResponseHeaders { }, false, SecurityOrigin::create(data.scriptURL).get(), MonotonicTime::now(), nullptr, nullptr, JSC::RuntimeFlags::createAllEnabled(), SessionID::defaultSessionID())
     , m_serverConnectionIdentifier(serverConnectionIdentifier)
     , m_data(data.isolatedCopy())
-    , m_workerObjectProxy(ServiceWorkerThreadProxy::sharedDummyProxy())
+    , m_workerObjectProxy(DummyServiceWorkerThreadProxy::shared())
 {
     AtomicString::init();
 }

Modified: trunk/Source/WebCore/workers/service/context/ServiceWorkerThread.h (223934 => 223935)


--- trunk/Source/WebCore/workers/service/context/ServiceWorkerThread.h	2017-10-24 22:23:12 UTC (rev 223934)
+++ trunk/Source/WebCore/workers/service/context/ServiceWorkerThread.h	2017-10-24 22:28:44 UTC (rev 223935)
@@ -34,6 +34,7 @@
 
 namespace WebCore {
 
+class CacheStorageProvider;
 class ContentSecurityPolicyResponseHeaders;
 class MessagePortChannel;
 class SerializedScriptValue;
@@ -60,7 +61,7 @@
     void runEventLoop() override;
 
 private:
-    WEBCORE_EXPORT ServiceWorkerThread(uint64_t serverConnectionIdentifier, const ServiceWorkerContextData&, PAL::SessionID);
+    WEBCORE_EXPORT ServiceWorkerThread(uint64_t serverConnectionIdentifier, const ServiceWorkerContextData&, PAL::SessionID, WorkerLoaderProxy&);
 
     uint64_t m_serverConnectionIdentifier;
     ServiceWorkerContextData m_data;

Added: trunk/Source/WebCore/workers/service/context/ServiceWorkerThreadProxy.cpp (0 => 223935)


--- trunk/Source/WebCore/workers/service/context/ServiceWorkerThreadProxy.cpp	                        (rev 0)
+++ trunk/Source/WebCore/workers/service/context/ServiceWorkerThreadProxy.cpp	2017-10-24 22:28:44 UTC (rev 223935)
@@ -0,0 +1,76 @@
+/*
+ * Copyright (C) 2017 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "ServiceWorkerThreadProxy.h"
+
+#if ENABLE(SERVICE_WORKER)
+
+#include <WebCore/CacheStorageProvider.h>
+#include <WebCore/FrameLoader.h>
+#include <WebCore/MainFrame.h>
+#include <pal/SessionID.h>
+#include <wtf/RunLoop.h>
+
+namespace WebCore {
+
+Ref<ServiceWorkerThreadProxy> ServiceWorkerThreadProxy::create(uint64_t serverConnectionIdentifier, const WebCore::ServiceWorkerContextData& data, PAL::SessionID sessionID, CacheStorageProvider& cacheStorageProvider)
+{
+    auto serviceWorker = adoptRef(*new ServiceWorkerThreadProxy { serverConnectionIdentifier, data, sessionID, cacheStorageProvider });
+    serviceWorker->m_serviceWorkerThread->start();
+    return serviceWorker;
+}
+
+ServiceWorkerThreadProxy::ServiceWorkerThreadProxy(uint64_t serverConnectionIdentifier, const WebCore::ServiceWorkerContextData& data, PAL::SessionID sessionID, CacheStorageProvider& cacheStorageProvider)
+    : m_serviceWorkerThread(ServiceWorkerThread::create(serverConnectionIdentifier, data, sessionID, *this))
+    , m_cacheStorageProvider(cacheStorageProvider)
+    , m_sessionID(sessionID)
+{
+    m_serviceWorkerThread->start();
+}
+
+bool ServiceWorkerThreadProxy::postTaskForModeToWorkerGlobalScope(ScriptExecutionContext::Task&& task, const String& mode)
+{
+    // FIXME: Handle termination case.
+    m_serviceWorkerThread->runLoop().postTaskForMode(WTFMove(task), mode);
+    return true;
+}
+
+void ServiceWorkerThreadProxy::postTaskToLoader(ScriptExecutionContext::Task&&)
+{
+    // Implement this.
+}
+
+Ref<CacheStorageConnection> ServiceWorkerThreadProxy::createCacheStorageConnection()
+{
+    ASSERT(isMainThread());
+    if (!m_cacheStorageConnection)
+        m_cacheStorageConnection = m_cacheStorageProvider.createCacheStorageConnection(m_sessionID);
+    return *m_cacheStorageConnection;
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(SERVICE_WORKER)

Copied: trunk/Source/WebCore/workers/service/context/ServiceWorkerThreadProxy.h (from rev 223934, trunk/Source/WebKit/WebProcess/Storage/ServiceWorkerContextManager.h) (0 => 223935)


--- trunk/Source/WebCore/workers/service/context/ServiceWorkerThreadProxy.h	                        (rev 0)
+++ trunk/Source/WebCore/workers/service/context/ServiceWorkerThreadProxy.h	2017-10-24 22:28:44 UTC (rev 223935)
@@ -0,0 +1,63 @@
+/*
+ * Copyright (C) 2017 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if ENABLE(SERVICE_WORKER)
+
+#include "CacheStorageConnection.h"
+#include "Document.h"
+#include "Page.h"
+#include "ServiceWorkerThread.h"
+#include "WorkerLoaderProxy.h"
+#include <wtf/HashMap.h>
+
+namespace WebCore {
+class CacheStorageProvider;
+class PageConfiguration;
+struct ServiceWorkerContextData;
+
+class ServiceWorkerThreadProxy final : public ThreadSafeRefCounted<ServiceWorkerThreadProxy>, public WorkerLoaderProxy {
+public:
+    WEBCORE_EXPORT static Ref<ServiceWorkerThreadProxy> create(uint64_t serverConnectionIdentifier, const ServiceWorkerContextData&, PAL::SessionID, CacheStorageProvider&);
+
+    uint64_t identifier() const { return m_serviceWorkerThread->identifier(); }
+    ServiceWorkerThread& thread() { return m_serviceWorkerThread.get(); }
+
+private:
+    ServiceWorkerThreadProxy(uint64_t serverConnectionIdentifier, const ServiceWorkerContextData&, PAL::SessionID, CacheStorageProvider&);
+    bool postTaskForModeToWorkerGlobalScope(ScriptExecutionContext::Task&&, const String& mode) final;
+    void postTaskToLoader(ScriptExecutionContext::Task&&) final;
+    Ref<CacheStorageConnection> createCacheStorageConnection() final;
+
+    Ref<ServiceWorkerThread> m_serviceWorkerThread;
+    CacheStorageProvider& m_cacheStorageProvider;
+    RefPtr<CacheStorageConnection> m_cacheStorageConnection;
+    PAL::SessionID m_sessionID;
+};
+
+} // namespace WebKit
+
+#endif // ENABLE(SERVICE_WORKER)

Modified: trunk/Source/WebKit/ChangeLog (223934 => 223935)


--- trunk/Source/WebKit/ChangeLog	2017-10-24 22:23:12 UTC (rev 223934)
+++ trunk/Source/WebKit/ChangeLog	2017-10-24 22:28:44 UTC (rev 223935)
@@ -1,3 +1,32 @@
+2017-10-24  Youenn Fablet  <[email protected]>
+
+        Enable service worker to use cache storage api
+        https://bugs.webkit.org/show_bug.cgi?id=178684
+
+        Reviewed by Brady Eidson.
+
+        Passing the WebPreferences store of the default page group of the WebProcessPool to its ServiceWorker process.
+        ServiceWorkerContextManager then uses it to initialize the preferences accordingly.
+        Patch is covered by new test which is using cache api previously disabled and now enabled through the store.
+
+        Made use of the new ServiceWorkerThreadProxy in ServiceWorkerContextManager to enable a cache storage connection.
+        Fixed the default size of quota in WebsiteDataStore.
+
+        * UIProcess/WebProcessPool.cpp:
+        (WebKit::WebProcessPool::getWorkerContextProcessConnection):
+        * UIProcess/WebsiteData/WebsiteDataStore.h:
+        * WebProcess/Storage/ServiceWorkerContextManager.cpp:
+        (WebKit::ServiceWorkerContextManager::ServiceWorkerContextManager):
+        (WebKit::ServiceWorkerContextManager::updatePreferences):
+        (WebKit::ServiceWorkerContextManager::startServiceWorker):
+        (WebKit::ServiceWorkerContextManager::startFetch):
+        * WebProcess/Storage/ServiceWorkerContextManager.h:
+        (WebKit::ServiceWorkerContextManager::ServiceWorkerContextManager): Deleted.
+        * WebProcess/WebProcess.cpp:
+        (WebKit::WebProcess::getWorkerContextConnection):
+        * WebProcess/WebProcess.h:
+        * WebProcess/WebProcess.messages.in:
+
 2017-10-24  Alex Christensen  <[email protected]>
 
         Selecting and right-clicking URL-like strings with IDNA-disallowed characters in host or authority causes rendering engine crash

Modified: trunk/Source/WebKit/UIProcess/WebProcessPool.cpp (223934 => 223935)


--- trunk/Source/WebKit/UIProcess/WebProcessPool.cpp	2017-10-24 22:23:12 UTC (rev 223934)
+++ trunk/Source/WebKit/UIProcess/WebProcessPool.cpp	2017-10-24 22:28:44 UTC (rev 223935)
@@ -596,7 +596,7 @@
         m_websiteDataStore = API::WebsiteDataStore::defaultDataStore().ptr();
     auto& newProcess = createNewWebProcess(m_websiteDataStore->websiteDataStore());
     m_workerContextProcess = &newProcess;
-    m_workerContextProcess->send(Messages::WebProcess::GetWorkerContextConnection(), 0);
+    m_workerContextProcess->send(Messages::WebProcess::GetWorkerContextConnection(m_defaultPageGroup->preferences().store()), 0);
 }
 
 void WebProcessPool::didGetWorkerContextProcessConnection(const IPC::Attachment& connection)

Modified: trunk/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.h (223934 => 223935)


--- trunk/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.h	2017-10-24 22:23:12 UTC (rev 223934)
+++ trunk/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.h	2017-10-24 22:28:44 UTC (rev 223935)
@@ -68,9 +68,11 @@
 
 class WebsiteDataStore : public RefCounted<WebsiteDataStore>, public WebProcessLifetimeObserver, public Identified<WebsiteDataStore>  {
 public:
+    constexpr static uint64_t defaultCacheStoragePerOriginQuota = 20 * 1024 * 1024;
+
     struct Configuration {
         String cacheStorageDirectory;
-        uint64_t cacheStoragePerOriginQuota;
+        uint64_t cacheStoragePerOriginQuota { defaultCacheStoragePerOriginQuota };
         String networkCacheDirectory;
         String applicationCacheDirectory;
         String applicationCacheFlatFileSubdirectoryName;
@@ -88,8 +90,6 @@
     static Ref<WebsiteDataStore> create(Configuration, PAL::SessionID);
     virtual ~WebsiteDataStore();
 
-    constexpr static uint64_t defaultCacheStoragePerOriginQuota = 20 * 1024 * 1024;
-
     bool isPersistent() const { return !m_sessionID.isEphemeral(); }
     PAL::SessionID sessionID() const { return m_sessionID; }
 

Modified: trunk/Source/WebKit/WebProcess/Storage/ServiceWorkerContextManager.cpp (223934 => 223935)


--- trunk/Source/WebKit/WebProcess/Storage/ServiceWorkerContextManager.cpp	2017-10-24 22:23:12 UTC (rev 223934)
+++ trunk/Source/WebKit/WebProcess/Storage/ServiceWorkerContextManager.cpp	2017-10-24 22:28:44 UTC (rev 223935)
@@ -31,11 +31,16 @@
 #include "DataReference.h"
 #include "Logging.h"
 #include "StorageProcessMessages.h"
+#include "WebCacheStorageProvider.h"
 #include "WebCoreArgumentCoders.h"
+#include "WebPreferencesKeys.h"
+#include "WebPreferencesStore.h"
+#include "WebProcess.h"
 #include "WebServiceWorkerFetchTaskClient.h"
 #include <WebCore/MessagePortChannel.h>
 #include <WebCore/ResourceRequest.h>
 #include <WebCore/ResourceResponse.h>
+#include <WebCore/RuntimeEnabledFeatures.h>
 #include <WebCore/SerializedScriptValue.h>
 #include <pal/SessionID.h>
 
@@ -44,41 +49,51 @@
 
 namespace WebKit {
 
+ServiceWorkerContextManager::ServiceWorkerContextManager(Ref<IPC::Connection>&& connection, const WebPreferencesStore& store)
+    : m_connectionToStorageProcess(WTFMove(connection))
+{
+    updatePreferences(store);
+}
+
+void ServiceWorkerContextManager::updatePreferences(const WebPreferencesStore& store)
+{
+    RuntimeEnabledFeatures::sharedFeatures().setCacheAPIEnabled(store.getBoolValueForKey(WebPreferencesKey::cacheAPIEnabledKey()));
+    RuntimeEnabledFeatures::sharedFeatures().setFetchAPIEnabled(store.getBoolValueForKey(WebPreferencesKey::fetchAPIEnabledKey()));
+}
+
 void ServiceWorkerContextManager::startServiceWorker(uint64_t serverConnectionIdentifier, const ServiceWorkerContextData& data)
 {
     // FIXME: Provide a sensical session ID.
-    auto thread = ServiceWorkerThread::create(serverConnectionIdentifier, data, SessionID::defaultSessionID());
-    auto threadIdentifier = thread->identifier();
-    auto result = m_workerThreadMap.add(threadIdentifier, WTFMove(thread));
-    ASSERT(result.isNewEntry);
+    auto serviceWorker = ServiceWorkerThreadProxy::create(serverConnectionIdentifier, data, SessionID::defaultSessionID(), WebProcess::singleton().cacheStorageProvider());
+    auto serviceWorkerIdentifier = serviceWorker->identifier();
+    auto result = m_workerMap.add(serviceWorkerIdentifier, WTFMove(serviceWorker));
+    ASSERT_UNUSED(result, result.isNewEntry);
 
-    result.iterator->value->start();
-
     LOG(ServiceWorker, "Context process PID: %i started worker thread %s\n", getpid(), data.workerID.utf8().data());
 
-    m_connectionToStorageProcess->send(Messages::StorageProcess::ServiceWorkerContextStarted(serverConnectionIdentifier, data.registrationKey, threadIdentifier, data.workerID), 0);
+    m_connectionToStorageProcess->send(Messages::StorageProcess::ServiceWorkerContextStarted(serverConnectionIdentifier, data.registrationKey, serviceWorkerIdentifier, data.workerID), 0);
 }
 
 void ServiceWorkerContextManager::startFetch(uint64_t serverConnectionIdentifier, uint64_t fetchIdentifier, uint64_t serviceWorkerIdentifier, ResourceRequest&& request, FetchOptions&& options)
 {
-    auto serviceWorkerThread = m_workerThreadMap.get(serviceWorkerIdentifier);
-    if (!serviceWorkerThread) {
+    auto serviceWorker = m_workerMap.get(serviceWorkerIdentifier);
+    if (!serviceWorker) {
         m_connectionToStorageProcess->send(Messages::StorageProcess::DidNotHandleFetch(serverConnectionIdentifier, fetchIdentifier), 0);
         return;
     }
 
     auto client = WebServiceWorkerFetchTaskClient::create(m_connectionToStorageProcess.copyRef(), serverConnectionIdentifier, fetchIdentifier);
-    serviceWorkerThread->postFetchTask(WTFMove(client), WTFMove(request), WTFMove(options));
+    serviceWorker->thread().postFetchTask(WTFMove(client), WTFMove(request), WTFMove(options));
 }
 
 void ServiceWorkerContextManager::postMessageToServiceWorkerGlobalScope(uint64_t serverConnectionIdentifier, uint64_t serviceWorkerIdentifier, const IPC::DataReference& message, const String& sourceOrigin)
 {
-    auto* workerThread = m_workerThreadMap.get(serviceWorkerIdentifier);
-    if (!workerThread)
+    auto* serviceWorker = m_workerMap.get(serviceWorkerIdentifier);
+    if (!serviceWorker)
         return;
 
     // FIXME: We should pass valid MessagePortChannels.
-    workerThread->postMessageToServiceWorkerGlobalScope(SerializedScriptValue::adopt(message.vector()), nullptr, sourceOrigin);
+    serviceWorker->thread().postMessageToServiceWorkerGlobalScope(SerializedScriptValue::adopt(message.vector()), nullptr, sourceOrigin);
 }
 
 } // namespace WebCore

Modified: trunk/Source/WebKit/WebProcess/Storage/ServiceWorkerContextManager.h (223934 => 223935)


--- trunk/Source/WebKit/WebProcess/Storage/ServiceWorkerContextManager.h	2017-10-24 22:23:12 UTC (rev 223934)
+++ trunk/Source/WebKit/WebProcess/Storage/ServiceWorkerContextManager.h	2017-10-24 22:28:44 UTC (rev 223935)
@@ -29,7 +29,7 @@
 
 #include "Connection.h"
 #include "MessageReceiver.h"
-#include <WebCore/ServiceWorkerThread.h>
+#include <WebCore/ServiceWorkerThreadProxy.h>
 #include <wtf/HashMap.h>
 
 namespace WebCore {
@@ -39,23 +39,23 @@
 }
 
 namespace WebKit {
+struct WebPreferencesStore;
 
 class ServiceWorkerContextManager : public IPC::MessageReceiver {
 public:
-    explicit ServiceWorkerContextManager(Ref<IPC::Connection>&& connection)
-        : m_connectionToStorageProcess(WTFMove(connection))
-    {
-    }
+    ServiceWorkerContextManager(Ref<IPC::Connection>&&, const WebPreferencesStore&);
 
     void didReceiveMessage(IPC::Connection&, IPC::Decoder&) final;
 
 private:
+    void updatePreferences(const WebPreferencesStore&);
+
     void startServiceWorker(uint64_t serverConnectionIdentifier, const WebCore::ServiceWorkerContextData&);
     void startFetch(uint64_t serverConnectionIdentifier, uint64_t fetchIdentifier, uint64_t serviceWorkerIdentifier, WebCore::ResourceRequest&&, WebCore::FetchOptions&&);
     void postMessageToServiceWorkerGlobalScope(uint64_t serverConnectionIdentifier, uint64_t serviceWorkerIdentifier, const IPC::DataReference& message, const String& sourceOrigin);
 
     Ref<IPC::Connection> m_connectionToStorageProcess;
-    HashMap<uint64_t, RefPtr<WebCore::ServiceWorkerThread>> m_workerThreadMap;
+    HashMap<uint64_t, RefPtr<WebCore::ServiceWorkerThreadProxy>> m_workerMap;
 };
 
 } // namespace WebKit

Modified: trunk/Source/WebKit/WebProcess/WebProcess.cpp (223934 => 223935)


--- trunk/Source/WebKit/WebProcess/WebProcess.cpp	2017-10-24 22:23:12 UTC (rev 223934)
+++ trunk/Source/WebKit/WebProcess/WebProcess.cpp	2017-10-24 22:28:44 UTC (rev 223935)
@@ -1640,7 +1640,7 @@
 #endif
 
 #if ENABLE(SERVICE_WORKER)
-void WebProcess::getWorkerContextConnection()
+void WebProcess::getWorkerContextConnection(const WebPreferencesStore& store)
 {
     ASSERT(!m_serviceWorkerManager);
 
@@ -1664,7 +1664,7 @@
 
     auto workerContextConnection = IPC::Connection::createServerConnection(connectionIdentifier, *this);
     workerContextConnection->open();
-    m_serviceWorkerManager =  ServiceWorkerContextManager(WTFMove(workerContextConnection));
+    m_serviceWorkerManager =  ServiceWorkerContextManager(WTFMove(workerContextConnection), store);
     WebProcess::singleton().parentProcessConnection()->send(Messages::WebProcessProxy::DidGetWorkerContextConnection(connectionClientPort), 0);
 }
 #endif

Modified: trunk/Source/WebKit/WebProcess/WebProcess.h (223934 => 223935)


--- trunk/Source/WebKit/WebProcess/WebProcess.h	2017-10-24 22:23:12 UTC (rev 223934)
+++ trunk/Source/WebKit/WebProcess/WebProcess.h	2017-10-24 22:28:44 UTC (rev 223935)
@@ -299,7 +299,7 @@
     void setNetworkProxySettings(const WebCore::SoupNetworkProxySettings&);
 #endif
 #if ENABLE(SERVICE_WORKER)
-    void getWorkerContextConnection();
+    void getWorkerContextConnection(const WebPreferencesStore&);
 #endif
 
     void releasePageCache();

Modified: trunk/Source/WebKit/WebProcess/WebProcess.messages.in (223934 => 223935)


--- trunk/Source/WebKit/WebProcess/WebProcess.messages.in	2017-10-24 22:23:12 UTC (rev 223934)
+++ trunk/Source/WebKit/WebProcess/WebProcess.messages.in	2017-10-24 22:28:44 UTC (rev 223935)
@@ -115,6 +115,6 @@
 #endif
 
 #if ENABLE(SERVICE_WORKER)
-    GetWorkerContextConnection()
+    GetWorkerContextConnection(struct WebKit::WebPreferencesStore store)
 #endif
 }
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to