LibWeb: Split out SimilarOriginWindowAgent from HTML::Agent

To allow for adding the concept of a WorkerAgent to be reused
between shared and dedicated workers. An event loop is the
commonality between the different agent types, though, there
are some differences between those event loops which we customize
on the construction of the HTML::EventLoop.
This commit is contained in:
Shannon Booth 2025-04-24 15:04:13 +12:00 committed by Andreas Kling
commit 084cceab5c
Notes: github-actions[bot] 2025-04-25 14:45:55 +00:00
11 changed files with 103 additions and 54 deletions

View file

@ -63,7 +63,7 @@
#include <LibWeb/HTML/HTMLUListElement.h>
#include <LibWeb/HTML/Numbers.h>
#include <LibWeb/HTML/Parser/HTMLParser.h>
#include <LibWeb/HTML/Scripting/Agent.h>
#include <LibWeb/HTML/Scripting/SimilarOriginWindowAgent.h>
#include <LibWeb/HTML/Scripting/TemporaryExecutionContext.h>
#include <LibWeb/HTML/TraversableNavigable.h>
#include <LibWeb/HTML/Window.h>
@ -2487,7 +2487,7 @@ bool Element::include_in_accessibility_tree() const
void Element::enqueue_an_element_on_the_appropriate_element_queue()
{
// 1. Let reactionsStack be element's relevant agent's custom element reactions stack.
auto& relevant_agent = HTML::relevant_agent(*this);
auto& relevant_agent = HTML::relevant_similar_origin_window_agent(*this);
auto& reactions_stack = relevant_agent.custom_element_reactions_stack;
// 2. If reactionsStack is empty, then:
@ -2505,7 +2505,7 @@ void Element::enqueue_an_element_on_the_appropriate_element_queue()
// 4. Queue a microtask to perform the following steps:
// NOTE: `this` is protected by GC::Function
HTML::queue_a_microtask(&document(), GC::create_function(heap(), [this]() {
auto& reactions_stack = HTML::relevant_agent(*this).custom_element_reactions_stack;
auto& reactions_stack = HTML::relevant_similar_origin_window_agent(*this).custom_element_reactions_stack;
// 1. Invoke custom element reactions in reactionsStack's backup element queue.
Bindings::invoke_custom_element_reactions(reactions_stack.backup_element_queue);

View file

@ -9,7 +9,7 @@
#include <LibWeb/Bindings/MutationObserverPrototype.h>
#include <LibWeb/DOM/MutationObserver.h>
#include <LibWeb/DOM/Node.h>
#include <LibWeb/HTML/Scripting/Agent.h>
#include <LibWeb/HTML/Scripting/SimilarOriginWindowAgent.h>
namespace Web::DOM {
@ -30,7 +30,7 @@ MutationObserver::MutationObserver(JS::Realm& realm, GC::Ptr<WebIDL::CallbackTyp
// 1. Set thiss callback to callback.
// 2. Append this to thiss relevant agents mutation observers.
HTML::relevant_agent(*this).mutation_observers.append(*this);
HTML::relevant_similar_origin_window_agent(*this).mutation_observers.append(*this);
}
MutationObserver::~MutationObserver()
@ -39,7 +39,7 @@ MutationObserver::~MutationObserver()
void MutationObserver::finalize()
{
HTML::relevant_agent(*this).mutation_observers.remove(*this);
HTML::relevant_similar_origin_window_agent(*this).mutation_observers.remove(*this);
}
void MutationObserver::initialize(JS::Realm& realm)

View file

@ -11,6 +11,7 @@
#include <LibWeb/DOM/Slottable.h>
#include <LibWeb/DOM/Text.h>
#include <LibWeb/HTML/HTMLSlotElement.h>
#include <LibWeb/HTML/Scripting/SimilarOriginWindowAgent.h>
namespace Web::DOM {
@ -207,7 +208,7 @@ void assign_a_slot(Slottable const& slottable)
void signal_a_slot_change(GC::Ref<HTML::HTMLSlotElement> slottable)
{
// 1. Append slot to slots relevant agents signal slots.
HTML::relevant_agent(slottable).signal_slots.append(slottable);
HTML::relevant_similar_origin_window_agent(slottable).signal_slots.append(slottable);
// 2. Queue a mutation observer microtask.
Bindings::queue_mutation_observer_microtask(slottable->document());