1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 07:58:11 +00:00

LibWeb: Defer creation of subframes until host element is connected

This allows parsing of document fragments with "<iframe>" to construct
the iframe element without requiring that the fragment have a frame.
This commit is contained in:
Andreas Kling 2021-04-03 16:45:14 +02:00
parent 57ead17d54
commit 5c67b2cb8f
4 changed files with 22 additions and 2 deletions

View file

@ -41,6 +41,15 @@ FrameHostElement::~FrameHostElement()
{
}
void FrameHostElement::inserted_into(Node& parent)
{
HTMLElement::inserted_into(parent);
if (!is_connected())
return;
if (auto* frame = document().frame())
m_content_frame = Frame::create_subframe(*this, frame->main_frame());
}
Origin FrameHostElement::content_origin() const
{
if (!m_content_frame || !m_content_frame->document())

View file

@ -45,6 +45,8 @@ public:
void content_frame_did_load(Badge<FrameLoader>);
virtual void inserted_into(Node&) override;
protected:
RefPtr<Frame> m_content_frame;
};

View file

@ -35,8 +35,6 @@ namespace Web::HTML {
HTMLIFrameElement::HTMLIFrameElement(DOM::Document& document, QualifiedName qualified_name)
: FrameHostElement(document, move(qualified_name))
{
VERIFY(document.frame());
m_content_frame = Frame::create_subframe(*this, document.frame()->main_frame());
}
HTMLIFrameElement::~HTMLIFrameElement()
@ -56,8 +54,18 @@ void HTMLIFrameElement::parse_attribute(const FlyString& name, const String& val
load_src(value);
}
void HTMLIFrameElement::inserted_into(Node& parent)
{
FrameHostElement::inserted_into(parent);
if (is_connected())
load_src(attribute(HTML::AttributeNames::src));
}
void HTMLIFrameElement::load_src(const String& value)
{
if (!m_content_frame)
return;
auto url = document().complete_url(value);
if (!url.is_valid()) {
dbgln("iframe failed to load URL: Invalid URL: {}", value);

View file

@ -40,6 +40,7 @@ public:
virtual RefPtr<Layout::Node> create_layout_node() override;
private:
virtual void inserted_into(Node&) override;
virtual void parse_attribute(const FlyString& name, const String& value) override;
void load_src(const String&);