Add preliminary support for ServiceWorker Handle Fetch
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 19 Oct 2017 02:26:00 +0000 (02:26 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 19 Oct 2017 02:26:00 +0000 (02:26 +0000)
commitc3501dfcd3e91400f3062f02c8826a847d4fab94
treedd61d6790b73dc942fe746c0da28d8f70a882c30
parentc4523c1b2191a215c097ec17e13894a5075575c9
Add preliminary support for ServiceWorker Handle Fetch
https://bugs.webkit.org/show_bug.cgi?id=178475

Patch by Youenn Fablet <youenn@apple.com> on 2017-10-18
Reviewed by Chris Dumez.

Source/WebCore:

Test: http/tests/workers/service/basic-fetch.https.html

Adding parameters to allow WebKit to do loading through Service Worker or through regular networking.
A script context is now storing its selected service worker identifier. This should be fully implemented later on.
This selected service worker identifier is passed to loading code as a ResourceLoaderOptions field.
Service workers mode is also added as a ResourceLoaderOptions field so that the service worker can be bypassed.

* WebCore.xcodeproj/project.pbxproj:
* dom/ScriptExecutionContext.h:
(WebCore::ScriptExecutionContext::selectedServiceWorkerIdentifier const):
(WebCore::ScriptExecutionContext::setSelectedServiceWorkerIdentifier):
* loader/DocumentThreadableLoader.cpp:
(WebCore::DocumentThreadableLoader::DocumentThreadableLoader):
* loader/FetchOptions.h:
(WebCore::isPotentialNavigationOrSubresourceRequest):
(WebCore::isNonSubresourceRequest):
* loader/ResourceLoaderOptions.h:
* loader/WorkerThreadableLoader.cpp:
(WebCore::WorkerThreadableLoader::WorkerThreadableLoader):
(WebCore::WorkerThreadableLoader::MainThreadBridge::MainThreadBridge):
* loader/WorkerThreadableLoader.h:
* platform/network/ResourceRequestBase.h:
* platform/network/ResourceResponseBase.h:
* workers/WorkerThread.h:
* workers/service/ServiceWorkerContainer.cpp:
(WebCore::ServiceWorkerContainer::jobResolvedWithRegistration):
* workers/service/ServiceWorkerProvider.h:
* workers/service/context/SWContextManager.cpp: Removed.
* workers/service/context/ServiceWorkerThread.h:
* workers/service/server/SWServer.h:

Source/WebKit:

Preliminary support of Handle Fetch algorithm and integration with fetch spec.
Adding ServiceWorkerClientFetch as the class responsible to do the load through ServiceWorker.
It is similar to WebResourceLoader that do the load through NetworkProcess.
In case ServiceWorkerClientFetch is not able to load through ServiceWorker,
it will fallback to WebResourceLoader through a fallback callback.

Loading through Service Worker is done currently if:
- There is a service worker registered for that origin
- Request is a subresource
- service workers mode is all
There will be cases where the service worker will not do the loading, for instance when fetch event handler is not set.
Future work should try to reduce the cases where the IPC dance is done unnecessarily.

ServiceWorkerClientFetch is responsible to adapt the ServiceWorker response to ResourceLoader.
In particular, it is calling ResourceLoader error callback if response is of type error.
It should call ResourceLoader redirection callback if response is a redirection response.
This will be done as a follow-up.

Implementing the IPC communication dedicated to fetch between WebProcess and ServiceWorker through StorageProcess.
In the future, WebProcess should create a direct IPC communication to the ServiceWorker process.

Moved SWContextManager from WebCore to WebKit and renamed it to ServiceWorkerContextManager.
This class is moved to WebKit as it will have to handle IPC and having a separation will add some unnecessary boilerplate.

* DerivedSources.make:
* StorageProcess/ServiceWorker/WebSWServerConnection.cpp:
(WebKit::WebSWServerConnection::startFetch):
(WebKit::WebSWServerConnection::didReceiveFetchResponse):
(WebKit::WebSWServerConnection::didReceiveFetchData):
(WebKit::WebSWServerConnection::didFinishFetch):
(WebKit::WebSWServerConnection::failedFetch):
* StorageProcess/ServiceWorker/WebSWServerConnection.h:
* StorageProcess/ServiceWorker/WebSWServerConnection.messages.in:
* StorageProcess/StorageProcess.cpp:
(WebKit::StorageProcess::failedFetch):
(WebKit::StorageProcess::didReceiveFetchResponse):
(WebKit::StorageProcess::didReceiveFetchData):
(WebKit::StorageProcess::didFinishFetch):
* StorageProcess/StorageProcess.h:
* StorageProcess/StorageProcess.messages.in:
* WebKit.xcodeproj/project.pbxproj:
* WebProcess/Network/WebLoaderStrategy.cpp:
(WebKit::WebLoaderStrategy::scheduleLoad):
(WebKit::WebLoaderStrategy::scheduleLoadFromNetworkProcess):
* WebProcess/Network/WebLoaderStrategy.h:
* WebProcess/Storage/ServiceWorkerClientFetch.cpp: Added.
(WebKit::ServiceWorkerClientFetch::didReceiveResponse):
(WebKit::ServiceWorkerClientFetch::didReceiveData):
(WebKit::ServiceWorkerClientFetch::didFinishFetch):
(WebKit::ServiceWorkerClientFetch::didFail):
* WebProcess/Storage/ServiceWorkerClientFetch.h: Added.
* WebProcess/Storage/ServiceWorkerClientFetch.messages.in: Added.
* WebProcess/Storage/ServiceWorkerContextManager.cpp: Renamed from Source/WebCore/workers/service/context/SWContextManager.cpp.
(WebKit::ServiceWorkerContextManager::startServiceWorkerContext):
(WebKit::ServiceWorkerContextManager::startFetch):
* WebProcess/Storage/ServiceWorkerContextManager.h: Renamed from Source/WebCore/workers/service/context/SWContextManager.h.
(WebKit::ServiceWorkerContextManager::ServiceWorkerContextManager):
* WebProcess/Storage/WebSWClientConnection.cpp:
(WebKit::WebSWClientConnection::startFetch):
* WebProcess/Storage/WebSWClientConnection.h:
* WebProcess/Storage/WebServiceWorkerProvider.cpp:
(WebKit::shouldHandleFetch):
(WebKit::WebServiceWorkerProvider::handleFetch):
(WebKit::WebServiceWorkerProvider::didReceiveServiceWorkerClientFetchMessage):
* WebProcess/Storage/WebServiceWorkerProvider.h:
* WebProcess/Storage/WebToStorageProcessConnection.cpp:
(WebKit::WebToStorageProcessConnection::didReceiveMessage):
* WebProcess/WebProcess.cpp:
(WebKit::WebProcess::getWorkerContextConnection):
(WebKit::WebProcess::startServiceWorkerContext):
(WebKit::WebProcess::startFetchInServiceWorker):
* WebProcess/WebProcess.h:
* WebProcess/WebProcess.messages.in:

LayoutTests:

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

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@223650 268f45cc-cd09-0410-ab3c-d52691b4dbfc
44 files changed:
LayoutTests/ChangeLog
LayoutTests/http/tests/workers/service/basic-fetch.https-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/workers/service/basic-fetch.https.html [new file with mode: 0644]
LayoutTests/http/tests/workers/service/resources/basic-fetch-worker.js [new file with mode: 0644]
LayoutTests/http/tests/workers/service/resources/basic-fetch.js [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/dom/ScriptExecutionContext.h
Source/WebCore/loader/DocumentThreadableLoader.cpp
Source/WebCore/loader/FetchOptions.h
Source/WebCore/loader/ResourceLoaderOptions.h
Source/WebCore/loader/WorkerThreadableLoader.cpp
Source/WebCore/loader/WorkerThreadableLoader.h
Source/WebCore/platform/network/ResourceRequestBase.h
Source/WebCore/platform/network/ResourceResponseBase.h
Source/WebCore/workers/WorkerThread.h
Source/WebCore/workers/service/ServiceWorkerContainer.cpp
Source/WebCore/workers/service/context/SWContextManager.cpp [deleted file]
Source/WebCore/workers/service/context/ServiceWorkerThread.h
Source/WebKit/CMakeLists.txt
Source/WebKit/ChangeLog
Source/WebKit/DerivedSources.make
Source/WebKit/StorageProcess/ServiceWorker/WebSWServerConnection.cpp
Source/WebKit/StorageProcess/ServiceWorker/WebSWServerConnection.h
Source/WebKit/StorageProcess/ServiceWorker/WebSWServerConnection.messages.in
Source/WebKit/StorageProcess/StorageProcess.cpp
Source/WebKit/StorageProcess/StorageProcess.h
Source/WebKit/StorageProcess/StorageProcess.messages.in
Source/WebKit/WebKit.xcodeproj/project.pbxproj
Source/WebKit/WebProcess/Network/WebLoaderStrategy.cpp
Source/WebKit/WebProcess/Network/WebLoaderStrategy.h
Source/WebKit/WebProcess/Storage/ServiceWorkerClientFetch.cpp [new file with mode: 0644]
Source/WebKit/WebProcess/Storage/ServiceWorkerClientFetch.h [new file with mode: 0644]
Source/WebKit/WebProcess/Storage/ServiceWorkerClientFetch.messages.in [new file with mode: 0644]
Source/WebKit/WebProcess/Storage/ServiceWorkerContextManager.cpp [new file with mode: 0644]
Source/WebKit/WebProcess/Storage/ServiceWorkerContextManager.h [moved from Source/WebCore/workers/service/context/SWContextManager.h with 66% similarity]
Source/WebKit/WebProcess/Storage/WebSWClientConnection.cpp
Source/WebKit/WebProcess/Storage/WebSWClientConnection.h
Source/WebKit/WebProcess/Storage/WebServiceWorkerProvider.cpp
Source/WebKit/WebProcess/Storage/WebServiceWorkerProvider.h
Source/WebKit/WebProcess/Storage/WebToStorageProcessConnection.cpp
Source/WebKit/WebProcess/WebProcess.cpp
Source/WebKit/WebProcess/WebProcess.h
Source/WebKit/WebProcess/WebProcess.messages.in