ServiceWorker registration should store any script fetched through importScripts
authoryouenn@apple.com <youenn@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 5 Jun 2018 18:50:41 +0000 (18:50 +0000)
committeryouenn@apple.com <youenn@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 5 Jun 2018 18:50:41 +0000 (18:50 +0000)
commit40724099fef41167f19a4d2e2af404b38036e715
tree5acef53331445274dfc62f2d27f2524ebc9ac8fc
parent8e4019bf2e6e01d5c5c5127b5f82e56bb0da9d71
ServiceWorker registration should store any script fetched through importScripts
https://bugs.webkit.org/show_bug.cgi?id=182444
<rdar://problem/37164835>

Reviewed by Chris Dumez.

LayoutTests/imported/w3c:

* web-platform-tests/service-workers/service-worker/registration-mime-types.https-expected.txt:

Source/WebCore:

Covered by added test http/wpt/service-workers/persistent-importScripts.html.

Update importScripts implementation to look for/update the resource map in case of service worker scope.
This resource map is stored persistently and sent when running the service worker.

Add support to persistent storage of this resource map.
This requires updating the schema database.
The schema version is bumped to 2 and we delete any data related to old registrations.

When updating the service worker, the resource map is currently flushed so that all scripts will be retrieved from the network.

Did some limited refactoring to put more loading handling in WorkerScriptLoader.

* workers/WorkerGlobalScope.cpp:
(WebCore::WorkerGlobalScope::importScripts):
* workers/WorkerScriptLoader.cpp:
(WebCore::WorkerScriptLoader::loadSynchronously):
(WebCore::WorkerScriptLoader::script):
* workers/WorkerScriptLoader.h:
* workers/service/ServiceWorkerContextData.cpp:
(WebCore::ServiceWorkerContextData::isolatedCopy const):
* workers/service/ServiceWorkerContextData.h:
(WebCore::ServiceWorkerContextData::ImportedScript::isolatedCopy const):
(WebCore::ServiceWorkerContextData::ImportedScript::encode const):
(WebCore::ServiceWorkerContextData::ImportedScript::decode):
(WebCore::ServiceWorkerContextData::encode const):
(WebCore::ServiceWorkerContextData::decode):
* workers/service/ServiceWorkerGlobalScope.cpp:
(WebCore::ServiceWorkerGlobalScope::scriptResource const):
(WebCore::ServiceWorkerGlobalScope::setScriptResource):
* workers/service/ServiceWorkerGlobalScope.h:
* workers/service/context/SWContextManager.h:
* workers/service/server/RegistrationDatabase.cpp:
(WebCore::v1RecordsTableSchema):
(WebCore::RegistrationDatabase::doPushChanges):
(WebCore::RegistrationDatabase::importRecords):
* workers/service/server/SWServer.cpp:
(WebCore::SWServer::addRegistrationFromStore):
(WebCore::SWServer::updateWorker):
(WebCore::SWServer::installContextData):
* workers/service/server/SWServer.h:
* workers/service/server/SWServerJobQueue.cpp:
(WebCore::SWServerJobQueue::scriptFetchFinished):
* workers/service/server/SWServerToContextConnection.cpp:
(WebCore::SWServerToContextConnection::setScriptResource):
* workers/service/server/SWServerToContextConnection.h:
* workers/service/server/SWServerWorker.cpp:
(WebCore::SWServerWorker::SWServerWorker):
(WebCore::m_scriptResourceMap):
(WebCore::SWServerWorker::contextData const):
(WebCore::SWServerWorker::setScriptResource):
* workers/service/server/SWServerWorker.h:

Source/WebKit:

Add C API to kill storage process.
In case a Storage Process is closed or crashed, ensure that all its related service worker processes also exit.

* StorageProcess/ServiceWorker/WebSWServerToContextConnection.messages.in:
* UIProcess/API/C/WKContext.cpp:
(WKContextTerminateStorageProcess):
* UIProcess/API/C/WKContextPrivate.h:
* WebProcess/WebProcess.cpp:
(WebKit::WebProcess::webToStorageProcessConnectionClosed):
* WebProcess/Storage/WebSWContextManagerConnection.cpp:
(WebKit::WebSWContextManagerConnection::setScriptResource):
* WebProcess/Storage/WebSWContextManagerConnection.h:

