mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-01 05:39:11 +00:00
LibWeb: Add a DocumentObserver hook to be notified of readyState changes
This commit is contained in:
parent
44b1c4f2b5
commit
0bbe836f8c
Notes:
github-actions[bot]
2024-10-26 09:27:09 +00:00
Author: https://github.com/trflynn89
Commit: 0bbe836f8c
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1967
3 changed files with 18 additions and 2 deletions
|
@ -2392,6 +2392,11 @@ void Document::update_readiness(HTML::DocumentReadyState readiness_value)
|
||||||
m_needs_to_call_page_did_load = true;
|
m_needs_to_call_page_did_load = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (auto document_observer : m_document_observers) {
|
||||||
|
if (document_observer->document_readiness_observer())
|
||||||
|
document_observer->document_readiness_observer()->function()(m_readiness);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/dom.html#dom-document-lastmodified
|
// https://html.spec.whatwg.org/multipage/dom.html#dom-document-lastmodified
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2023, Tim Flynn <trflynn89@serenityos.org>
|
* Copyright (c) 2023-2024, Tim Flynn <trflynn89@ladybird.org>
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
@ -25,6 +25,7 @@ void DocumentObserver::visit_edges(Cell::Visitor& visitor)
|
||||||
visitor.visit(m_document);
|
visitor.visit(m_document);
|
||||||
visitor.visit(m_document_became_inactive);
|
visitor.visit(m_document_became_inactive);
|
||||||
visitor.visit(m_document_completely_loaded);
|
visitor.visit(m_document_completely_loaded);
|
||||||
|
visitor.visit(m_document_readiness_observer);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DocumentObserver::finalize()
|
void DocumentObserver::finalize()
|
||||||
|
@ -43,4 +44,9 @@ void DocumentObserver::set_document_completely_loaded(Function<void()> callback)
|
||||||
m_document_completely_loaded = JS::create_heap_function(vm().heap(), move(callback));
|
m_document_completely_loaded = JS::create_heap_function(vm().heap(), move(callback));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DocumentObserver::set_document_readiness_observer(Function<void(HTML::DocumentReadyState)> callback)
|
||||||
|
{
|
||||||
|
m_document_readiness_observer = JS::create_heap_function(vm().heap(), move(callback));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2023, Tim Flynn <trflynn89@serenityos.org>
|
* Copyright (c) 2023-2024, Tim Flynn <trflynn89@ladybird.org>
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
@ -11,6 +11,7 @@
|
||||||
#include <LibJS/SafeFunction.h>
|
#include <LibJS/SafeFunction.h>
|
||||||
#include <LibWeb/Bindings/PlatformObject.h>
|
#include <LibWeb/Bindings/PlatformObject.h>
|
||||||
#include <LibWeb/Forward.h>
|
#include <LibWeb/Forward.h>
|
||||||
|
#include <LibWeb/HTML/DocumentReadyState.h>
|
||||||
|
|
||||||
namespace Web::DOM {
|
namespace Web::DOM {
|
||||||
|
|
||||||
|
@ -25,6 +26,9 @@ public:
|
||||||
[[nodiscard]] JS::GCPtr<JS::HeapFunction<void()>> document_completely_loaded() const { return m_document_completely_loaded; }
|
[[nodiscard]] JS::GCPtr<JS::HeapFunction<void()>> document_completely_loaded() const { return m_document_completely_loaded; }
|
||||||
void set_document_completely_loaded(Function<void()>);
|
void set_document_completely_loaded(Function<void()>);
|
||||||
|
|
||||||
|
[[nodiscard]] JS::GCPtr<JS::HeapFunction<void(HTML::DocumentReadyState)>> document_readiness_observer() const { return m_document_readiness_observer; }
|
||||||
|
void set_document_readiness_observer(Function<void(HTML::DocumentReadyState)>);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
explicit DocumentObserver(JS::Realm&, DOM::Document&);
|
explicit DocumentObserver(JS::Realm&, DOM::Document&);
|
||||||
|
|
||||||
|
@ -34,6 +38,7 @@ private:
|
||||||
JS::NonnullGCPtr<DOM::Document> m_document;
|
JS::NonnullGCPtr<DOM::Document> m_document;
|
||||||
JS::GCPtr<JS::HeapFunction<void()>> m_document_became_inactive;
|
JS::GCPtr<JS::HeapFunction<void()>> m_document_became_inactive;
|
||||||
JS::GCPtr<JS::HeapFunction<void()>> m_document_completely_loaded;
|
JS::GCPtr<JS::HeapFunction<void()>> m_document_completely_loaded;
|
||||||
|
JS::GCPtr<JS::HeapFunction<void(HTML::DocumentReadyState)>> m_document_readiness_observer;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue