summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimothy Flynn <trflynn89@pm.me>2022-11-15 15:27:58 -0500
committerLinus Groh <mail@linusgroh.de>2022-11-16 17:23:56 +0000
commit4b8729aea63b8f426d2728ae22a106894d62b775 (patch)
tree6e8145d577914ad3aa08433e66899481fe7b498c
parent894bddf62cc8da242017750f0f4690e9b461bc03 (diff)
downloadserenity-4b8729aea63b8f426d2728ae22a106894d62b775.zip
LibWeb: Add a flag to pause an HTML event loop's execution
This will be used to unblock the WebContent IPC event loop while waiting for a dialog response.
-rw-r--r--Userland/Libraries/LibWeb/HTML/EventLoop/EventLoop.h6
-rw-r--r--Userland/Libraries/LibWeb/HTML/EventLoop/TaskQueue.cpp6
2 files changed, 12 insertions, 0 deletions
diff --git a/Userland/Libraries/LibWeb/HTML/EventLoop/EventLoop.h b/Userland/Libraries/LibWeb/HTML/EventLoop/EventLoop.h
index e77f0e066e..3827297abe 100644
--- a/Userland/Libraries/LibWeb/HTML/EventLoop/EventLoop.h
+++ b/Userland/Libraries/LibWeb/HTML/EventLoop/EventLoop.h
@@ -73,6 +73,10 @@ public:
double compute_deadline() const;
+ // https://html.spec.whatwg.org/multipage/webappapis.html#pause
+ void set_execution_paused(bool execution_paused) { m_execution_paused = execution_paused; }
+ bool execution_paused() const { return m_execution_paused; }
+
private:
Type m_type { Type::Window };
@@ -104,6 +108,8 @@ private:
// https://html.spec.whatwg.org/multipage/browsing-the-web.html#termination-nesting-level
size_t m_termination_nesting_level { 0 };
+
+ bool m_execution_paused { false };
};
EventLoop& main_thread_event_loop();
diff --git a/Userland/Libraries/LibWeb/HTML/EventLoop/TaskQueue.cpp b/Userland/Libraries/LibWeb/HTML/EventLoop/TaskQueue.cpp
index 1431b73952..a8c8a51905 100644
--- a/Userland/Libraries/LibWeb/HTML/EventLoop/TaskQueue.cpp
+++ b/Userland/Libraries/LibWeb/HTML/EventLoop/TaskQueue.cpp
@@ -24,6 +24,9 @@ void TaskQueue::add(NonnullOwnPtr<Task> task)
OwnPtr<Task> TaskQueue::take_first_runnable()
{
+ if (m_event_loop.execution_paused())
+ return nullptr;
+
for (size_t i = 0; i < m_tasks.size(); ++i) {
if (m_tasks[i]->is_runnable())
return m_tasks.take(i);
@@ -33,6 +36,9 @@ OwnPtr<Task> TaskQueue::take_first_runnable()
bool TaskQueue::has_runnable_tasks() const
{
+ if (m_event_loop.execution_paused())
+ return false;
+
for (auto& task : m_tasks) {
if (task->is_runnable())
return true;