Changeset 223935 in webkit
- Timestamp:
- Oct 24, 2017 3:28:44 PM (7 years ago)
- Location:
- trunk
- Files:
-
- 5 added
- 17 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r223932 r223935 1 2017-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 1 13 2017-10-24 Matt Lewis <jlewis3@apple.com> 2 14 -
trunk/Source/WebCore/ChangeLog
r223933 r223935 1 2017-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 1 45 2017-10-24 Alex Christensen <achristensen@webkit.org> 2 46 -
trunk/Source/WebCore/Modules/cache/WorkerCacheStorageConnection.cpp
r223476 r223935 92 92 { 93 93 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(); 100 97 }); 101 98 return connection; … … 112 109 { 113 110 if (m_mainThreadConnection) 114 m_proxy.postTaskToLoader([mainThreadConnection = WTFMove(m_mainThreadConnection)](ScriptExecutionContext&) mutable { });111 callOnMainThread([mainThreadConnection = WTFMove(m_mainThreadConnection)]() mutable { }); 115 112 } 116 113 117 114 void WorkerCacheStorageConnection::doOpen(uint64_t requestIdentifier, const String& origin, const String& cacheName) 118 115 { 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 { 120 117 ASSERT(isMainThread()); 121 118 ASSERT(m_mainThreadConnection); … … 132 129 void WorkerCacheStorageConnection::doRemove(uint64_t requestIdentifier, uint64_t cacheIdentifier) 133 130 { 134 m_proxy.postTaskToLoader([this, protectedThis = makeRef(*this), requestIdentifier, cacheIdentifier](ScriptExecutionContext&) mutable {131 callOnMainThread([this, protectedThis = makeRef(*this), requestIdentifier, cacheIdentifier]() mutable { 135 132 ASSERT(isMainThread()); 136 133 ASSERT(m_mainThreadConnection); … … 148 145 void WorkerCacheStorageConnection::doRetrieveCaches(uint64_t requestIdentifier, const String& origin, uint64_t updateCounter) 149 146 { 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 { 151 148 ASSERT(isMainThread()); 152 149 ASSERT(m_mainThreadConnection); … … 169 166 void WorkerCacheStorageConnection::reference(uint64_t cacheIdentifier) 170 167 { 171 m_proxy.postTaskToLoader([this, protectedThis = makeRef(*this), cacheIdentifier](ScriptExecutionContext&) {168 callOnMainThread([this, protectedThis = makeRef(*this), cacheIdentifier]() { 172 169 ASSERT(isMainThread()); 173 170 ASSERT(m_mainThreadConnection); … … 179 176 void WorkerCacheStorageConnection::dereference(uint64_t cacheIdentifier) 180 177 { 181 m_proxy.postTaskToLoader([this, protectedThis = makeRef(*this), cacheIdentifier](ScriptExecutionContext&) {178 callOnMainThread([this, protectedThis = makeRef(*this), cacheIdentifier]() { 182 179 ASSERT(isMainThread()); 183 180 ASSERT(m_mainThreadConnection); … … 214 211 void WorkerCacheStorageConnection::doRetrieveRecords(uint64_t requestIdentifier, uint64_t cacheIdentifier, const URL& url) 215 212 { 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 { 217 214 ASSERT(isMainThread()); 218 215 ASSERT(m_mainThreadConnection); … … 229 226 void WorkerCacheStorageConnection::doBatchDeleteOperation(uint64_t requestIdentifier, uint64_t cacheIdentifier, const ResourceRequest& request, CacheQueryOptions&& options) 230 227 { 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 { 232 229 ASSERT(isMainThread()); 233 230 ASSERT(m_mainThreadConnection); … … 245 242 void WorkerCacheStorageConnection::doBatchPutOperation(uint64_t requestIdentifier, uint64_t cacheIdentifier, Vector<Record>&& records) 246 243 { 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 { 248 245 ASSERT(isMainThread()); 249 246 ASSERT(m_mainThreadConnection); -
trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj
r223922 r223935 566 566 188604B30F2E654A000B6443 /* DOMTimer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 188604B10F2E654A000B6443 /* DOMTimer.cpp */; }; 567 567 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, ); }; }; 569 569 1921327411C0E6BB00456238 /* SVGFEConvolveMatrixElement.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1921327111C0E6BB00456238 /* SVGFEConvolveMatrixElement.cpp */; }; 570 570 1921327511C0E6BB00456238 /* SVGFEConvolveMatrixElement.h in Headers */ = {isa = PBXBuildFile; fileRef = 1921327211C0E6BB00456238 /* SVGFEConvolveMatrixElement.h */; }; … … 1384 1384 41103AAE1E39791000769F03 /* RealtimeIncomingAudioSource.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 41103AAA1E39790A00769F03 /* RealtimeIncomingAudioSource.cpp */; }; 1385 1385 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, ); }; }; 1386 1388 4123081B138C429700BCCFCA /* WebCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 93F19B1A08245E5A001E9ABC /* WebCore.framework */; }; 1387 1389 41230913138C42FF00BCCFCA /* JavaScriptCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F8216299029F4FB501000131 /* JavaScriptCore.framework */; }; … … 8233 8235 41103AAA1E39790A00769F03 /* RealtimeIncomingAudioSource.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RealtimeIncomingAudioSource.cpp; sourceTree = "<group>"; }; 8234 8236 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>"; }; 8235 8239 41189EF71AD8232800B90A0D /* ReadableStreamDefaultController.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = ReadableStreamDefaultController.idl; sourceTree = "<group>"; }; 8236 8240 41189EF71AD8232800B93F64 /* ReadableByteStreamController.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = ReadableByteStreamController.idl; sourceTree = "<group>"; }; … … 18179 18183 517C87111F8EE72F00EB8076 /* ServiceWorkerThread.cpp */, 18180 18184 517C87101F8EE72E00EB8076 /* ServiceWorkerThread.h */, 18185 4112B5411F9F9C9C00E67875 /* ServiceWorkerThreadProxy.cpp */, 18186 4112B53F1F9F9C9B00E67875 /* ServiceWorkerThreadProxy.h */, 18181 18187 ); 18182 18188 path = context; … … 29581 29587 51F175691F3EBC8300C74950 /* ServiceWorkerRegistrationOptions.h in Headers */, 29582 29588 51BCCE301F8F179E006BA0ED /* ServiceWorkerThread.h in Headers */, 29589 4112B5431F9F9CA000E67875 /* ServiceWorkerThreadProxy.h in Headers */, 29583 29590 51F1756C1F3EBC8300C74950 /* ServiceWorkerUpdateViaCache.h in Headers */, 29584 29591 46EF142A1F97B7D800C2A524 /* ServiceWorkerWindowClient.h in Headers */, … … 32109 32116 51F645A21F4BF53C00B54DED /* ServiceWorkerRegistrationOptions.cpp in Sources */, 32110 32117 51BCCE2F1F8F1795006BA0ED /* ServiceWorkerThread.cpp in Sources */, 32118 4112B5421F9F9CA000E67875 /* ServiceWorkerThreadProxy.cpp in Sources */, 32111 32119 46EF142E1F97B7D800C2A524 /* ServiceWorkerWindowClient.cpp in Sources */, 32112 32120 7CD58DFD1F9565A800112791 /* Settings.cpp in Sources */, -
trunk/Source/WebCore/workers/WorkerLoaderProxy.h
r223728 r223935 35 35 namespace WebCore { 36 36 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; 37 class CacheStorageConnection; 45 38 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. 44 class WorkerLoaderProxy { 45 public: 46 virtual ~WorkerLoaderProxy() = default; 48 47 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 }; 54 59 55 60 } // namespace WebCore -
trunk/Source/WebCore/workers/WorkerMessagingProxy.cpp
r223732 r223935 29 29 #include "WorkerMessagingProxy.h" 30 30 31 #include "CacheStorageProvider.h" 31 32 #include "ContentSecurityPolicy.h" 32 33 #include "DOMWindow.h" … … 37 38 #include "EventNames.h" 38 39 #include "MessageEvent.h" 40 #include "Page.h" 39 41 #include "ScriptExecutionContext.h" 40 42 #include "Worker.h" … … 134 136 } 135 137 138 Ref<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 136 145 bool WorkerMessagingProxy::postTaskForModeToWorkerGlobalScope(ScriptExecutionContext::Task&& task, const String& mode) 137 146 { -
trunk/Source/WebCore/workers/WorkerMessagingProxy.h
r223732 r223935 68 68 void postTaskToLoader(ScriptExecutionContext::Task&&) final; 69 69 bool postTaskForModeToWorkerGlobalScope(ScriptExecutionContext::Task&&, const String& mode) final; 70 Ref<CacheStorageConnection> createCacheStorageConnection() final; 70 71 71 72 void workerThreadCreated(DedicatedWorkerThread&); -
trunk/Source/WebCore/workers/service/context/ServiceWorkerThread.cpp
r223922 r223935 29 29 #if ENABLE(SERVICE_WORKER) 30 30 31 #include "CacheStorageProvider.h" 31 32 #include "ContentSecurityPolicyResponseHeaders.h" 32 33 #include "ExtendableMessageEvent.h" … … 44 45 namespace WebCore { 45 46 46 class ServiceWorkerThreadProxy : public WorkerLoaderProxy,public WorkerObjectProxy {47 class DummyServiceWorkerThreadProxy : public WorkerObjectProxy { 47 48 public: 48 static ServiceWorkerThreadProxy& sharedDummyProxy()49 static DummyServiceWorkerThreadProxy& shared() 49 50 { 50 static NeverDestroyed< ServiceWorkerThreadProxy> proxy;51 static NeverDestroyed<DummyServiceWorkerThreadProxy> proxy; 51 52 return proxy; 52 53 } 53 54 54 55 private: 55 void postTaskToLoader(ScriptExecutionContext::Task&&) final { };56 bool postTaskForModeToWorkerGlobalScope(ScriptExecutionContext::Task&&, const String&) final { return false; };57 56 void postExceptionToWorkerObject(const String&, int, int, const String&) final { }; 58 57 void postMessageToPageInspector(const String&) final { }; … … 71 70 // FIXME: Use valid runtime flags 72 71 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())72 ServiceWorkerThread::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()) 75 74 , m_serverConnectionIdentifier(serverConnectionIdentifier) 76 75 , m_data(data.isolatedCopy()) 77 , m_workerObjectProxy( ServiceWorkerThreadProxy::sharedDummyProxy())76 , m_workerObjectProxy(DummyServiceWorkerThreadProxy::shared()) 78 77 { 79 78 AtomicString::init(); -
trunk/Source/WebCore/workers/service/context/ServiceWorkerThread.h
r223922 r223935 35 35 namespace WebCore { 36 36 37 class CacheStorageProvider; 37 38 class ContentSecurityPolicyResponseHeaders; 38 39 class MessagePortChannel; … … 61 62 62 63 private: 63 WEBCORE_EXPORT ServiceWorkerThread(uint64_t serverConnectionIdentifier, const ServiceWorkerContextData&, PAL::SessionID );64 WEBCORE_EXPORT ServiceWorkerThread(uint64_t serverConnectionIdentifier, const ServiceWorkerContextData&, PAL::SessionID, WorkerLoaderProxy&); 64 65 65 66 uint64_t m_serverConnectionIdentifier; -
trunk/Source/WebCore/workers/service/context/ServiceWorkerThreadProxy.h
r223934 r223935 28 28 #if ENABLE(SERVICE_WORKER) 29 29 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" 33 35 #include <wtf/HashMap.h> 34 36 35 37 namespace WebCore { 36 struct FetchOptions;37 class ResourceRequest;38 class CacheStorageProvider; 39 class PageConfiguration; 38 40 struct ServiceWorkerContextData; 39 }40 41 41 namespace WebKit { 42 class ServiceWorkerThreadProxy final : public ThreadSafeRefCounted<ServiceWorkerThreadProxy>, public WorkerLoaderProxy { 43 public: 44 WEBCORE_EXPORT static Ref<ServiceWorkerThreadProxy> create(uint64_t serverConnectionIdentifier, const ServiceWorkerContextData&, PAL::SessionID, CacheStorageProvider&); 42 45 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(); } 51 48 52 49 private: 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; 56 54 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; 59 59 }; 60 60 -
trunk/Source/WebKit/ChangeLog
r223934 r223935 1 2017-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 1 30 2017-10-24 Alex Christensen <achristensen@webkit.org> 2 31 -
trunk/Source/WebKit/UIProcess/WebProcessPool.cpp
r223890 r223935 597 597 auto& newProcess = createNewWebProcess(m_websiteDataStore->websiteDataStore()); 598 598 m_workerContextProcess = &newProcess; 599 m_workerContextProcess->send(Messages::WebProcess::GetWorkerContextConnection( ), 0);599 m_workerContextProcess->send(Messages::WebProcess::GetWorkerContextConnection(m_defaultPageGroup->preferences().store()), 0); 600 600 } 601 601 -
trunk/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.h
r223791 r223935 69 69 class WebsiteDataStore : public RefCounted<WebsiteDataStore>, public WebProcessLifetimeObserver, public Identified<WebsiteDataStore> { 70 70 public: 71 constexpr static uint64_t defaultCacheStoragePerOriginQuota = 20 * 1024 * 1024; 72 71 73 struct Configuration { 72 74 String cacheStorageDirectory; 73 uint64_t cacheStoragePerOriginQuota ;75 uint64_t cacheStoragePerOriginQuota { defaultCacheStoragePerOriginQuota }; 74 76 String networkCacheDirectory; 75 77 String applicationCacheDirectory; … … 89 91 virtual ~WebsiteDataStore(); 90 92 91 constexpr static uint64_t defaultCacheStoragePerOriginQuota = 20 * 1024 * 1024;92 93 93 bool isPersistent() const { return !m_sessionID.isEphemeral(); } 94 94 PAL::SessionID sessionID() const { return m_sessionID; } -
trunk/Source/WebKit/WebProcess/Storage/ServiceWorkerContextManager.cpp
r223922 r223935 32 32 #include "Logging.h" 33 33 #include "StorageProcessMessages.h" 34 #include "WebCacheStorageProvider.h" 34 35 #include "WebCoreArgumentCoders.h" 36 #include "WebPreferencesKeys.h" 37 #include "WebPreferencesStore.h" 38 #include "WebProcess.h" 35 39 #include "WebServiceWorkerFetchTaskClient.h" 36 40 #include <WebCore/MessagePortChannel.h> 37 41 #include <WebCore/ResourceRequest.h> 38 42 #include <WebCore/ResourceResponse.h> 43 #include <WebCore/RuntimeEnabledFeatures.h> 39 44 #include <WebCore/SerializedScriptValue.h> 40 45 #include <pal/SessionID.h> … … 45 50 namespace WebKit { 46 51 52 ServiceWorkerContextManager::ServiceWorkerContextManager(Ref<IPC::Connection>&& connection, const WebPreferencesStore& store) 53 : m_connectionToStorageProcess(WTFMove(connection)) 54 { 55 updatePreferences(store); 56 } 57 58 void ServiceWorkerContextManager::updatePreferences(const WebPreferencesStore& store) 59 { 60 RuntimeEnabledFeatures::sharedFeatures().setCacheAPIEnabled(store.getBoolValueForKey(WebPreferencesKey::cacheAPIEnabledKey())); 61 RuntimeEnabledFeatures::sharedFeatures().setFetchAPIEnabled(store.getBoolValueForKey(WebPreferencesKey::fetchAPIEnabledKey())); 62 } 63 47 64 void ServiceWorkerContextManager::startServiceWorker(uint64_t serverConnectionIdentifier, const ServiceWorkerContextData& data) 48 65 { 49 66 // 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); 56 71 57 72 LOG(ServiceWorker, "Context process PID: %i started worker thread %s\n", getpid(), data.workerID.utf8().data()); 58 73 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); 60 75 } 61 76 62 77 void ServiceWorkerContextManager::startFetch(uint64_t serverConnectionIdentifier, uint64_t fetchIdentifier, uint64_t serviceWorkerIdentifier, ResourceRequest&& request, FetchOptions&& options) 63 78 { 64 auto serviceWorker Thread = m_workerThreadMap.get(serviceWorkerIdentifier);65 if (!serviceWorker Thread) {79 auto serviceWorker = m_workerMap.get(serviceWorkerIdentifier); 80 if (!serviceWorker) { 66 81 m_connectionToStorageProcess->send(Messages::StorageProcess::DidNotHandleFetch(serverConnectionIdentifier, fetchIdentifier), 0); 67 82 return; … … 69 84 70 85 auto client = WebServiceWorkerFetchTaskClient::create(m_connectionToStorageProcess.copyRef(), serverConnectionIdentifier, fetchIdentifier); 71 serviceWorker Thread->postFetchTask(WTFMove(client), WTFMove(request), WTFMove(options));86 serviceWorker->thread().postFetchTask(WTFMove(client), WTFMove(request), WTFMove(options)); 72 87 } 73 88 74 89 void ServiceWorkerContextManager::postMessageToServiceWorkerGlobalScope(uint64_t serverConnectionIdentifier, uint64_t serviceWorkerIdentifier, const IPC::DataReference& message, const String& sourceOrigin) 75 90 { 76 auto* workerThread = m_workerThreadMap.get(serviceWorkerIdentifier);77 if (! workerThread)91 auto* serviceWorker = m_workerMap.get(serviceWorkerIdentifier); 92 if (!serviceWorker) 78 93 return; 79 94 80 95 // 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); 82 97 } 83 98 -
trunk/Source/WebKit/WebProcess/Storage/ServiceWorkerContextManager.h
r223922 r223935 30 30 #include "Connection.h" 31 31 #include "MessageReceiver.h" 32 #include <WebCore/ServiceWorkerThread .h>32 #include <WebCore/ServiceWorkerThreadProxy.h> 33 33 #include <wtf/HashMap.h> 34 34 … … 40 40 41 41 namespace WebKit { 42 struct WebPreferencesStore; 42 43 43 44 class ServiceWorkerContextManager : public IPC::MessageReceiver { 44 45 public: 45 explicit ServiceWorkerContextManager(Ref<IPC::Connection>&& connection) 46 : m_connectionToStorageProcess(WTFMove(connection)) 47 { 48 } 46 ServiceWorkerContextManager(Ref<IPC::Connection>&&, const WebPreferencesStore&); 49 47 50 48 void didReceiveMessage(IPC::Connection&, IPC::Decoder&) final; 51 49 52 50 private: 51 void updatePreferences(const WebPreferencesStore&); 52 53 53 void startServiceWorker(uint64_t serverConnectionIdentifier, const WebCore::ServiceWorkerContextData&); 54 54 void startFetch(uint64_t serverConnectionIdentifier, uint64_t fetchIdentifier, uint64_t serviceWorkerIdentifier, WebCore::ResourceRequest&&, WebCore::FetchOptions&&); … … 56 56 57 57 Ref<IPC::Connection> m_connectionToStorageProcess; 58 HashMap<uint64_t, RefPtr<WebCore::ServiceWorkerThread >> m_workerThreadMap;58 HashMap<uint64_t, RefPtr<WebCore::ServiceWorkerThreadProxy>> m_workerMap; 59 59 }; 60 60 -
trunk/Source/WebKit/WebProcess/WebProcess.cpp
r223791 r223935 1641 1641 1642 1642 #if ENABLE(SERVICE_WORKER) 1643 void WebProcess::getWorkerContextConnection( )1643 void WebProcess::getWorkerContextConnection(const WebPreferencesStore& store) 1644 1644 { 1645 1645 ASSERT(!m_serviceWorkerManager); … … 1665 1665 auto workerContextConnection = IPC::Connection::createServerConnection(connectionIdentifier, *this); 1666 1666 workerContextConnection->open(); 1667 m_serviceWorkerManager = ServiceWorkerContextManager(WTFMove(workerContextConnection) );1667 m_serviceWorkerManager = ServiceWorkerContextManager(WTFMove(workerContextConnection), store); 1668 1668 WebProcess::singleton().parentProcessConnection()->send(Messages::WebProcessProxy::DidGetWorkerContextConnection(connectionClientPort), 0); 1669 1669 } -
trunk/Source/WebKit/WebProcess/WebProcess.h
r223739 r223935 300 300 #endif 301 301 #if ENABLE(SERVICE_WORKER) 302 void getWorkerContextConnection( );302 void getWorkerContextConnection(const WebPreferencesStore&); 303 303 #endif 304 304 -
trunk/Source/WebKit/WebProcess/WebProcess.messages.in
r223739 r223935 116 116 117 117 #if ENABLE(SERVICE_WORKER) 118 GetWorkerContextConnection( )118 GetWorkerContextConnection(struct WebKit::WebPreferencesStore store) 119 119 #endif 120 120 }
Note: See TracChangeset
for help on using the changeset viewer.