Changeset 256900 in webkit
- Timestamp:
- Feb 18, 2020 7:26:28 PM (4 years ago)
- Location:
- trunk/Source
- Files:
-
- 16 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r256895 r256900 1 2020-02-18 Youenn Fablet <youenn@apple.com> 2 3 SWServer::claim should check for the service worker to be active 4 https://bugs.webkit.org/show_bug.cgi?id=207739 5 <rdar://problem/45441129> 6 7 Reviewed by Alex Christensen. 8 9 claim is only working for service workers that are active. 10 But there might be a time when a service worker is active in its web process but redundant in networking process. 11 Thus, we need to move the check from WebProcess to NetworkProcess. 12 13 * workers/service/ServiceWorkerClients.cpp: 14 (WebCore::ServiceWorkerClients::claim): 15 * workers/service/context/SWContextManager.h: 16 * workers/service/server/SWServer.cpp: 17 (WebCore::SWServer::claim): 18 * workers/service/server/SWServer.h: 19 * workers/service/server/SWServerToContextConnection.cpp: 20 (WebCore::SWServerToContextConnection::claim): 21 * workers/service/server/SWServerToContextConnection.h: 22 * workers/service/server/SWServerWorker.cpp: 23 (WebCore::SWServerWorker::claim): Deleted. 24 * workers/service/server/SWServerWorker.h: 25 (WebCore::SWServerWorker::isActive const): 26 1 27 2020-02-18 Zalan Bujtas <zalan@apple.com> 2 28 -
trunk/Source/WebCore/workers/service/ServiceWorkerClients.cpp
r244115 r256900 117 117 auto serviceWorkerIdentifier = serviceWorkerGlobalScope.thread().identifier(); 118 118 119 if (!serviceWorkerGlobalScope.registration().active() || serviceWorkerGlobalScope.registration().active()->identifier() != serviceWorkerIdentifier) {120 promise->reject(Exception { InvalidStateError, "Service worker is not active"_s });121 return;122 }123 124 119 auto promisePointer = promise.ptr(); 125 120 m_pendingPromises.add(promisePointer, WTFMove(promise)); … … 127 122 callOnMainThread([promisePointer, serviceWorkerIdentifier] () mutable { 128 123 auto connection = SWContextManager::singleton().connection(); 129 connection->claim(serviceWorkerIdentifier, [promisePointer, serviceWorkerIdentifier] () mutable { 130 SWContextManager::singleton().postTaskToServiceWorker(serviceWorkerIdentifier, [promisePointer] (auto& scope) mutable { 131 if (auto promise = scope.clients().m_pendingPromises.take(promisePointer)) 132 promise.value()->resolve(); 124 connection->claim(serviceWorkerIdentifier, [promisePointer, serviceWorkerIdentifier](auto&& result) mutable { 125 SWContextManager::singleton().postTaskToServiceWorker(serviceWorkerIdentifier, [promisePointer, result = isolatedCopy(WTFMove(result))](auto& scope) mutable { 126 if (auto promise = scope.clients().m_pendingPromises.take(promisePointer)) { 127 DOMPromiseDeferred<void> pendingPromise { WTFMove(promise.value()) }; 128 pendingPromise.settle(WTFMove(result)); 129 } 133 130 }); 134 131 }); -
trunk/Source/WebCore/workers/service/context/SWContextManager.h
r255681 r256900 64 64 virtual void findClientByIdentifier(ServiceWorkerIdentifier, ServiceWorkerClientIdentifier, FindClientByIdentifierCallback&&) = 0; 65 65 virtual void matchAll(ServiceWorkerIdentifier, const ServiceWorkerClientQueryOptions&, ServiceWorkerClientsMatchAllCallback&&) = 0; 66 virtual void claim(ServiceWorkerIdentifier, CompletionHandler<void( )>&&) = 0;66 virtual void claim(ServiceWorkerIdentifier, CompletionHandler<void(ExceptionOr<void>&&)>&&) = 0; 67 67 68 68 virtual void didFailHeartBeatCheck(ServiceWorkerIdentifier) = 0; -
trunk/Source/WebCore/workers/service/server/SWServer.cpp
r256664 r256900 560 560 } 561 561 562 void SWServer::claim(SWServerWorker& worker) 563 { 562 Optional<ExceptionData> SWServer::claim(SWServerWorker& worker) 563 { 564 if (!worker.isActive()) 565 return ExceptionData { InvalidStateError, "Service worker is not active"_s }; 566 564 567 auto& origin = worker.origin(); 565 568 forEachClientForOrigin(origin, [&](auto& clientData) { … … 579 582 registration->controlClient(clientData.identifier); 580 583 }); 584 return { }; 581 585 } 582 586 -
trunk/Source/WebCore/workers/service/server/SWServer.h
r256749 r256900 30 30 #include "ClientOrigin.h" 31 31 #include "DocumentIdentifier.h" 32 #include "ExceptionOr.h" 32 33 #include "SWServerWorker.h" 33 34 #include "SecurityOriginData.h" … … 179 180 void workerContextTerminated(SWServerWorker&); 180 181 void matchAll(SWServerWorker&, const ServiceWorkerClientQueryOptions&, ServiceWorkerClientsMatchAllCallback&&); 181 voidclaim(SWServerWorker&);182 Optional<ExceptionData> claim(SWServerWorker&); 182 183 183 184 WEBCORE_EXPORT static HashSet<SWServer*>& allServers(); -
trunk/Source/WebCore/workers/service/server/SWServerToContextConnection.cpp
r253898 r256900 102 102 } 103 103 104 void SWServerToContextConnection::claim( uint64_t requestIdentifier, ServiceWorkerIdentifier serviceWorkerIdentifier)104 void SWServerToContextConnection::claim(ServiceWorkerIdentifier serviceWorkerIdentifier, CompletionHandler<void(Optional<ExceptionData>&&)>&& callback) 105 105 { 106 if (auto* worker = SWServerWorker::existingWorkerForIdentifier(serviceWorkerIdentifier)) { 107 worker->claim(); 108 worker->contextConnection()->claimCompleted(requestIdentifier); 109 } 106 auto* worker = SWServerWorker::existingWorkerForIdentifier(serviceWorkerIdentifier); 107 auto* server = worker ? worker->server() : nullptr; 108 callback(server ? server->claim(*worker) : WTF::nullopt); 110 109 } 111 110 -
trunk/Source/WebCore/workers/service/server/SWServerToContextConnection.h
r253898 r256900 28 28 #if ENABLE(SERVICE_WORKER) 29 29 30 #include "ExceptionData.h" 30 31 #include "RegistrableDomain.h" 31 32 #include "ServiceWorkerClientQueryOptions.h" … … 57 58 virtual void findClientByIdentifierCompleted(uint64_t requestIdentifier, const Optional<ServiceWorkerClientData>&, bool hasSecurityError) = 0; 58 59 virtual void matchAllCompleted(uint64_t requestIdentifier, const Vector<ServiceWorkerClientData>&) = 0; 59 virtual void claimCompleted(uint64_t requestIdentifier) = 0;60 60 61 61 // Messages back from the SW host process … … 69 69 WEBCORE_EXPORT void findClientByIdentifier(uint64_t clientIdRequestIdentifier, ServiceWorkerIdentifier, ServiceWorkerClientIdentifier); 70 70 WEBCORE_EXPORT void matchAll(uint64_t requestIdentifier, ServiceWorkerIdentifier, const ServiceWorkerClientQueryOptions&); 71 WEBCORE_EXPORT void claim( uint64_t requestIdentifier, ServiceWorkerIdentifier);71 WEBCORE_EXPORT void claim(ServiceWorkerIdentifier, CompletionHandler<void(Optional<ExceptionData>&&)>&&); 72 72 WEBCORE_EXPORT void setScriptResource(ServiceWorkerIdentifier, URL&& scriptURL, String&& script, URL&& responseURL, String&& mimeType); 73 73 WEBCORE_EXPORT void didFailHeartBeatCheck(ServiceWorkerIdentifier); -
trunk/Source/WebCore/workers/service/server/SWServerWorker.cpp
r255058 r256900 173 173 } 174 174 175 void SWServerWorker::claim()176 {177 ASSERT(m_server);178 if (m_server)179 m_server->claim(*this);180 }181 182 175 void SWServerWorker::setScriptResource(URL&& url, ServiceWorkerContextData::ImportedScript&& script) 183 176 { -
trunk/Source/WebCore/workers/service/server/SWServerWorker.h
r255058 r256900 83 83 84 84 ServiceWorkerState state() const { return m_data.state; } 85 bool isActive() const { return m_data.state == ServiceWorkerState::Activated || m_data.state == ServiceWorkerState::Activating; } 86 85 87 void setState(ServiceWorkerState); 86 88 … … 95 97 WEBCORE_EXPORT Optional<ServiceWorkerClientData> findClientByIdentifier(const ServiceWorkerClientIdentifier&) const; 96 98 void matchAll(const ServiceWorkerClientQueryOptions&, ServiceWorkerClientsMatchAllCallback&&); 97 void claim();98 99 void setScriptResource(URL&&, ServiceWorkerContextData::ImportedScript&&); 99 100 -
trunk/Source/WebKit/ChangeLog
r256892 r256900 1 2020-02-18 Youenn Fablet <youenn@apple.com> 2 3 SWServer::claim should check for the service worker to be active 4 https://bugs.webkit.org/show_bug.cgi?id=207739 5 <rdar://problem/45441129> 6 7 Reviewed by Alex Christensen. 8 9 Use Async Reply to remove the need for a map and passing integers around. 10 11 * NetworkProcess/ServiceWorker/WebSWServerToContextConnection.cpp: 12 (WebKit::WebSWServerToContextConnection::claimCompleted): Deleted. 13 * NetworkProcess/ServiceWorker/WebSWServerToContextConnection.h: 14 * NetworkProcess/ServiceWorker/WebSWServerToContextConnection.messages.in: 15 * WebProcess/Storage/WebSWContextManagerConnection.cpp: 16 (WebKit::WebSWContextManagerConnection::claim): 17 (WebKit::WebSWContextManagerConnection::claimCompleted): Deleted. 18 * WebProcess/Storage/WebSWContextManagerConnection.h: 19 * WebProcess/Storage/WebSWContextManagerConnection.messages.in: 20 1 21 2020-02-18 Said Abou-Hallawa <sabouhallawa@apple.com> 2 22 -
trunk/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerToContextConnection.cpp
r255058 r256900 123 123 } 124 124 125 void WebSWServerToContextConnection::claimCompleted(uint64_t requestIdentifier)126 {127 send(Messages::WebSWContextManagerConnection::ClaimCompleted { requestIdentifier });128 }129 130 125 void WebSWServerToContextConnection::connectionIsNoLongerNeeded() 131 126 { -
trunk/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerToContextConnection.h
r255058 r256900 91 91 void findClientByIdentifierCompleted(uint64_t requestIdentifier, const Optional<WebCore::ServiceWorkerClientData>&, bool hasSecurityError) final; 92 92 void matchAllCompleted(uint64_t requestIdentifier, const Vector<WebCore::ServiceWorkerClientData>&) final; 93 void claimCompleted(uint64_t requestIdentifier) final;94 93 95 94 void connectionIsNoLongerNeeded() final; -
trunk/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerToContextConnection.messages.in
r253898 r256900 26 26 # When possible, these messages can be implemented directly by WebCore::SWServerToContextConnection 27 27 28 ScriptContextFailedToStart(Optional<WebCore::ServiceWorkerJobDataIdentifier> jobDataIdentifier, WebCore::ServiceWorkerIdentifier serviceWorkerIdentifier, String message) ;29 ScriptContextStarted(Optional<WebCore::ServiceWorkerJobDataIdentifier> jobDataIdentifier, WebCore::ServiceWorkerIdentifier serviceWorkerIdentifier, bool doesHandleFetch) ;30 DidFinishInstall(Optional<WebCore::ServiceWorkerJobDataIdentifier> jobDataIdentifier, WebCore::ServiceWorkerIdentifier serviceWorkerIdentifier, bool wasSuccessful) ;31 DidFinishActivation(WebCore::ServiceWorkerIdentifier identifier) ;32 SetServiceWorkerHasPendingEvents(WebCore::ServiceWorkerIdentifier identifier, bool hasPendingEvents) ;28 ScriptContextFailedToStart(Optional<WebCore::ServiceWorkerJobDataIdentifier> jobDataIdentifier, WebCore::ServiceWorkerIdentifier serviceWorkerIdentifier, String message) 29 ScriptContextStarted(Optional<WebCore::ServiceWorkerJobDataIdentifier> jobDataIdentifier, WebCore::ServiceWorkerIdentifier serviceWorkerIdentifier, bool doesHandleFetch) 30 DidFinishInstall(Optional<WebCore::ServiceWorkerJobDataIdentifier> jobDataIdentifier, WebCore::ServiceWorkerIdentifier serviceWorkerIdentifier, bool wasSuccessful) 31 DidFinishActivation(WebCore::ServiceWorkerIdentifier identifier) 32 SetServiceWorkerHasPendingEvents(WebCore::ServiceWorkerIdentifier identifier, bool hasPendingEvents) 33 33 SkipWaiting(WebCore::ServiceWorkerIdentifier identifier) -> () Async 34 WorkerTerminated(WebCore::ServiceWorkerIdentifier identifier) ;35 FindClientByIdentifier(uint64_t requestIdentifier, WebCore::ServiceWorkerIdentifier serviceWorkerIdentifier, struct WebCore::ServiceWorkerClientIdentifier clientIdentifier) ;34 WorkerTerminated(WebCore::ServiceWorkerIdentifier identifier) 35 FindClientByIdentifier(uint64_t requestIdentifier, WebCore::ServiceWorkerIdentifier serviceWorkerIdentifier, struct WebCore::ServiceWorkerClientIdentifier clientIdentifier) 36 36 MatchAll(uint64_t matchAllRequestIdentifier, WebCore::ServiceWorkerIdentifier serviceWorkerIdentifier, struct WebCore::ServiceWorkerClientQueryOptions options); 37 Claim( uint64_t claimRequestIdentifier, WebCore::ServiceWorkerIdentifier serviceWorkerIdentifier);38 SetScriptResource(WebCore::ServiceWorkerIdentifier identifier, URL scriptURL, String script, URL responseURL, String mimeType) ;37 Claim(WebCore::ServiceWorkerIdentifier serviceWorkerIdentifier) -> (Optional<WebCore::ExceptionData> result) Async 38 SetScriptResource(WebCore::ServiceWorkerIdentifier identifier, URL scriptURL, String script, URL responseURL, String mimeType) 39 39 PostMessageToServiceWorkerClient(struct WebCore::ServiceWorkerClientIdentifier destination, struct WebCore::MessageWithMessagePorts message, WebCore::ServiceWorkerIdentifier source, String sourceOrigin) 40 DidFailHeartBeatCheck(WebCore::ServiceWorkerIdentifier identifier) ;40 DidFailHeartBeatCheck(WebCore::ServiceWorkerIdentifier identifier) 41 41 } 42 42 -
trunk/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.cpp
r255681 r256900 338 338 } 339 339 340 void WebSWContextManagerConnection::claim(WebCore::ServiceWorkerIdentifier serviceWorkerIdentifier, CompletionHandler<void()>&& callback) 341 { 342 auto requestIdentifier = ++m_previousRequestIdentifier; 343 m_claimRequests.add(requestIdentifier, WTFMove(callback)); 344 m_connectionToNetworkProcess->send(Messages::WebSWServerToContextConnection::Claim { requestIdentifier, serviceWorkerIdentifier }, 0); 345 } 346 347 void WebSWContextManagerConnection::claimCompleted(uint64_t claimRequestIdentifier) 348 { 349 if (auto callback = m_claimRequests.take(claimRequestIdentifier)) 350 callback(); 340 void WebSWContextManagerConnection::claim(WebCore::ServiceWorkerIdentifier serviceWorkerIdentifier, CompletionHandler<void(ExceptionOr<void>&&)>&& callback) 341 { 342 m_connectionToNetworkProcess->sendWithAsyncReply(Messages::WebSWServerToContextConnection::Claim { serviceWorkerIdentifier }, [callback = WTFMove(callback)](auto&& result) mutable { 343 callback(result ? result->toException() : ExceptionOr<void> { }); 344 }); 351 345 } 352 346 -
trunk/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.h
r255681 r256900 77 77 void findClientByIdentifier(WebCore::ServiceWorkerIdentifier, WebCore::ServiceWorkerClientIdentifier, FindClientByIdentifierCallback&&) final; 78 78 void matchAll(WebCore::ServiceWorkerIdentifier, const WebCore::ServiceWorkerClientQueryOptions&, WebCore::ServiceWorkerClientsMatchAllCallback&&) final; 79 void claim(WebCore::ServiceWorkerIdentifier, CompletionHandler<void( )>&&) final;79 void claim(WebCore::ServiceWorkerIdentifier, CompletionHandler<void(WebCore::ExceptionOr<void>&&)>&&) final; 80 80 void skipWaiting(WebCore::ServiceWorkerIdentifier, CompletionHandler<void()>&&) final; 81 81 void setScriptResource(WebCore::ServiceWorkerIdentifier, const URL&, const WebCore::ServiceWorkerContextData::ImportedScript&) final; … … 97 97 void findClientByIdentifierCompleted(uint64_t requestIdentifier, Optional<WebCore::ServiceWorkerClientData>&&, bool hasSecurityError); 98 98 void matchAllCompleted(uint64_t matchAllRequestIdentifier, Vector<WebCore::ServiceWorkerClientData>&&); 99 void claimCompleted(uint64_t claimRequestIdentifier);100 99 void setUserAgent(String&& userAgent); 101 100 void close(); … … 114 113 HashMap<uint64_t, FindClientByIdentifierCallback> m_findClientByIdentifierRequests; 115 114 HashMap<uint64_t, WebCore::ServiceWorkerClientsMatchAllCallback> m_matchAllRequests; 116 HashMap<uint64_t, WTF::CompletionHandler<void()>> m_claimRequests;117 115 uint64_t m_previousRequestIdentifier { 0 }; 118 116 String m_userAgent; -
trunk/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.messages.in
r253752 r256900 35 35 FindClientByIdentifierCompleted(uint64_t clientIdRequestIdentifier, Optional<WebCore::ServiceWorkerClientData> data, bool hasSecurityError) 36 36 MatchAllCompleted(uint64_t matchAllRequestIdentifier, Vector<WebCore::ServiceWorkerClientData> clientsData) 37 ClaimCompleted(uint64_t claimRequestIdentifier)38 37 SetUserAgent(String userAgent) 39 38 UpdatePreferencesStore(struct WebKit::WebPreferencesStore store)
Note: See TracChangeset
for help on using the changeset viewer.