mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 05:27:43 +00:00
LibWeb: Implement synchronous session history steps
This commit is contained in:
parent
d6d1485720
commit
4f088aff3d
4 changed files with 117 additions and 26 deletions
|
@ -6,10 +6,19 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <AK/Vector.h>
|
||||
#include <LibCore/Timer.h>
|
||||
#include <LibJS/Heap/GCPtr.h>
|
||||
#include <LibJS/SafeFunction.h>
|
||||
#include <LibWeb/Forward.h>
|
||||
|
||||
namespace Web::HTML {
|
||||
|
||||
struct SessionHistoryTraversalQueueEntry {
|
||||
JS::SafeFunction<void()> steps;
|
||||
JS::GCPtr<HTML::Navigable> target_navigable;
|
||||
};
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/document-sequences.html#tn-session-history-traversal-queue
|
||||
class SessionHistoryTraversalQueue {
|
||||
public:
|
||||
|
@ -17,30 +26,47 @@ public:
|
|||
{
|
||||
m_timer = Core::Timer::create_single_shot(0, [this] {
|
||||
while (m_queue.size() > 0) {
|
||||
auto steps = m_queue.take_first();
|
||||
steps();
|
||||
auto entry = m_queue.take_first();
|
||||
entry.steps();
|
||||
}
|
||||
}).release_value_but_fixme_should_propagate_errors();
|
||||
}
|
||||
|
||||
void append(JS::SafeFunction<void()> steps)
|
||||
{
|
||||
m_queue.append(move(steps));
|
||||
m_queue.append({ move(steps), nullptr });
|
||||
if (!m_timer->is_active()) {
|
||||
m_timer->start();
|
||||
}
|
||||
}
|
||||
|
||||
void append_sync(JS::SafeFunction<void()> steps, JS::GCPtr<Navigable> target_navigable)
|
||||
{
|
||||
m_queue.append({ move(steps), target_navigable });
|
||||
if (!m_timer->is_active()) {
|
||||
m_timer->start();
|
||||
}
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/browsing-the-web.html#sync-navigations-jump-queue
|
||||
SessionHistoryTraversalQueueEntry first_synchronous_navigation_steps_with_target_navigable_not_contained_in(Vector<JS::GCPtr<Navigable>> const& list)
|
||||
{
|
||||
auto index = m_queue.find_first_index_if([&list](auto const& entry) -> bool {
|
||||
return (entry.target_navigable != nullptr) && !list.contains_slow(entry.target_navigable);
|
||||
});
|
||||
return index.has_value() ? m_queue.take(*index) : SessionHistoryTraversalQueueEntry {};
|
||||
}
|
||||
|
||||
void process()
|
||||
{
|
||||
while (m_queue.size() > 0) {
|
||||
auto steps = m_queue.take_first();
|
||||
steps();
|
||||
auto entry = m_queue.take_first();
|
||||
entry.steps();
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
Vector<JS::SafeFunction<void()>> m_queue;
|
||||
Vector<SessionHistoryTraversalQueueEntry> m_queue;
|
||||
RefPtr<Core::Timer> m_timer;
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue