summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2021-04-03 16:45:14 +0200
committerAndreas Kling <kling@serenityos.org>2021-04-03 16:54:33 +0200
commit5c67b2cb8fed0a98aa9781d1a272ff890409ff43 (patch)
treee9bf0f772a9db60b2f33e4442d6eacf569659313
parent57ead17d54b73cbb0b113ad2980f71fd77637601 (diff)
downloadserenity-5c67b2cb8fed0a98aa9781d1a272ff890409ff43.zip
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.
-rw-r--r--Userland/Libraries/LibWeb/HTML/FrameHostElement.cpp9
-rw-r--r--Userland/Libraries/LibWeb/HTML/FrameHostElement.h2
-rw-r--r--Userland/Libraries/LibWeb/HTML/HTMLIFrameElement.cpp12
-rw-r--r--Userland/Libraries/LibWeb/HTML/HTMLIFrameElement.h1
4 files changed, 22 insertions, 2 deletions
diff --git a/Userland/Libraries/LibWeb/HTML/FrameHostElement.cpp b/Userland/Libraries/LibWeb/HTML/FrameHostElement.cpp
index b4d8a55c17..8215fbd61b 100644
--- a/Userland/Libraries/LibWeb/HTML/FrameHostElement.cpp
+++ b/Userland/Libraries/LibWeb/HTML/FrameHostElement.cpp
@@ -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())
diff --git a/Userland/Libraries/LibWeb/HTML/FrameHostElement.h b/Userland/Libraries/LibWeb/HTML/FrameHostElement.h
index 24b6675563..f23868fb5d 100644
--- a/Userland/Libraries/LibWeb/HTML/FrameHostElement.h
+++ b/Userland/Libraries/LibWeb/HTML/FrameHostElement.h
@@ -45,6 +45,8 @@ public:
void content_frame_did_load(Badge<FrameLoader>);
+ virtual void inserted_into(Node&) override;
+
protected:
RefPtr<Frame> m_content_frame;
};
diff --git a/Userland/Libraries/LibWeb/HTML/HTMLIFrameElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLIFrameElement.cpp
index c183fa6074..7d8cce2ef6 100644
--- a/Userland/Libraries/LibWeb/HTML/HTMLIFrameElement.cpp
+++ b/Userland/Libraries/LibWeb/HTML/HTMLIFrameElement.cpp
@@ -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);
diff --git a/Userland/Libraries/LibWeb/HTML/HTMLIFrameElement.h b/Userland/Libraries/LibWeb/HTML/HTMLIFrameElement.h
index 1039c7d0ed..75e6b424bc 100644
--- a/Userland/Libraries/LibWeb/HTML/HTMLIFrameElement.h
+++ b/Userland/Libraries/LibWeb/HTML/HTMLIFrameElement.h
@@ -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&);