Diff
Modified: trunk/LayoutTests/ChangeLog (245298 => 245299)
--- trunk/LayoutTests/ChangeLog 2019-05-14 19:48:09 UTC (rev 245298)
+++ trunk/LayoutTests/ChangeLog 2019-05-14 19:48:51 UTC (rev 245299)
@@ -1,3 +1,16 @@
+2019-05-14 Youenn Fablet <[email protected]>
+
+ 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 Alex Christensen.
+
+ * http/wpt/service-workers/mac/throttleable-worker.js: Added.
+ * http/wpt/service-workers/mac/throttleable.https-expected.txt: Added.
+ * http/wpt/service-workers/mac/throttleable.https.html: Added.
+ * platform/ios-wk2/TestExpectations:
+
2019-05-14 Oriol Brufau <[email protected]>
[css-grid] Update grid when changing auto repeat type
Added: trunk/LayoutTests/http/wpt/service-workers/mac/throttleable-worker.js (0 => 245299)
--- trunk/LayoutTests/http/wpt/service-workers/mac/throttleable-worker.js (rev 0)
+++ trunk/LayoutTests/http/wpt/service-workers/mac/throttleable-worker.js 2019-05-14 19:48:51 UTC (rev 245299)
@@ -0,0 +1,8 @@
+_onactivate_ = (e) => e.waitUntil(clients.claim());
+
+function checkThrottleable(event)
+{
+ event.source.postMessage(self.internals ? self.internals.isThrottleable : "needs internals");
+}
+
+self.addEventListener("message", checkThrottleable);
Added: trunk/LayoutTests/http/wpt/service-workers/mac/throttleable.https-expected.txt (0 => 245299)
--- trunk/LayoutTests/http/wpt/service-workers/mac/throttleable.https-expected.txt (rev 0)
+++ trunk/LayoutTests/http/wpt/service-workers/mac/throttleable.https-expected.txt 2019-05-14 19:48:51 UTC (rev 245299)
@@ -0,0 +1,5 @@
+
+PASS Setup worker
+PASS Service worker should not be throttleable
+PASS Service worker should be throttleable
+
Added: trunk/LayoutTests/http/wpt/service-workers/mac/throttleable.https.html (0 => 245299)
--- trunk/LayoutTests/http/wpt/service-workers/mac/throttleable.https.html (rev 0)
+++ trunk/LayoutTests/http/wpt/service-workers/mac/throttleable.https.html 2019-05-14 19:48:51 UTC (rev 245299)
@@ -0,0 +1,63 @@
+<!doctype html><!-- webkit-test-runner [ enableAppNap=true ] -->
+<html>
+<head>
+<script src=""
+<script src=""
+</head>
+<body>
+<script>
+var scope = "/WebKit/service-workers/mac/throttleable.https.html";
+var activeWorker;
+
+promise_test(async (test) => {
+ var registration = await navigator.serviceWorker.getRegistration(scope);
+ if (registration && registration.scope === scope)
+ await registration.unregister();
+
+ var registration = await navigator.serviceWorker.register("throttleable-worker.js", { scope : scope });
+ activeWorker = registration.active;
+ if (activeWorker)
+ return;
+ activeWorker = registration.installing;
+ return new Promise(resolve => {
+ activeWorker.addEventListener('statechange', () => {
+ if (activeWorker.state === "activated")
+ resolve();
+ });
+ });
+}, "Setup worker");
+
+promise_test(async (test) => {
+ var promise = new Promise((resolve, reject) => {
+ navigator.serviceWorker.addEventListener("message", (event) => {
+ resolve(event.data);
+ });
+ });
+
+ activeWorker.postMessage("checkThrottleable");
+
+ assert_false(await promise);
+}, "Service worker should not be throttleable");
+
+promise_test(async (test) => {
+ if (window.testRunner) {
+ testRunner.setWindowIsKey(false);
+ testRunner.setPageVisibility("hidden");
+ }
+
+ let throttleable = false;
+ for (let cptr = 0; cptr < 1000 && !throttleable; ++cptr) {
+ throttleable = await new Promise((resolve, reject) => {
+ navigator.serviceWorker.addEventListener("message", (event) => {
+ resolve(event.data);
+ });
+ activeWorker.postMessage("checkThrottleable");
+ });
+ await new Promise(resolve => setTimeout(resolve, 50));
+ }
+ assert_true(throttleable);
+}, "Service worker should be throttleable");
+
+</script>
+</body>
+</html>
Modified: trunk/LayoutTests/platform/ios-wk2/TestExpectations (245298 => 245299)
--- trunk/LayoutTests/platform/ios-wk2/TestExpectations 2019-05-14 19:48:09 UTC (rev 245298)
+++ trunk/LayoutTests/platform/ios-wk2/TestExpectations 2019-05-14 19:48:51 UTC (rev 245299)
@@ -367,6 +367,8 @@
http/tests/websocket/tests/hybi/invalid-subprotocol-characters.html
http/tests/xmlhttprequest/cross-origin-authorization-with-embedder.html
+http/wpt/service-workers/mac/ [ 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 ]
Modified: trunk/Source/WebCore/ChangeLog (245298 => 245299)
--- trunk/Source/WebCore/ChangeLog 2019-05-14 19:48:09 UTC (rev 245298)
+++ trunk/Source/WebCore/ChangeLog 2019-05-14 19:48:51 UTC (rev 245299)
@@ -1,5 +1,36 @@
2019-05-14 Youenn Fablet <[email protected]>
+ 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 Alex Christensen.
+
+ Update RegistrableDomain to work with SecurityOriginData.
+ Add internal API to enable accessing to service worker process throttle state.
+
+ Test: http/wpt/service-workers/mac/processSuppression.https.html
+
+ * platform/RegistrableDomain.h:
+ (WebCore::RegistrableDomain::RegistrableDomain):
+ (WebCore::RegistrableDomain::matches const):
+ (WebCore::RegistrableDomain::registrableDomainFromHost):
+ * testing/ServiceWorkerInternals.cpp:
+ (WebCore::ServiceWorkerInternals::isThrottleable const):
+ * testing/ServiceWorkerInternals.h:
+ * testing/ServiceWorkerInternals.idl:
+ * workers/service/SWClientConnection.h:
+ * workers/service/context/SWContextManager.cpp:
+ * workers/service/context/SWContextManager.h:
+ * workers/service/server/SWServer.cpp:
+ (WebCore::SWServer::serverToContextConnectionCreated):
+ * workers/service/server/SWServer.h:
+ (WebCore::SWServer::Connection::server const):
+ (WebCore::SWServer::connections const):
+ * workers/service/server/SWServerToContextConnection.h:
+
+2019-05-14 Youenn Fablet <[email protected]>
+
getUserMedia capture changes on iOS after homing out
https://bugs.webkit.org/show_bug.cgi?id=197707
Modified: trunk/Source/WebCore/platform/RegistrableDomain.h (245298 => 245299)
--- trunk/Source/WebCore/platform/RegistrableDomain.h 2019-05-14 19:48:09 UTC (rev 245298)
+++ trunk/Source/WebCore/platform/RegistrableDomain.h 2019-05-14 19:48:51 UTC (rev 245299)
@@ -26,6 +26,7 @@
#pragma once
#include "PublicSuffix.h"
+#include "SecurityOriginData.h"
#include <wtf/HashTraits.h>
#include <wtf/URL.h>
#include <wtf/text/WTFString.h>
@@ -36,20 +37,17 @@
WTF_MAKE_FAST_ALLOCATED;
public:
RegistrableDomain() = default;
+
explicit RegistrableDomain(const URL& url)
-#if ENABLE(PUBLIC_SUFFIX_LIST)
- : m_registrableDomain { topPrivatelyControlledDomain(url.host().toString()) }
-#else
- : m_registrableDomain { url.host().toString() }
-#endif
+ : RegistrableDomain(registrableDomainFromHost(url.host().toString()))
{
- auto hostString = url.host().toString();
- if (hostString.isEmpty())
- m_registrableDomain = "nullOrigin"_s;
- else if (m_registrableDomain.isEmpty())
- m_registrableDomain = hostString;
}
+ explicit RegistrableDomain(const SecurityOriginData& origin)
+ : RegistrableDomain(registrableDomainFromHost(origin.host))
+ {
+ }
+
bool isEmpty() const { return m_registrableDomain.isEmpty() || m_registrableDomain == "nullOrigin"_s; }
const String& string() const { return m_registrableDomain; }
@@ -58,16 +56,14 @@
bool matches(const URL& url) const
{
- auto host = url.host();
- if (host.isEmpty() && m_registrableDomain == "nullOrigin"_s)
- return true;
- if (!host.endsWith(m_registrableDomain))
- return false;
- if (host.length() == m_registrableDomain.length())
- return true;
- return host[host.length() - m_registrableDomain.length() - 1] == '.';
+ return matches(url.host());
}
+ bool matches(const SecurityOriginData& origin) const
+ {
+ return matches(origin.host);
+ }
+
RegistrableDomain isolatedCopy() const { return RegistrableDomain { m_registrableDomain.isolatedCopy() }; }
RegistrableDomain(WTF::HashTableDeletedValueType)
@@ -109,6 +105,31 @@
{
}
+ bool matches(StringView host) const
+ {
+ if (host.isEmpty() && m_registrableDomain == "nullOrigin"_s)
+ return true;
+ if (!host.endsWith(m_registrableDomain))
+ return false;
+ if (host.length() == m_registrableDomain.length())
+ return true;
+ return host[host.length() - m_registrableDomain.length() - 1] == '.';
+ }
+
+ static inline String registrableDomainFromHost(const String& host)
+ {
+#if ENABLE(PUBLIC_SUFFIX_LIST)
+ auto domain = topPrivatelyControlledDomain(host);
+#else
+ auto domain = host;
+#endif
+ if (host.isEmpty())
+ domain = "nullOrigin"_s;
+ else if (domain.isEmpty())
+ domain = host;
+ return domain;
+ }
+
String m_registrableDomain;
};
Modified: trunk/Source/WebCore/testing/ServiceWorkerInternals.cpp (245298 => 245299)
--- trunk/Source/WebCore/testing/ServiceWorkerInternals.cpp 2019-05-14 19:48:09 UTC (rev 245298)
+++ trunk/Source/WebCore/testing/ServiceWorkerInternals.cpp 2019-05-14 19:48:51 UTC (rev 245299)
@@ -96,6 +96,12 @@
}
#endif
+bool ServiceWorkerInternals::isThrottleable() const
+{
+ auto* connection = SWContextManager::singleton().connection();
+ return connection ? connection->isThrottleable() : true;
+}
+
} // namespace WebCore
#endif
Modified: trunk/Source/WebCore/testing/ServiceWorkerInternals.h (245298 => 245299)
--- trunk/Source/WebCore/testing/ServiceWorkerInternals.h 2019-05-14 19:48:09 UTC (rev 245298)
+++ trunk/Source/WebCore/testing/ServiceWorkerInternals.h 2019-05-14 19:48:51 UTC (rev 245299)
@@ -51,6 +51,8 @@
String processName() const;
+ bool isThrottleable() const;
+
private:
explicit ServiceWorkerInternals(ServiceWorkerIdentifier);
Modified: trunk/Source/WebCore/testing/ServiceWorkerInternals.idl (245298 => 245299)
--- trunk/Source/WebCore/testing/ServiceWorkerInternals.idl 2019-05-14 19:48:09 UTC (rev 245298)
+++ trunk/Source/WebCore/testing/ServiceWorkerInternals.idl 2019-05-14 19:48:51 UTC (rev 245299)
@@ -37,4 +37,5 @@
sequence<ByteString> fetchResponseHeaderList(FetchResponse response);
readonly attribute DOMString processName;
+ readonly attribute boolean isThrottleable;
};
Modified: trunk/Source/WebCore/workers/service/SWClientConnection.h (245298 => 245299)
--- trunk/Source/WebCore/workers/service/SWClientConnection.h 2019-05-14 19:48:09 UTC (rev 245298)
+++ trunk/Source/WebCore/workers/service/SWClientConnection.h 2019-05-14 19:48:51 UTC (rev 245299)
@@ -85,6 +85,9 @@
virtual void finishFetchingScriptInServer(const ServiceWorkerFetchResult&) = 0;
+ virtual bool isThrottleable() const = 0;
+ virtual void updateThrottleState() = 0;
+
protected:
WEBCORE_EXPORT SWClientConnection();
Modified: trunk/Source/WebCore/workers/service/context/SWContextManager.h (245298 => 245299)
--- trunk/Source/WebCore/workers/service/context/SWContextManager.h 2019-05-14 19:48:09 UTC (rev 245298)
+++ trunk/Source/WebCore/workers/service/context/SWContextManager.h 2019-05-14 19:48:51 UTC (rev 245299)
@@ -62,6 +62,8 @@
virtual void findClientByIdentifier(ServiceWorkerIdentifier, ServiceWorkerClientIdentifier, FindClientByIdentifierCallback&&) = 0;
virtual void matchAll(ServiceWorkerIdentifier, const ServiceWorkerClientQueryOptions&, ServiceWorkerClientsMatchAllCallback&&) = 0;
virtual void claim(ServiceWorkerIdentifier, CompletionHandler<void()>&&) = 0;
+
+ virtual bool isThrottleable() const = 0;
};
WEBCORE_EXPORT void setConnection(std::unique_ptr<Connection>&&);
Modified: trunk/Source/WebCore/workers/service/server/SWServer.cpp (245298 => 245299)
--- trunk/Source/WebCore/workers/service/server/SWServer.cpp 2019-05-14 19:48:09 UTC (rev 245298)
+++ trunk/Source/WebCore/workers/service/server/SWServer.cpp 2019-05-14 19:48:51 UTC (rev 245299)
@@ -544,6 +544,9 @@
void SWServer::serverToContextConnectionCreated(SWServerToContextConnection& contextConnection)
{
+ for (auto& connection : m_connections.values())
+ connection->serverToContextConnectionCreated(contextConnection);
+
auto pendingContextDatas = m_pendingContextDatas.take(contextConnection.registrableDomain());
for (auto& data : pendingContextDatas)
installContextData(data);
Modified: trunk/Source/WebCore/workers/service/server/SWServer.h (245298 => 245299)
--- trunk/Source/WebCore/workers/service/server/SWServer.h 2019-05-14 19:48:09 UTC (rev 245298)
+++ trunk/Source/WebCore/workers/service/server/SWServer.h 2019-05-14 19:48:51 UTC (rev 245299)
@@ -87,7 +87,10 @@
virtual void notifyClientsOfControllerChange(const HashSet<DocumentIdentifier>& contextIdentifiers, const ServiceWorkerData& newController) = 0;
virtual void registrationReady(uint64_t registrationReadyRequestIdentifier, ServiceWorkerRegistrationData&&) = 0;
+ virtual void serverToContextConnectionCreated(SWServerToContextConnection&) = 0;
+
SWServer& server() { return m_server; }
+ const SWServer& server() const { return m_server; }
protected:
WEBCORE_EXPORT explicit Connection(SWServer&);
@@ -153,6 +156,8 @@
WEBCORE_EXPORT void removeConnection(SWServerConnectionIdentifier);
Connection* connection(SWServerConnectionIdentifier identifier) const { return m_connections.get(identifier); }
+ const HashMap<SWServerConnectionIdentifier, std::unique_ptr<Connection>>& connections() const { return m_connections; }
+
SWOriginStore& originStore() { return m_originStore; }
void scriptContextFailedToStart(const Optional<ServiceWorkerJobDataIdentifier>&, SWServerWorker&, const String& message);
Modified: trunk/Source/WebCore/workers/service/server/SWServerToContextConnection.h (245298 => 245299)
--- trunk/Source/WebCore/workers/service/server/SWServerToContextConnection.h 2019-05-14 19:48:09 UTC (rev 245298)
+++ trunk/Source/WebCore/workers/service/server/SWServerToContextConnection.h 2019-05-14 19:48:51 UTC (rev 245299)
@@ -76,7 +76,7 @@
WEBCORE_EXPORT void claim(uint64_t requestIdentifier, ServiceWorkerIdentifier);
WEBCORE_EXPORT void setScriptResource(ServiceWorkerIdentifier, URL&& scriptURL, String&& script, URL&& responseURL, String&& mimeType);
- static SWServerToContextConnection* connectionForRegistrableDomain(const RegistrableDomain&);
+ WEBCORE_EXPORT static SWServerToContextConnection* connectionForRegistrableDomain(const RegistrableDomain&);
const RegistrableDomain& registrableDomain() const { return m_registrableDomain; }
Modified: trunk/Source/WebKit/ChangeLog (245298 => 245299)
--- trunk/Source/WebKit/ChangeLog 2019-05-14 19:48:09 UTC (rev 245298)
+++ trunk/Source/WebKit/ChangeLog 2019-05-14 19:48:51 UTC (rev 245299)
@@ -1,3 +1,50 @@
+2019-05-14 Youenn Fablet <[email protected]>
+
+ 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 Alex Christensen.
+
+ Compute whether a given web process can be throttled on every page throttling change.
+ Send that information to network process which stores that information in WebSWServerConnection.
+ Every WebSWServerToContextConnection throttle state is then computed based on all WebSWServerConnection
+ that have a client that matches the registrable domain of the context connection.
+
+ * NetworkProcess/ServiceWorker/WebSWServerConnection.cpp:
+ (WebKit::WebSWServerConnection::registerServiceWorkerClient):
+ (WebKit::WebSWServerConnection::unregisterServiceWorkerClient):
+ (WebKit::WebSWServerConnection::hasMatchingClient const):
+ (WebKit::WebSWServerConnection::computeThrottleState const):
+ (WebKit::WebSWServerConnection::setThrottleState):
+ (WebKit::WebSWServerConnection::updateThrottleState):
+ (WebKit::WebSWServerConnection::serverToContextConnectionCreated):
+ * NetworkProcess/ServiceWorker/WebSWServerConnection.h:
+ (WebKit::WebSWServerConnection::isThrottleable const):
+ * NetworkProcess/ServiceWorker/WebSWServerConnection.messages.in:
+ * NetworkProcess/ServiceWorker/WebSWServerToContextConnection.cpp:
+ (WebKit::WebSWServerToContextConnection::setThrottleState):
+ * NetworkProcess/ServiceWorker/WebSWServerToContextConnection.h:
+ (WebKit::WebSWServerToContextConnection::isThrottleable const):
+ * UIProcess/ServiceWorkerProcessProxy.cpp:
+ * UIProcess/ServiceWorkerProcessProxy.h:
+ * WebProcess/Storage/WebSWClientConnection.cpp:
+ (WebKit::WebSWClientConnection::WebSWClientConnection):
+ (WebKit::WebSWClientConnection::updateThrottleState):
+ * WebProcess/Storage/WebSWClientConnection.h:
+ * WebProcess/Storage/WebSWContextManagerConnection.cpp:
+ (WebKit::WebSWContextManagerConnection::setThrottleState):
+ (WebKit::WebSWContextManagerConnection::isThrottleable const):
+ * WebProcess/Storage/WebSWContextManagerConnection.h:
+ * WebProcess/Storage/WebSWContextManagerConnection.messages.in:
+ * WebProcess/WebPage/WebPage.cpp:
+ (WebKit::WebPage::updateUserActivity):
+ (WebKit::WebPage::isThrottleable const):
+ * WebProcess/WebPage/WebPage.h:
+ * WebProcess/WebProcess.cpp:
+ (WebKit::WebProcess::arePagesThrottleable const):
+ * WebProcess/WebProcess.h:
+
2019-05-14 Chris Dumez <[email protected]>
Crash under WebKit::WebProcessProxy::didBecomeUnresponsive()
Modified: trunk/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerConnection.cpp (245298 => 245299)
--- trunk/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerConnection.cpp 2019-05-14 19:48:09 UTC (rev 245298)
+++ trunk/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerConnection.cpp 2019-05-14 19:48:51 UTC (rev 245299)
@@ -51,6 +51,7 @@
#include <WebCore/ServiceWorkerContextData.h>
#include <WebCore/ServiceWorkerJobData.h>
#include <WebCore/ServiceWorkerUpdateViaCache.h>
+#include <wtf/Algorithms.h>
#include <wtf/MainThread.h>
namespace WebKit {
@@ -278,6 +279,9 @@
auto clientOrigin = ClientOrigin { WTFMove(topOrigin), SecurityOriginData::fromURL(data.url) };
m_clientOrigins.add(data.identifier, clientOrigin);
server().registerServiceWorkerClient(WTFMove(clientOrigin), WTFMove(data), controllingServiceWorkerRegistrationIdentifier, WTFMove(userAgent));
+
+ if (!m_isThrottleable)
+ updateThrottleState();
}
void WebSWServerConnection::unregisterServiceWorkerClient(const ServiceWorkerClientIdentifier& clientIdentifier)
@@ -288,8 +292,58 @@
server().unregisterServiceWorkerClient(iterator->value, clientIdentifier);
m_clientOrigins.remove(iterator);
+
+ if (!m_isThrottleable)
+ updateThrottleState();
}
+bool WebSWServerConnection::hasMatchingClient(const RegistrableDomain& domain) const
+{
+ return WTF::anyOf(m_clientOrigins.values(), [&domain](auto& origin) {
+ return domain.matches(origin.clientOrigin);
+ });
+}
+
+bool WebSWServerConnection::computeThrottleState(const RegistrableDomain& domain) const
+{
+ return WTF::allOf(server().connections().values(), [&domain](auto& serverConnection) {
+ auto& connection = static_cast<WebSWServerConnection&>(*serverConnection);
+ return connection.isThrottleable() || !connection.hasMatchingClient(domain);
+ });
+}
+
+void WebSWServerConnection::setThrottleState(bool isThrottleable)
+{
+ m_isThrottleable = isThrottleable;
+ updateThrottleState();
+}
+
+void WebSWServerConnection::updateThrottleState()
+{
+ HashSet<SecurityOriginData> origins;
+ for (auto& origin : m_clientOrigins.values())
+ origins.add(origin.clientOrigin);
+
+ for (auto& origin : origins) {
+ if (auto* contextConnection = SWServerToContextConnection::connectionForRegistrableDomain(RegistrableDomain { origin })) {
+ auto& connection = static_cast<WebSWServerToContextConnection&>(*contextConnection);
+
+ if (connection.isThrottleable() == m_isThrottleable)
+ continue;
+ bool newThrottleState = computeThrottleState(connection.registrableDomain());
+ if (connection.isThrottleable() == newThrottleState)
+ continue;
+ connection.setThrottleState(newThrottleState);
+ }
+ }
+}
+
+void WebSWServerConnection::serverToContextConnectionCreated(WebCore::SWServerToContextConnection& contextConnection)
+{
+ auto& connection = static_cast<WebSWServerToContextConnection&>(contextConnection);
+ connection.setThrottleState(computeThrottleState(connection.registrableDomain()));
+}
+
void WebSWServerConnection::syncTerminateWorkerFromClient(WebCore::ServiceWorkerIdentifier&& identifier, CompletionHandler<void()>&& completionHandler)
{
syncTerminateWorker(WTFMove(identifier));
Modified: trunk/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerConnection.h (245298 => 245299)
--- trunk/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerConnection.h 2019-05-14 19:48:09 UTC (rev 245298)
+++ trunk/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerConnection.h 2019-05-14 19:48:51 UTC (rev 245299)
@@ -94,6 +94,14 @@
void unregisterServiceWorkerClient(const WebCore::ServiceWorkerClientIdentifier&);
void syncTerminateWorkerFromClient(WebCore::ServiceWorkerIdentifier&&, CompletionHandler<void()>&&);
+ void serverToContextConnectionCreated(WebCore::SWServerToContextConnection&) final;
+
+ bool isThrottleable() const { return m_isThrottleable; }
+ bool hasMatchingClient(const WebCore::RegistrableDomain&) const;
+ bool computeThrottleState(const WebCore::RegistrableDomain&) const;
+ void setThrottleState(bool isThrottleable);
+ void updateThrottleState();
+
IPC::Connection* messageSenderConnection() const final { return m_contentConnection.ptr(); }
uint64_t messageSenderDestinationID() const final { return identifier().toUInt64(); }
@@ -103,6 +111,7 @@
Ref<IPC::Connection> m_contentConnection;
Ref<NetworkProcess> m_networkProcess;
HashMap<WebCore::ServiceWorkerClientIdentifier, WebCore::ClientOrigin> m_clientOrigins;
+ bool m_isThrottleable { true };
};
} // namespace WebKit
Modified: trunk/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerConnection.messages.in (245298 => 245299)
--- trunk/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerConnection.messages.in 2019-05-14 19:48:09 UTC (rev 245298)
+++ trunk/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerConnection.messages.in 2019-05-14 19:48:51 UTC (rev 245299)
@@ -44,6 +44,8 @@
UnregisterServiceWorkerClient(struct WebCore::ServiceWorkerClientIdentifier identifier)
SyncTerminateWorkerFromClient(WebCore::ServiceWorkerIdentifier workerIdentifier) -> () Synchronous
+
+ SetThrottleState(bool isThrottleable)
}
#endif // ENABLE(SERVICE_WORKER)
Modified: trunk/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerToContextConnection.cpp (245298 => 245299)
--- trunk/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerToContextConnection.cpp 2019-05-14 19:48:09 UTC (rev 245298)
+++ trunk/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerToContextConnection.cpp 2019-05-14 19:48:51 UTC (rev 245299)
@@ -115,6 +115,12 @@
m_networkProcess->swContextConnectionMayNoLongerBeNeeded(*this);
}
+void WebSWServerToContextConnection::setThrottleState(bool isThrottleable)
+{
+ m_isThrottleable = isThrottleable;
+ send(Messages::WebSWContextManagerConnection::SetThrottleState { isThrottleable });
+}
+
void WebSWServerToContextConnection::terminate()
{
send(Messages::WebSWContextManagerConnection::TerminateProcess());
Modified: trunk/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerToContextConnection.h (245298 => 245299)
--- trunk/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerToContextConnection.h 2019-05-14 19:48:09 UTC (rev 245298)
+++ trunk/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerToContextConnection.h 2019-05-14 19:48:51 UTC (rev 245299)
@@ -71,6 +71,9 @@
void didReceiveFetchTaskMessage(IPC::Connection&, IPC::Decoder&);
+ void setThrottleState(bool isThrottleable);
+ bool isThrottleable() const { return m_isThrottleable; }
+
private:
WebSWServerToContextConnection(NetworkProcess&, const WebCore::RegistrableDomain&, Ref<IPC::Connection>&&);
~WebSWServerToContextConnection();
@@ -97,6 +100,7 @@
HashMap<ServiceWorkerFetchTask::Identifier, WebCore::FetchIdentifier> m_ongoingFetchIdentifiers;
HashMap<WebCore::FetchIdentifier, Ref<ServiceWorkerFetchTask>> m_ongoingFetches;
+ bool m_isThrottleable { true };
}; // class WebSWServerToContextConnection
} // namespace WebKit
Modified: trunk/Source/WebKit/UIProcess/ServiceWorkerProcessProxy.cpp (245298 => 245299)
--- trunk/Source/WebKit/UIProcess/ServiceWorkerProcessProxy.cpp 2019-05-14 19:48:09 UTC (rev 245298)
+++ trunk/Source/WebKit/UIProcess/ServiceWorkerProcessProxy.cpp 2019-05-14 19:48:51 UTC (rev 245299)
@@ -106,15 +106,6 @@
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)
Modified: trunk/Source/WebKit/UIProcess/ServiceWorkerProcessProxy.h (245298 => 245299)
--- trunk/Source/WebKit/UIProcess/ServiceWorkerProcessProxy.h 2019-05-14 19:48:09 UTC (rev 245298)
+++ trunk/Source/WebKit/UIProcess/ServiceWorkerProcessProxy.h 2019-05-14 19:48:51 UTC (rev 245299)
@@ -54,9 +54,6 @@
// 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&);
Modified: trunk/Source/WebKit/WebProcess/Storage/WebSWClientConnection.cpp (245298 => 245299)
--- trunk/Source/WebKit/WebProcess/Storage/WebSWClientConnection.cpp 2019-05-14 19:48:09 UTC (rev 245298)
+++ trunk/Source/WebKit/WebProcess/Storage/WebSWClientConnection.cpp 2019-05-14 19:48:51 UTC (rev 245299)
@@ -60,6 +60,7 @@
bool result = sendSync(Messages::NetworkConnectionToWebProcess::EstablishSWServerConnection(sessionID), Messages::NetworkConnectionToWebProcess::EstablishSWServerConnection::Reply(m_identifier));
ASSERT_UNUSED(result, result);
+ updateThrottleState();
}
WebSWClientConnection::~WebSWClientConnection()
@@ -231,6 +232,12 @@
sendSync(Messages::WebSWServerConnection::SyncTerminateWorkerFromClient(identifier), Messages::WebSWServerConnection::SyncTerminateWorkerFromClient::Reply());
}
+void WebSWClientConnection::updateThrottleState()
+{
+ m_isThrottleable = WebProcess::singleton().areAllPagesThrottleable();
+ send(Messages::WebSWServerConnection::SetThrottleState { m_isThrottleable });
+}
+
} // namespace WebKit
#endif // ENABLE(SERVICE_WORKER)
Modified: trunk/Source/WebKit/WebProcess/Storage/WebSWClientConnection.h (245298 => 245299)
--- trunk/Source/WebKit/WebProcess/Storage/WebSWClientConnection.h 2019-05-14 19:48:09 UTC (rev 245298)
+++ trunk/Source/WebKit/WebProcess/Storage/WebSWClientConnection.h 2019-05-14 19:48:51 UTC (rev 245299)
@@ -87,6 +87,8 @@
void getRegistrations(WebCore::SecurityOriginData&& topOrigin, const URL& clientURL, GetRegistrationsCallback&&) final;
void didResolveRegistrationPromise(const WebCore::ServiceWorkerRegistrationKey&) final;
+ void updateThrottleState() final;
+ bool isThrottleable() const final { return m_isThrottleable; }
void scheduleStorageJob(const WebCore::ServiceWorkerJobData&);
@@ -109,7 +111,7 @@
HashMap<uint64_t, GetRegistrationsCallback> m_ongoingGetRegistrationsTasks;
HashMap<uint64_t, WhenRegistrationReadyCallback> m_ongoingRegistrationReadyTasks;
Deque<WTF::Function<void()>> m_tasksPendingOriginImport;
-
+ bool m_isThrottleable { true };
}; // class WebSWServerConnection
} // namespace WebKit
Modified: trunk/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.cpp (245298 => 245299)
--- trunk/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.cpp 2019-05-14 19:48:09 UTC (rev 245298)
+++ trunk/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.cpp 2019-05-14 19:48:51 UTC (rev 245299)
@@ -364,6 +364,18 @@
_exit(EXIT_SUCCESS);
}
+void WebSWContextManagerConnection::setThrottleState(bool isThrottleable)
+{
+ RELEASE_LOG(ServiceWorker, "Service worker throttleable state is set to %d", isThrottleable);
+ m_isThrottleable = isThrottleable;
+ WebProcess::singleton().setProcessSuppressionEnabled(isThrottleable);
+}
+
+bool WebSWContextManagerConnection::isThrottleable() const
+{
+ return m_isThrottleable;
+}
+
} // namespace WebCore
#endif // ENABLE(SERVICE_WORKER)
Modified: trunk/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.h (245298 => 245299)
--- trunk/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.h 2019-05-14 19:48:09 UTC (rev 245298)
+++ trunk/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.h 2019-05-14 19:48:51 UTC (rev 245299)
@@ -73,6 +73,7 @@
void claim(WebCore::ServiceWorkerIdentifier, CompletionHandler<void()>&&) final;
void skipWaiting(WebCore::ServiceWorkerIdentifier, Function<void()>&&) final;
void setScriptResource(WebCore::ServiceWorkerIdentifier, const URL&, const WebCore::ServiceWorkerContextData::ImportedScript&) final;
+ bool isThrottleable() const final;
// IPC messages.
void serviceWorkerStartedWithMessage(Optional<WebCore::ServiceWorkerJobDataIdentifier>, WebCore::ServiceWorkerIdentifier, const String& exceptionMessage) final;
@@ -91,6 +92,7 @@
void didFinishSkipWaiting(uint64_t callbackID);
void setUserAgent(String&& userAgent);
NO_RETURN void terminateProcess();
+ void setThrottleState(bool isThrottleable);
Ref<IPC::Connection> m_connectionToNetworkProcess;
uint64_t m_pageGroupID;
@@ -106,6 +108,7 @@
HashMap<uint64_t, WTF::Function<void()>> m_skipWaitingRequests;
uint64_t m_previousRequestIdentifier { 0 };
String m_userAgent;
+ bool m_isThrottleable { true };
};
} // namespace WebKit
Modified: trunk/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.messages.in (245298 => 245299)
--- trunk/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.messages.in 2019-05-14 19:48:09 UTC (rev 245298)
+++ trunk/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.messages.in 2019-05-14 19:48:51 UTC (rev 245299)
@@ -39,6 +39,7 @@
SetUserAgent(String userAgent)
UpdatePreferencesStore(struct WebKit::WebPreferencesStore store)
TerminateProcess()
+ SetThrottleState(bool isThrottleable)
}
#endif
Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp (245298 => 245299)
--- trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp 2019-05-14 19:48:09 UTC (rev 245298)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp 2019-05-14 19:48:51 UTC (rev 245299)
@@ -213,6 +213,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>
@@ -765,19 +766,31 @@
void WebPage::updateThrottleState()
{
- bool isActive = m_activityState.containsAny({ ActivityState::IsLoading, ActivityState::IsAudible, ActivityState::IsCapturingMedia, ActivityState::WindowIsActive });
- bool isVisuallyIdle = m_activityState.contains(ActivityState::IsVisuallyIdle);
+ bool isThrottleable = this->isThrottleable();
- bool shouldAllowAppNap = m_isAppNapEnabled && !isActive && isVisuallyIdle;
-
// The UserActivity prevents App Nap. So if we want to allow App Nap of the page, stop the activity.
// If the page should not be app nap'd, start it.
- if (shouldAllowAppNap)
+ if (isThrottleable)
m_userActivity.stop();
else
m_userActivity.start();
+
+#if ENABLE(SERVICE_WORKER)
+ if (auto* connection = ServiceWorkerProvider::singleton().existingServiceWorkerConnectionForSession(sessionID())) {
+ if (isThrottleable != connection->isThrottleable())
+ connection->updateThrottleState();
+ }
+#endif
}
+bool WebPage::isThrottleable() const
+{
+ bool isActive = m_activityState.containsAny({ ActivityState::IsLoading, ActivityState::IsAudible, ActivityState::IsCapturingMedia, ActivityState::WindowIsActive });
+ bool isVisuallyIdle = m_activityState.contains(ActivityState::IsVisuallyIdle);
+
+ return m_isAppNapEnabled && !isActive && isVisuallyIdle;
+}
+
WebPage::~WebPage()
{
ASSERT(!m_page);
Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPage.h (245298 => 245299)
--- trunk/Source/WebKit/WebProcess/WebPage/WebPage.h 2019-05-14 19:48:09 UTC (rev 245298)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPage.h 2019-05-14 19:48:51 UTC (rev 245299)
@@ -1191,6 +1191,7 @@
void updateIntrinsicContentSizeIfNeeded(const WebCore::IntSize&);
void scheduleFullEditorStateUpdate();
+ bool isThrottleable() const;
private:
WebPage(uint64_t pageID, WebPageCreationParameters&&);
Modified: trunk/Source/WebKit/WebProcess/WebProcess.cpp (245298 => 245299)
--- trunk/Source/WebKit/WebProcess/WebProcess.cpp 2019-05-14 19:48:09 UTC (rev 245298)
+++ trunk/Source/WebKit/WebProcess/WebProcess.cpp 2019-05-14 19:48:51 UTC (rev 245299)
@@ -117,6 +117,7 @@
#include <WebCore/ServiceWorkerContextData.h>
#include <WebCore/Settings.h>
#include <WebCore/UserGestureIndicator.h>
+#include <wtf/Algorithms.h>
#include <wtf/Language.h>
#include <wtf/ProcessPrivilege.h>
#include <wtf/RunLoop.h>
@@ -1907,4 +1908,11 @@
}
#endif
+bool WebProcess::areAllPagesThrottleable() const
+{
+ return WTF::allOf(m_pageMap.values(), [](auto& page) {
+ return page->isThrottleable();
+ });
+}
+
} // namespace WebKit
Modified: trunk/Source/WebKit/WebProcess/WebProcess.h (245298 => 245299)
--- trunk/Source/WebKit/WebProcess/WebProcess.h 2019-05-14 19:48:09 UTC (rev 245298)
+++ trunk/Source/WebKit/WebProcess/WebProcess.h 2019-05-14 19:48:51 UTC (rev 245299)
@@ -269,6 +269,8 @@
void setMediaMIMETypes(const Vector<String>);
#endif
+ bool areAllPagesThrottleable() const;
+
private:
WebProcess();
~WebProcess();
Modified: trunk/Tools/ChangeLog (245298 => 245299)
--- trunk/Tools/ChangeLog 2019-05-14 19:48:09 UTC (rev 245298)
+++ trunk/Tools/ChangeLog 2019-05-14 19:48:51 UTC (rev 245299)
@@ -1,3 +1,19 @@
+2019-05-14 Youenn Fablet <[email protected]>
+
+ 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 Alex Christensen.
+
+ Allow to enable app nap through test header.
+
+ * WebKitTestRunner/TestController.cpp:
+ (WTR::TestController::resetPreferencesToConsistentValues):
+ (WTR::updateTestOptionsFromTestHeader):
+ * WebKitTestRunner/TestOptions.h:
+ (WTR::TestOptions::hasSameInitializationOptions const):
+
2019-05-14 Commit Queue <[email protected]>
Unreviewed, rolling out r245281.
Modified: trunk/Tools/WebKitTestRunner/TestController.cpp (245298 => 245299)
--- trunk/Tools/WebKitTestRunner/TestController.cpp 2019-05-14 19:48:09 UTC (rev 245298)
+++ trunk/Tools/WebKitTestRunner/TestController.cpp 2019-05-14 19:48:51 UTC (rev 245299)
@@ -784,7 +784,7 @@
WKPreferencesSetInternalDebugFeatureForKey(preferences, internalDebugFeature.value, toWK(internalDebugFeature.key).get());
WKPreferencesSetProcessSwapOnNavigationEnabled(preferences, options.contextOptions.shouldEnableProcessSwapOnNavigation());
- WKPreferencesSetPageVisibilityBasedProcessSuppressionEnabled(preferences, false);
+ WKPreferencesSetPageVisibilityBasedProcessSuppressionEnabled(preferences, options.enableAppNap);
WKPreferencesSetOfflineWebApplicationCacheEnabled(preferences, true);
WKPreferencesSetSubpixelAntialiasedLayerTextEnabled(preferences, false);
WKPreferencesSetXSSAuditorEnabled(preferences, false);
@@ -1397,6 +1397,8 @@
testOptions.contextOptions.ignoreSynchronousMessagingTimeouts = parseBooleanTestHeaderValue(value);
else if (key == "shouldUseModernCompatibilityMode")
testOptions.shouldUseModernCompatibilityMode = parseBooleanTestHeaderValue(value);
+ else if (key == "enableAppNap")
+ testOptions.enableAppNap = parseBooleanTestHeaderValue(value);
pairStart = pairEnd + 1;
}
}
Modified: trunk/Tools/WebKitTestRunner/TestOptions.h (245298 => 245299)
--- trunk/Tools/WebKitTestRunner/TestOptions.h 2019-05-14 19:48:09 UTC (rev 245298)
+++ trunk/Tools/WebKitTestRunner/TestOptions.h 2019-05-14 19:48:51 UTC (rev 245299)
@@ -92,6 +92,7 @@
bool shouldHandleRunOpenPanel { true };
bool shouldPresentPopovers { true };
bool shouldUseModernCompatibilityMode { false };
+ bool enableAppNap { false };
double contentInsetTop { 0 };
@@ -144,7 +145,8 @@
|| shouldHandleRunOpenPanel != options.shouldHandleRunOpenPanel
|| shouldPresentPopovers != options.shouldPresentPopovers
|| contentInsetTop != options.contentInsetTop
- || shouldUseModernCompatibilityMode != options.shouldUseModernCompatibilityMode)
+ || shouldUseModernCompatibilityMode != options.shouldUseModernCompatibilityMode
+ || enableAppNap != options.enableAppNap)
return false;
if (!contextOptions.hasSameInitializationOptions(options.contextOptions))