Source/WebCore:
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 23 Oct 2017 17:25:32 +0000 (17:25 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 23 Oct 2017 17:25:32 +0000 (17:25 +0000)
commit001431e209050ed8c2bafd1b0c30825894a46d31
tree66dd7cb73b250e8cdfd63ce7cd4452ddf9a855e1
parent795a10b5ae25e5522889abea1d9038e6eee1be64
Source/WebCore:
Create a Fetch event when ServiceWorker has to handle a fetch
https://bugs.webkit.org/show_bug.cgi?id=178491

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

Covered by existing test.

Updating FetchEvent to pass a FetchResponse* within its onResponse callback.
Making it a CompletionHandler.
Fixing a check on respondWith to ensure that event is dispatched when respondWith is called.

Adding ServiceWorkerFetch class to handle the creation of the fetch event, waiting for the fetch event to be responded
and processing when fetch event is responded.
ServiceWorkerFetchTask takes a client to which will be sent the response body or the error.
WebKit implementation of it will be to send the related IPC message back to the WebProcess that made the fetch request.

Adding a method to ServiceWorkerThread to create the fetch event on worker thread and dispatch on the global scope.

* WebCore.xcodeproj/project.pbxproj:
* platform/network/ResourceResponseBase.h:
* testing/Internals.cpp:
(WebCore::Internals::waitForFetchEventToFinish):
* workers/service/FetchEvent.cpp:
(WebCore::FetchEvent::~FetchEvent):
(WebCore::FetchEvent::respondWith):
(WebCore::FetchEvent::onResponse):
(WebCore::FetchEvent::respondWithError):
(WebCore::FetchEvent::processResponse):
(WebCore::FetchEvent::promiseIsSettled):
* workers/service/FetchEvent.h:
* workers/service/context/ServiceWorkerFetch.cpp: Added.
(WebCore::ServiceWorkerFetch::dispatchFetchTask):
(WebCore::ServiceWorkerFetch::processResponse):
* workers/service/context/ServiceWorkerFetch.h: Added.
* workers/service/context/ServiceWorkerThread.cpp:
(WebCore::m_workerObjectProxy):
(WebCore::ServiceWorkerThread::dispatchFetchEvent):
* workers/service/context/ServiceWorkerThread.h:

Source/WebKit:
TestController should clear all fetch caches when resetting its state
https://bugs.webkit.org/show_bug.cgi?id=178486
<rdar://problem/35066305>

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

Adding a new DidNotHandle message to disambiguate with the DidFail fetch case.
With DidNotHandle, the loading should go the network process.
With DidFail, the loading should return a network error.

On receiving an order to start a fetch, ServiceWorkerThread will dispatch a fetch event.
The client of this event will retrieve the response and return it to the WebProcess through IPC.

* StorageProcess/ServiceWorker/WebSWServerConnection.cpp:
(WebKit::WebSWServerConnection::didNotHandleFetch):
* StorageProcess/ServiceWorker/WebSWServerConnection.h:
* StorageProcess/StorageProcess.cpp:
(WebKit::StorageProcess::didNotHandleFetch):
* StorageProcess/StorageProcess.h:
* StorageProcess/StorageProcess.messages.in:
* WebKit.xcodeproj/project.pbxproj:
* WebProcess/Storage/ServiceWorkerClientFetch.cpp:
(WebKit::ServiceWorkerClientFetch::didFail):
(WebKit::ServiceWorkerClientFetch::didNotHandle):
* WebProcess/Storage/ServiceWorkerClientFetch.h:
* WebProcess/Storage/ServiceWorkerClientFetch.messages.in:
* WebProcess/Storage/ServiceWorkerContextManager.cpp:
(WebKit::ServiceWorkerContextManager::startFetch):
* WebProcess/Storage/ServiceWorkerContextManager.h:
* WebProcess/Storage/WebServiceWorkerFetchTaskClient.cpp: Added.
(WebKit::WebServiceWorkerFetchTaskClient::~WebServiceWorkerFetchTaskClient):
(WebKit::WebServiceWorkerFetchTaskClient::WebServiceWorkerFetchTaskClient):
(WebKit::WebServiceWorkerFetchTaskClient::didReceiveResponse):
(WebKit::WebServiceWorkerFetchTaskClient::didReceiveData):
(WebKit::WebServiceWorkerFetchTaskClient::didFail):
(WebKit::WebServiceWorkerFetchTaskClient::didFinish):
* WebProcess/Storage/WebServiceWorkerFetchTaskClient.h: Added.
* WebProcess/WebProcess.cpp:
(WebKit::WebProcess::startFetchInServiceWorker):
* WebProcess/WebProcess.h:

LayoutTests:
TestController should clear all fetch caches when resetting its state
https://bugs.webkit.org/show_bug.cgi?id=178486
<rdar://problem/35066305>

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

Beefing up the test by using fetch event handler to return responses
previously hard coded in ServiceWorkerContextManager.

* http/tests/workers/service/basic-fetch.https-expected.txt:
* http/tests/workers/service/resources/basic-fetch-worker.js:
(event.event.request.url.indexOf):
* http/tests/workers/service/resources/basic-fetch.js:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@223839 268f45cc-cd09-0410-ab3c-d52691b4dbfc
31 files changed:
LayoutTests/ChangeLog
LayoutTests/http/tests/workers/service/resources/basic-fetch-worker.js
LayoutTests/http/tests/workers/service/resources/sw-test-pre.js
LayoutTests/http/wpt/service-workers/fetchEvent.https.html
Source/WebCore/ChangeLog
Source/WebCore/Modules/fetch/FetchRequest.h
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/testing/Internals.cpp
Source/WebCore/testing/Internals.h
Source/WebCore/testing/Internals.idl
Source/WebCore/workers/service/FetchEvent.cpp
Source/WebCore/workers/service/FetchEvent.h
Source/WebCore/workers/service/FetchEvent.idl
Source/WebCore/workers/service/context/ServiceWorkerFetch.cpp [new file with mode: 0644]
Source/WebCore/workers/service/context/ServiceWorkerFetch.h [new file with mode: 0644]
Source/WebCore/workers/service/context/ServiceWorkerThread.cpp
Source/WebCore/workers/service/context/ServiceWorkerThread.h
Source/WebKit/ChangeLog
Source/WebKit/StorageProcess/ServiceWorker/WebSWServerConnection.cpp
Source/WebKit/StorageProcess/ServiceWorker/WebSWServerConnection.h
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/Storage/ServiceWorkerClientFetch.cpp
Source/WebKit/WebProcess/Storage/ServiceWorkerClientFetch.h
Source/WebKit/WebProcess/Storage/ServiceWorkerClientFetch.messages.in
Source/WebKit/WebProcess/Storage/ServiceWorkerContextManager.cpp
Source/WebKit/WebProcess/Storage/ServiceWorkerContextManager.h
Source/WebKit/WebProcess/Storage/WebServiceWorkerFetchTaskClient.cpp [new file with mode: 0644]
Source/WebKit/WebProcess/Storage/WebServiceWorkerFetchTaskClient.h [new file with mode: 0644]