WebKit Bugzilla
Attachment 362067 Details for
Bug 194651
: Make ServiceWorkerClientFetch closer to WebResourceLoader
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Patch
bug-194651-20190214150252.patch (text/plain), 50.42 KB, created by
youenn fablet
on 2019-02-14 15:02:53 PST
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
youenn fablet
Created:
2019-02-14 15:02:53 PST
Size:
50.42 KB
patch
obsolete
>Subversion Revision: 241548 >diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog >index d36f5136b437839cfeddba1b5db4e0e1200b22f0..b2f91d753f9ab0b191a90b5310fe8f9a89f0333b 100644 >--- a/Source/WebCore/ChangeLog >+++ b/Source/WebCore/ChangeLog >@@ -1,3 +1,26 @@ >+2019-02-14 Youenn Fablet <youenn@apple.com> >+ >+ Make ServiceWorkerClientFetch closer to WebResourceLoader >+ https://bugs.webkit.org/show_bug.cgi?id=194651 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ Check for redirection response and if so call a specific client API. >+ Ensure ServiceWorkerFetch::Client gets called in the service worker thread proxy >+ so that its m_connection is only accessed on that thread. >+ >+ Covered by existing tests. >+ >+ * platform/network/FormData.h: >+ * platform/network/ResourceErrorBase.h: >+ * workers/service/context/ServiceWorkerFetch.cpp: >+ (WebCore::ServiceWorkerFetch::processResponse): >+ * workers/service/context/ServiceWorkerFetch.h: >+ * workers/service/context/ServiceWorkerThreadProxy.cpp: >+ (WebCore::ServiceWorkerThreadProxy::cancelFetch): >+ (WebCore::ServiceWorkerThreadProxy::continueDidReceiveFetchResponse): >+ * workers/service/context/ServiceWorkerThreadProxy.h: >+ > 2019-02-14 Youenn Fablet <youenn@apple.com> > > Make navigator.mediaDevices SecureContext >diff --git a/Source/WebKit/ChangeLog b/Source/WebKit/ChangeLog >index 6fd94b3af071a2fdc0c87d3ed155b380c90c58d2..afc2099217e404d45099917e4444674ae808ef0f 100644 >--- a/Source/WebKit/ChangeLog >+++ b/Source/WebKit/ChangeLog >@@ -1,3 +1,61 @@ >+2019-02-14 Youenn Fablet <youenn@apple.com> >+ >+ Make ServiceWorkerClientFetch closer to WebResourceLoader >+ https://bugs.webkit.org/show_bug.cgi?id=194651 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ The goal of this refactoring is to, at some point use the regular network process load path for service worker loads. >+ This should simplify things and allow less IPC exchanges, for instance in the case of fetch not handled by service worker. >+ >+ Introduce two IPC messages for supporting redirect responses and allow the didReceiveResponse/continueDidReceiveResponse >+ handshake for navigation loads. >+ >+ This makes ServiceWorker having to buffer load information for this particular case. >+ >+ * NetworkProcess/NetworkProcess.cpp: >+ (WebKit::NetworkProcess::didReceiveFetchRedirectResponse): >+ (WebKit::NetworkProcess::didReceiveFetchResponse): >+ * NetworkProcess/NetworkProcess.h: >+ * NetworkProcess/NetworkProcess.messages.in: >+ * NetworkProcess/ServiceWorker/WebSWServerConnection.cpp: >+ (WebKit::WebSWServerConnection::continueDidReceiveFetchResponse): >+ (WebKit::WebSWServerConnection::didReceiveFetchRedirectResponse): >+ (WebKit::WebSWServerConnection::didReceiveFetchResponse): >+ * NetworkProcess/ServiceWorker/WebSWServerConnection.h: >+ * NetworkProcess/ServiceWorker/WebSWServerConnection.messages.in: >+ * WebProcess/Storage/ServiceWorkerClientFetch.cpp: >+ (WebKit::ServiceWorkerClientFetch::start): >+ (WebKit::ServiceWorkerClientFetch::didReceiveRedirectResponse): >+ (WebKit::ServiceWorkerClientFetch::didReceiveResponse): >+ (WebKit::ServiceWorkerClientFetch::didReceiveData): >+ (WebKit::ServiceWorkerClientFetch::didFinish): >+ (WebKit::ServiceWorkerClientFetch::didFail): >+ (WebKit::ServiceWorkerClientFetch::didNotHandle): >+ (WebKit::ServiceWorkerClientFetch::cancel): >+ * WebProcess/Storage/ServiceWorkerClientFetch.h: >+ * WebProcess/Storage/ServiceWorkerClientFetch.messages.in: >+ * WebProcess/Storage/WebSWClientConnection.cpp: >+ (WebKit::WebSWClientConnection::startFetch): >+ (WebKit::WebSWClientConnection::cancelFetch): >+ (WebKit::WebSWClientConnection::continueDidReceiveFetchResponse): >+ * WebProcess/Storage/WebSWClientConnection.h: >+ * WebProcess/Storage/WebSWContextManagerConnection.cpp: >+ (WebKit::WebSWContextManagerConnection::continueDidReceiveFetchResponse): >+ (WebKit::WebSWContextManagerConnection::startFetch): >+ * WebProcess/Storage/WebSWContextManagerConnection.h: >+ * WebProcess/Storage/WebSWContextManagerConnection.messages.in: >+ * WebProcess/Storage/WebServiceWorkerFetchTaskClient.cpp: >+ (WebKit::WebServiceWorkerFetchTaskClient::WebServiceWorkerFetchTaskClient): >+ (WebKit::WebServiceWorkerFetchTaskClient::didReceiveRedirection): >+ (WebKit::WebServiceWorkerFetchTaskClient::didReceiveResponse): >+ (WebKit::WebServiceWorkerFetchTaskClient::didReceiveData): >+ (WebKit::WebServiceWorkerFetchTaskClient::didReceiveFormDataAndFinish): >+ (WebKit::WebServiceWorkerFetchTaskClient::didFail): >+ (WebKit::WebServiceWorkerFetchTaskClient::didFinish): >+ (WebKit::WebServiceWorkerFetchTaskClient::continueDidReceiveResponse): >+ * WebProcess/Storage/WebServiceWorkerFetchTaskClient.h: >+ > 2019-02-14 Commit Queue <commit-queue@webkit.org> > > Unreviewed, rolling out r241486. >diff --git a/Source/WebCore/platform/network/FormData.h b/Source/WebCore/platform/network/FormData.h >index 3b50e733812e55e284db6777cb338e2a17e66613..c00a1998662897a78b816e6f50f3432514d59c92 100644 >--- a/Source/WebCore/platform/network/FormData.h >+++ b/Source/WebCore/platform/network/FormData.h >@@ -210,7 +210,7 @@ public: > // FIXME: Both these functions perform a deep copy of m_elements, but differ in handling of other data members. > // How much of that is intentional? We need better names that explain the difference. > Ref<FormData> copy() const; >- Ref<FormData> isolatedCopy() const; >+ WEBCORE_EXPORT Ref<FormData> isolatedCopy() const; > > template<typename Encoder> > void encode(Encoder&) const; >diff --git a/Source/WebCore/platform/network/ResourceErrorBase.h b/Source/WebCore/platform/network/ResourceErrorBase.h >index e0bf04b8ac8f00b3939791ebfd0087ecb90db799..a9843f50e5a43403d8f52f0a967f9027865e8d56 100644 >--- a/Source/WebCore/platform/network/ResourceErrorBase.h >+++ b/Source/WebCore/platform/network/ResourceErrorBase.h >@@ -38,7 +38,7 @@ WEBCORE_EXPORT extern const char* const errorDomainWebKitServiceWorker; // Used > > class ResourceErrorBase { > public: >- ResourceError isolatedCopy() const; >+ WEBCORE_EXPORT ResourceError isolatedCopy() const; > > const String& domain() const { lazyInit(); return m_domain; } > int errorCode() const { lazyInit(); return m_errorCode; } >diff --git a/Source/WebCore/workers/service/context/ServiceWorkerFetch.cpp b/Source/WebCore/workers/service/context/ServiceWorkerFetch.cpp >index f62959d80da526c56e41c2dc7687ba316368f8e6..b8d4d123a9f08ff89a9d956c2d54303fe4b81759 100644 >--- a/Source/WebCore/workers/service/context/ServiceWorkerFetch.cpp >+++ b/Source/WebCore/workers/service/context/ServiceWorkerFetch.cpp >@@ -51,14 +51,20 @@ static void processResponse(Ref<Client>&& client, Expected<Ref<FetchResponse>, R > } > auto response = WTFMove(result.value()); > >- client->didReceiveResponse(response->resourceResponse()); >- > auto loadingError = response->loadingError(); > if (!loadingError.isNull()) { > client->didFail(loadingError); > return; > } > >+ auto resourceResponse = response->resourceResponse(); >+ if (resourceResponse.isRedirection() && resourceResponse.httpHeaderFields().contains(HTTPHeaderName::Location)) { >+ client->didReceiveRedirection(resourceResponse); >+ return; >+ } >+ >+ client->didReceiveResponse(resourceResponse); >+ > if (response->isBodyReceivedByChunk()) { > response->consumeBodyReceivedByChunk([client = WTFMove(client)] (auto&& result) mutable { > if (result.hasException()) { >diff --git a/Source/WebCore/workers/service/context/ServiceWorkerFetch.h b/Source/WebCore/workers/service/context/ServiceWorkerFetch.h >index 0983425159d731c7b4d0d324789253ba47c486d1..3155d56e9fd6e92bd62080a76a4745b387ea491b 100644 >--- a/Source/WebCore/workers/service/context/ServiceWorkerFetch.h >+++ b/Source/WebCore/workers/service/context/ServiceWorkerFetch.h >@@ -44,10 +44,11 @@ class ServiceWorkerGlobalScope; > class SharedBuffer; > > namespace ServiceWorkerFetch { >-class Client : public ThreadSafeRefCounted<Client> { >+class Client : public ThreadSafeRefCounted<Client, WTF::DestructionThread::Main> { > public: > virtual ~Client() = default; > >+ virtual void didReceiveRedirection(const ResourceResponse&) = 0; > virtual void didReceiveResponse(const ResourceResponse&) = 0; > virtual void didReceiveData(Ref<SharedBuffer>&&) = 0; > virtual void didReceiveFormDataAndFinish(Ref<FormData>&&) = 0; >@@ -55,6 +56,7 @@ public: > virtual void didFinish() = 0; > virtual void didNotHandle() = 0; > virtual void cancel() = 0; >+ virtual void continueDidReceiveResponse() = 0; > }; > > void dispatchFetchEvent(Ref<Client>&&, ServiceWorkerGlobalScope&, Optional<ServiceWorkerClientIdentifier>, ResourceRequest&&, String&& referrer, FetchOptions&&); >diff --git a/Source/WebCore/workers/service/context/ServiceWorkerThreadProxy.cpp b/Source/WebCore/workers/service/context/ServiceWorkerThreadProxy.cpp >index fe8e53fe7fa4fe6ed115a2327e2beb2cda0c9e93..f6fc8beac7b4998976ba9d7c6df105099d129af0 100644 >--- a/Source/WebCore/workers/service/context/ServiceWorkerThreadProxy.cpp >+++ b/Source/WebCore/workers/service/context/ServiceWorkerThreadProxy.cpp >@@ -200,8 +200,24 @@ void ServiceWorkerThreadProxy::startFetch(SWServerConnectionIdentifier connectio > > void ServiceWorkerThreadProxy::cancelFetch(SWServerConnectionIdentifier connectionIdentifier, FetchIdentifier fetchIdentifier) > { >- if (auto client = m_ongoingFetchTasks.take(std::make_pair(connectionIdentifier, fetchIdentifier))) >- client.value()->cancel(); >+ auto client = m_ongoingFetchTasks.take(std::make_pair(connectionIdentifier, fetchIdentifier)); >+ if (!client) >+ return; >+ >+ postTaskForModeToWorkerGlobalScope([client = WTFMove(client.value())] (ScriptExecutionContext&) { >+ client->cancel(); >+ }, WorkerRunLoop::defaultMode()); >+} >+ >+void ServiceWorkerThreadProxy::continueDidReceiveFetchResponse(SWServerConnectionIdentifier connectionIdentifier, FetchIdentifier fetchIdentifier) >+{ >+ auto client = m_ongoingFetchTasks.get(std::make_pair(connectionIdentifier, fetchIdentifier)); >+ if (!client) >+ return; >+ >+ postTaskForModeToWorkerGlobalScope([client = makeRef(*client)] (ScriptExecutionContext&) { >+ client->continueDidReceiveResponse(); >+ }, WorkerRunLoop::defaultMode()); > } > > void ServiceWorkerThreadProxy::removeFetch(SWServerConnectionIdentifier connectionIdentifier, FetchIdentifier fetchIdentifier) >diff --git a/Source/WebCore/workers/service/context/ServiceWorkerThreadProxy.h b/Source/WebCore/workers/service/context/ServiceWorkerThreadProxy.h >index e5ffa93620a2066f8fdf438ed272f9d0447ee30c..f46cfd1478aea274d21903623235c363d323fd87 100644 >--- a/Source/WebCore/workers/service/context/ServiceWorkerThreadProxy.h >+++ b/Source/WebCore/workers/service/context/ServiceWorkerThreadProxy.h >@@ -73,6 +73,7 @@ public: > > WEBCORE_EXPORT void startFetch(SWServerConnectionIdentifier, FetchIdentifier, Ref<ServiceWorkerFetch::Client>&&, Optional<ServiceWorkerClientIdentifier>&&, ResourceRequest&&, String&& referrer, FetchOptions&&); > WEBCORE_EXPORT void cancelFetch(SWServerConnectionIdentifier, FetchIdentifier); >+ WEBCORE_EXPORT void continueDidReceiveFetchResponse(SWServerConnectionIdentifier, FetchIdentifier); > WEBCORE_EXPORT void removeFetch(SWServerConnectionIdentifier, FetchIdentifier); > > private: >diff --git a/Source/WebKit/NetworkProcess/NetworkProcess.cpp b/Source/WebKit/NetworkProcess/NetworkProcess.cpp >index 3cef6a574a0eb883fddad48086fde0a3a1c13392..6024dd7e09f5f2a91207425605cd40588c6afa1b 100644 >--- a/Source/WebKit/NetworkProcess/NetworkProcess.cpp >+++ b/Source/WebKit/NetworkProcess/NetworkProcess.cpp >@@ -2170,10 +2170,16 @@ void NetworkProcess::didNotHandleFetch(SWServerConnectionIdentifier serverConnec > connection->didNotHandleFetch(fetchIdentifier); > } > >-void NetworkProcess::didReceiveFetchResponse(SWServerConnectionIdentifier serverConnectionIdentifier, FetchIdentifier fetchIdentifier, const WebCore::ResourceResponse& response) >+void NetworkProcess::didReceiveFetchRedirectResponse(SWServerConnectionIdentifier serverConnectionIdentifier, FetchIdentifier fetchIdentifier, const WebCore::ResourceResponse& response) > { > if (auto* connection = m_swServerConnections.get(serverConnectionIdentifier)) >- connection->didReceiveFetchResponse(fetchIdentifier, response); >+ connection->didReceiveFetchRedirectResponse(fetchIdentifier, response); >+} >+ >+void NetworkProcess::didReceiveFetchResponse(SWServerConnectionIdentifier serverConnectionIdentifier, FetchIdentifier fetchIdentifier, const WebCore::ResourceResponse& response, bool needsContinueDidReceiveResponseMessage) >+{ >+ if (auto* connection = m_swServerConnections.get(serverConnectionIdentifier)) >+ connection->didReceiveFetchResponse(fetchIdentifier, response, needsContinueDidReceiveResponseMessage); > } > > void NetworkProcess::didReceiveFetchData(SWServerConnectionIdentifier serverConnectionIdentifier, FetchIdentifier fetchIdentifier, const IPC::DataReference& data, int64_t encodedDataLength) >diff --git a/Source/WebKit/NetworkProcess/NetworkProcess.h b/Source/WebKit/NetworkProcess/NetworkProcess.h >index 4ae4c665d38134f00dcc748d568edbacf370a63b..3991bcd1baeb82eb8b7e4abe542d363c30f84d7a 100644 >--- a/Source/WebKit/NetworkProcess/NetworkProcess.h >+++ b/Source/WebKit/NetworkProcess/NetworkProcess.h >@@ -403,7 +403,8 @@ private: > #endif > > #if ENABLE(SERVICE_WORKER) >- void didReceiveFetchResponse(WebCore::SWServerConnectionIdentifier, WebCore::FetchIdentifier, const WebCore::ResourceResponse&); >+ void didReceiveFetchRedirectResponse(WebCore::SWServerConnectionIdentifier, WebCore::FetchIdentifier, const WebCore::ResourceResponse&); >+ void didReceiveFetchResponse(WebCore::SWServerConnectionIdentifier, WebCore::FetchIdentifier, const WebCore::ResourceResponse&, bool needsContinueDidReceiveResponseMessage); > void didReceiveFetchData(WebCore::SWServerConnectionIdentifier, WebCore::FetchIdentifier, const IPC::DataReference&, int64_t encodedDataLength); > void didReceiveFetchFormData(WebCore::SWServerConnectionIdentifier, WebCore::FetchIdentifier, const IPC::FormDataReference&); > void didFinishFetch(WebCore::SWServerConnectionIdentifier, WebCore::FetchIdentifier); >diff --git a/Source/WebKit/NetworkProcess/NetworkProcess.messages.in b/Source/WebKit/NetworkProcess/NetworkProcess.messages.in >index fc65a278899da20bde72781507c8f1537eadbe90..1f6b22bc19db840f0bb9b3fff69d1e132cc5dd6e 100644 >--- a/Source/WebKit/NetworkProcess/NetworkProcess.messages.in >+++ b/Source/WebKit/NetworkProcess/NetworkProcess.messages.in >@@ -149,7 +149,8 @@ messages -> NetworkProcess LegacyReceiver { > #if ENABLE(SERVICE_WORKER) > DidNotHandleFetch(WebCore::SWServerConnectionIdentifier serverConnectionIdentifier, WebCore::FetchIdentifier fetchIdentifier) > DidFailFetch(WebCore::SWServerConnectionIdentifier serverConnectionIdentifier, WebCore::FetchIdentifier fetchIdentifier, WebCore::ResourceError error) >- DidReceiveFetchResponse(WebCore::SWServerConnectionIdentifier serverConnectionIdentifier, WebCore::FetchIdentifier fetchIdentifier, WebCore::ResourceResponse response) >+ DidReceiveFetchRedirectResponse(WebCore::SWServerConnectionIdentifier serverConnectionIdentifier, WebCore::FetchIdentifier fetchIdentifier, WebCore::ResourceResponse response) >+ DidReceiveFetchResponse(WebCore::SWServerConnectionIdentifier serverConnectionIdentifier, WebCore::FetchIdentifier fetchIdentifier, WebCore::ResourceResponse response, bool needsContinueDidReceiveResponseMessage) > DidReceiveFetchData(WebCore::SWServerConnectionIdentifier serverConnectionIdentifier, WebCore::FetchIdentifier fetchIdentifier, IPC::SharedBufferDataReference data, int64_t encodedDataLength) > DidReceiveFetchFormData(WebCore::SWServerConnectionIdentifier serverConnectionIdentifier, WebCore::FetchIdentifier fetchIdentifier, IPC::FormDataReference data) > DidFinishFetch(WebCore::SWServerConnectionIdentifier serverConnectionIdentifier, WebCore::FetchIdentifier fetchIdentifier) >diff --git a/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerConnection.cpp b/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerConnection.cpp >index b375c6f13f3281c603edfe126674ba761764a4e9..5aac7fd9dd0920eb6f8e56af8f90180c7848a29f 100644 >--- a/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerConnection.cpp >+++ b/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerConnection.cpp >@@ -139,6 +139,19 @@ void WebSWServerConnection::cancelFetch(ServiceWorkerRegistrationIdentifier serv > }); > } > >+void WebSWServerConnection::continueDidReceiveFetchResponse(ServiceWorkerRegistrationIdentifier serviceWorkerRegistrationIdentifier, FetchIdentifier fetchIdentifier) >+{ >+ auto* worker = server().activeWorkerFromRegistrationID(serviceWorkerRegistrationIdentifier); >+ if (!worker || !worker->isRunning()) >+ return; >+ >+ auto serviceWorkerIdentifier = worker->identifier(); >+ server().runServiceWorkerIfNecessary(serviceWorkerIdentifier, [weakThis = makeWeakPtr(this), this, serviceWorkerIdentifier, fetchIdentifier](auto* contextConnection) mutable { >+ if (weakThis && contextConnection) >+ sendToContextProcess(*contextConnection, Messages::WebSWContextManagerConnection::ContinueDidReceiveFetchResponse { this->identifier(), serviceWorkerIdentifier, fetchIdentifier }); >+ }); >+} >+ > void WebSWServerConnection::startFetch(ServiceWorkerRegistrationIdentifier serviceWorkerRegistrationIdentifier, FetchIdentifier fetchIdentifier, ResourceRequest&& request, FetchOptions&& options, IPC::FormDataReference&& formData, String&& referrer) > { > auto* worker = server().activeWorkerFromRegistrationID(serviceWorkerRegistrationIdentifier); >@@ -230,9 +243,14 @@ void WebSWServerConnection::scheduleJobInServer(ServiceWorkerJobData&& jobData) > server().scheduleJob(WTFMove(jobData)); > } > >-void WebSWServerConnection::didReceiveFetchResponse(FetchIdentifier fetchIdentifier, const ResourceResponse& response) >+void WebSWServerConnection::didReceiveFetchRedirectResponse(FetchIdentifier fetchIdentifier, const ResourceResponse& response) >+{ >+ m_contentConnection->send(Messages::ServiceWorkerClientFetch::DidReceiveRedirectResponse { response }, fetchIdentifier.toUInt64()); >+} >+ >+void WebSWServerConnection::didReceiveFetchResponse(FetchIdentifier fetchIdentifier, const ResourceResponse& response, bool needsContinueDidReceiveResponseMessage) > { >- m_contentConnection->send(Messages::ServiceWorkerClientFetch::DidReceiveResponse { response }, fetchIdentifier.toUInt64()); >+ m_contentConnection->send(Messages::ServiceWorkerClientFetch::DidReceiveResponse { response, needsContinueDidReceiveResponseMessage }, fetchIdentifier.toUInt64()); > } > > void WebSWServerConnection::didReceiveFetchData(FetchIdentifier fetchIdentifier, const IPC::DataReference& data, int64_t encodedDataLength) >diff --git a/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerConnection.h b/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerConnection.h >index e96da208dcfab94a2bf041173add09fed4886e85..2b4aee63b54ac69fdb4adfd7c291f10000165fa6 100644 >--- a/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerConnection.h >+++ b/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerConnection.h >@@ -63,7 +63,8 @@ public: > > PAL::SessionID sessionID() const { return m_sessionID; } > >- void didReceiveFetchResponse(WebCore::FetchIdentifier, const WebCore::ResourceResponse&); >+ void didReceiveFetchRedirectResponse(WebCore::FetchIdentifier, const WebCore::ResourceResponse&); >+ void didReceiveFetchResponse(WebCore::FetchIdentifier, const WebCore::ResourceResponse&, bool needsContinueDidReceiveResponseMessage); > void didReceiveFetchData(WebCore::FetchIdentifier, const IPC::DataReference&, int64_t encodedDataLength); > void didReceiveFetchFormData(WebCore::FetchIdentifier, const IPC::FormDataReference&); > void didFinishFetch(WebCore::FetchIdentifier); >@@ -91,6 +92,7 @@ private: > > void startFetch(WebCore::ServiceWorkerRegistrationIdentifier, WebCore::FetchIdentifier, WebCore::ResourceRequest&&, WebCore::FetchOptions&&, IPC::FormDataReference&&, String&& referrer); > void cancelFetch(WebCore::ServiceWorkerRegistrationIdentifier, WebCore::FetchIdentifier); >+ void continueDidReceiveFetchResponse(WebCore::ServiceWorkerRegistrationIdentifier, WebCore::FetchIdentifier); > > void matchRegistration(uint64_t registrationMatchRequestIdentifier, const WebCore::SecurityOriginData& topOrigin, const URL& clientURL); > void getRegistrations(uint64_t registrationMatchRequestIdentifier, const WebCore::SecurityOriginData& topOrigin, const URL& clientURL); >diff --git a/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerConnection.messages.in b/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerConnection.messages.in >index f7543ff82957f2745ffb93fac564be16acdd1987..9e2d5ef8060a651b64cba3432a4e0f5a4bf9d960 100644 >--- a/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerConnection.messages.in >+++ b/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerConnection.messages.in >@@ -31,6 +31,7 @@ messages -> WebSWServerConnection { > > StartFetch(WebCore::ServiceWorkerRegistrationIdentifier serviceWorkerRegistrationIdentifier, WebCore::FetchIdentifier fetchIdentifier, WebCore::ResourceRequest request, struct WebCore::FetchOptions options, IPC::FormDataReference requestBody, String referrer) > CancelFetch(WebCore::ServiceWorkerRegistrationIdentifier serviceWorkerRegistrationIdentifier, WebCore::FetchIdentifier fetchIdentifier) >+ ContinueDidReceiveFetchResponse(WebCore::ServiceWorkerRegistrationIdentifier serviceWorkerRegistrationIdentifier, WebCore::FetchIdentifier fetchIdentifier) > > PostMessageToServiceWorker(WebCore::ServiceWorkerIdentifier destination, struct WebCore::MessageWithMessagePorts message, WebCore::ServiceWorkerOrClientIdentifier source) > >diff --git a/Source/WebKit/WebProcess/Storage/ServiceWorkerClientFetch.cpp b/Source/WebKit/WebProcess/Storage/ServiceWorkerClientFetch.cpp >index 30f0322facb1aab752c1ac3865af3c24d0adb27f..f07473c855bcf1217265fc82155c291cdcb57306 100644 >--- a/Source/WebKit/WebProcess/Storage/ServiceWorkerClientFetch.cpp >+++ b/Source/WebKit/WebProcess/Storage/ServiceWorkerClientFetch.cpp >@@ -70,17 +70,12 @@ void ServiceWorkerClientFetch::start() > > auto referrer = request.httpReferrer(); > >- m_didFail = false; >- m_didFinish = false; >- > // We are intercepting fetch calls after going through the HTTP layer, which may add some specific headers. > cleanHTTPRequestHeadersForAccessControl(request, options.httpHeadersToKeep); > > ASSERT(options.serviceWorkersMode != ServiceWorkersMode::None); > m_serviceWorkerRegistrationIdentifier = options.serviceWorkerRegistrationIdentifier.value(); > m_connection->startFetch(m_identifier, m_serviceWorkerRegistrationIdentifier, request, options, referrer); >- >- m_redirectionStatus = RedirectionStatus::None; > } > > // https://fetch.spec.whatwg.org/#http-fetch step 3.3 >@@ -104,42 +99,53 @@ Optional<ResourceError> ServiceWorkerClientFetch::validateResponse(const Resourc > return WTF::nullopt; > } > >-void ServiceWorkerClientFetch::didReceiveResponse(ResourceResponse&& response) >+void ServiceWorkerClientFetch::didReceiveRedirectResponse(ResourceResponse&& response) > { >- m_isCheckingResponse = true; > callOnMainThread([this, protectedThis = makeRef(*this), response = WTFMove(response)]() mutable { >- if (!m_loader) { >- m_isCheckingResponse = false; >+ if (!m_loader) > return; >- } > > if (auto error = validateResponse(response)) { >- m_isCheckingResponse = false; > m_loader->didFail(error.value()); > ASSERT(!m_loader); > if (auto callback = WTFMove(m_callback)) > callback(Result::Succeeded); >+ > return; > } > response.setSource(ResourceResponse::Source::ServiceWorker); > >- if (response.isRedirection() && response.httpHeaderFields().contains(HTTPHeaderName::Location)) { >- m_isCheckingResponse = false; >- continueLoadingAfterCheckingResponse(); >- m_redirectionStatus = RedirectionStatus::Receiving; >- m_loader->willSendRequest(m_loader->request().redirectedRequest(response, m_shouldClearReferrerOnHTTPSToHTTPRedirect), response, [protectedThis = makeRef(*this), this](ResourceRequest&& request) { >- if (request.isNull() || !m_callback) >- return; >- >- ASSERT(request == m_loader->request()); >- if (m_redirectionStatus == RedirectionStatus::Received) { >- start(); >- return; >- } >- m_redirectionStatus = RedirectionStatus::Following; >- }); >+ m_loader->willSendRequest(m_loader->request().redirectedRequest(response, m_shouldClearReferrerOnHTTPSToHTTPRedirect), response, [protectedThis = makeRef(*this), this](ResourceRequest&& request) { >+ if (!m_loader || request.isNull()) { >+ if (auto callback = WTFMove(m_callback)) >+ callback(Result::Succeeded); >+ return; >+ } >+ ASSERT(request == m_loader->request()); >+ start(); >+ }); >+ }); >+} >+ >+void ServiceWorkerClientFetch::didReceiveResponse(ResourceResponse&& response, bool needsContinueDidReceiveResponseMessage) >+{ >+ callOnMainThread([this, protectedThis = makeRef(*this), response = WTFMove(response), needsContinueDidReceiveResponseMessage]() mutable { >+ if (!m_loader) >+ return; >+ >+ if (auto error = validateResponse(response)) { >+ m_loader->didFail(error.value()); >+ ASSERT(!m_loader); >+ if (auto callback = WTFMove(m_callback)) >+ callback(Result::Succeeded); >+ > return; > } >+ response.setSource(ResourceResponse::Source::ServiceWorker); >+ ASSERT(!response.isRedirection() || !response.httpHeaderFields().contains(HTTPHeaderName::Location)); >+ >+ if (auto callback = WTFMove(m_callback)) >+ callback(Result::Succeeded); > > // In case of main resource and mime type is the default one, we set it to text/html to pass more service worker WPT tests. > // FIXME: We should refine our MIME type sniffing strategy for synthetic responses. >@@ -154,11 +160,16 @@ void ServiceWorkerClientFetch::didReceiveResponse(ResourceResponse&& response) > if (response.url().isNull()) > response.setURL(m_loader->request().url()); > >+ if (!needsContinueDidReceiveResponseMessage) { >+ m_loader->didReceiveResponse(response, [] { }); >+ return; >+ } >+ > m_loader->didReceiveResponse(response, [this, protectedThis = WTFMove(protectedThis)] { >- m_isCheckingResponse = false; >- continueLoadingAfterCheckingResponse(); >- if (auto callback = WTFMove(m_callback)) >- callback(Result::Succeeded); >+ if (!m_loader) >+ return; >+ >+ m_connection->continueDidReceiveFetchResponse(m_identifier, m_serviceWorkerRegistrationIdentifier); > }); > }); > } >@@ -166,23 +177,13 @@ void ServiceWorkerClientFetch::didReceiveResponse(ResourceResponse&& response) > void ServiceWorkerClientFetch::didReceiveData(const IPC::DataReference& dataReference, int64_t encodedDataLength) > { > auto* data = reinterpret_cast<const char*>(dataReference.data()); >- if (!m_buffer) { >- m_buffer = SharedBuffer::create(data, dataReference.size()); >- m_encodedDataLength = encodedDataLength; >- } else { >- m_buffer->append(data, dataReference.size()); >- m_encodedDataLength += encodedDataLength; >- } >- >- if (m_isCheckingResponse) >- return; >- >- callOnMainThread([this, protectedThis = makeRef(*this)] { >- if (!m_loader || !m_encodedDataLength) >+ callOnMainThread([this, protectedThis = makeRef(*this), encodedDataLength, buffer = SharedBuffer::create(data, dataReference.size())]() mutable { >+ if (!m_loader) > return; > >- m_loader->didReceiveBuffer(m_buffer.releaseNonNull(), m_encodedDataLength, DataPayloadBytes); >- m_encodedDataLength = 0; >+ m_encodedDataLength += encodedDataLength; >+ >+ m_loader->didReceiveBuffer(WTFMove(buffer), m_encodedDataLength, DataPayloadBytes); > }); > } > >@@ -193,29 +194,10 @@ void ServiceWorkerClientFetch::didReceiveFormData(const IPC::FormDataReference&) > > void ServiceWorkerClientFetch::didFinish() > { >- m_didFinish = true; >- >- if (m_isCheckingResponse) >- return; >- > callOnMainThread([this, protectedThis = makeRef(*this)] { > if (!m_loader) > return; > >- switch (m_redirectionStatus) { >- case RedirectionStatus::None: >- break; >- case RedirectionStatus::Receiving: >- m_redirectionStatus = RedirectionStatus::Received; >- return; >- case RedirectionStatus::Following: >- start(); >- return; >- case RedirectionStatus::Received: >- ASSERT_NOT_REACHED(); >- m_redirectionStatus = RedirectionStatus::None; >- } >- > ASSERT(!m_callback); > > m_loader->didFinishLoading(NetworkLoadMetrics { }); >@@ -225,24 +207,18 @@ void ServiceWorkerClientFetch::didFinish() > > void ServiceWorkerClientFetch::didFail(ResourceError&& error) > { >- m_didFail = true; >- m_error = WTFMove(error); >- >- if (m_isCheckingResponse) >- return; >- >- callOnMainThread([this, protectedThis = makeRef(*this)] { >+ callOnMainThread([this, protectedThis = makeRef(*this), error = WTFMove(error)] { > if (!m_loader) > return; > > auto* document = m_loader->frame() ? m_loader->frame()->document() : nullptr; > if (document) { >- document->addConsoleMessage(MessageSource::JS, MessageLevel::Error, m_error.localizedDescription()); >+ document->addConsoleMessage(MessageSource::JS, MessageLevel::Error, error.localizedDescription()); > if (m_loader->options().destination != FetchOptions::Destination::EmptyString) >- document->addConsoleMessage(MessageSource::JS, MessageLevel::Error, makeString("Cannot load ", m_error.failingURL().string(), ".")); >+ document->addConsoleMessage(MessageSource::JS, MessageLevel::Error, makeString("Cannot load ", error.failingURL().string(), ".")); > } > >- m_loader->didFail(m_error); >+ m_loader->didFail(error); > > if (auto callback = WTFMove(m_callback)) > callback(Result::Succeeded); >@@ -253,8 +229,6 @@ void ServiceWorkerClientFetch::didFail(ResourceError&& error) > > void ServiceWorkerClientFetch::didNotHandle() > { >- ASSERT(!m_isCheckingResponse); >- > callOnMainThread([this, protectedThis = makeRef(*this)] { > if (!m_loader) > return; >@@ -271,36 +245,8 @@ void ServiceWorkerClientFetch::cancel() > if (auto callback = WTFMove(m_callback)) > callback(Result::Cancelled); > >- if (!m_didFinish && !m_didFail) { >- m_connection->cancelFetch(m_identifier, m_serviceWorkerRegistrationIdentifier); >- >- } >+ m_connection->cancelFetch(m_identifier, m_serviceWorkerRegistrationIdentifier); > m_loader = nullptr; >- m_buffer = nullptr; >-} >- >-void ServiceWorkerClientFetch::continueLoadingAfterCheckingResponse() >-{ >- ASSERT(!m_isCheckingResponse); >- if (!m_loader) >- return; >- >- if (m_encodedDataLength) { >- callOnMainThread([this, protectedThis = makeRef(*this)] { >- if (!m_loader || !m_encodedDataLength) >- return; >- m_loader->didReceiveBuffer(m_buffer.releaseNonNull(), m_encodedDataLength, DataPayloadBytes); >- m_encodedDataLength = 0; >- }); >- } >- >- if (m_didFail) { >- didFail(WTFMove(m_error)); >- return; >- } >- >- if (m_didFinish) >- didFinish(); > } > > } // namespace WebKit >diff --git a/Source/WebKit/WebProcess/Storage/ServiceWorkerClientFetch.h b/Source/WebKit/WebProcess/Storage/ServiceWorkerClientFetch.h >index 736b3ac03bc7229be9e4ead365ad9c7255cc4125..c667ac757fdd710888b8b2d4eee944990f0b0d03 100644 >--- a/Source/WebKit/WebProcess/Storage/ServiceWorkerClientFetch.h >+++ b/Source/WebKit/WebProcess/Storage/ServiceWorkerClientFetch.h >@@ -61,30 +61,22 @@ private: > > Optional<WebCore::ResourceError> validateResponse(const WebCore::ResourceResponse&); > >- void didReceiveResponse(WebCore::ResourceResponse&&); >+ void didReceiveResponse(WebCore::ResourceResponse&&, bool needsContinueDidReceiveResponseMessage); >+ void didReceiveRedirectResponse(WebCore::ResourceResponse&&); > void didReceiveData(const IPC::DataReference&, int64_t encodedDataLength); > void didReceiveFormData(const IPC::FormDataReference&); > void didFinish(); > void didFail(WebCore::ResourceError&&); > void didNotHandle(); > >- void continueLoadingAfterCheckingResponse(); >- > WebServiceWorkerProvider& m_serviceWorkerProvider; > RefPtr<WebCore::ResourceLoader> m_loader; > WebCore::FetchIdentifier m_identifier; > Ref<WebSWClientConnection> m_connection; > Callback m_callback; >- enum class RedirectionStatus { None, Receiving, Following, Received }; >- RedirectionStatus m_redirectionStatus { RedirectionStatus::None }; > bool m_shouldClearReferrerOnHTTPSToHTTPRedirect { true }; >- RefPtr<WebCore::SharedBuffer> m_buffer; > int64_t m_encodedDataLength { 0 }; >- bool m_isCheckingResponse { false }; >- bool m_didFinish { false }; > bool m_didFail { false }; >- WebCore::ResourceError m_error; >- > WebCore::ServiceWorkerRegistrationIdentifier m_serviceWorkerRegistrationIdentifier; > }; > >diff --git a/Source/WebKit/WebProcess/Storage/ServiceWorkerClientFetch.messages.in b/Source/WebKit/WebProcess/Storage/ServiceWorkerClientFetch.messages.in >index e0153d36fc79f331c245cd1892b52224b67da1fc..3d3bc7404bfb47d61e0d1588e1a5f2a9c06a1661 100644 >--- a/Source/WebKit/WebProcess/Storage/ServiceWorkerClientFetch.messages.in >+++ b/Source/WebKit/WebProcess/Storage/ServiceWorkerClientFetch.messages.in >@@ -23,7 +23,8 @@ > #if ENABLE(SERVICE_WORKER) > > messages -> ServiceWorkerClientFetch { >- DidReceiveResponse(WebCore::ResourceResponse response) >+ DidReceiveResponse(WebCore::ResourceResponse response, bool needsContinueDidReceiveResponseMessage) >+ DidReceiveRedirectResponse(WebCore::ResourceResponse response) > DidReceiveData(IPC::DataReference data, int64_t encodedDataLength) > DidReceiveFormData(IPC::FormDataReference data) > DidFinish() >diff --git a/Source/WebKit/WebProcess/Storage/WebSWClientConnection.cpp b/Source/WebKit/WebProcess/Storage/WebSWClientConnection.cpp >index a555ca3c00083bd95eaed0323d52bb3e603986bb..507b990765ca1f8d546f9c07cca89c7d8c7b12af 100644 >--- a/Source/WebKit/WebProcess/Storage/WebSWClientConnection.cpp >+++ b/Source/WebKit/WebProcess/Storage/WebSWClientConnection.cpp >@@ -198,16 +198,21 @@ void WebSWClientConnection::getRegistrations(SecurityOriginData&& topOrigin, con > }); > } > >-void WebSWClientConnection::startFetch(WebCore::FetchIdentifier fetchIdentifier, WebCore::ServiceWorkerRegistrationIdentifier serviceWorkerRegistrationIdentifier, const WebCore::ResourceRequest& request, const WebCore::FetchOptions& options, const String& referrer) >+void WebSWClientConnection::startFetch(FetchIdentifier fetchIdentifier, ServiceWorkerRegistrationIdentifier serviceWorkerRegistrationIdentifier, const ResourceRequest& request, const FetchOptions& options, const String& referrer) > { > send(Messages::WebSWServerConnection::StartFetch { serviceWorkerRegistrationIdentifier, fetchIdentifier, request, options, IPC::FormDataReference { request.httpBody() }, referrer }); > } > >-void WebSWClientConnection::cancelFetch(WebCore::FetchIdentifier fetchIdentifier, WebCore::ServiceWorkerRegistrationIdentifier serviceWorkerRegistrationIdentifier) >+void WebSWClientConnection::cancelFetch(FetchIdentifier fetchIdentifier, ServiceWorkerRegistrationIdentifier serviceWorkerRegistrationIdentifier) > { > send(Messages::WebSWServerConnection::CancelFetch { serviceWorkerRegistrationIdentifier, fetchIdentifier }); > } > >+void WebSWClientConnection::continueDidReceiveFetchResponse(FetchIdentifier fetchIdentifier, ServiceWorkerRegistrationIdentifier serviceWorkerRegistrationIdentifier) >+{ >+ send(Messages::WebSWServerConnection::ContinueDidReceiveFetchResponse { serviceWorkerRegistrationIdentifier, fetchIdentifier }); >+} >+ > void WebSWClientConnection::postMessageToServiceWorkerClient(DocumentIdentifier destinationContextIdentifier, MessageWithMessagePorts&& message, ServiceWorkerData&& source, const String& sourceOrigin) > { > SWClientConnection::postMessageToServiceWorkerClient(destinationContextIdentifier, WTFMove(message), WTFMove(source), sourceOrigin); >diff --git a/Source/WebKit/WebProcess/Storage/WebSWClientConnection.h b/Source/WebKit/WebProcess/Storage/WebSWClientConnection.h >index cb1a10cbb17d3d7b23415262e1841516684af359..58d69dac8da03f5512b00a30fe180d519d0e4886 100644 >--- a/Source/WebKit/WebProcess/Storage/WebSWClientConnection.h >+++ b/Source/WebKit/WebProcess/Storage/WebSWClientConnection.h >@@ -63,6 +63,7 @@ public: > bool mayHaveServiceWorkerRegisteredForOrigin(const WebCore::SecurityOriginData&) const final; > void startFetch(WebCore::FetchIdentifier, WebCore::ServiceWorkerRegistrationIdentifier, const WebCore::ResourceRequest&, const WebCore::FetchOptions&, const String& referrer); > void cancelFetch(WebCore::FetchIdentifier, WebCore::ServiceWorkerRegistrationIdentifier); >+ void continueDidReceiveFetchResponse(WebCore::FetchIdentifier, WebCore::ServiceWorkerRegistrationIdentifier); > > void postMessageToServiceWorkerClient(WebCore::DocumentIdentifier destinationContextIdentifier, WebCore::MessageWithMessagePorts&&, WebCore::ServiceWorkerData&& source, const String& sourceOrigin); > >diff --git a/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.cpp b/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.cpp >index e46cf80ea79c230f4f2f0f2a9b44490c83a80a8a..5bd823f7774d396c4389d47b4dc6105fabebb23e 100644 >--- a/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.cpp >+++ b/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.cpp >@@ -215,6 +215,12 @@ void WebSWContextManagerConnection::cancelFetch(SWServerConnectionIdentifier ser > serviceWorkerThreadProxy->cancelFetch(serverConnectionIdentifier, fetchIdentifier); > } > >+void WebSWContextManagerConnection::continueDidReceiveFetchResponse(SWServerConnectionIdentifier serverConnectionIdentifier, ServiceWorkerIdentifier serviceWorkerIdentifier, FetchIdentifier fetchIdentifier) >+{ >+ if (auto* serviceWorkerThreadProxy = SWContextManager::singleton().serviceWorkerThreadProxy(serviceWorkerIdentifier)) >+ serviceWorkerThreadProxy->continueDidReceiveFetchResponse(serverConnectionIdentifier, fetchIdentifier); >+} >+ > void WebSWContextManagerConnection::startFetch(SWServerConnectionIdentifier serverConnectionIdentifier, ServiceWorkerIdentifier serviceWorkerIdentifier, FetchIdentifier fetchIdentifier, ResourceRequest&& request, FetchOptions&& options, IPC::FormDataReference&& formData, String&& referrer) > { > auto* serviceWorkerThreadProxy = SWContextManager::singleton().serviceWorkerThreadProxy(serviceWorkerIdentifier); >@@ -228,7 +234,7 @@ void WebSWContextManagerConnection::startFetch(SWServerConnectionIdentifier serv > return; > } > >- auto client = WebServiceWorkerFetchTaskClient::create(m_connectionToNetworkProcess.copyRef(), serviceWorkerIdentifier, serverConnectionIdentifier, fetchIdentifier); >+ auto client = WebServiceWorkerFetchTaskClient::create(m_connectionToNetworkProcess.copyRef(), serviceWorkerIdentifier, serverConnectionIdentifier, fetchIdentifier, request.requester() == ResourceRequest::Requester::Main); > Optional<ServiceWorkerClientIdentifier> clientId; > if (options.clientIdentifier) > clientId = ServiceWorkerClientIdentifier { serverConnectionIdentifier, options.clientIdentifier.value() }; >diff --git a/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.h b/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.h >index 0d24144982324f2ecc866c0fb4165f57697d1538..9460f0e2c9cc1989b7e303f07de385a4133739b6 100644 >--- a/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.h >+++ b/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.h >@@ -79,6 +79,7 @@ private: > void installServiceWorker(const WebCore::ServiceWorkerContextData&, PAL::SessionID, String&& userAgent); > void startFetch(WebCore::SWServerConnectionIdentifier, WebCore::ServiceWorkerIdentifier, WebCore::FetchIdentifier, WebCore::ResourceRequest&&, WebCore::FetchOptions&&, IPC::FormDataReference&&, String&& referrer); > void cancelFetch(WebCore::SWServerConnectionIdentifier, WebCore::ServiceWorkerIdentifier, WebCore::FetchIdentifier); >+ void continueDidReceiveFetchResponse(WebCore::SWServerConnectionIdentifier, WebCore::ServiceWorkerIdentifier, WebCore::FetchIdentifier); > void postMessageToServiceWorker(WebCore::ServiceWorkerIdentifier destinationIdentifier, WebCore::MessageWithMessagePorts&&, WebCore::ServiceWorkerOrClientData&& sourceData); > void fireInstallEvent(WebCore::ServiceWorkerIdentifier); > void fireActivateEvent(WebCore::ServiceWorkerIdentifier); >diff --git a/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.messages.in b/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.messages.in >index dfe5a38e16ece8bfcb062fccd8c4e60ecdf21c13..a31f54a5355b42291ca153431243549696d65db4 100644 >--- a/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.messages.in >+++ b/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.messages.in >@@ -26,6 +26,7 @@ messages -> WebSWContextManagerConnection { > InstallServiceWorker(struct WebCore::ServiceWorkerContextData contextData, PAL::SessionID sessionID, String userAgent) > StartFetch(WebCore::SWServerConnectionIdentifier serverConnectionIdentifier, WebCore::ServiceWorkerIdentifier serviceWorkerIdentifier, WebCore::FetchIdentifier fetchIdentifier, WebCore::ResourceRequest request, struct WebCore::FetchOptions options, IPC::FormDataReference requestBody, String referrer) > CancelFetch(WebCore::SWServerConnectionIdentifier serverConnectionIdentifier, WebCore::ServiceWorkerIdentifier serviceWorkerIdentifier, WebCore::FetchIdentifier fetchIdentifier) >+ ContinueDidReceiveFetchResponse(WebCore::SWServerConnectionIdentifier serverConnectionIdentifier, WebCore::ServiceWorkerIdentifier serviceWorkerIdentifier, WebCore::FetchIdentifier fetchIdentifier) > PostMessageToServiceWorker(WebCore::ServiceWorkerIdentifier destinationIdentifier, struct WebCore::MessageWithMessagePorts message, WebCore::ServiceWorkerOrClientData sourceData) > FireInstallEvent(WebCore::ServiceWorkerIdentifier identifier) > FireActivateEvent(WebCore::ServiceWorkerIdentifier identifier) >diff --git a/Source/WebKit/WebProcess/Storage/WebServiceWorkerFetchTaskClient.cpp b/Source/WebKit/WebProcess/Storage/WebServiceWorkerFetchTaskClient.cpp >index 6f4300678105eb34c456dd48e4c50ce1ce00449a..74cbd0e90e19257a0de2a8d19eaac6f379da0b57 100644 >--- a/Source/WebKit/WebProcess/Storage/WebServiceWorkerFetchTaskClient.cpp >+++ b/Source/WebKit/WebProcess/Storage/WebServiceWorkerFetchTaskClient.cpp >@@ -42,31 +42,48 @@ > namespace WebKit { > using namespace WebCore; > >-WebServiceWorkerFetchTaskClient::~WebServiceWorkerFetchTaskClient() >-{ >- if (m_connection) >- RunLoop::main().dispatch([connection = WTFMove(m_connection)] { }); >-} >- >-WebServiceWorkerFetchTaskClient::WebServiceWorkerFetchTaskClient(Ref<IPC::Connection>&& connection, WebCore::ServiceWorkerIdentifier serviceWorkerIdentifier, WebCore::SWServerConnectionIdentifier serverConnectionIdentifier, FetchIdentifier fetchIdentifier) >+WebServiceWorkerFetchTaskClient::WebServiceWorkerFetchTaskClient(Ref<IPC::Connection>&& connection, WebCore::ServiceWorkerIdentifier serviceWorkerIdentifier, WebCore::SWServerConnectionIdentifier serverConnectionIdentifier, FetchIdentifier fetchIdentifier, bool needsContinueDidReceiveResponseMessage) > : m_connection(WTFMove(connection)) > , m_serverConnectionIdentifier(serverConnectionIdentifier) > , m_serviceWorkerIdentifier(serviceWorkerIdentifier) > , m_fetchIdentifier(fetchIdentifier) >+ , m_needsContinueDidReceiveResponseMessage(needsContinueDidReceiveResponseMessage) >+{ >+} >+ >+void WebServiceWorkerFetchTaskClient::didReceiveRedirection(const WebCore::ResourceResponse& response) > { >+ if (!m_connection) >+ return; >+ m_connection->send(Messages::NetworkProcess::DidReceiveFetchRedirectResponse { m_serverConnectionIdentifier, m_fetchIdentifier, response }, 0); >+ >+ cleanup(); > } > > void WebServiceWorkerFetchTaskClient::didReceiveResponse(const ResourceResponse& response) > { > if (!m_connection) > return; >- m_connection->send(Messages::NetworkProcess::DidReceiveFetchResponse { m_serverConnectionIdentifier, m_fetchIdentifier, response }, 0); >+ >+ if (m_needsContinueDidReceiveResponseMessage) >+ m_waitingForContinueDidReceiveResponseMessage = true; >+ >+ m_connection->send(Messages::NetworkProcess::DidReceiveFetchResponse { m_serverConnectionIdentifier, m_fetchIdentifier, response, m_needsContinueDidReceiveResponseMessage }, 0); > } > > void WebServiceWorkerFetchTaskClient::didReceiveData(Ref<SharedBuffer>&& buffer) > { > if (!m_connection) > return; >+ >+ if (m_waitingForContinueDidReceiveResponseMessage) { >+ if (!m_buffer) >+ m_buffer = buffer->copy(); >+ else >+ m_buffer->append(WTFMove(buffer)); >+ return; >+ } >+ > m_connection->send(Messages::NetworkProcess::DidReceiveFetchData { m_serverConnectionIdentifier, m_fetchIdentifier, { buffer }, static_cast<int64_t>(buffer->size()) }, 0); > } > >@@ -75,6 +92,11 @@ void WebServiceWorkerFetchTaskClient::didReceiveFormDataAndFinish(Ref<FormData>& > if (!m_connection) > return; > >+ if (m_waitingForContinueDidReceiveResponseMessage) { >+ m_formData = formData->isolatedCopy(); >+ return; >+ } >+ > // FIXME: We should send this form data to the other process and consume it there. > // For now and for the case of blobs, we read it there and send the data through IPC. > URL blobURL = formData->asBlobURL(); >@@ -122,6 +144,11 @@ void WebServiceWorkerFetchTaskClient::didFail(const ResourceError& error) > if (!m_connection) > return; > >+ if (m_waitingForContinueDidReceiveResponseMessage) { >+ m_error = error.isolatedCopy(); >+ return; >+ } >+ > m_connection->send(Messages::NetworkProcess::DidFailFetch { m_serverConnectionIdentifier, m_fetchIdentifier, error }, 0); > > cleanup(); >@@ -132,6 +159,11 @@ void WebServiceWorkerFetchTaskClient::didFinish() > if (!m_connection) > return; > >+ if (m_waitingForContinueDidReceiveResponseMessage) { >+ m_didFinish = true; >+ return; >+ } >+ > m_connection->send(Messages::NetworkProcess::DidFinishFetch { m_serverConnectionIdentifier, m_fetchIdentifier }, 0); > > cleanup(); >@@ -152,6 +184,33 @@ void WebServiceWorkerFetchTaskClient::cancel() > m_connection = nullptr; > } > >+void WebServiceWorkerFetchTaskClient::continueDidReceiveResponse() >+{ >+ if (!m_connection) >+ return; >+ >+ m_waitingForContinueDidReceiveResponseMessage = false; >+ >+ if (m_error) { >+ didFail(*m_error); >+ return; >+ } >+ >+ if (m_formData) { >+ auto formData = WTFMove(m_formData); >+ didReceiveFormDataAndFinish(formData.releaseNonNull()); >+ return; >+ } >+ >+ if (m_buffer) { >+ auto buffer = WTFMove(m_buffer); >+ didReceiveData(buffer.releaseNonNull()); >+ } >+ >+ if (m_didFinish) >+ didFinish(); >+} >+ > void WebServiceWorkerFetchTaskClient::cleanup() > { > m_connection = nullptr; >diff --git a/Source/WebKit/WebProcess/Storage/WebServiceWorkerFetchTaskClient.h b/Source/WebKit/WebProcess/Storage/WebServiceWorkerFetchTaskClient.h >index 53303c8da6c14f0316996fd13aa57aaaef6478e8..16289ea9356d4574382dc37de81cd5e1f6be03a0 100644 >--- a/Source/WebKit/WebProcess/Storage/WebServiceWorkerFetchTaskClient.h >+++ b/Source/WebKit/WebProcess/Storage/WebServiceWorkerFetchTaskClient.h >@@ -31,6 +31,7 @@ > #include <WebCore/FetchIdentifier.h> > #include <WebCore/FetchLoader.h> > #include <WebCore/FetchLoaderClient.h> >+#include <WebCore/ResourceError.h> > #include <WebCore/ServiceWorkerFetch.h> > #include <WebCore/ServiceWorkerTypes.h> > >@@ -38,23 +39,23 @@ namespace WebKit { > > class WebServiceWorkerFetchTaskClient final : public WebCore::ServiceWorkerFetch::Client { > public: >- static Ref<WebServiceWorkerFetchTaskClient> create(Ref<IPC::Connection>&& connection, WebCore::ServiceWorkerIdentifier serviceWorkerIdentifier, WebCore::SWServerConnectionIdentifier serverConnectionIdentifier, WebCore::FetchIdentifier fetchTaskIdentifier) >+ static Ref<WebServiceWorkerFetchTaskClient> create(Ref<IPC::Connection>&& connection, WebCore::ServiceWorkerIdentifier serviceWorkerIdentifier, WebCore::SWServerConnectionIdentifier serverConnectionIdentifier, WebCore::FetchIdentifier fetchTaskIdentifier, bool needsContinueDidReceiveResponseMessage) > { >- return adoptRef(*new WebServiceWorkerFetchTaskClient(WTFMove(connection), serviceWorkerIdentifier, serverConnectionIdentifier, fetchTaskIdentifier)); >+ return adoptRef(*new WebServiceWorkerFetchTaskClient(WTFMove(connection), serviceWorkerIdentifier, serverConnectionIdentifier, fetchTaskIdentifier, needsContinueDidReceiveResponseMessage)); > } > >- ~WebServiceWorkerFetchTaskClient(); >- > private: >- WebServiceWorkerFetchTaskClient(Ref<IPC::Connection>&&, WebCore::ServiceWorkerIdentifier, WebCore::SWServerConnectionIdentifier, WebCore::FetchIdentifier); >+ WebServiceWorkerFetchTaskClient(Ref<IPC::Connection>&&, WebCore::ServiceWorkerIdentifier, WebCore::SWServerConnectionIdentifier, WebCore::FetchIdentifier, bool needsContinueDidReceiveResponseMessage); > > void didReceiveResponse(const WebCore::ResourceResponse&) final; >+ void didReceiveRedirection(const WebCore::ResourceResponse&) final; > void didReceiveData(Ref<WebCore::SharedBuffer>&&) final; > void didReceiveFormDataAndFinish(Ref<WebCore::FormData>&&) final; > void didFail(const WebCore::ResourceError&) final; > void didFinish() final; > void didNotHandle() final; > void cancel() final; >+ void continueDidReceiveResponse() final; > > void cleanup(); > >@@ -79,6 +80,12 @@ private: > WebCore::ServiceWorkerIdentifier m_serviceWorkerIdentifier; > WebCore::FetchIdentifier m_fetchIdentifier; > Optional<BlobLoader> m_blobLoader; >+ bool m_needsContinueDidReceiveResponseMessage { false }; >+ bool m_waitingForContinueDidReceiveResponseMessage { false }; >+ RefPtr<WebCore::SharedBuffer> m_buffer; >+ RefPtr<FormData> m_formData; >+ bool m_didFinish { false }; >+ Optional<ResourceError> m_error; > }; > > } // namespace WebKit
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 194651
:
362019
|
362067
|
362140
|
362146