ladybird/Libraries/LibWeb/HTML/NavigableContainer.h
Aliaksandr Kalenik 2a69fd4c52 LibWeb: Replace spin_until in apply_the_history_step with state machine
Replace the blocking spin_processing_tasks_with_source_until calls
in apply_the_history_step_after_unload_check() with an event-driven
ApplyHistoryStepState GC cell that tracks 5 phases, following the
same pattern used by CheckUnloadingCanceledState.

Key changes:
- Introduce ApplyHistoryStepState with phases:
  WaitingForDocumentPopulation, ProcessingContinuations,
  WaitingForChangeJobCompletion, WaitingForNonChangingJobs and Completed
- Add on_complete callbacks to apply_the_push_or_replace_history_step,
  finalize_a_same_document_navigation,
  finalize_a_cross_document_navigation, and
  update_for_navigable_creation_or_destruction
- Remove spin_until from Document::open()
- Use null-document tasks for non-changing navigable updates and
  document unload/destroy to avoid stuck tasks when documents become
  non-fully-active
- Defer completely_finish_loading when document has no navigable yet,
  and re-trigger post-load steps in activate_history_entry for documents
  that completed loading before activation

Co-Authored-By: Shannon Booth <shannon@serenityos.org>
2026-03-31 09:47:59 +02:00

81 lines
2.7 KiB
C++

/*
* Copyright (c) 2020-2021, Andreas Kling <andreas@ladybird.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <LibWeb/Export.h>
#include <LibWeb/HTML/HTMLElement.h>
#include <LibWeb/HTML/InitialInsertion.h>
namespace Web::HTML {
class WEB_API NavigableContainer : public HTMLElement {
WEB_NON_IDL_PLATFORM_OBJECT(NavigableContainer, HTMLElement);
public:
static constexpr bool OVERRIDES_FINALIZE = true;
static GC::Ptr<NavigableContainer> navigable_container_with_content_navigable(GC::Ref<Navigable> navigable);
virtual ~NavigableContainer() override;
static HashTable<NavigableContainer*>& all_instances();
GC::Ptr<Navigable> content_navigable() { return m_content_navigable; }
GC::Ptr<Navigable const> content_navigable() const { return m_content_navigable.ptr(); }
DOM::Document const* content_document() const;
DOM::Document const* content_document_without_origin_check() const;
HTML::WindowProxy* content_window();
DOM::Document const* get_svg_document() const;
void destroy_the_child_navigable();
// All elements that extend NavigableContainer "potentially delay the load event".
// (embed, frame, iframe, and object)
// https://html.spec.whatwg.org/multipage/iframe-embed-object.html#potentially-delays-the-load-event
bool currently_delays_the_load_event() const;
bool content_navigable_has_session_history_entry_and_ready_for_navigation() const;
protected:
NavigableContainer(DOM::Document&, DOM::QualifiedName);
virtual void visit_edges(Cell::Visitor&) override;
// https://html.spec.whatwg.org/multipage/iframe-embed-object.html#shared-attribute-processing-steps-for-iframe-and-frame-elements
Optional<URL::URL> shared_attribute_processing_steps_for_iframe_and_frame(InitialInsertion initial_insertion);
// https://html.spec.whatwg.org/multipage/iframe-embed-object.html#navigate-an-iframe-or-frame
void navigate_an_iframe_or_frame(URL::URL url, ReferrerPolicy::ReferrerPolicy referrer_policy, Optional<String> srcdoc_string = {}, InitialInsertion = InitialInsertion::No);
WebIDL::ExceptionOr<void> create_new_child_navigable();
// https://html.spec.whatwg.org/multipage/document-sequences.html#content-navigable
GC::Ptr<Navigable> m_content_navigable { nullptr };
void set_potentially_delays_the_load_event(bool value);
void set_content_navigable_has_session_history_entry_and_ready_for_navigation();
private:
virtual bool is_navigable_container() const override { return true; }
virtual void finalize() override;
bool m_potentially_delays_the_load_event { true };
};
}
namespace Web::DOM {
template<>
inline bool Node::fast_is<HTML::NavigableContainer>() const { return is_navigable_container(); }
}