Changeset 223935 in webkit


Ignore:
Timestamp:
Oct 24, 2017 3:28:44 PM (7 years ago)
Author:
commit-queue@webkit.org
Message:

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

Patch by Youenn Fablet <youenn@apple.com> 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.
Location:
trunk
Files:
5 added
17 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r223932 r223935  
     12017-10-24  Youenn Fablet  <youenn@apple.com>
     2
     3        Enable service worker to use cache storage api
     4        https://bugs.webkit.org/show_bug.cgi?id=178684
     5
     6        Reviewed by Brady Eidson.
     7
     8        * http/tests/workers/service/resources/service-worker-cache-api-worker.js: Added.
     9        * http/tests/workers/service/resources/service-worker-cache-api.js: Added.
     10        * http/tests/workers/service/service-worker-cache-api.https-expected.txt: Added.
     11        * http/tests/workers/service/service-worker-cache-api.https.html: Added.
     12
    1132017-10-24  Matt Lewis  <jlewis3@apple.com>
    214
  • trunk/Source/WebCore/ChangeLog

    r223933 r223935  
     12017-10-24  Youenn Fablet  <youenn@apple.com>
     2
     3        Enable service worker to use cache storage api
     4        https://bugs.webkit.org/show_bug.cgi?id=178684
     5
     6        Reviewed by Brady Eidson.
     7
     8        Test: http/tests/workers/service/service-worker-cache-api.https.html
     9
     10        Updated WorkerLoaderProxy so that it can create a CacheStorageConnection.
     11        Update WorkerCacheStorageConnection to take benefit of that.
     12        This allows creating a CacheStorageConnection based on the page for regular workers and differently for Service Worker context.
     13
     14        Added ServiceWorkerThreadProxy as a proxy to ServiceWorkerThread.
     15        It is in particular responsible to do proxy for loading tasks.
     16        It implements cache API support for service worker by creating a dedicated CacheStorageConnection.
     17
     18        * Modules/cache/WorkerCacheStorageConnection.cpp:
     19        (WebCore::WorkerCacheStorageConnection::create):
     20        (WebCore::WorkerCacheStorageConnection::~WorkerCacheStorageConnection):
     21        (WebCore::WorkerCacheStorageConnection::doOpen):
     22        (WebCore::WorkerCacheStorageConnection::doRemove):
     23        (WebCore::WorkerCacheStorageConnection::doRetrieveCaches):
     24        (WebCore::WorkerCacheStorageConnection::reference):
     25        (WebCore::WorkerCacheStorageConnection::dereference):
     26        (WebCore::WorkerCacheStorageConnection::doRetrieveRecords):
     27        (WebCore::WorkerCacheStorageConnection::doBatchDeleteOperation):
     28        (WebCore::WorkerCacheStorageConnection::doBatchPutOperation):
     29        * WebCore.xcodeproj/project.pbxproj:
     30        * workers/WorkerLoaderProxy.h:
     31        * workers/WorkerMessagingProxy.cpp:
     32        (WebCore::WorkerMessagingProxy::createCacheStorageConnection):
     33        * workers/WorkerMessagingProxy.h:
     34        * workers/service/context/ServiceWorkerThread.cpp:
     35        (WebCore::ServiceWorkerThread::ServiceWorkerThread):
     36        * workers/service/context/ServiceWorkerThread.h:
     37        * workers/service/context/ServiceWorkerThreadProxy.cpp: Added.
     38        (WebCore::ServiceWorkerThreadProxy::create):
     39        (WebCore::ServiceWorkerThreadProxy::ServiceWorkerThreadProxy):
     40        (WebCore::ServiceWorkerThreadProxy::postTaskForModeToWorkerGlobalScope):
     41        (WebCore::ServiceWorkerThreadProxy::postTaskToLoader):
     42        (WebCore::ServiceWorkerThreadProxy::createCacheStorageConnection):
     43        * workers/service/context/ServiceWorkerThreadProxy.h: Added.
     44
    1452017-10-24  Alex Christensen  <achristensen@webkit.org>
    246
  • trunk/Source/WebCore/Modules/cache/WorkerCacheStorageConnection.cpp

    r223476 r223935  
    9292{
    9393    auto connection = adoptRef(*new WorkerCacheStorageConnection(scope));
    94     connection->m_proxy.postTaskToLoader([protectedConnection = makeRef(connection.get())](ScriptExecutionContext& context) mutable {
    95         ASSERT(isMainThread());
    96         Document& document = downcast<Document>(context);
    97 
    98         ASSERT(document.page());
    99         protectedConnection->m_mainThreadConnection = document.page()->cacheStorageProvider().createCacheStorageConnection(document.page()->sessionID());
     94    callOnMainThread([protectedConnection = connection.copyRef()]() mutable {
     95        ASSERT(isMainThread());
     96        protectedConnection->m_mainThreadConnection = protectedConnection->m_proxy.createCacheStorageConnection();
    10097    });
    10198    return connection;
     
    112109{
    113110    if (m_mainThreadConnection)
    114         m_proxy.postTaskToLoader([mainThreadConnection = WTFMove(m_mainThreadConnection)](ScriptExecutionContext&) mutable { });
     111        callOnMainThread([mainThreadConnection = WTFMove(m_mainThreadConnection)]() mutable { });
    115112}
    116113
    117114void WorkerCacheStorageConnection::doOpen(uint64_t requestIdentifier, const String& origin, const String& cacheName)
    118115{
    119     m_proxy.postTaskToLoader([this, protectedThis = makeRef(*this), requestIdentifier, origin = origin.isolatedCopy(), cacheName = cacheName.isolatedCopy()](ScriptExecutionContext&) mutable {
     116    callOnMainThread([this, protectedThis = makeRef(*this), requestIdentifier, origin = origin.isolatedCopy(), cacheName = cacheName.isolatedCopy()]() mutable {
    120117        ASSERT(isMainThread());
    121118        ASSERT(m_mainThreadConnection);
     
    132129void WorkerCacheStorageConnection::doRemove(uint64_t requestIdentifier, uint64_t cacheIdentifier)
    133130{
    134     m_proxy.postTaskToLoader([this, protectedThis = makeRef(*this), requestIdentifier, cacheIdentifier](ScriptExecutionContext&) mutable {
     131    callOnMainThread([this, protectedThis = makeRef(*this), requestIdentifier, cacheIdentifier]() mutable {
    135132        ASSERT(isMainThread());
    136133        ASSERT(m_mainThreadConnection);
     
    148145void WorkerCacheStorageConnection::doRetrieveCaches(uint64_t requestIdentifier, const String& origin, uint64_t updateCounter)
    149146{
    150     m_proxy.postTaskToLoader([this, protectedThis = makeRef(*this), requestIdentifier, origin = origin.isolatedCopy(), updateCounter](ScriptExecutionContext&) mutable {
     147    callOnMainThread([this, protectedThis = makeRef(*this), requestIdentifier, origin = origin.isolatedCopy(), updateCounter]() mutable {
    151148        ASSERT(isMainThread());
    152149        ASSERT(m_mainThreadConnection);
     
    169166void WorkerCacheStorageConnection::reference(uint64_t cacheIdentifier)
    170167{
    171     m_proxy.postTaskToLoader([this, protectedThis = makeRef(*this), cacheIdentifier](ScriptExecutionContext&) {
     168    callOnMainThread([this, protectedThis = makeRef(*this), cacheIdentifier]() {
    172169        ASSERT(isMainThread());
    173170        ASSERT(m_mainThreadConnection);
     
    179176void WorkerCacheStorageConnection::dereference(uint64_t cacheIdentifier)
    180177{
    181     m_proxy.postTaskToLoader([this, protectedThis = makeRef(*this), cacheIdentifier](ScriptExecutionContext&) {
     178    callOnMainThread([this, protectedThis = makeRef(*this), cacheIdentifier]() {
    182179        ASSERT(isMainThread());
    183180        ASSERT(m_mainThreadConnection);
     
    214211void WorkerCacheStorageConnection::doRetrieveRecords(uint64_t requestIdentifier, uint64_t cacheIdentifier, const URL& url)
    215212{
    216     m_proxy.postTaskToLoader([this, protectedThis = makeRef(*this), requestIdentifier, cacheIdentifier, url = url.isolatedCopy()](ScriptExecutionContext&) mutable {
     213    callOnMainThread([this, protectedThis = makeRef(*this), requestIdentifier, cacheIdentifier, url = url.isolatedCopy()]() mutable {
    217214        ASSERT(isMainThread());
    218215        ASSERT(m_mainThreadConnection);
     
    229226void WorkerCacheStorageConnection::doBatchDeleteOperation(uint64_t requestIdentifier, uint64_t cacheIdentifier, const ResourceRequest& request, CacheQueryOptions&& options)
    230227{
    231     m_proxy.postTaskToLoader([this, protectedThis = makeRef(*this), requestIdentifier, cacheIdentifier, request = request.isolatedCopy(), options = options.isolatedCopy()](ScriptExecutionContext&) mutable {
     228    callOnMainThread([this, protectedThis = makeRef(*this), requestIdentifier, cacheIdentifier, request = request.isolatedCopy(), options = options.isolatedCopy()]() mutable {
    232229        ASSERT(isMainThread());
    233230        ASSERT(m_mainThreadConnection);
     
    245242void WorkerCacheStorageConnection::doBatchPutOperation(uint64_t requestIdentifier, uint64_t cacheIdentifier, Vector<Record>&& records)
    246243{
    247     m_proxy.postTaskToLoader([this, protectedThis = makeRef(*this), requestIdentifier, cacheIdentifier, recordsData = recordsDataFromRecords(records)](ScriptExecutionContext&) mutable {
     244    callOnMainThread([this, protectedThis = makeRef(*this), requestIdentifier, cacheIdentifier, recordsData = recordsDataFromRecords(records)]() mutable {
    248245        ASSERT(isMainThread());
    249246        ASSERT(m_mainThreadConnection);
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r223922 r223935  
    566566                188604B30F2E654A000B6443 /* DOMTimer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 188604B10F2E654A000B6443 /* DOMTimer.cpp */; };
    567567                188604B40F2E654A000B6443 /* DOMTimer.h in Headers */ = {isa = PBXBuildFile; fileRef = 188604B20F2E654A000B6443 /* DOMTimer.h */; settings = {ATTRIBUTES = (Private, ); }; };
    568                 18F831B80FD48C7800D8C56B /* WorkerLoaderProxy.h in Headers */ = {isa = PBXBuildFile; fileRef = 18F831B70FD48C7800D8C56B /* WorkerLoaderProxy.h */; };
     568                18F831B80FD48C7800D8C56B /* WorkerLoaderProxy.h in Headers */ = {isa = PBXBuildFile; fileRef = 18F831B70FD48C7800D8C56B /* WorkerLoaderProxy.h */; settings = {ATTRIBUTES = (Private, ); }; };
    569569                1921327411C0E6BB00456238 /* SVGFEConvolveMatrixElement.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1921327111C0E6BB00456238 /* SVGFEConvolveMatrixElement.cpp */; };
    570570                1921327511C0E6BB00456238 /* SVGFEConvolveMatrixElement.h in Headers */ = {isa = PBXBuildFile; fileRef = 1921327211C0E6BB00456238 /* SVGFEConvolveMatrixElement.h */; };
     
    13841384                41103AAE1E39791000769F03 /* RealtimeIncomingAudioSource.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 41103AAA1E39790A00769F03 /* RealtimeIncomingAudioSource.cpp */; };
    13851385                41103AAE1E39791000769F14 /* RealtimeIncomingAudioSourceCocoa.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 41103AAA1E39790A00769F14 /* RealtimeIncomingAudioSourceCocoa.cpp */; };
     1386                4112B5421F9F9CA000E67875 /* ServiceWorkerThreadProxy.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4112B5411F9F9C9C00E67875 /* ServiceWorkerThreadProxy.cpp */; };
     1387                4112B5431F9F9CA000E67875 /* ServiceWorkerThreadProxy.h in Headers */ = {isa = PBXBuildFile; fileRef = 4112B53F1F9F9C9B00E67875 /* ServiceWorkerThreadProxy.h */; settings = {ATTRIBUTES = (Private, ); }; };
    13861388                4123081B138C429700BCCFCA /* WebCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 93F19B1A08245E5A001E9ABC /* WebCore.framework */; };
    13871389                41230913138C42FF00BCCFCA /* JavaScriptCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F8216299029F4FB501000131 /* JavaScriptCore.framework */; };
     
    82338235                41103AAA1E39790A00769F03 /* RealtimeIncomingAudioSource.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RealtimeIncomingAudioSource.cpp; sourceTree = "<group>"; };
    82348236                41103AAA1E39790A00769F14 /* RealtimeIncomingAudioSourceCocoa.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RealtimeIncomingAudioSourceCocoa.cpp; sourceTree = "<group>"; };
     8237                4112B53F1F9F9C9B00E67875 /* ServiceWorkerThreadProxy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ServiceWorkerThreadProxy.h; sourceTree = "<group>"; };
     8238                4112B5411F9F9C9C00E67875 /* ServiceWorkerThreadProxy.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ServiceWorkerThreadProxy.cpp; sourceTree = "<group>"; };
    82358239                41189EF71AD8232800B90A0D /* ReadableStreamDefaultController.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = ReadableStreamDefaultController.idl; sourceTree = "<group>"; };
    82368240                41189EF71AD8232800B93F64 /* ReadableByteStreamController.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = ReadableByteStreamController.idl; sourceTree = "<group>"; };
     
    1817918183                                517C87111F8EE72F00EB8076 /* ServiceWorkerThread.cpp */,
    1818018184                                517C87101F8EE72E00EB8076 /* ServiceWorkerThread.h */,
     18185                                4112B5411F9F9C9C00E67875 /* ServiceWorkerThreadProxy.cpp */,
     18186                                4112B53F1F9F9C9B00E67875 /* ServiceWorkerThreadProxy.h */,
    1818118187                        );
    1818218188                        path = context;
     
    2958129587                                51F175691F3EBC8300C74950 /* ServiceWorkerRegistrationOptions.h in Headers */,
    2958229588                                51BCCE301F8F179E006BA0ED /* ServiceWorkerThread.h in Headers */,
     29589                                4112B5431F9F9CA000E67875 /* ServiceWorkerThreadProxy.h in Headers */,
    2958329590                                51F1756C1F3EBC8300C74950 /* ServiceWorkerUpdateViaCache.h in Headers */,
    2958429591                                46EF142A1F97B7D800C2A524 /* ServiceWorkerWindowClient.h in Headers */,
     
    3210932116                                51F645A21F4BF53C00B54DED /* ServiceWorkerRegistrationOptions.cpp in Sources */,
    3211032117                                51BCCE2F1F8F1795006BA0ED /* ServiceWorkerThread.cpp in Sources */,
     32118                                4112B5421F9F9CA000E67875 /* ServiceWorkerThreadProxy.cpp in Sources */,
    3211132119                                46EF142E1F97B7D800C2A524 /* ServiceWorkerWindowClient.cpp in Sources */,
    3211232120                                7CD58DFD1F9565A800112791 /* Settings.cpp in Sources */,
  • trunk/Source/WebCore/workers/WorkerLoaderProxy.h

    r223728 r223935  
    3535namespace WebCore {
    3636
    37     // A proxy to talk to the loader context. Normally, the document on the main thread
    38     // provides loading services for the subordinate workers. This interface provides 2-way
    39     // communications to the Document context and back to the worker.
    40     // Note that in multi-process browsers, the Worker object context and the Document
    41     // context can be distinct.
    42     class WorkerLoaderProxy {
    43     public:
    44         virtual ~WorkerLoaderProxy() = default;
     37class CacheStorageConnection;
    4538
    46         // Posts a task to the thread which runs the loading code (normally, the main thread).
    47         virtual void postTaskToLoader(ScriptExecutionContext::Task&&) = 0;
     39// A proxy to talk to the loader context. Normally, the document on the main thread
     40// provides loading services for the subordinate workers. This interface provides 2-way
     41// communications to the Document context and back to the worker.
     42// Note that in multi-process browsers, the Worker object context and the Document
     43// context can be distinct.
     44class WorkerLoaderProxy {
     45public:
     46    virtual ~WorkerLoaderProxy() = default;
    4847
    49         // Posts callbacks from loading code to the WorkerGlobalScope. The 'mode' is used to differentiate
    50         // specific synchronous loading requests so they can be 'nested', per spec.
    51         // Returns true if the task was posted successfully.
    52         virtual bool postTaskForModeToWorkerGlobalScope(ScriptExecutionContext::Task&&, const String& mode) = 0;
    53     };
     48    // Creates a cache storage connection to be used on the main thread. Method must be called on the main thread.
     49    virtual Ref<CacheStorageConnection> createCacheStorageConnection() = 0;
     50
     51    // Posts a task to the thread which runs the loading code (normally, the main thread).
     52    virtual void postTaskToLoader(ScriptExecutionContext::Task&&) = 0;
     53
     54    // Posts callbacks from loading code to the WorkerGlobalScope. The 'mode' is used to differentiate
     55    // specific synchronous loading requests so they can be 'nested', per spec.
     56    // Returns true if the task was posted successfully.
     57    virtual bool postTaskForModeToWorkerGlobalScope(ScriptExecutionContext::Task&&, const String& mode) = 0;
     58};
    5459
    5560} // namespace WebCore
  • trunk/Source/WebCore/workers/WorkerMessagingProxy.cpp

    r223732 r223935  
    2929#include "WorkerMessagingProxy.h"
    3030
     31#include "CacheStorageProvider.h"
    3132#include "ContentSecurityPolicy.h"
    3233#include "DOMWindow.h"
     
    3738#include "EventNames.h"
    3839#include "MessageEvent.h"
     40#include "Page.h"
    3941#include "ScriptExecutionContext.h"
    4042#include "Worker.h"
     
    134136}
    135137
     138Ref<CacheStorageConnection> WorkerMessagingProxy::createCacheStorageConnection()
     139{
     140    ASSERT(isMainThread());
     141    auto& document = downcast<Document>(*m_scriptExecutionContext);
     142    return document.page()->cacheStorageProvider().createCacheStorageConnection(document.page()->sessionID());
     143}
     144
    136145bool WorkerMessagingProxy::postTaskForModeToWorkerGlobalScope(ScriptExecutionContext::Task&& task, const String& mode)
    137146{
  • trunk/Source/WebCore/workers/WorkerMessagingProxy.h

    r223732 r223935  
    6868    void postTaskToLoader(ScriptExecutionContext::Task&&) final;
    6969    bool postTaskForModeToWorkerGlobalScope(ScriptExecutionContext::Task&&, const String& mode) final;
     70    Ref<CacheStorageConnection> createCacheStorageConnection() final;
    7071
    7172    void workerThreadCreated(DedicatedWorkerThread&);
  • trunk/Source/WebCore/workers/service/context/ServiceWorkerThread.cpp

    r223922 r223935  
    2929#if ENABLE(SERVICE_WORKER)
    3030
     31#include "CacheStorageProvider.h"
    3132#include "ContentSecurityPolicyResponseHeaders.h"
    3233#include "ExtendableMessageEvent.h"
     
    4445namespace WebCore {
    4546
    46 class ServiceWorkerThreadProxy : public WorkerLoaderProxy, public WorkerObjectProxy {
     47class DummyServiceWorkerThreadProxy : public WorkerObjectProxy {
    4748public:
    48     static ServiceWorkerThreadProxy& sharedDummyProxy()
     49    static DummyServiceWorkerThreadProxy& shared()
    4950    {
    50         static NeverDestroyed<ServiceWorkerThreadProxy> proxy;
     51        static NeverDestroyed<DummyServiceWorkerThreadProxy> proxy;
    5152        return proxy;
    5253    }
    5354
    5455private:
    55     void postTaskToLoader(ScriptExecutionContext::Task&&) final { };
    56     bool postTaskForModeToWorkerGlobalScope(ScriptExecutionContext::Task&&, const String&) final { return false; };
    5756    void postExceptionToWorkerObject(const String&, int, int, const String&) final { };
    5857    void postMessageToPageInspector(const String&) final { };
     
    7170// FIXME: Use valid runtime flags
    7271
    73 ServiceWorkerThread::ServiceWorkerThread(uint64_t serverConnectionIdentifier, const ServiceWorkerContextData& data, PAL::SessionID)
    74     : 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())
     72ServiceWorkerThread::ServiceWorkerThread(uint64_t serverConnectionIdentifier, const ServiceWorkerContextData& data, PAL::SessionID, WorkerLoaderProxy& loaderProxy)
     73    : 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())
    7574    , m_serverConnectionIdentifier(serverConnectionIdentifier)
    7675    , m_data(data.isolatedCopy())
    77     , m_workerObjectProxy(ServiceWorkerThreadProxy::sharedDummyProxy())
     76    , m_workerObjectProxy(DummyServiceWorkerThreadProxy::shared())
    7877{
    7978    AtomicString::init();
  • trunk/Source/WebCore/workers/service/context/ServiceWorkerThread.h

    r223922 r223935  
    3535namespace WebCore {
    3636
     37class CacheStorageProvider;
    3738class ContentSecurityPolicyResponseHeaders;
    3839class MessagePortChannel;
     
    6162
    6263private:
    63     WEBCORE_EXPORT ServiceWorkerThread(uint64_t serverConnectionIdentifier, const ServiceWorkerContextData&, PAL::SessionID);
     64    WEBCORE_EXPORT ServiceWorkerThread(uint64_t serverConnectionIdentifier, const ServiceWorkerContextData&, PAL::SessionID, WorkerLoaderProxy&);
    6465
    6566    uint64_t m_serverConnectionIdentifier;
  • trunk/Source/WebCore/workers/service/context/ServiceWorkerThreadProxy.h

    r223934 r223935  
    2828#if ENABLE(SERVICE_WORKER)
    2929
    30 #include "Connection.h"
    31 #include "MessageReceiver.h"
    32 #include <WebCore/ServiceWorkerThread.h>
     30#include "CacheStorageConnection.h"
     31#include "Document.h"
     32#include "Page.h"
     33#include "ServiceWorkerThread.h"
     34#include "WorkerLoaderProxy.h"
    3335#include <wtf/HashMap.h>
    3436
    3537namespace WebCore {
    36 struct FetchOptions;
    37 class ResourceRequest;
     38class CacheStorageProvider;
     39class PageConfiguration;
    3840struct ServiceWorkerContextData;
    39 }
    4041
    41 namespace WebKit {
     42class ServiceWorkerThreadProxy final : public ThreadSafeRefCounted<ServiceWorkerThreadProxy>, public WorkerLoaderProxy {
     43public:
     44    WEBCORE_EXPORT static Ref<ServiceWorkerThreadProxy> create(uint64_t serverConnectionIdentifier, const ServiceWorkerContextData&, PAL::SessionID, CacheStorageProvider&);
    4245
    43 class ServiceWorkerContextManager : public IPC::MessageReceiver {
    44 public:
    45     explicit ServiceWorkerContextManager(Ref<IPC::Connection>&& connection)
    46         : m_connectionToStorageProcess(WTFMove(connection))
    47     {
    48     }
    49 
    50     void didReceiveMessage(IPC::Connection&, IPC::Decoder&) final;
     46    uint64_t identifier() const { return m_serviceWorkerThread->identifier(); }
     47    ServiceWorkerThread& thread() { return m_serviceWorkerThread.get(); }
    5148
    5249private:
    53     void startServiceWorker(uint64_t serverConnectionIdentifier, const WebCore::ServiceWorkerContextData&);
    54     void startFetch(uint64_t serverConnectionIdentifier, uint64_t fetchIdentifier, uint64_t serviceWorkerIdentifier, WebCore::ResourceRequest&&, WebCore::FetchOptions&&);
    55     void postMessageToServiceWorkerGlobalScope(uint64_t serverConnectionIdentifier, uint64_t serviceWorkerIdentifier, const IPC::DataReference& message, const String& sourceOrigin);
     50    ServiceWorkerThreadProxy(uint64_t serverConnectionIdentifier, const ServiceWorkerContextData&, PAL::SessionID, CacheStorageProvider&);
     51    bool postTaskForModeToWorkerGlobalScope(ScriptExecutionContext::Task&&, const String& mode) final;
     52    void postTaskToLoader(ScriptExecutionContext::Task&&) final;
     53    Ref<CacheStorageConnection> createCacheStorageConnection() final;
    5654
    57     Ref<IPC::Connection> m_connectionToStorageProcess;
    58     HashMap<uint64_t, RefPtr<WebCore::ServiceWorkerThread>> m_workerThreadMap;
     55    Ref<ServiceWorkerThread> m_serviceWorkerThread;
     56    CacheStorageProvider& m_cacheStorageProvider;
     57    RefPtr<CacheStorageConnection> m_cacheStorageConnection;
     58    PAL::SessionID m_sessionID;
    5959};
    6060
  • trunk/Source/WebKit/ChangeLog

    r223934 r223935  
     12017-10-24  Youenn Fablet  <youenn@apple.com>
     2
     3        Enable service worker to use cache storage api
     4        https://bugs.webkit.org/show_bug.cgi?id=178684
     5
     6        Reviewed by Brady Eidson.
     7
     8        Passing the WebPreferences store of the default page group of the WebProcessPool to its ServiceWorker process.
     9        ServiceWorkerContextManager then uses it to initialize the preferences accordingly.
     10        Patch is covered by new test which is using cache api previously disabled and now enabled through the store.
     11
     12        Made use of the new ServiceWorkerThreadProxy in ServiceWorkerContextManager to enable a cache storage connection.
     13        Fixed the default size of quota in WebsiteDataStore.
     14
     15        * UIProcess/WebProcessPool.cpp:
     16        (WebKit::WebProcessPool::getWorkerContextProcessConnection):
     17        * UIProcess/WebsiteData/WebsiteDataStore.h:
     18        * WebProcess/Storage/ServiceWorkerContextManager.cpp:
     19        (WebKit::ServiceWorkerContextManager::ServiceWorkerContextManager):
     20        (WebKit::ServiceWorkerContextManager::updatePreferences):
     21        (WebKit::ServiceWorkerContextManager::startServiceWorker):
     22        (WebKit::ServiceWorkerContextManager::startFetch):
     23        * WebProcess/Storage/ServiceWorkerContextManager.h:
     24        (WebKit::ServiceWorkerContextManager::ServiceWorkerContextManager): Deleted.
     25        * WebProcess/WebProcess.cpp:
     26        (WebKit::WebProcess::getWorkerContextConnection):
     27        * WebProcess/WebProcess.h:
     28        * WebProcess/WebProcess.messages.in:
     29
    1302017-10-24  Alex Christensen  <achristensen@webkit.org>
    231
  • trunk/Source/WebKit/UIProcess/WebProcessPool.cpp

    r223890 r223935  
    597597    auto& newProcess = createNewWebProcess(m_websiteDataStore->websiteDataStore());
    598598    m_workerContextProcess = &newProcess;
    599     m_workerContextProcess->send(Messages::WebProcess::GetWorkerContextConnection(), 0);
     599    m_workerContextProcess->send(Messages::WebProcess::GetWorkerContextConnection(m_defaultPageGroup->preferences().store()), 0);
    600600}
    601601
  • trunk/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.h

    r223791 r223935  
    6969class WebsiteDataStore : public RefCounted<WebsiteDataStore>, public WebProcessLifetimeObserver, public Identified<WebsiteDataStore>  {
    7070public:
     71    constexpr static uint64_t defaultCacheStoragePerOriginQuota = 20 * 1024 * 1024;
     72
    7173    struct Configuration {
    7274        String cacheStorageDirectory;
    73         uint64_t cacheStoragePerOriginQuota;
     75        uint64_t cacheStoragePerOriginQuota { defaultCacheStoragePerOriginQuota };
    7476        String networkCacheDirectory;
    7577        String applicationCacheDirectory;
     
    8991    virtual ~WebsiteDataStore();
    9092
    91     constexpr static uint64_t defaultCacheStoragePerOriginQuota = 20 * 1024 * 1024;
    92 
    9393    bool isPersistent() const { return !m_sessionID.isEphemeral(); }
    9494    PAL::SessionID sessionID() const { return m_sessionID; }
  • trunk/Source/WebKit/WebProcess/Storage/ServiceWorkerContextManager.cpp

    r223922 r223935  
    3232#include "Logging.h"
    3333#include "StorageProcessMessages.h"
     34#include "WebCacheStorageProvider.h"
    3435#include "WebCoreArgumentCoders.h"
     36#include "WebPreferencesKeys.h"
     37#include "WebPreferencesStore.h"
     38#include "WebProcess.h"
    3539#include "WebServiceWorkerFetchTaskClient.h"
    3640#include <WebCore/MessagePortChannel.h>
    3741#include <WebCore/ResourceRequest.h>
    3842#include <WebCore/ResourceResponse.h>
     43#include <WebCore/RuntimeEnabledFeatures.h>
    3944#include <WebCore/SerializedScriptValue.h>
    4045#include <pal/SessionID.h>
     
    4550namespace WebKit {
    4651
     52ServiceWorkerContextManager::ServiceWorkerContextManager(Ref<IPC::Connection>&& connection, const WebPreferencesStore& store)
     53    : m_connectionToStorageProcess(WTFMove(connection))
     54{
     55    updatePreferences(store);
     56}
     57
     58void ServiceWorkerContextManager::updatePreferences(const WebPreferencesStore& store)
     59{
     60    RuntimeEnabledFeatures::sharedFeatures().setCacheAPIEnabled(store.getBoolValueForKey(WebPreferencesKey::cacheAPIEnabledKey()));
     61    RuntimeEnabledFeatures::sharedFeatures().setFetchAPIEnabled(store.getBoolValueForKey(WebPreferencesKey::fetchAPIEnabledKey()));
     62}
     63
    4764void ServiceWorkerContextManager::startServiceWorker(uint64_t serverConnectionIdentifier, const ServiceWorkerContextData& data)
    4865{
    4966    // FIXME: Provide a sensical session ID.
    50     auto thread = ServiceWorkerThread::create(serverConnectionIdentifier, data, SessionID::defaultSessionID());
    51     auto threadIdentifier = thread->identifier();
    52     auto result = m_workerThreadMap.add(threadIdentifier, WTFMove(thread));
    53     ASSERT(result.isNewEntry);
    54 
    55     result.iterator->value->start();
     67    auto serviceWorker = ServiceWorkerThreadProxy::create(serverConnectionIdentifier, data, SessionID::defaultSessionID(), WebProcess::singleton().cacheStorageProvider());
     68    auto serviceWorkerIdentifier = serviceWorker->identifier();
     69    auto result = m_workerMap.add(serviceWorkerIdentifier, WTFMove(serviceWorker));
     70    ASSERT_UNUSED(result, result.isNewEntry);
    5671
    5772    LOG(ServiceWorker, "Context process PID: %i started worker thread %s\n", getpid(), data.workerID.utf8().data());
    5873
    59     m_connectionToStorageProcess->send(Messages::StorageProcess::ServiceWorkerContextStarted(serverConnectionIdentifier, data.registrationKey, threadIdentifier, data.workerID), 0);
     74    m_connectionToStorageProcess->send(Messages::StorageProcess::ServiceWorkerContextStarted(serverConnectionIdentifier, data.registrationKey, serviceWorkerIdentifier, data.workerID), 0);
    6075}
    6176
    6277void ServiceWorkerContextManager::startFetch(uint64_t serverConnectionIdentifier, uint64_t fetchIdentifier, uint64_t serviceWorkerIdentifier, ResourceRequest&& request, FetchOptions&& options)
    6378{
    64     auto serviceWorkerThread = m_workerThreadMap.get(serviceWorkerIdentifier);
    65     if (!serviceWorkerThread) {
     79    auto serviceWorker = m_workerMap.get(serviceWorkerIdentifier);
     80    if (!serviceWorker) {
    6681        m_connectionToStorageProcess->send(Messages::StorageProcess::DidNotHandleFetch(serverConnectionIdentifier, fetchIdentifier), 0);
    6782        return;
     
    6984
    7085    auto client = WebServiceWorkerFetchTaskClient::create(m_connectionToStorageProcess.copyRef(), serverConnectionIdentifier, fetchIdentifier);
    71     serviceWorkerThread->postFetchTask(WTFMove(client), WTFMove(request), WTFMove(options));
     86    serviceWorker->thread().postFetchTask(WTFMove(client), WTFMove(request), WTFMove(options));
    7287}
    7388
    7489void ServiceWorkerContextManager::postMessageToServiceWorkerGlobalScope(uint64_t serverConnectionIdentifier, uint64_t serviceWorkerIdentifier, const IPC::DataReference& message, const String& sourceOrigin)
    7590{
    76     auto* workerThread = m_workerThreadMap.get(serviceWorkerIdentifier);
    77     if (!workerThread)
     91    auto* serviceWorker = m_workerMap.get(serviceWorkerIdentifier);
     92    if (!serviceWorker)
    7893        return;
    7994
    8095    // FIXME: We should pass valid MessagePortChannels.
    81     workerThread->postMessageToServiceWorkerGlobalScope(SerializedScriptValue::adopt(message.vector()), nullptr, sourceOrigin);
     96    serviceWorker->thread().postMessageToServiceWorkerGlobalScope(SerializedScriptValue::adopt(message.vector()), nullptr, sourceOrigin);
    8297}
    8398
  • trunk/Source/WebKit/WebProcess/Storage/ServiceWorkerContextManager.h

    r223922 r223935  
    3030#include "Connection.h"
    3131#include "MessageReceiver.h"
    32 #include <WebCore/ServiceWorkerThread.h>
     32#include <WebCore/ServiceWorkerThreadProxy.h>
    3333#include <wtf/HashMap.h>
    3434
     
    4040
    4141namespace WebKit {
     42struct WebPreferencesStore;
    4243
    4344class ServiceWorkerContextManager : public IPC::MessageReceiver {
    4445public:
    45     explicit ServiceWorkerContextManager(Ref<IPC::Connection>&& connection)
    46         : m_connectionToStorageProcess(WTFMove(connection))
    47     {
    48     }
     46    ServiceWorkerContextManager(Ref<IPC::Connection>&&, const WebPreferencesStore&);
    4947
    5048    void didReceiveMessage(IPC::Connection&, IPC::Decoder&) final;
    5149
    5250private:
     51    void updatePreferences(const WebPreferencesStore&);
     52
    5353    void startServiceWorker(uint64_t serverConnectionIdentifier, const WebCore::ServiceWorkerContextData&);
    5454    void startFetch(uint64_t serverConnectionIdentifier, uint64_t fetchIdentifier, uint64_t serviceWorkerIdentifier, WebCore::ResourceRequest&&, WebCore::FetchOptions&&);
     
    5656
    5757    Ref<IPC::Connection> m_connectionToStorageProcess;
    58     HashMap<uint64_t, RefPtr<WebCore::ServiceWorkerThread>> m_workerThreadMap;
     58    HashMap<uint64_t, RefPtr<WebCore::ServiceWorkerThreadProxy>> m_workerMap;
    5959};
    6060
  • trunk/Source/WebKit/WebProcess/WebProcess.cpp

    r223791 r223935  
    16411641
    16421642#if ENABLE(SERVICE_WORKER)
    1643 void WebProcess::getWorkerContextConnection()
     1643void WebProcess::getWorkerContextConnection(const WebPreferencesStore& store)
    16441644{
    16451645    ASSERT(!m_serviceWorkerManager);
     
    16651665    auto workerContextConnection = IPC::Connection::createServerConnection(connectionIdentifier, *this);
    16661666    workerContextConnection->open();
    1667     m_serviceWorkerManager =  ServiceWorkerContextManager(WTFMove(workerContextConnection));
     1667    m_serviceWorkerManager =  ServiceWorkerContextManager(WTFMove(workerContextConnection), store);
    16681668    WebProcess::singleton().parentProcessConnection()->send(Messages::WebProcessProxy::DidGetWorkerContextConnection(connectionClientPort), 0);
    16691669}
  • trunk/Source/WebKit/WebProcess/WebProcess.h

    r223739 r223935  
    300300#endif
    301301#if ENABLE(SERVICE_WORKER)
    302     void getWorkerContextConnection();
     302    void getWorkerContextConnection(const WebPreferencesStore&);
    303303#endif
    304304
  • trunk/Source/WebKit/WebProcess/WebProcess.messages.in

    r223739 r223935  
    116116
    117117#if ENABLE(SERVICE_WORKER)
    118     GetWorkerContextConnection()
     118    GetWorkerContextConnection(struct WebKit::WebPreferencesStore store)
    119119#endif
    120120}
Note: See TracChangeset for help on using the changeset viewer.