Add preliminary support for ServiceWorker Handle Fetch
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 19 Oct 2017 22:44:57 +0000 (22:44 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 19 Oct 2017 22:44:57 +0000 (22:44 +0000)
commitb204f09a8440c01ed49f924d36ed7788a4e7ad4d
tree21caa8464e2aa81666e70bee835df07c4ad7c959
parent1fee3ff78a58968de901e74a68f9d17d13fb46bb
Add preliminary support for ServiceWorker Handle Fetch
https://bugs.webkit.org/show_bug.cgi?id=178475
<rdar://problem/35066424>

Patch by Youenn Fablet <youenn@apple.com> on 2017-10-19
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/context/SWContextManager.cpp: Removed.
* workers/service/context/ServiceWorkerThread.h:

Source/WebKit:

Relanding now that underlying issue is fixed in https://bugs.webkit.org/show_bug.cgi?id=178527.

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.

* CMakeLists.txt:
* DerivedSources.make:
* StorageProcess/ServiceWorker/WebSWServerConnection.cpp:
(WebKit::WebSWServerConnection::startFetch):
(WebKit::WebSWServerConnection::didReceiveFetchResponse):
(WebKit::WebSWServerConnection::didReceiveFetchData):
(WebKit::WebSWServerConnection::didFinishFetch):
(WebKit::WebSWServerConnection::didFailFetch):
* StorageProcess/ServiceWorker/WebSWServerConnection.h:
* StorageProcess/ServiceWorker/WebSWServerConnection.messages.in:
* StorageProcess/StorageProcess.cpp:
(WebKit::StorageProcess::didFailFetch):
(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):
(WebKit::WebLoaderStrategy::remove):
* WebProcess/Network/WebLoaderStrategy.h:
* WebProcess/Storage/ServiceWorkerClientFetch.cpp: Added.
(WebKit::ServiceWorkerClientFetch::ServiceWorkerClientFetch):
(WebKit::ServiceWorkerClientFetch::didReceiveResponse):
(WebKit::ServiceWorkerClientFetch::didReceiveData):
(WebKit::ServiceWorkerClientFetch::didFinish):
(WebKit::ServiceWorkerClientFetch::didFail):
(WebKit::ServiceWorkerClientFetch::cancel):
* WebProcess/Storage/ServiceWorkerClientFetch.h: Copied from Source/WebKit/WebProcess/Storage/WebSWClientConnection.h.
* WebProcess/Storage/ServiceWorkerClientFetch.messages.in: Copied from Source/WebKit/StorageProcess/ServiceWorker/WebSWServerConnection.messages.in.
* WebProcess/Storage/ServiceWorkerContextManager.cpp: Added.
(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::cancelFetch):
(WebKit::WebServiceWorkerProvider::fetchFinished):
(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@223718 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