LibWeb: Allow removing DocumentObserver hooks

Some callers (namely WebDriver) will want to stop receiving updates from
the DocumentObserver.
This commit is contained in:
Timothy Flynn 2024-10-25 10:22:27 -04:00 committed by Andreas Kling
parent 0bbe836f8c
commit 247307a2a2
Notes: github-actions[bot] 2024-10-26 09:27:04 +00:00

View file

@ -36,17 +36,26 @@ void DocumentObserver::finalize()
void DocumentObserver::set_document_became_inactive(Function<void()> callback)
{
m_document_became_inactive = JS::create_heap_function(vm().heap(), move(callback));
if (callback)
m_document_became_inactive = JS::create_heap_function(vm().heap(), move(callback));
else
m_document_became_inactive = nullptr;
}
void DocumentObserver::set_document_completely_loaded(Function<void()> callback)
{
m_document_completely_loaded = JS::create_heap_function(vm().heap(), move(callback));
if (callback)
m_document_completely_loaded = JS::create_heap_function(vm().heap(), move(callback));
else
m_document_completely_loaded = nullptr;
}
void DocumentObserver::set_document_readiness_observer(Function<void(HTML::DocumentReadyState)> callback)
{
m_document_readiness_observer = JS::create_heap_function(vm().heap(), move(callback));
if (callback)
m_document_readiness_observer = JS::create_heap_function(vm().heap(), move(callback));
else
m_document_readiness_observer = nullptr;
}
}