WebKit Bugzilla
Attachment 369330 Details for
Bug 185626
: A service worker process should app nap when all its clients app nap
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Patch
bug-185626-20190507151203.patch (text/plain), 50.54 KB, created by
youenn fablet
on 2019-05-07 15:12:04 PDT
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
youenn fablet
Created:
2019-05-07 15:12:04 PDT
Size:
50.54 KB
patch
obsolete
>Subversion Revision: 245009 >diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog >index 26177d0480c0ee5f982bbef8fd38d16ff051bbee..23708afa6ee300ae5a08f792e251db24fe9673ef 100644 >--- a/Source/WebCore/ChangeLog >+++ b/Source/WebCore/ChangeLog >@@ -1,3 +1,59 @@ >+2019-05-06 Youenn Fablet <youenn@apple.com> >+ >+ A service worker process should app nap when all its clients app nap >+ https://bugs.webkit.org/show_bug.cgi?id=185626 >+ <rdar://problem/46785908> >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ Store in network process the process suppression value of all service worker clients. >+ Compute the process suppression for a given registration by >+ consolidating the values of the service worker clients the registration controls. >+ In case of process suppression value change, send the process >+ suppression value to each service worker instance of the registration. >+ Compute the service worker process suppression value by looking at >+ all service worker process suppression values. >+ >+ To correctly handle this, the process suppression state is sent whenever registering a client. >+ It is also updated for all clients of a page whose process suppression state is changing. >+ >+ Test: http/wpt/service-workers/mac/processSuppression.https.html >+ >+ * page/Page.cpp: >+ (WebCore::Page::forEachDocument const): >+ (WebCore::Page::serviceWorkerClients const): >+ * page/Page.h: >+ (WebCore::Page::processSuppressionEnabled const): >+ (WebCore::Page::setProcessSuppressionEnabled): >+ * testing/Internals.cpp: >+ (WebCore::Internals::resetToConsistentState): >+ (WebCore::Internals::setProcessSuppressionEnabled): >+ * testing/Internals.h: >+ * testing/Internals.idl: >+ * testing/ServiceWorkerInternals.cpp: >+ (WebCore::ServiceWorkerInternals::isProcessSuppressionEnabled const): >+ * testing/ServiceWorkerInternals.h: >+ * testing/ServiceWorkerInternals.idl: >+ * workers/service/SWClientConnection.h: >+ * workers/service/context/SWContextManager.cpp: >+ (WebCore::SWContextManager::forEachServiceWorkerThread const): >+ (WebCore::SWContextManager::isProcessSuppressionEnabled const): >+ * workers/service/context/SWContextManager.h: >+ * workers/service/context/ServiceWorkerThreadProxy.h: >+ * workers/service/server/SWServer.cpp: >+ (WebCore::SWServer::serviceWorkerClientWithOriginByID const): >+ (WebCore::SWServer::serviceWorkerClientByID const): >+ (WebCore::SWServer::forEachClientForOrigin): >+ (WebCore::SWServer::registerServiceWorkerClient): >+ (WebCore::SWServer::updateClientsActivity): >+ * workers/service/server/SWServer.h: >+ (WebCore::SWServer::Connection::processSuppressionEnabled const): >+ (WebCore::SWServer::Client::fromServiceWorkerClientData): >+ * workers/service/server/SWServerRegistration.cpp: >+ (WebCore::SWServerRegistration::updateProcessSuppression): >+ * workers/service/server/SWServerRegistration.h: >+ * workers/service/server/SWServerToContextConnection.h: >+ > 2019-05-07 Antti Koivisto <antti@apple.com> > > <body> with overflow:hidden CSS is scrollable on iOS >diff --git a/Source/WebKit/ChangeLog b/Source/WebKit/ChangeLog >index 88ce45ee303d8a8e33e9b3d41a62ad179616778e..7f668cb8badd308d6758935973cfa97dd978195d 100644 >--- a/Source/WebKit/ChangeLog >+++ b/Source/WebKit/ChangeLog >@@ -1,3 +1,36 @@ >+2019-05-06 Youenn Fablet <youenn@apple.com> >+ >+ A service worker process should app nap when all its clients app nap >+ https://bugs.webkit.org/show_bug.cgi?id=185626 >+ <rdar://problem/46785908> >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ Move processSuppressionEnabled from WebPage to Page. >+ This allows setting it through Internals. >+ >+ * NetworkProcess/ServiceWorker/WebSWServerConnection.cpp: >+ (WebKit::WebSWServerConnection::updateClientsActivity): >+ * NetworkProcess/ServiceWorker/WebSWServerConnection.h: >+ * NetworkProcess/ServiceWorker/WebSWServerConnection.messages.in: >+ * NetworkProcess/ServiceWorker/WebSWServerToContextConnection.cpp: >+ (WebKit::WebSWServerToContextConnection::setProcessSuppressionEnabled): >+ * NetworkProcess/ServiceWorker/WebSWServerToContextConnection.h: >+ * UIProcess/ServiceWorkerProcessProxy.cpp: >+ * UIProcess/ServiceWorkerProcessProxy.h: >+ * WebProcess/Storage/WebSWClientConnection.cpp: >+ (WebKit::WebSWClientConnection::updateClientsActivity): >+ * WebProcess/Storage/WebSWClientConnection.h: >+ * WebProcess/Storage/WebSWContextManagerConnection.cpp: >+ (WebKit::WebSWContextManagerConnection::setProcessSuppressionEnabled): >+ * WebProcess/Storage/WebSWContextManagerConnection.h: >+ * WebProcess/Storage/WebSWContextManagerConnection.messages.in: >+ * WebProcess/WebPage/WebPage.cpp: >+ (WebKit::WebPage::updateThrottleState): >+ (WebKit::WebPage::updateUserActivity): >+ (WebKit::WebPage::updatePreferences): >+ * WebProcess/WebPage/WebPage.h: >+ > 2019-05-07 Wenson Hsieh <wenson_hsieh@apple.com> > > [macOS] Avoid crashing the UI process when writing empty data to the pasteboard >diff --git a/Source/WebCore/dom/Document.cpp b/Source/WebCore/dom/Document.cpp >index ce429277c7eac60022375d9cb89e8d651d43daa0..ecc5feda1d84dc2860958a353b245a3027835412 100644 >--- a/Source/WebCore/dom/Document.cpp >+++ b/Source/WebCore/dom/Document.cpp >@@ -8110,7 +8110,8 @@ void Document::setServiceWorkerConnection(SWClientConnection* serviceWorkerConne > return; > > auto controllingServiceWorkerRegistrationIdentifier = activeServiceWorker() ? makeOptional<ServiceWorkerRegistrationIdentifier>(activeServiceWorker()->registrationIdentifier()) : WTF::nullopt; >- m_serviceWorkerConnection->registerServiceWorkerClient(topOrigin(), ServiceWorkerClientData::from(*this, *serviceWorkerConnection), controllingServiceWorkerRegistrationIdentifier, userAgent(url())); >+ >+ m_serviceWorkerConnection->registerServiceWorkerClient(topOrigin(), ServiceWorkerClientData::from(*this, *serviceWorkerConnection), controllingServiceWorkerRegistrationIdentifier, userAgent(url()), page()->processSuppressionEnabled()); > } > #endif > >diff --git a/Source/WebCore/loader/DocumentLoader.cpp b/Source/WebCore/loader/DocumentLoader.cpp >index fceea1bed92b0ea596b28246738f238c4f3b8719..e357e78a07331e8dccb8dfc43dc7b6edca66d791 100644 >--- a/Source/WebCore/loader/DocumentLoader.cpp >+++ b/Source/WebCore/loader/DocumentLoader.cpp >@@ -1826,7 +1826,7 @@ void DocumentLoader::registerTemporaryServiceWorkerClient(const URL& url) > topOrigin = SecurityOrigin::create(url); > else > topOrigin = &m_frame->mainFrame().document()->topOrigin(); >- m_temporaryServiceWorkerClient->serviceWorkerConnection->registerServiceWorkerClient(*topOrigin, WTFMove(data), m_serviceWorkerRegistrationData->identifier, m_frame->loader().userAgent(url)); >+ m_temporaryServiceWorkerClient->serviceWorkerConnection->registerServiceWorkerClient(*topOrigin, WTFMove(data), m_serviceWorkerRegistrationData->identifier, m_frame->loader().userAgent(url), m_frame->page()->processSuppressionEnabled()); > #else > UNUSED_PARAM(url); > #endif >diff --git a/Source/WebCore/page/Page.cpp b/Source/WebCore/page/Page.cpp >index c9e7722e3410e09bbdba91725c5fbd4b8b31215d..bc847b12f3fda5ef7feb84187b26352a228f57d0 100644 >--- a/Source/WebCore/page/Page.cpp >+++ b/Source/WebCore/page/Page.cpp >@@ -2870,6 +2870,27 @@ void Page::forEachDocument(const Function<void(Document&)>& functor) > } > } > >+void Page::forEachDocument(const Function<void(const Document&)>& functor) const >+{ >+ for (const auto* frame = &mainFrame(); frame; frame = frame->tree().traverseNext()) { >+ if (!frame->document()) >+ continue; >+ >+ functor(*frame->document()); >+ } >+} >+ >+#if ENABLE(SERVICE_WORKER) >+Vector<ServiceWorkerClientIdentifier> Page::serviceWorkerClients(SWServerConnectionIdentifier connectionIdentifier) const >+{ >+ Vector<ServiceWorkerClientIdentifier> clients; >+ forEachDocument([&](auto& document) { >+ clients.append({ connectionIdentifier, document.identifier() }); >+ }); >+ return clients; >+} >+#endif >+ > void Page::applicationWillResignActive() > { > forEachDocument([&] (Document& document) { >diff --git a/Source/WebCore/page/Page.h b/Source/WebCore/page/Page.h >index fcf3f77590f6a69213c80c5b0e7b6269c31d9883..725a5210e6a5615a1cda39a5f374afd4030469b3 100644 >--- a/Source/WebCore/page/Page.h >+++ b/Source/WebCore/page/Page.h >@@ -714,6 +714,13 @@ public: > > void configureLoggingChannel(const String&, WTFLogChannelState, WTFLogLevel); > >+#if ENABLE(SERVICE_WORKER) >+ WEBCORE_EXPORT Vector<ServiceWorkerClientIdentifier> serviceWorkerClients(SWServerConnectionIdentifier) const; >+#endif >+ >+ bool processSuppressionEnabled() const { return m_processSuppressionEnabled; } >+ void setProcessSuppressionEnabled(bool enabled) { m_processSuppressionEnabled = enabled; } >+ > private: > struct Navigation { > RegistrableDomain domain; >@@ -749,6 +756,7 @@ private: > void handleLowModePowerChange(bool); > > void forEachDocument(const WTF::Function<void(Document&)>&); >+ void forEachDocument(const WTF::Function<void(const Document&)>&) const; > > enum class TimerThrottlingState { Disabled, Enabled, EnabledIncreasing }; > void hiddenPageDOMTimerThrottlingStateChanged(); >@@ -987,6 +995,7 @@ private: > bool m_mediaPlaybackIsSuspended { false }; > bool m_mediaBufferingIsSuspended { false }; > bool m_inUpdateRendering { false }; >+ bool m_processSuppressionEnabled { true }; > }; > > inline PageGroup& Page::group() >diff --git a/Source/WebCore/testing/Internals.cpp b/Source/WebCore/testing/Internals.cpp >index d4cd40b7eb8d64ca8a3792240d1bc2029fe709c8..ba6a41f8417508afc5fc1f2fc2cae4109d9c062d 100644 >--- a/Source/WebCore/testing/Internals.cpp >+++ b/Source/WebCore/testing/Internals.cpp >@@ -529,6 +529,8 @@ void Internals::resetToConsistentState(Page& page) > page.setFullscreenControlsHidden(false); > > MediaEngineConfigurationFactory::disableMock(); >+ >+ page.setProcessSuppressionEnabled(false); > } > > Internals::Internals(Document& document) >@@ -5037,4 +5039,17 @@ void Internals::setXHRMaximumIntervalForUserGestureForwarding(XMLHttpRequest& re > request.setMaximumIntervalForUserGestureForwarding(interval); > } > >+void Internals::setProcessSuppressionEnabled(bool enabled) >+{ >+ auto* document = contextDocument(); >+ if (!document) >+ return; >+ >+ auto* page = document->page(); >+ if (!page) >+ return; >+ >+ page->setProcessSuppressionEnabled(enabled); >+} >+ > } // namespace WebCore >diff --git a/Source/WebCore/testing/Internals.h b/Source/WebCore/testing/Internals.h >index 491197a86d177680ebe7d589c840ca913d760b90..b63395444ecee1ff5ef4e3d77972d25c71b6c749 100644 >--- a/Source/WebCore/testing/Internals.h >+++ b/Source/WebCore/testing/Internals.h >@@ -819,6 +819,8 @@ public: > > void setXHRMaximumIntervalForUserGestureForwarding(XMLHttpRequest&, double); > >+ void setProcessSuppressionEnabled(bool); >+ > private: > explicit Internals(Document&); > Document* contextDocument() const; >diff --git a/Source/WebCore/testing/Internals.idl b/Source/WebCore/testing/Internals.idl >index 78d4b88a65182158a35c78b5bcd2ddec4551e39d..499e00aeaf85f665c999c60bd4f3be1bb684bc51 100644 >--- a/Source/WebCore/testing/Internals.idl >+++ b/Source/WebCore/testing/Internals.idl >@@ -749,4 +749,6 @@ enum CompositingPolicy { > void testDictionaryLogging(); > > void setXHRMaximumIntervalForUserGestureForwarding(XMLHttpRequest xhr, double interval); >+ >+ void setProcessSuppressionEnabled(boolean enabled); > }; >diff --git a/Source/WebCore/testing/ServiceWorkerInternals.cpp b/Source/WebCore/testing/ServiceWorkerInternals.cpp >index 27417da0606667f85c8183ada8bf654cee06f289..5c58e71b35ba230c1d0c236e63c6141f2fc5d638 100644 >--- a/Source/WebCore/testing/ServiceWorkerInternals.cpp >+++ b/Source/WebCore/testing/ServiceWorkerInternals.cpp >@@ -96,6 +96,11 @@ String ServiceWorkerInternals::processName() const > } > #endif > >+bool ServiceWorkerInternals::isProcessSuppressionEnabled() const >+{ >+ return SWContextManager::singleton().isProcessSuppressionEnabled(); >+} >+ > } // namespace WebCore > > #endif >diff --git a/Source/WebCore/testing/ServiceWorkerInternals.h b/Source/WebCore/testing/ServiceWorkerInternals.h >index 8171c865c2be9eea4946e2d27eaf8380b62c2c0f..a368d860a2613a9be7fc66a9d8cb8a2252979476 100644 >--- a/Source/WebCore/testing/ServiceWorkerInternals.h >+++ b/Source/WebCore/testing/ServiceWorkerInternals.h >@@ -51,6 +51,8 @@ public: > > String processName() const; > >+ bool isProcessSuppressionEnabled() const; >+ > private: > explicit ServiceWorkerInternals(ServiceWorkerIdentifier); > >diff --git a/Source/WebCore/testing/ServiceWorkerInternals.idl b/Source/WebCore/testing/ServiceWorkerInternals.idl >index 1d131b2ac7024368e89b9c47ee83374f7c183182..d3720d25e02eed73939513396eb2a2e829eeae59 100644 >--- a/Source/WebCore/testing/ServiceWorkerInternals.idl >+++ b/Source/WebCore/testing/ServiceWorkerInternals.idl >@@ -37,4 +37,5 @@ > sequence<ByteString> fetchResponseHeaderList(FetchResponse response); > > readonly attribute DOMString processName; >+ readonly attribute boolean isProcessSuppressionEnabled; > }; >diff --git a/Source/WebCore/workers/service/SWClientConnection.h b/Source/WebCore/workers/service/SWClientConnection.h >index 1fc7162399ed41a8c8d20843627db5e1ffcf2cf3..b0f9cffbf97e4e1a37b50e98661bad7cc9965d91 100644 >--- a/Source/WebCore/workers/service/SWClientConnection.h >+++ b/Source/WebCore/workers/service/SWClientConnection.h >@@ -36,6 +36,7 @@ > > namespace WebCore { > >+class Page; > class ResourceError; > class SecurityOrigin; > class SerializedScriptValue; >@@ -80,11 +81,13 @@ public: > virtual bool mayHaveServiceWorkerRegisteredForOrigin(const SecurityOriginData&) const = 0; > virtual void syncTerminateWorker(ServiceWorkerIdentifier) = 0; > >- virtual void registerServiceWorkerClient(const SecurityOrigin& topOrigin, const ServiceWorkerClientData&, const Optional<ServiceWorkerRegistrationIdentifier>&, const String& userAgent) = 0; >+ virtual void registerServiceWorkerClient(const SecurityOrigin& topOrigin, const ServiceWorkerClientData&, const Optional<ServiceWorkerRegistrationIdentifier>&, const String& userAgent, bool isActive) = 0; > virtual void unregisterServiceWorkerClient(DocumentIdentifier) = 0; > > virtual void finishFetchingScriptInServer(const ServiceWorkerFetchResult&) = 0; > >+ virtual void updateClientsActivity(Page&, bool areClientsActive) = 0; >+ > protected: > WEBCORE_EXPORT SWClientConnection(); > >diff --git a/Source/WebCore/workers/service/context/SWContextManager.cpp b/Source/WebCore/workers/service/context/SWContextManager.cpp >index edbc8f91ee43462a5049e88c1cef5efa762c98ff..f453d74129e370db7c2e044b9092bb693cc955a8 100644 >--- a/Source/WebCore/workers/service/context/SWContextManager.cpp >+++ b/Source/WebCore/workers/service/context/SWContextManager.cpp >@@ -31,6 +31,7 @@ > #include "MessageWithMessagePorts.h" > #include "ServiceWorkerClientIdentifier.h" > #include "ServiceWorkerGlobalScope.h" >+#include <wtf/Algorithms.h> > > namespace WebCore { > >@@ -164,6 +165,13 @@ SWContextManager::ServiceWorkerTerminationRequest::ServiceWorkerTerminationReque > m_timeoutTimer.startOneShot(timeout); > } > >+bool SWContextManager::isProcessSuppressionEnabled() const >+{ >+ return WTF::allOf(m_workerMap.values(), [](auto& worker) { >+ return worker->processSuppressionEnabled(); >+ }); >+} >+ > } // namespace WebCore > > #endif >diff --git a/Source/WebCore/workers/service/context/SWContextManager.h b/Source/WebCore/workers/service/context/SWContextManager.h >index 7607a8639b4c79b38661daadfdbe523800c2d294..abea2215b3e223e879fdac154bf1c04c08223f4a 100644 >--- a/Source/WebCore/workers/service/context/SWContextManager.h >+++ b/Source/WebCore/workers/service/context/SWContextManager.h >@@ -82,6 +82,7 @@ public: > void setServiceWorkerCreationCallback(ServiceWorkerCreationCallback* callback) { m_serviceWorkerCreationCallback = callback; } > > ServiceWorkerThreadProxy* workerByID(ServiceWorkerIdentifier identifier) { return m_workerMap.get(identifier); } >+ WEBCORE_EXPORT bool isProcessSuppressionEnabled() const; > > private: > SWContextManager() = default; >diff --git a/Source/WebCore/workers/service/context/ServiceWorkerThreadProxy.h b/Source/WebCore/workers/service/context/ServiceWorkerThreadProxy.h >index f46cfd1478aea274d21903623235c363d323fd87..244a405345dc11028dc04717b3b4eaca4152bb39 100644 >--- a/Source/WebCore/workers/service/context/ServiceWorkerThreadProxy.h >+++ b/Source/WebCore/workers/service/context/ServiceWorkerThreadProxy.h >@@ -76,6 +76,9 @@ public: > WEBCORE_EXPORT void continueDidReceiveFetchResponse(SWServerConnectionIdentifier, FetchIdentifier); > WEBCORE_EXPORT void removeFetch(SWServerConnectionIdentifier, FetchIdentifier); > >+ void setProcessSuppressionEnabled(bool enabled) { m_processSuppressionEnabled = enabled; } >+ bool processSuppressionEnabled() const { return m_processSuppressionEnabled; } >+ > private: > WEBCORE_EXPORT ServiceWorkerThreadProxy(PageConfiguration&&, const ServiceWorkerContextData&, PAL::SessionID, String&& userAgent, CacheStorageProvider&, SecurityOrigin::StorageBlockingPolicy); > >@@ -103,6 +106,7 @@ private: > std::unique_ptr<ServiceWorkerDebuggable> m_remoteDebuggable; > #endif > HashMap<std::pair<SWServerConnectionIdentifier, FetchIdentifier>, Ref<ServiceWorkerFetch::Client>> m_ongoingFetchTasks; >+ bool m_processSuppressionEnabled { true }; > }; > > } // namespace WebKit >diff --git a/Source/WebCore/workers/service/server/SWServer.cpp b/Source/WebCore/workers/service/server/SWServer.cpp >index 2a283f46f543c47c235a4df81c60b0f5f23117b1..2c81c125ed23700341405eb2de97705ac572b64a 100644 >--- a/Source/WebCore/workers/service/server/SWServer.cpp >+++ b/Source/WebCore/workers/service/server/SWServer.cpp >@@ -79,7 +79,7 @@ SWServerWorker* SWServer::workerByID(ServiceWorkerIdentifier identifier) const > return worker; > } > >-Optional<ServiceWorkerClientData> SWServer::serviceWorkerClientWithOriginByID(const ClientOrigin& clientOrigin, const ServiceWorkerClientIdentifier& clientIdentifier) const >+Optional<ServiceWorkerClientData> SWServer::serviceWorkerClientWithOriginByID(const ClientOrigin& clientOrigin, ServiceWorkerClientIdentifier clientIdentifier) const > { > auto iterator = m_clientIdentifiersPerOrigin.find(clientOrigin); > if (iterator == m_clientIdentifiersPerOrigin.end()) >@@ -88,6 +88,11 @@ Optional<ServiceWorkerClientData> SWServer::serviceWorkerClientWithOriginByID(co > if (!iterator->value.identifiers.contains(clientIdentifier)) > return WTF::nullopt; > >+ return serviceWorkerClientByID(clientIdentifier).data; >+} >+ >+const SWServer::Client& SWServer::serviceWorkerClientByID(ServiceWorkerClientIdentifier clientIdentifier) const >+{ > auto clientIterator = m_clientsById.find(clientIdentifier); > ASSERT(clientIterator != m_clientsById.end()); > return clientIterator->value; >@@ -465,7 +470,7 @@ void SWServer::forEachClientForOrigin(const ClientOrigin& origin, const WTF::Fun > for (auto& clientIdentifier : iterator->value.identifiers) { > auto clientIterator = m_clientsById.find(clientIdentifier); > ASSERT(clientIterator != m_clientsById.end()); >- apply(clientIterator->value); >+ apply(clientIterator->value.data); > } > } > >@@ -753,12 +758,12 @@ SWServerRegistration* SWServer::registrationFromServiceWorkerIdentifier(ServiceW > return m_registrations.get(iterator->value->registrationKey()); > } > >-void SWServer::registerServiceWorkerClient(ClientOrigin&& clientOrigin, ServiceWorkerClientData&& data, const Optional<ServiceWorkerRegistrationIdentifier>& controllingServiceWorkerRegistrationIdentifier, String&& userAgent) >+void SWServer::registerServiceWorkerClient(ClientOrigin&& clientOrigin, ServiceWorkerClientData&& data, const Optional<ServiceWorkerRegistrationIdentifier>& controllingServiceWorkerRegistrationIdentifier, String&& userAgent, bool isActive) > { > auto clientIdentifier = data.identifier; > > ASSERT(!m_clientsById.contains(clientIdentifier)); >- m_clientsById.add(clientIdentifier, WTFMove(data)); >+ m_clientsById.add(clientIdentifier, Client { WTFMove(data), isActive }); > > auto& clientIdentifiersForOrigin = m_clientIdentifiersPerOrigin.ensure(clientOrigin, [] { > return Clients { }; >@@ -842,6 +847,29 @@ void SWServer::unregisterServiceWorkerClient(const ClientOrigin& clientOrigin, S > m_clientToControllingRegistration.remove(registrationIterator); > } > >+void SWServer::updateClientsActivity(const Vector<WebCore::ServiceWorkerClientIdentifier>& identifiers, bool areActive) >+{ >+ HashSet<SWServerRegistration*> registrations; >+ for (auto& clientIdentifier : identifiers) { >+ auto clientIterator = m_clientsById.find(clientIdentifier); >+ ASSERT(clientIterator != m_clientsById.end()); >+ if (clientIterator == m_clientsById.end()) >+ continue; >+ clientIterator->value.isActive = areActive; >+ >+ auto registrationIterator = m_clientToControllingRegistration.find(clientIdentifier); >+ if (registrationIterator == m_clientToControllingRegistration.end()) >+ return; >+ >+ auto* registration = m_registrationsByID.get(registrationIterator->value); >+ ASSERT(registration); >+ if (registration) >+ registrations.add(registration); >+ } >+ for (auto* registration : registrations) >+ registration->updateProcessSuppression(); >+} >+ > bool SWServer::needsServerToContextConnectionForRegistrableDomain(const RegistrableDomain& registrableDomain) const > { > return m_clientsByRegistrableDomain.contains(registrableDomain); >diff --git a/Source/WebCore/workers/service/server/SWServer.h b/Source/WebCore/workers/service/server/SWServer.h >index 3ed3da912df4ffd1d9f6e65738cee741874f5617..ea43b508904e179d91548fd89ab245f55ee3aa25 100644 >--- a/Source/WebCore/workers/service/server/SWServer.h >+++ b/Source/WebCore/workers/service/server/SWServer.h >@@ -88,6 +88,7 @@ public: > virtual void registrationReady(uint64_t registrationReadyRequestIdentifier, ServiceWorkerRegistrationData&&) = 0; > > SWServer& server() { return m_server; } >+ bool processSuppressionEnabled() const { return m_processSuppressionEnabled; } > > protected: > WEBCORE_EXPORT explicit Connection(SWServer&); >@@ -98,6 +99,8 @@ public: > WEBCORE_EXPORT void syncTerminateWorker(ServiceWorkerIdentifier); > WEBCORE_EXPORT void whenRegistrationReady(uint64_t registrationReadyRequestIdentifier, const SecurityOriginData& topOrigin, const URL& clientURL); > >+ bool m_processSuppressionEnabled { true }; >+ > private: > // Messages to the client WebProcess > virtual void rejectJobInClient(ServiceWorkerJobIdentifier, const ExceptionData&) = 0; >@@ -143,7 +146,13 @@ public: > void fireActivateEvent(SWServerWorker&); > > WEBCORE_EXPORT SWServerWorker* workerByID(ServiceWorkerIdentifier) const; >- Optional<ServiceWorkerClientData> serviceWorkerClientWithOriginByID(const ClientOrigin&, const ServiceWorkerClientIdentifier&) const; >+ Optional<ServiceWorkerClientData> serviceWorkerClientWithOriginByID(const ClientOrigin&, ServiceWorkerClientIdentifier) const; >+ struct Client { >+ ServiceWorkerClientData data; >+ bool isActive { false }; >+ }; >+ const Client& serviceWorkerClientByID(ServiceWorkerClientIdentifier) const; >+ > String serviceWorkerClientUserAgent(const ClientOrigin&) const; > WEBCORE_EXPORT SWServerWorker* activeWorkerFromRegistrationID(ServiceWorkerRegistrationIdentifier); > >@@ -167,7 +176,7 @@ public: > > WEBCORE_EXPORT static HashSet<SWServer*>& allServers(); > >- WEBCORE_EXPORT void registerServiceWorkerClient(ClientOrigin&&, ServiceWorkerClientData&&, const Optional<ServiceWorkerRegistrationIdentifier>&, String&& userAgent); >+ WEBCORE_EXPORT void registerServiceWorkerClient(ClientOrigin&&, ServiceWorkerClientData&&, const Optional<ServiceWorkerRegistrationIdentifier>&, String&& userAgent, bool isActive); > WEBCORE_EXPORT void unregisterServiceWorkerClient(const ClientOrigin&, ServiceWorkerClientIdentifier); > > using RunServiceWorkerCallback = WTF::Function<void(SWServerToContextConnection*)>; >@@ -185,6 +194,7 @@ public: > WEBCORE_EXPORT bool needsServerToContextConnectionForRegistrableDomain(const RegistrableDomain&) const; > > void disableServiceWorkerProcessTerminationDelay() { m_shouldDisableServiceWorkerProcessTerminationDelay = true; } >+ WEBCORE_EXPORT void updateClientsActivity(const Vector<ServiceWorkerClientIdentifier>&, bool isVisible); > > private: > void scriptFetchFinished(Connection&, const ServiceWorkerFetchResult&); >@@ -227,7 +237,8 @@ private: > String userAgent; > }; > HashMap<ClientOrigin, Clients> m_clientIdentifiersPerOrigin; >- HashMap<ServiceWorkerClientIdentifier, ServiceWorkerClientData> m_clientsById; >+ >+ HashMap<ServiceWorkerClientIdentifier, Client> m_clientsById; > HashMap<ServiceWorkerClientIdentifier, ServiceWorkerRegistrationIdentifier> m_clientToControllingRegistration; > > UniqueRef<SWOriginStore> m_originStore; >diff --git a/Source/WebCore/workers/service/server/SWServerRegistration.cpp b/Source/WebCore/workers/service/server/SWServerRegistration.cpp >index 4d1c554f4602a955e2eb13413f723cd0b523bcf5..2e426cab8ea4ff516acfd4462f7fa94dff6ad796 100644 >--- a/Source/WebCore/workers/service/server/SWServerRegistration.cpp >+++ b/Source/WebCore/workers/service/server/SWServerRegistration.cpp >@@ -32,6 +32,7 @@ > #include "SWServerWorker.h" > #include "ServiceWorkerTypes.h" > #include "ServiceWorkerUpdateViaCache.h" >+#include <wtf/Algorithms.h> > > namespace WebCore { > >@@ -174,6 +175,8 @@ void SWServerRegistration::addClientUsingRegistration(const ServiceWorkerClientI > return HashSet<DocumentIdentifier> { }; > }).iterator->value.add(clientIdentifier.contextIdentifier); > ASSERT_UNUSED(addResult, addResult.isNewEntry); >+ >+ updateProcessSuppression(); > } > > void SWServerRegistration::removeClientUsingRegistration(const ServiceWorkerClientIdentifier& clientIdentifier) >@@ -190,6 +193,8 @@ void SWServerRegistration::removeClientUsingRegistration(const ServiceWorkerClie > m_clientsUsingRegistration.remove(iterator); > > handleClientUnload(); >+ >+ updateProcessSuppression(); > } > > // https://w3c.github.io/ServiceWorker/#notify-controller-change >@@ -362,6 +367,37 @@ void SWServerRegistration::setIsUninstalling(bool value) > } > } > >+void SWServerRegistration::updateProcessSuppression() >+{ >+ ASSERT(hasClientsUsingRegistration()); >+ >+ bool processSuppressionEnabled = true; >+ >+ for (auto keyValue : m_clientsUsingRegistration) { >+ bool hasAnyActiveClient = WTF::anyOf(keyValue.value, [this, &keyValue](auto identifier) { >+ return m_server.serviceWorkerClientByID({ keyValue.key, identifier }).isActive; >+ }); >+ if (hasAnyActiveClient) { >+ processSuppressionEnabled = false; >+ break; >+ } >+ } >+ >+ if (processSuppressionEnabled == m_processSuppressionEnabled) >+ return; >+ >+ m_processSuppressionEnabled = processSuppressionEnabled; >+ >+ if (m_preInstallationWorker && m_preInstallationWorker->contextConnection()) >+ m_preInstallationWorker->contextConnection()->setProcessSuppressionEnabled(m_preInstallationWorker->identifier(), m_processSuppressionEnabled); >+ if (m_installingWorker && m_installingWorker->contextConnection()) >+ m_installingWorker->contextConnection()->setProcessSuppressionEnabled(m_installingWorker->identifier(), m_processSuppressionEnabled); >+ if (m_waitingWorker && m_waitingWorker->contextConnection()) >+ m_waitingWorker->contextConnection()->setProcessSuppressionEnabled(m_waitingWorker->identifier(), m_processSuppressionEnabled); >+ if (m_activeWorker && m_activeWorker->contextConnection()) >+ m_activeWorker->contextConnection()->setProcessSuppressionEnabled(m_activeWorker->identifier(), m_processSuppressionEnabled); >+} >+ > } // namespace WebCore > > #endif // ENABLE(SERVICE_WORKER) >diff --git a/Source/WebCore/workers/service/server/SWServerRegistration.h b/Source/WebCore/workers/service/server/SWServerRegistration.h >index a69f2626ba62707f8be68101ee92165ac1b0dd6e..f26c3e3586ff904ec185e914e02e88fc2c530469 100644 >--- a/Source/WebCore/workers/service/server/SWServerRegistration.h >+++ b/Source/WebCore/workers/service/server/SWServerRegistration.h >@@ -85,6 +85,8 @@ public: > void addClientUsingRegistration(const ServiceWorkerClientIdentifier&); > void removeClientUsingRegistration(const ServiceWorkerClientIdentifier&); > void unregisterServerConnection(SWServerConnectionIdentifier); >+ void processSuppressionChanged(SWServerConnectionIdentifier); >+ void updateProcessSuppression(); > > void notifyClientsOfControllerChange(); > void controlClient(ServiceWorkerClientIdentifier); >@@ -95,6 +97,7 @@ public: > void didFinishActivation(ServiceWorkerIdentifier); > > void forEachConnection(const WTF::Function<void(SWServer::Connection&)>&); >+ void updateClientVisibility(ServiceWorkerIdentifier, bool isVisible); > > private: > void activate(); >@@ -119,6 +122,7 @@ private: > > MonotonicTime m_creationTime; > HashMap<SWServerConnectionIdentifier, HashSet<DocumentIdentifier>> m_clientsUsingRegistration; >+ bool m_processSuppressionEnabled { true }; > }; > > } // namespace WebCore >diff --git a/Source/WebCore/workers/service/server/SWServerToContextConnection.h b/Source/WebCore/workers/service/server/SWServerToContextConnection.h >index 2b60f1e718ba63a60fd96289e8331a5d658bf73a..94518181d6179599c4495ca5fbcc1a3197c043fc 100644 >--- a/Source/WebCore/workers/service/server/SWServerToContextConnection.h >+++ b/Source/WebCore/workers/service/server/SWServerToContextConnection.h >@@ -81,6 +81,7 @@ public: > const RegistrableDomain& registrableDomain() const { return m_registrableDomain; } > > virtual void connectionMayNoLongerBeNeeded() = 0; >+ virtual void setProcessSuppressionEnabled(WebCore::ServiceWorkerIdentifier, bool) = 0; > > protected: > WEBCORE_EXPORT explicit SWServerToContextConnection(const RegistrableDomain&); >diff --git a/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerConnection.cpp b/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerConnection.cpp >index 373aaea9200ba3ba67ca4c31b69588ba069c7a8b..7fedbb00eedf2f3175c54c1032a05b3f2ff87282 100644 >--- a/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerConnection.cpp >+++ b/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerConnection.cpp >@@ -273,11 +273,11 @@ void WebSWServerConnection::getRegistrations(uint64_t registrationMatchRequestId > send(Messages::WebSWClientConnection::DidGetRegistrations { registrationMatchRequestIdentifier, registrations }); > } > >-void WebSWServerConnection::registerServiceWorkerClient(SecurityOriginData&& topOrigin, ServiceWorkerClientData&& data, const Optional<ServiceWorkerRegistrationIdentifier>& controllingServiceWorkerRegistrationIdentifier, String&& userAgent) >+void WebSWServerConnection::registerServiceWorkerClient(SecurityOriginData&& topOrigin, ServiceWorkerClientData&& data, const Optional<ServiceWorkerRegistrationIdentifier>& controllingServiceWorkerRegistrationIdentifier, String&& userAgent, bool isActive) > { > auto clientOrigin = ClientOrigin { WTFMove(topOrigin), SecurityOriginData::fromURL(data.url) }; > m_clientOrigins.add(data.identifier, clientOrigin); >- server().registerServiceWorkerClient(WTFMove(clientOrigin), WTFMove(data), controllingServiceWorkerRegistrationIdentifier, WTFMove(userAgent)); >+ server().registerServiceWorkerClient(WTFMove(clientOrigin), WTFMove(data), controllingServiceWorkerRegistrationIdentifier, WTFMove(userAgent), isActive); > } > > void WebSWServerConnection::unregisterServiceWorkerClient(const ServiceWorkerClientIdentifier& clientIdentifier) >@@ -290,6 +290,11 @@ void WebSWServerConnection::unregisterServiceWorkerClient(const ServiceWorkerCli > m_clientOrigins.remove(iterator); > } > >+void WebSWServerConnection::updateClientsActivity(const Vector<WebCore::ServiceWorkerClientIdentifier>& identifiers, bool isActive) >+{ >+ server().updateClientsActivity(identifiers, isActive); >+} >+ > void WebSWServerConnection::syncTerminateWorkerFromClient(WebCore::ServiceWorkerIdentifier&& identifier, CompletionHandler<void()>&& completionHandler) > { > syncTerminateWorker(WTFMove(identifier)); >diff --git a/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerConnection.h b/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerConnection.h >index 1f59d11bf8414987919b43fb8e232e396056ae01..b02df7e240d285f1755dff4c5a7c3ca4fe2da5c7 100644 >--- a/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerConnection.h >+++ b/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerConnection.h >@@ -90,10 +90,12 @@ private: > void matchRegistration(uint64_t registrationMatchRequestIdentifier, const WebCore::SecurityOriginData& topOrigin, const URL& clientURL); > void getRegistrations(uint64_t registrationMatchRequestIdentifier, const WebCore::SecurityOriginData& topOrigin, const URL& clientURL); > >- void registerServiceWorkerClient(WebCore::SecurityOriginData&& topOrigin, WebCore::ServiceWorkerClientData&&, const Optional<WebCore::ServiceWorkerRegistrationIdentifier>&, String&& userAgent); >+ void registerServiceWorkerClient(WebCore::SecurityOriginData&& topOrigin, WebCore::ServiceWorkerClientData&&, const Optional<WebCore::ServiceWorkerRegistrationIdentifier>&, String&& userAgent, bool isActive); > void unregisterServiceWorkerClient(const WebCore::ServiceWorkerClientIdentifier&); > void syncTerminateWorkerFromClient(WebCore::ServiceWorkerIdentifier&&, CompletionHandler<void()>&&); > >+ void updateClientsActivity(const Vector<WebCore::ServiceWorkerClientIdentifier>&, bool isVisible); >+ > IPC::Connection* messageSenderConnection() const final { return m_contentConnection.ptr(); } > uint64_t messageSenderDestinationID() const final { return identifier().toUInt64(); } > >diff --git a/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerConnection.messages.in b/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerConnection.messages.in >index e3bd740bb509d6b47202f96c8e4d3411c71f3d14..b0387cbe04ffe5659312c0eae7c6783a4230fb7f 100644 >--- a/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerConnection.messages.in >+++ b/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerConnection.messages.in >@@ -40,10 +40,12 @@ messages -> WebSWServerConnection { > MatchRegistration(uint64_t serviceRegistrationMatchRequestIdentifier, struct WebCore::SecurityOriginData topOrigin, URL clientURL) > WhenRegistrationReady(uint64_t serviceRegistrationMatchRequestIdentifier, struct WebCore::SecurityOriginData topOrigin, URL clientURL) > GetRegistrations(uint64_t serviceRegistrationMatchRequestIdentifier, struct WebCore::SecurityOriginData topOrigin, URL clientURL) >- RegisterServiceWorkerClient(struct WebCore::SecurityOriginData topOrigin, struct WebCore::ServiceWorkerClientData data, Optional<WebCore::ServiceWorkerRegistrationIdentifier> controllingServiceWorkerRegistrationIdentifier, String userAgent) >+ RegisterServiceWorkerClient(struct WebCore::SecurityOriginData topOrigin, struct WebCore::ServiceWorkerClientData data, Optional<WebCore::ServiceWorkerRegistrationIdentifier> controllingServiceWorkerRegistrationIdentifier, String userAgent, bool isActive) > UnregisterServiceWorkerClient(struct WebCore::ServiceWorkerClientIdentifier identifier) > > SyncTerminateWorkerFromClient(WebCore::ServiceWorkerIdentifier workerIdentifier) -> () Synchronous >+ >+ UpdateClientsActivity(Vector<WebCore::ServiceWorkerClientIdentifier> identifiers, bool areActive) > } > > #endif // ENABLE(SERVICE_WORKER) >diff --git a/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerToContextConnection.cpp b/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerToContextConnection.cpp >index 3752e5697210f71c51c573ede985290724f7e037..25a97a291969b2c24d910ca525d2f14c0df78f4a 100644 >--- a/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerToContextConnection.cpp >+++ b/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerToContextConnection.cpp >@@ -115,6 +115,11 @@ void WebSWServerToContextConnection::connectionMayNoLongerBeNeeded() > m_networkProcess->swContextConnectionMayNoLongerBeNeeded(*this); > } > >+void WebSWServerToContextConnection::setProcessSuppressionEnabled(ServiceWorkerIdentifier identifier, bool enabled) >+{ >+ send(Messages::WebSWContextManagerConnection::setProcessSuppressionEnabled { identifier, enabled }); >+} >+ > void WebSWServerToContextConnection::terminate() > { > send(Messages::WebSWContextManagerConnection::TerminateProcess()); >diff --git a/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerToContextConnection.h b/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerToContextConnection.h >index 82905eac64ac3ebefc51473eb4de421b9bb82ae2..5a2fa11a7f8ed19e12dc645368939deb22a3f126 100644 >--- a/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerToContextConnection.h >+++ b/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerToContextConnection.h >@@ -91,6 +91,7 @@ private: > void didFinishSkipWaiting(uint64_t callbackID) final; > > void connectionMayNoLongerBeNeeded() final; >+ void setProcessSuppressionEnabled(WebCore::ServiceWorkerIdentifier, bool) final; > > Ref<IPC::Connection> m_ipcConnection; > Ref<NetworkProcess> m_networkProcess; >diff --git a/Source/WebKit/UIProcess/ServiceWorkerProcessProxy.cpp b/Source/WebKit/UIProcess/ServiceWorkerProcessProxy.cpp >index f1ff2f1f256f08c432760d95693a8b6a4ee871d4..5a14fbe4dcd4b38c7a0bfd5c2f70a06c5c575f86 100644 >--- a/Source/WebKit/UIProcess/ServiceWorkerProcessProxy.cpp >+++ b/Source/WebKit/UIProcess/ServiceWorkerProcessProxy.cpp >@@ -106,15 +106,6 @@ void ServiceWorkerProcessProxy::didReceiveAuthenticationChallenge(uint64_t pageI > challenge->listener().completeChallenge(AuthenticationChallengeDisposition::PerformDefaultHandling); > } > >-void ServiceWorkerProcessProxy::didFinishLaunching(ProcessLauncher* launcher, IPC::Connection::Identifier connectionIdentifier) >-{ >- WebProcessProxy::didFinishLaunching(launcher, connectionIdentifier); >- >- // Prevent App Nap for Service Worker processes. >- // FIXME: Ideally, the Service Worker process would app nap when all its clients app nap (http://webkit.org/b/185626). >- setProcessSuppressionEnabled(false); >-} >- > } // namespace WebKit > > #endif // ENABLE(SERVICE_WORKER) >diff --git a/Source/WebKit/UIProcess/ServiceWorkerProcessProxy.h b/Source/WebKit/UIProcess/ServiceWorkerProcessProxy.h >index 6f759e9ff45fd5afce273baeb3f05dbd6a09f798..93245f0dc76f265757ec2bfe7163e9edaae9c0f0 100644 >--- a/Source/WebKit/UIProcess/ServiceWorkerProcessProxy.h >+++ b/Source/WebKit/UIProcess/ServiceWorkerProcessProxy.h >@@ -54,9 +54,6 @@ private: > // AuxiliaryProcessProxy > void getLaunchOptions(ProcessLauncher::LaunchOptions&) final; > >- // ProcessLauncher::Client >- void didFinishLaunching(ProcessLauncher*, IPC::Connection::Identifier) final; >- > bool isServiceWorkerProcess() const final { return true; } > > ServiceWorkerProcessProxy(WebProcessPool&, const WebCore::RegistrableDomain&, WebsiteDataStore&); >diff --git a/Source/WebKit/WebProcess/Storage/WebSWClientConnection.cpp b/Source/WebKit/WebProcess/Storage/WebSWClientConnection.cpp >index 7905b63af1aaff4b1dae8bafeb9c7f03f5d3b7c3..ba82ddd0c08fb0c681d9fac9120535eac902854d 100644 >--- a/Source/WebKit/WebProcess/Storage/WebSWClientConnection.cpp >+++ b/Source/WebKit/WebProcess/Storage/WebSWClientConnection.cpp >@@ -39,6 +39,7 @@ > #include "WebSWOriginTable.h" > #include "WebSWServerConnectionMessages.h" > #include <WebCore/Document.h> >+#include <WebCore/Page.h> > #include <WebCore/SecurityOrigin.h> > #include <WebCore/SerializedScriptValue.h> > #include <WebCore/ServiceWorkerClientData.h> >@@ -93,9 +94,9 @@ void WebSWClientConnection::postMessageToServiceWorker(ServiceWorkerIdentifier d > WebProcess::singleton().send(Messages::WebProcessPool::PostMessageToServiceWorker(destinationIdentifier, WTFMove(message), sourceIdentifier, serverConnectionIdentifier()), 0); > } > >-void WebSWClientConnection::registerServiceWorkerClient(const SecurityOrigin& topOrigin, const WebCore::ServiceWorkerClientData& data, const Optional<WebCore::ServiceWorkerRegistrationIdentifier>& controllingServiceWorkerRegistrationIdentifier, const String& userAgent) >+void WebSWClientConnection::registerServiceWorkerClient(const SecurityOrigin& topOrigin, const WebCore::ServiceWorkerClientData& data, const Optional<WebCore::ServiceWorkerRegistrationIdentifier>& controllingServiceWorkerRegistrationIdentifier, const String& userAgent, bool isActive) > { >- send(Messages::WebSWServerConnection::RegisterServiceWorkerClient { topOrigin.data(), data, controllingServiceWorkerRegistrationIdentifier, userAgent }); >+ send(Messages::WebSWServerConnection::RegisterServiceWorkerClient { topOrigin.data(), data, controllingServiceWorkerRegistrationIdentifier, userAgent, isActive }); > } > > void WebSWClientConnection::unregisterServiceWorkerClient(DocumentIdentifier contextIdentifier) >@@ -231,6 +232,13 @@ void WebSWClientConnection::syncTerminateWorker(ServiceWorkerIdentifier identifi > sendSync(Messages::WebSWServerConnection::SyncTerminateWorkerFromClient(identifier), Messages::WebSWServerConnection::SyncTerminateWorkerFromClient::Reply()); > } > >+void WebSWClientConnection::updateClientsActivity(Page& page, bool areClientsActive) >+{ >+ auto clients = page.serviceWorkerClients(serverConnectionIdentifier()); >+ if (!clients.isEmpty()) >+ send(Messages::WebSWServerConnection::UpdateClientsActivity { clients, areClientsActive }); >+} >+ > } // namespace WebKit > > #endif // ENABLE(SERVICE_WORKER) >diff --git a/Source/WebKit/WebProcess/Storage/WebSWClientConnection.h b/Source/WebKit/WebProcess/Storage/WebSWClientConnection.h >index 63e18d558fffbf534ea1bb9fce33113875ad197b..3f887c1dd73c8be4fa57ae08042f7803aea577ca 100644 >--- a/Source/WebKit/WebProcess/Storage/WebSWClientConnection.h >+++ b/Source/WebKit/WebProcess/Storage/WebSWClientConnection.h >@@ -75,7 +75,7 @@ private: > void scheduleJobInServer(const WebCore::ServiceWorkerJobData&) final; > void finishFetchingScriptInServer(const WebCore::ServiceWorkerFetchResult&) final; > void postMessageToServiceWorker(WebCore::ServiceWorkerIdentifier destinationIdentifier, WebCore::MessageWithMessagePorts&&, const WebCore::ServiceWorkerOrClientIdentifier& source) final; >- void registerServiceWorkerClient(const WebCore::SecurityOrigin& topOrigin, const WebCore::ServiceWorkerClientData&, const Optional<WebCore::ServiceWorkerRegistrationIdentifier>&, const String& userAgent) final; >+ void registerServiceWorkerClient(const WebCore::SecurityOrigin& topOrigin, const WebCore::ServiceWorkerClientData&, const Optional<WebCore::ServiceWorkerRegistrationIdentifier>&, const String& userAgent, bool isActive) final; > void unregisterServiceWorkerClient(WebCore::DocumentIdentifier) final; > > void matchRegistration(WebCore::SecurityOriginData&& topOrigin, const URL& clientURL, RegistrationCallback&&) final; >@@ -87,6 +87,7 @@ private: > void getRegistrations(WebCore::SecurityOriginData&& topOrigin, const URL& clientURL, GetRegistrationsCallback&&) final; > > void didResolveRegistrationPromise(const WebCore::ServiceWorkerRegistrationKey&) final; >+ void updateClientsActivity(WebCore::Page&, bool areClientsActive) final; > > void scheduleStorageJob(const WebCore::ServiceWorkerJobData&); > >diff --git a/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.cpp b/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.cpp >index 4d9a654e193ad65f607ccc9d8891a5fe2ad0ee34..2236db397fb08484f81fd08441a1e6ed8246af96 100644 >--- a/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.cpp >+++ b/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.cpp >@@ -364,6 +364,20 @@ void WebSWContextManagerConnection::terminateProcess() > _exit(EXIT_SUCCESS); > } > >+void WebSWContextManagerConnection::setProcessSuppressionEnabled(WebCore::ServiceWorkerIdentifier identifier, bool enabled) >+{ >+ auto& manager = SWContextManager::singleton(); >+ auto* serviceWorkerThreadProxy = manager.serviceWorkerThreadProxy(identifier); >+ if (!serviceWorkerThreadProxy) >+ return; >+ >+ serviceWorkerThreadProxy->setProcessSuppressionEnabled(enabled); >+ >+ bool processSuppressionEnabled = manager.isProcessSuppressionEnabled(); >+ RELEASE_LOG(ServiceWorker, "Service worker process suppression is set to %d", processSuppressionEnabled); >+ WebProcess::singleton().setProcessSuppressionEnabled(SWContextManager::singleton().isProcessSuppressionEnabled()); >+} >+ > } // namespace WebCore > > #endif // ENABLE(SERVICE_WORKER) >diff --git a/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.h b/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.h >index f71af45e68226c7f4bd1248af67a25cb6a2da4af..5e4fb9c6f1ed25a39a46f21d1c0929b4701aeaae 100644 >--- a/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.h >+++ b/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.h >@@ -91,6 +91,7 @@ private: > void didFinishSkipWaiting(uint64_t callbackID); > void setUserAgent(String&& userAgent); > NO_RETURN void terminateProcess(); >+ void setProcessSuppressionEnabled(WebCore::ServiceWorkerIdentifier, bool enabled); > > Ref<IPC::Connection> m_connectionToNetworkProcess; > uint64_t m_pageGroupID; >diff --git a/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.messages.in b/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.messages.in >index 96350c057ac521a60dbbc2eabdfe6a422a156407..a52ece5902fa998b6e44dc315019e384dc1397c1 100644 >--- a/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.messages.in >+++ b/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.messages.in >@@ -39,6 +39,7 @@ messages -> WebSWContextManagerConnection { > SetUserAgent(String userAgent) > UpdatePreferencesStore(struct WebKit::WebPreferencesStore store) > TerminateProcess() >+ setProcessSuppressionEnabled(WebCore::ServiceWorkerIdentifier identifier, bool enabled) > } > > #endif >diff --git a/Source/WebKit/WebProcess/WebPage/WebPage.cpp b/Source/WebKit/WebProcess/WebPage/WebPage.cpp >index 4370222ae8d38776799307f8903916735cf80a80..9c69bbebfefba99b062fc532c74130d4cf69dc29 100644 >--- a/Source/WebKit/WebProcess/WebPage/WebPage.cpp >+++ b/Source/WebKit/WebProcess/WebPage/WebPage.cpp >@@ -212,6 +212,7 @@ > #include <WebCore/ResourceRequest.h> > #include <WebCore/ResourceResponse.h> > #include <WebCore/RuntimeEnabledFeatures.h> >+#include <WebCore/SWClientConnection.h> > #include <WebCore/SchemeRegistry.h> > #include <WebCore/ScriptController.h> > #include <WebCore/SerializedScriptValue.h> >@@ -415,7 +416,6 @@ WebPage::WebPage(uint64_t pageID, WebPageCreationParameters&& parameters) > #endif > , m_layerVolatilityTimer(*this, &WebPage::layerVolatilityTimerFired) > , m_activityState(parameters.activityState) >- , m_processSuppressionEnabled(true) > , m_userActivity("Process suppression disabled for page.") > , m_userActivityHysteresis([this](PAL::HysteresisState) { updateUserActivity(); }) > , m_userInterfaceLayoutDirection(parameters.userInterfaceLayoutDirection) >@@ -764,7 +764,7 @@ void WebPage::updateThrottleState() > { > bool isActive = m_activityState.containsAny({ ActivityState::IsLoading, ActivityState::IsAudible, ActivityState::IsCapturingMedia, ActivityState::WindowIsActive }); > bool isVisuallyIdle = m_activityState.contains(ActivityState::IsVisuallyIdle); >- bool pageSuppressed = m_processSuppressionEnabled && !isActive && isVisuallyIdle; >+ bool pageSuppressed = (m_page ? m_page->processSuppressionEnabled() : true) && !isActive && isVisuallyIdle; > > // The UserActivity keeps the processes runnable. So if the page should be suppressed, stop the activity. > // If the page should not be supressed, start it. >@@ -780,6 +780,13 @@ void WebPage::updateUserActivity() > m_userActivity.start(); > else > m_userActivity.stop(); >+ >+#if ENABLE(SERVICE_WORKER) >+ if (m_page) { >+ if (auto* connection = ServiceWorkerProvider::singleton().existingServiceWorkerConnectionForSession(sessionID())) >+ connection->updateClientsActivity(*m_page, m_userActivityHysteresis.state() == PAL::HysteresisState::Started); >+ } >+#endif > } > > WebPage::~WebPage() >@@ -3519,8 +3526,8 @@ void WebPage::updatePreferences(const WebPreferencesStore& store) > setSessionID(PAL::SessionID::defaultSessionID()); > > bool processSuppressionEnabled = store.getBoolValueForKey(WebPreferencesKey::pageVisibilityBasedProcessSuppressionEnabledKey()); >- if (m_processSuppressionEnabled != processSuppressionEnabled) { >- m_processSuppressionEnabled = processSuppressionEnabled; >+ if (m_page->processSuppressionEnabled() != processSuppressionEnabled) { >+ m_page->setProcessSuppressionEnabled(processSuppressionEnabled); > updateThrottleState(); > } > >diff --git a/Source/WebKit/WebProcess/WebPage/WebPage.h b/Source/WebKit/WebProcess/WebPage/WebPage.h >index d9d804cbd637991052c8c6d2c1ce229e67d36a98..938febef0c6b3350c3fd904a2353e9dc8298ecaf 100644 >--- a/Source/WebKit/WebProcess/WebPage/WebPage.h >+++ b/Source/WebKit/WebProcess/WebPage/WebPage.h >@@ -1852,7 +1852,6 @@ private: > > OptionSet<WebCore::ActivityState::Flag> m_activityState; > >- bool m_processSuppressionEnabled; > UserActivity m_userActivity; > PAL::HysteresisActivity m_userActivityHysteresis; > >diff --git a/LayoutTests/ChangeLog b/LayoutTests/ChangeLog >index 8b1d32e90313c2d2d32d911a040b43f940b75629..a2281a0e872b169872db598f162557b1d134537a 100644 >--- a/LayoutTests/ChangeLog >+++ b/LayoutTests/ChangeLog >@@ -1,3 +1,17 @@ >+2019-05-06 Youenn Fablet <youenn@apple.com> >+ >+ A service worker process should app nap when all its clients app nap >+ https://bugs.webkit.org/show_bug.cgi?id=185626 >+ <rdar://problem/46785908> >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ * http/wpt/service-workers/mac/processSuppression-worker.js: Added. >+ (checkProcessSuppression): >+ * http/wpt/service-workers/mac/processSuppression.https-expected.txt: Added. >+ * http/wpt/service-workers/mac/processSuppression.https.html: Added. >+ * platform/ios-wk2/TestExpectations: >+ > 2019-05-07 Antti Koivisto <antti@apple.com> > > <body> with overflow:hidden CSS is scrollable on iOS >diff --git a/LayoutTests/platform/ios-wk2/TestExpectations b/LayoutTests/platform/ios-wk2/TestExpectations >index 3532523ae7c28c7ee107a98cbb1266560111a0d8..d68cf1edf104a745fca308fcd0cfa10ece94e96e 100644 >--- a/LayoutTests/platform/ios-wk2/TestExpectations >+++ b/LayoutTests/platform/ios-wk2/TestExpectations >@@ -365,6 +365,8 @@ http/tests/security/video-cross-origin-readback.html > http/tests/websocket/tests/hybi/invalid-subprotocol-characters.html > http/tests/xmlhttprequest/cross-origin-authorization-with-embedder.html > >+http/wpt/service-workers/mac/processSuppression.https.html [ Skip ] >+ > # HTTP tests that are flaky: > http/tests/navigation/forward-and-cancel.html [ Failure Pass ] > http/tests/security/xss-DENIED-xsl-external-entity-redirect.xml [ Failure Pass ]
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 185626
:
369227
|
369298
|
369306
|
369330
|
369578
|
369599
|
369613
|
369872