ladybird/Userland/Libraries/LibWeb/HTML/NavigableContainer.h
Aliaksandr Kalenik 11011cf250 LibWeb: Don't rely on SHTQ::process() in process_the_iframe_attributes
`HTMLIFrameElement::inserted()` does following:
1. Init a new navigable. This step appends a task on session history
   traversal queue (SHTQ) that creates a new nested history.
2. Process iframe's attributes

Processing of iframe's attributes might result in synchronous
navigation that fails to get active SHE if SHTQ task that creates
new nested history is not yet completed.

Before this change, a workaround involved forcing the processing of
SHTQ, which was terrible hack because it could occur in the middle of
another SHTQ task.

This change removes the need for "force SHTQ processing" by ensuring
that the processing of iframe's attributes is always executed after
the iframe's navigable nested history has been created.
2024-04-05 21:28:41 +02:00

85 lines
3 KiB
C++

/*
* Copyright (c) 2020-2021, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <LibWeb/HTML/HTMLElement.h>
#include <LibWeb/HTML/Navigable.h>
namespace Web::HTML {
class NavigableContainer : public HTMLElement {
WEB_PLATFORM_OBJECT(NavigableContainer, HTMLElement);
public:
static JS::GCPtr<NavigableContainer> navigable_container_with_content_navigable(JS::NonnullGCPtr<Navigable> navigable);
virtual ~NavigableContainer() override;
static HashTable<NavigableContainer*>& all_instances();
JS::GCPtr<Navigable> content_navigable() { return m_content_navigable; }
JS::GCPtr<Navigable const> content_navigable() const { return m_content_navigable.ptr(); }
BrowsingContext* nested_browsing_context()
{
if (m_content_navigable)
return m_content_navigable->active_browsing_context();
return nullptr;
}
BrowsingContext const* nested_browsing_context() const
{
if (m_content_navigable)
return m_content_navigable->active_browsing_context();
return nullptr;
}
const DOM::Document* 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;
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(bool 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 = {});
WebIDL::ExceptionOr<void> create_new_child_navigable(JS::SafeFunction<void()> afterSessionHistoryUpdate = {});
// https://html.spec.whatwg.org/multipage/document-sequences.html#content-navigable
JS::GCPtr<Navigable> m_content_navigable { nullptr };
void set_potentially_delays_the_load_event(bool value) { m_potentially_delays_the_load_event = value; }
void set_content_navigable_initialized() { m_content_navigable_initialized = true; }
private:
virtual bool is_navigable_container() const override { return true; }
bool m_potentially_delays_the_load_event { true };
bool m_content_navigable_initialized { false };
};
}
namespace Web::DOM {
template<>
inline bool Node::fast_is<HTML::NavigableContainer>() const { return is_navigable_container(); }
}