Diff
Modified: trunk/Source/WebCore/ChangeLog (224908 => 224909)
--- trunk/Source/WebCore/ChangeLog 2017-11-16 01:17:02 UTC (rev 224908)
+++ trunk/Source/WebCore/ChangeLog 2017-11-16 03:05:02 UTC (rev 224909)
@@ -1,3 +1,42 @@
+2017-11-15 Brady Eidson <beid...@apple.com>
+
+ Implement basics of "Terminate Service Worker" algorithm.
+ https://bugs.webkit.org/show_bug.cgi?id=179551
+
+ Reviewed by Chris Dumez.
+
+ No new tests (No observable behavior change yet).
+
+ * workers/WorkerGlobalScope.cpp:
+ (WebCore::WorkerGlobalScope::stopIndexedDatabase):
+
+ * workers/WorkerMessagingProxy.cpp:
+ (WebCore::WorkerMessagingProxy::workerThreadCreated):
+ (WebCore::WorkerMessagingProxy::terminateWorkerGlobalScope):
+
+ * workers/WorkerThread.cpp:
+ (WebCore::WorkerThread::workerThread):
+ (WebCore::WorkerThread::stop):
+ * workers/WorkerThread.h:
+
+ * workers/service/context/SWContextManager.cpp:
+ (WebCore::SWContextManager::terminateWorker):
+ * workers/service/context/SWContextManager.h:
+
+ * workers/service/server/SWServer.cpp:
+ (WebCore::SWServer::workerContextTerminated):
+ (WebCore::SWServer::terminateWorker):
+ * workers/service/server/SWServer.h:
+
+ * workers/service/server/SWServerToContextConnection.cpp:
+ (WebCore::SWServerToContextConnection::workerTerminated):
+ * workers/service/server/SWServerToContextConnection.h:
+
+ * workers/service/server/SWServerWorker.cpp:
+ (WebCore::SWServerWorker::terminate):
+ (WebCore::SWServerWorker::contextTerminated):
+ * workers/service/server/SWServerWorker.h:
+
2017-11-15 Eric Carlson <eric.carl...@apple.com>
Log media readyState and networkState as strings
Modified: trunk/Source/WebCore/workers/WorkerGlobalScope.cpp (224908 => 224909)
--- trunk/Source/WebCore/workers/WorkerGlobalScope.cpp 2017-11-16 01:17:02 UTC (rev 224908)
+++ trunk/Source/WebCore/workers/WorkerGlobalScope.cpp 2017-11-16 03:05:02 UTC (rev 224909)
@@ -162,8 +162,8 @@
void WorkerGlobalScope::stopIndexedDatabase()
{
#if ENABLE(INDEXED_DATABASE_IN_WORKERS)
- ASSERT(m_connectionProxy);
- m_connectionProxy->forgetActivityForCurrentThread();
+ if (m_connectionProxy)
+ m_connectionProxy->forgetActivityForCurrentThread();
#endif
}
Modified: trunk/Source/WebCore/workers/WorkerMessagingProxy.cpp (224908 => 224909)
--- trunk/Source/WebCore/workers/WorkerMessagingProxy.cpp 2017-11-16 01:17:02 UTC (rev 224908)
+++ trunk/Source/WebCore/workers/WorkerMessagingProxy.cpp 2017-11-16 03:05:02 UTC (rev 224909)
@@ -192,7 +192,7 @@
if (m_askedToTerminate) {
// Worker.terminate() could be called from JS before the thread was created.
- m_workerThread->stop();
+ m_workerThread->stop(nullptr);
} else {
ASSERT(!m_unconfirmedMessageCount);
m_unconfirmedMessageCount = m_queuedEarlyTasks.size();
@@ -268,7 +268,7 @@
m_inspectorProxy->workerTerminated();
if (m_workerThread)
- m_workerThread->stop();
+ m_workerThread->stop(nullptr);
}
void WorkerMessagingProxy::confirmMessageFromWorkerObject(bool hasPendingActivity)
Modified: trunk/Source/WebCore/workers/WorkerThread.cpp (224908 => 224909)
--- trunk/Source/WebCore/workers/WorkerThread.cpp 2017-11-16 01:17:02 UTC (rev 224908)
+++ trunk/Source/WebCore/workers/WorkerThread.cpp 2017-11-16 03:05:02 UTC (rev 224909)
@@ -188,7 +188,7 @@
String exceptionMessage;
scriptController->evaluate(ScriptSourceCode(m_startupData->m_sourceCode, m_startupData->m_scriptURL), &exceptionMessage);
- RunLoop::main().dispatch([evaluateCallback = WTFMove(m_evaluateCallback), message = exceptionMessage.isolatedCopy()] {
+ callOnMainThread([evaluateCallback = WTFMove(m_evaluateCallback), message = exceptionMessage.isolatedCopy()] {
if (evaluateCallback)
evaluateCallback(message);
});
@@ -228,6 +228,9 @@
// Clean up WebCore::ThreadGlobalData before WTF::Thread goes away!
threadGlobalData().destroy();
+ if (m_stoppedCallback)
+ callOnMainThread(WTFMove(m_stoppedCallback));
+
// The thread object may be already destroyed from notification now, don't try to access "this".
protector->detach();
}
@@ -254,8 +257,11 @@
m_runLoop.run(m_workerGlobalScope.get());
}
-void WorkerThread::stop()
+void WorkerThread::stop(WTF::Function<void()>&& stoppedCallback)
{
+ ASSERT(!m_stoppedCallback);
+ m_stoppedCallback = WTFMove(stoppedCallback);
+
// Mutex protection is necessary to ensure that m_workerGlobalScope isn't changed by
// WorkerThread::workerThread() while we're accessing it. Note also that stop() can
// be called before m_workerGlobalScope is fully created.
Modified: trunk/Source/WebCore/workers/WorkerThread.h (224908 => 224909)
--- trunk/Source/WebCore/workers/WorkerThread.h 2017-11-16 01:17:02 UTC (rev 224908)
+++ trunk/Source/WebCore/workers/WorkerThread.h 2017-11-16 03:05:02 UTC (rev 224909)
@@ -64,7 +64,7 @@
virtual ~WorkerThread();
WEBCORE_EXPORT bool start(WTF::Function<void(const String&)>&& evaluateCallback);
- void stop();
+ void stop(WTF::Function<void()>&& terminatedCallback);
ThreadIdentifier threadID() const { return m_thread ? m_thread->id() : 0; }
WorkerRunLoop& runLoop() { return m_runLoop; }
@@ -126,6 +126,8 @@
RefPtr<IDBClient::IDBConnectionProxy> m_idbConnectionProxy;
#endif
RefPtr<SocketProvider> m_socketProvider;
+
+ WTF::Function<void()> m_stoppedCallback;
};
} // namespace WebCore
Modified: trunk/Source/WebCore/workers/service/context/SWContextManager.cpp (224908 => 224909)
--- trunk/Source/WebCore/workers/service/context/SWContextManager.cpp 2017-11-16 01:17:02 UTC (rev 224908)
+++ trunk/Source/WebCore/workers/service/context/SWContextManager.cpp 2017-11-16 03:05:02 UTC (rev 224909)
@@ -92,6 +92,18 @@
serviceWorker->thread().fireActivateEvent();
}
+void SWContextManager::terminateWorker(ServiceWorkerIdentifier identifier)
+{
+ auto* serviceWorker = m_workerMap.get(identifier);
+ if (!serviceWorker)
+ return;
+
+ serviceWorker->thread().stop([identifier] {
+ if (auto* connection = SWContextManager::singleton().connection())
+ connection->workerTerminated(identifier);
+ });
+}
+
} // namespace WebCore
#endif
Modified: trunk/Source/WebCore/workers/service/context/SWContextManager.h (224908 => 224909)
--- trunk/Source/WebCore/workers/service/context/SWContextManager.h 2017-11-16 01:17:02 UTC (rev 224908)
+++ trunk/Source/WebCore/workers/service/context/SWContextManager.h 2017-11-16 03:05:02 UTC (rev 224909)
@@ -50,6 +50,7 @@
virtual void didFinishInstall(ServiceWorkerIdentifier, bool wasSuccessful) = 0;
virtual void didFinishActivation(ServiceWorkerIdentifier) = 0;
virtual void setServiceWorkerHasPendingEvents(ServiceWorkerIdentifier, bool) = 0;
+ virtual void workerTerminated(ServiceWorkerIdentifier) = 0;
};
WEBCORE_EXPORT void setConnection(std::unique_ptr<Connection>&&);
@@ -60,6 +61,7 @@
WEBCORE_EXPORT void postMessageToServiceWorkerGlobalScope(ServiceWorkerIdentifier destination, Ref<SerializedScriptValue>&& message, ServiceWorkerClientData&& source);
WEBCORE_EXPORT void fireInstallEvent(ServiceWorkerIdentifier);
WEBCORE_EXPORT void fireActivateEvent(ServiceWorkerIdentifier);
+ WEBCORE_EXPORT void terminateWorker(ServiceWorkerIdentifier);
private:
SWContextManager() = default;
Modified: trunk/Source/WebCore/workers/service/server/SWServer.cpp (224908 => 224909)
--- trunk/Source/WebCore/workers/service/server/SWServer.cpp 2017-11-16 01:17:02 UTC (rev 224908)
+++ trunk/Source/WebCore/workers/service/server/SWServer.cpp 2017-11-16 03:05:02 UTC (rev 224909)
@@ -272,6 +272,12 @@
SWServerJobQueue::didFinishActivation(*registration, worker.identifier());
}
+void SWServer::workerContextTerminated(SWServerWorker& worker)
+{
+ auto result = m_workersByID.remove(worker.identifier());
+ ASSERT_UNUSED(result, result);
+}
+
void SWServer::didResolveRegistrationPromise(Connection& connection, const ServiceWorkerRegistrationKey& registrationKey)
{
ASSERT_UNUSED(connection, m_connections.contains(connection.identifier()));
@@ -345,6 +351,16 @@
connection->installServiceWorkerContext(data);
}
+
+void SWServer::terminateWorker(SWServerWorker& worker)
+{
+ auto* connection = SWServerToContextConnection::connectionForIdentifier(worker.contextConnectionIdentifier());
+ if (connection)
+ connection->terminateWorker(worker.identifier());
+ else
+ LOG_ERROR("Request to terminate a worker whose context connection does not exist");
+}
+
void SWServer::fireInstallEvent(SWServerWorker& worker)
{
auto* connection = SWServerToContextConnection::connectionForIdentifier(worker.contextConnectionIdentifier());
Modified: trunk/Source/WebCore/workers/service/server/SWServer.h (224908 => 224909)
--- trunk/Source/WebCore/workers/service/server/SWServer.h 2017-11-16 01:17:02 UTC (rev 224908)
+++ trunk/Source/WebCore/workers/service/server/SWServer.h 2017-11-16 03:05:02 UTC (rev 224909)
@@ -112,6 +112,7 @@
void postTaskReply(CrossThreadTask&&);
void updateWorker(Connection&, const ServiceWorkerRegistrationKey&, const URL&, const String& script, WorkerType);
+ void terminateWorker(SWServerWorker&);
void fireInstallEvent(SWServerWorker&);
void fireActivateEvent(SWServerWorker&);
SWServerWorker* workerByID(ServiceWorkerIdentifier identifier) const { return m_workersByID.get(identifier); }
@@ -123,6 +124,7 @@
void scriptContextStarted(SWServerWorker&);
void didFinishInstall(SWServerWorker&, bool wasSuccessful);
void didFinishActivation(SWServerWorker&);
+ void workerContextTerminated(SWServerWorker&);
WEBCORE_EXPORT void serverToContextConnectionCreated();
Modified: trunk/Source/WebCore/workers/service/server/SWServerToContextConnection.cpp (224908 => 224909)
--- trunk/Source/WebCore/workers/service/server/SWServerToContextConnection.cpp 2017-11-16 01:17:02 UTC (rev 224908)
+++ trunk/Source/WebCore/workers/service/server/SWServerToContextConnection.cpp 2017-11-16 03:05:02 UTC (rev 224909)
@@ -102,6 +102,12 @@
worker->setHasPendingEvents(hasPendingEvents);
}
+void SWServerToContextConnection::workerTerminated(ServiceWorkerIdentifier serviceWorkerIdentifier)
+{
+ if (auto* worker = SWServerWorker::existingWorkerForIdentifier(serviceWorkerIdentifier))
+ worker->contextTerminated();
+}
+
} // namespace WebCore
#endif // ENABLE(SERVICE_WORKER)
Modified: trunk/Source/WebCore/workers/service/server/SWServerToContextConnection.h (224908 => 224909)
--- trunk/Source/WebCore/workers/service/server/SWServerToContextConnection.h 2017-11-16 01:17:02 UTC (rev 224908)
+++ trunk/Source/WebCore/workers/service/server/SWServerToContextConnection.h 2017-11-16 03:05:02 UTC (rev 224909)
@@ -46,6 +46,7 @@
virtual void installServiceWorkerContext(const ServiceWorkerContextData&) = 0;
virtual void fireInstallEvent(ServiceWorkerIdentifier) = 0;
virtual void fireActivateEvent(ServiceWorkerIdentifier) = 0;
+ virtual void terminateWorker(ServiceWorkerIdentifier) = 0;
// Messages back from the SW host process
WEBCORE_EXPORT void scriptContextFailedToStart(ServiceWorkerIdentifier, const String& message);
@@ -53,6 +54,7 @@
WEBCORE_EXPORT void didFinishInstall(ServiceWorkerIdentifier, bool wasSuccessful);
WEBCORE_EXPORT void didFinishActivation(ServiceWorkerIdentifier);
WEBCORE_EXPORT void setServiceWorkerHasPendingEvents(ServiceWorkerIdentifier, bool hasPendingEvents);
+ WEBCORE_EXPORT void workerTerminated(ServiceWorkerIdentifier);
static SWServerToContextConnection* connectionForIdentifier(SWServerToContextConnectionIdentifier);
Modified: trunk/Source/WebCore/workers/service/server/SWServerWorker.cpp (224908 => 224909)
--- trunk/Source/WebCore/workers/service/server/SWServerWorker.cpp 2017-11-16 01:17:02 UTC (rev 224908)
+++ trunk/Source/WebCore/workers/service/server/SWServerWorker.cpp 2017-11-16 03:05:02 UTC (rev 224909)
@@ -62,7 +62,7 @@
void SWServerWorker::terminate()
{
- // FIXME: Implement
+ m_server.terminateWorker(*this);
}
void SWServerWorker::scriptContextFailedToStart(const String& message)
@@ -85,6 +85,11 @@
m_server.didFinishActivation(*this);
}
+void SWServerWorker::contextTerminated()
+{
+ m_server.workerContextTerminated(*this);
+}
+
} // namespace WebCore
#endif // ENABLE(SERVICE_WORKER)
Modified: trunk/Source/WebCore/workers/service/server/SWServerWorker.h (224908 => 224909)
--- trunk/Source/WebCore/workers/service/server/SWServerWorker.h 2017-11-16 01:17:02 UTC (rev 224908)
+++ trunk/Source/WebCore/workers/service/server/SWServerWorker.h 2017-11-16 03:05:02 UTC (rev 224909)
@@ -70,6 +70,7 @@
void scriptContextStarted();
void didFinishInstall(bool wasSuccessful);
void didFinishActivation();
+ void contextTerminated();
WEBCORE_EXPORT static SWServerWorker* existingWorkerForIdentifier(ServiceWorkerIdentifier);
Modified: trunk/Source/WebKit/ChangeLog (224908 => 224909)
--- trunk/Source/WebKit/ChangeLog 2017-11-16 01:17:02 UTC (rev 224908)
+++ trunk/Source/WebKit/ChangeLog 2017-11-16 03:05:02 UTC (rev 224909)
@@ -1,3 +1,21 @@
+2017-11-15 Brady Eidson <beid...@apple.com>
+
+ Implement basics of "Terminate Service Worker" algorithm.
+ https://bugs.webkit.org/show_bug.cgi?id=179551
+
+ Reviewed by Chris Dumez.
+
+ * StorageProcess/ServiceWorker/WebSWServerToContextConnection.cpp:
+ (WebKit::WebSWServerToContextConnection::terminateWorker):
+ * StorageProcess/ServiceWorker/WebSWServerToContextConnection.h:
+ * StorageProcess/ServiceWorker/WebSWServerToContextConnection.messages.in:
+
+ * WebProcess/Storage/WebSWContextManagerConnection.cpp:
+ (WebKit::WebSWContextManagerConnection::terminateWorker):
+ (WebKit::WebSWContextManagerConnection::workerTerminated):
+ * WebProcess/Storage/WebSWContextManagerConnection.h:
+ * WebProcess/Storage/WebSWContextManagerConnection.messages.in:
+
2017-11-15 Brent Fulgham <bfulg...@apple.com>
Remove access to 'com.apple.mediaaccessibility.public' preferences in WebContent sandbox
Modified: trunk/Source/WebKit/StorageProcess/ServiceWorker/WebSWServerToContextConnection.cpp (224908 => 224909)
--- trunk/Source/WebKit/StorageProcess/ServiceWorker/WebSWServerToContextConnection.cpp 2017-11-16 01:17:02 UTC (rev 224908)
+++ trunk/Source/WebKit/StorageProcess/ServiceWorker/WebSWServerToContextConnection.cpp 2017-11-16 03:05:02 UTC (rev 224909)
@@ -71,6 +71,11 @@
send(Messages::WebSWContextManagerConnection::FireActivateEvent(serviceWorkerIdentifier));
}
+void WebSWServerToContextConnection::terminateWorker(ServiceWorkerIdentifier serviceWorkerIdentifier)
+{
+ send(Messages::WebSWContextManagerConnection::TerminateWorker(serviceWorkerIdentifier));
+}
+
} // namespace WebKit
#endif // ENABLE(SERVICE_WORKER)
Modified: trunk/Source/WebKit/StorageProcess/ServiceWorker/WebSWServerToContextConnection.h (224908 => 224909)
--- trunk/Source/WebKit/StorageProcess/ServiceWorker/WebSWServerToContextConnection.h 2017-11-16 01:17:02 UTC (rev 224908)
+++ trunk/Source/WebKit/StorageProcess/ServiceWorker/WebSWServerToContextConnection.h 2017-11-16 03:05:02 UTC (rev 224909)
@@ -58,7 +58,8 @@
void installServiceWorkerContext(const WebCore::ServiceWorkerContextData&) final;
void fireInstallEvent(WebCore::ServiceWorkerIdentifier) final;
void fireActivateEvent(WebCore::ServiceWorkerIdentifier) final;
-
+ void terminateWorker(WebCore::ServiceWorkerIdentifier) final;
+
Ref<IPC::Connection> m_ipcConnection;
}; // class WebSWServerToContextConnection
Modified: trunk/Source/WebKit/StorageProcess/ServiceWorker/WebSWServerToContextConnection.messages.in (224908 => 224909)
--- trunk/Source/WebKit/StorageProcess/ServiceWorker/WebSWServerToContextConnection.messages.in 2017-11-16 01:17:02 UTC (rev 224908)
+++ trunk/Source/WebKit/StorageProcess/ServiceWorker/WebSWServerToContextConnection.messages.in 2017-11-16 03:05:02 UTC (rev 224909)
@@ -29,7 +29,8 @@
ScriptContextStarted(WebCore::ServiceWorkerIdentifier identifier);
DidFinishInstall(WebCore::ServiceWorkerIdentifier identifier, bool wasSuccessful);
DidFinishActivation(WebCore::ServiceWorkerIdentifier identifier);
- SetServiceWorkerHasPendingEvents(WebCore::ServiceWorkerIdentifier serviceWorkerIdentifier, bool hasPendingEvents);
+ SetServiceWorkerHasPendingEvents(WebCore::ServiceWorkerIdentifier identifier, bool hasPendingEvents);
+ WorkerTerminated(WebCore::ServiceWorkerIdentifier identifier);
}
#endif // ENABLE(SERVICE_WORKER)
Modified: trunk/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.cpp (224908 => 224909)
--- trunk/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.cpp 2017-11-16 01:17:02 UTC (rev 224908)
+++ trunk/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.cpp 2017-11-16 03:05:02 UTC (rev 224909)
@@ -158,6 +158,11 @@
SWContextManager::singleton().fireActivateEvent(identifier);
}
+void WebSWContextManagerConnection::terminateWorker(ServiceWorkerIdentifier identifier)
+{
+ SWContextManager::singleton().terminateWorker(identifier);
+}
+
void WebSWContextManagerConnection::postMessageToServiceWorkerClient(const ServiceWorkerClientIdentifier& destinationIdentifier, Ref<SerializedScriptValue>&& message, ServiceWorkerIdentifier sourceIdentifier, const String& sourceOrigin)
{
m_connectionToStorageProcess->send(Messages::StorageProcess::PostMessageToServiceWorkerClient(destinationIdentifier, IPC::DataReference { message->data() }, sourceIdentifier, sourceOrigin), 0);
@@ -178,6 +183,11 @@
m_connectionToStorageProcess->send(Messages::WebSWServerToContextConnection::SetServiceWorkerHasPendingEvents(serviceWorkerIdentifier, hasPendingEvents), 0);
}
+void WebSWContextManagerConnection::workerTerminated(ServiceWorkerIdentifier serviceWorkerIdentifier)
+{
+ m_connectionToStorageProcess->send(Messages::WebSWServerToContextConnection::WorkerTerminated(serviceWorkerIdentifier), 0);
+}
+
} // namespace WebCore
#endif // ENABLE(SERVICE_WORKER)
Modified: trunk/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.h (224908 => 224909)
--- trunk/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.h 2017-11-16 01:17:02 UTC (rev 224908)
+++ trunk/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.h 2017-11-16 03:05:02 UTC (rev 224909)
@@ -55,6 +55,7 @@
void didFinishInstall(WebCore::ServiceWorkerIdentifier, bool wasSuccessful) final;
void didFinishActivation(WebCore::ServiceWorkerIdentifier) final;
void setServiceWorkerHasPendingEvents(WebCore::ServiceWorkerIdentifier, bool) final;
+ void workerTerminated(WebCore::ServiceWorkerIdentifier) final;
// IPC messages.
void serviceWorkerStartedWithMessage(WebCore::ServiceWorkerIdentifier, const String& exceptionMessage) final;
@@ -63,6 +64,7 @@
void postMessageToServiceWorkerGlobalScope(WebCore::ServiceWorkerIdentifier destinationIdentifier, const IPC::DataReference& message, WebCore::ServiceWorkerClientData&& source);
void fireInstallEvent(WebCore::ServiceWorkerIdentifier);
void fireActivateEvent(WebCore::ServiceWorkerIdentifier);
+ void terminateWorker(WebCore::ServiceWorkerIdentifier);
Ref<IPC::Connection> m_connectionToStorageProcess;
uint64_t m_pageID { 0 };
Modified: trunk/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.messages.in (224908 => 224909)
--- trunk/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.messages.in 2017-11-16 01:17:02 UTC (rev 224908)
+++ trunk/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.messages.in 2017-11-16 03:05:02 UTC (rev 224909)
@@ -28,6 +28,7 @@
PostMessageToServiceWorkerGlobalScope(WebCore::ServiceWorkerIdentifier destinationIdentifier, IPC::DataReference message, struct WebCore::ServiceWorkerClientData source)
FireInstallEvent(WebCore::ServiceWorkerIdentifier identifier)
FireActivateEvent(WebCore::ServiceWorkerIdentifier identifier)
+ TerminateWorker(WebCore::ServiceWorkerIdentifier identifier)
}
#endif