Source/WTF:

* wtf/persistence/PersistentCoders.h:

Tools:

Add support to crash the storage process from Internals.

* WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl:
* WebKitTestRunner/InjectedBundle/TestRunner.cpp:
(WTR::TestRunner::terminateStorageProcess):
* WebKitTestRunner/InjectedBundle/TestRunner.h:
* WebKitTestRunner/TestController.cpp:
(WTR::TestController::terminateStorageProcess):
* WebKitTestRunner/TestController.h:
* WebKitTestRunner/TestInvocation.cpp:
(WTR::TestInvocation::didReceiveMessageFromInjectedBundle):

LayoutTests:

* http/wpt/service-workers/persistent-importScripts-expected.txt: Added.
* http/wpt/service-workers/persistent-importScripts.html: Added.
* http/wpt/service-workers/resources/persistent-importScripts-script.py: Added.
* http/wpt/service-workers/resources/persistent-importScripts-worker.js: Added.
* http/wpt/service-workers/resources/routines.js: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@232516 268f45cc-cd09-0410-ab3c-d52691b4dbfc
42 files changed:
LayoutTests/ChangeLog
LayoutTests/http/wpt/service-workers/persistent-importScripts-expected.txt [new file with mode: 0644]
LayoutTests/http/wpt/service-workers/persistent-importScripts.html [new file with mode: 0644]
LayoutTests/http/wpt/service-workers/resources/persistent-importScripts-script.py [new file with mode: 0644]
LayoutTests/http/wpt/service-workers/resources/persistent-importScripts-worker.js [new file with mode: 0644]
LayoutTests/http/wpt/service-workers/resources/routines.js [new file with mode: 0644]
LayoutTests/imported/w3c/ChangeLog
LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/registration-mime-types.https-expected.txt
Source/WTF/ChangeLog
Source/WTF/wtf/CrossThreadCopier.h
Source/WTF/wtf/persistence/PersistentCoders.h
Source/WebCore/ChangeLog
Source/WebCore/workers/WorkerGlobalScope.cpp
Source/WebCore/workers/WorkerScriptLoader.cpp
Source/WebCore/workers/WorkerScriptLoader.h
Source/WebCore/workers/service/ServiceWorkerContextData.cpp
Source/WebCore/workers/service/ServiceWorkerContextData.h
Source/WebCore/workers/service/ServiceWorkerGlobalScope.cpp
Source/WebCore/workers/service/ServiceWorkerGlobalScope.h
Source/WebCore/workers/service/context/SWContextManager.h
Source/WebCore/workers/service/server/RegistrationDatabase.cpp
Source/WebCore/workers/service/server/SWServer.cpp
Source/WebCore/workers/service/server/SWServer.h
Source/WebCore/workers/service/server/SWServerJobQueue.cpp
Source/WebCore/workers/service/server/SWServerToContextConnection.cpp
Source/WebCore/workers/service/server/SWServerToContextConnection.h
Source/WebCore/workers/service/server/SWServerWorker.cpp
Source/WebCore/workers/service/server/SWServerWorker.h
Source/WebKit/ChangeLog
Source/WebKit/StorageProcess/ServiceWorker/WebSWServerToContextConnection.messages.in
Source/WebKit/UIProcess/API/C/WKContext.cpp
Source/WebKit/UIProcess/API/C/WKContextPrivate.h
Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.cpp
Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.h
Source/WebKit/WebProcess/WebProcess.cpp
Tools/ChangeLog
Tools/WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl
Tools/WebKitTestRunner/InjectedBundle/TestRunner.cpp
Tools/WebKitTestRunner/InjectedBundle/TestRunner.h
Tools/WebKitTestRunner/TestController.cpp
Tools/WebKitTestRunner/TestController.h
Tools/WebKitTestRunner/TestInvocation.cpp