mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-05-01 03:57:15 +02:00
LibWeb: Add a NavigationObserver to be notified of navigable updates
This contains a hook to be notified when a navigable navigation is complete, to be used by WebDriver.
This commit is contained in:
committed by
Andreas Kling
parent
247307a2a2
commit
74ef9dc393
Notes:
github-actions[bot]
2024-10-26 09:26:57 +00:00
Author: https://github.com/trflynn89 Commit: https://github.com/LadybirdBrowser/ladybird/commit/74ef9dc3936 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1967
43
Userland/Libraries/LibWeb/HTML/NavigationObserver.cpp
Normal file
43
Userland/Libraries/LibWeb/HTML/NavigationObserver.cpp
Normal file
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright (c) 2024, Tim Flynn <trflynn89@ladybird.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibJS/Runtime/Realm.h>
|
||||
#include <LibWeb/HTML/Navigable.h>
|
||||
#include <LibWeb/HTML/NavigationObserver.h>
|
||||
|
||||
namespace Web::HTML {
|
||||
|
||||
JS_DEFINE_ALLOCATOR(NavigationObserver);
|
||||
|
||||
NavigationObserver::NavigationObserver(JS::Realm& realm, Navigable& navigable)
|
||||
: Bindings::PlatformObject(realm)
|
||||
, m_navigable(navigable)
|
||||
{
|
||||
m_navigable->register_navigation_observer({}, *this);
|
||||
}
|
||||
|
||||
void NavigationObserver::visit_edges(Cell::Visitor& visitor)
|
||||
{
|
||||
Base::visit_edges(visitor);
|
||||
visitor.visit(m_navigable);
|
||||
visitor.visit(m_navigation_complete);
|
||||
}
|
||||
|
||||
void NavigationObserver::finalize()
|
||||
{
|
||||
Base::finalize();
|
||||
m_navigable->unregister_navigation_observer({}, *this);
|
||||
}
|
||||
|
||||
void NavigationObserver::set_navigation_complete(Function<void()> callback)
|
||||
{
|
||||
if (callback)
|
||||
m_navigation_complete = JS::create_heap_function(vm().heap(), move(callback));
|
||||
else
|
||||
m_navigation_complete = nullptr;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user