Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
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. Canonical link: https://commits.webkit.org/194733@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@223718 268f45cc-cd09-0410-ab3c-d52691b4dbfc
- Loading branch information
Showing
44 changed files
with
804 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,6 @@ | ||
CONSOLE MESSAGE: line 12: test1 status code: 200 | ||
CONSOLE MESSAGE: line 13: test1 status text: Hello from service worker | ||
CONSOLE MESSAGE: line 16: test2 status code: 500 | ||
CONSOLE MESSAGE: line 17: test2 status text: Error from service worker | ||
CONSOLE MESSAGE: line 26: test3 fetch failed as expected | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,9 @@ | ||
<html> | ||
<head> | ||
<script src="resources/sw-test-pre.js"></script> | ||
</head> | ||
<body> | ||
|
||
<script src="resources/basic-fetch.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1 @@ | ||
// FIXME: register an onfetch event handler and handle "test1", "test2" and "test3" URLs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,34 @@ | ||
function done() | ||
{ | ||
finishSWTest(); | ||
} | ||
|
||
async function test() | ||
{ | ||
try { | ||
await navigator.serviceWorker.register("resources/basic-fetch-worker.js", { }); | ||
|
||
var response = await fetch("test1"); | ||
console.log("test1 status code: " + response.status); | ||
console.log("test1 status text: " + response.statusText); | ||
|
||
var response = await fetch("test2"); | ||
console.log("test2 status code: " + response.status); | ||
console.log("test2 status text: " + response.statusText); | ||
|
||
try { | ||
response = await fetch("test3"); | ||
console.log("test3 fetch succeeded unexpectedly"); | ||
console.log("test3 status code: " + response.status); | ||
console.log("test3 status text: " + response.statusText); | ||
|
||
} catch (e) { | ||
console.log("test3 fetch failed as expected"); | ||
} | ||
} catch(e) { | ||
console.log("Got exception: " + e); | ||
} | ||
finishSWTest(); | ||
} | ||
|
||
test(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.