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

LibWeb: Move automatic browsing context creation to HTMLIFrameElement

We will soon have two DOM nodes which contain nested browsing contexts:
HTMLIFrameElement and HTMLObjectElement. Only HTMLIFrameElement should
have its nested context created automatically upon insertion, so move
the invocation of that logic to HTMLIFrameElement.
This commit is contained in:
Timothy Flynn 2022-03-23 20:13:34 -04:00 committed by Andreas Kling
parent 5608bc4eaf
commit f733385cc4
4 changed files with 50 additions and 19 deletions

View file

@ -21,25 +21,38 @@ BrowsingContextContainer::BrowsingContextContainer(DOM::Document& document, DOM:
BrowsingContextContainer::~BrowsingContextContainer() = default; BrowsingContextContainer::~BrowsingContextContainer() = default;
void BrowsingContextContainer::inserted() // https://html.spec.whatwg.org/multipage/browsers.html#creating-a-new-nested-browsing-context
void BrowsingContextContainer::create_new_nested_browsing_context()
{ {
HTMLElement::inserted(); // 1. Let group be element's node document's browsing context's top-level browsing context's group.
if (!is_connected()) // FIXME: We do not have a concept of "browsing context groups" yet.
auto* group = document().browsing_context();
if (!group)
return; return;
if (auto* browsing_context = document().browsing_context()) {
VERIFY(browsing_context->page()); VERIFY(group->page());
m_nested_browsing_context = BrowsingContext::create_nested(*browsing_context->page(), *this);
browsing_context->append_child(*m_nested_browsing_context); // 2. Let browsingContext be the result of creating a new browsing context with element's node document, element, and group.
m_nested_browsing_context->set_frame_nesting_levels(browsing_context->frame_nesting_levels()); // 3. Set element's nested browsing context to browsingContext.
m_nested_browsing_context->register_frame_nesting(document().url()); m_nested_browsing_context = BrowsingContext::create_nested(*group->page(), *this);
} group->append_child(*m_nested_browsing_context);
m_nested_browsing_context->set_frame_nesting_levels(group->frame_nesting_levels());
m_nested_browsing_context->register_frame_nesting(document().url());
// 4. If element has a name attribute, then set browsingContext's name to the value of this attribute.
if (auto name = attribute(HTML::AttributeNames::name); !name.is_empty())
m_nested_browsing_context->set_name(name);
} }
void BrowsingContextContainer::removed_from(Node* old_parent) // https://html.spec.whatwg.org/multipage/window-object.html#a-browsing-context-is-discarded
void BrowsingContextContainer::discard_nested_browsing_context()
{ {
HTMLElement::removed_from(old_parent); // 1. Discard all Document objects for all the entries in browsingContext's session history.
if (m_nested_browsing_context && m_nested_browsing_context->parent()) if (m_nested_browsing_context && m_nested_browsing_context->parent())
m_nested_browsing_context->parent()->remove_child(*m_nested_browsing_context); m_nested_browsing_context->parent()->remove_child(*m_nested_browsing_context);
// 2. If browsingContext is a top-level browsing context, then remove browsingContext.
// NOTE: We skip this here because this is by definition a nested browsing context, not top-level.
} }
// https://html.spec.whatwg.org/multipage/browsers.html#concept-bcc-content-document // https://html.spec.whatwg.org/multipage/browsers.html#concept-bcc-content-document
@ -55,7 +68,7 @@ const DOM::Document* BrowsingContextContainer::content_document() const
// 3. Let document be context's active document. // 3. Let document be context's active document.
auto const* document = context.active_document(); auto const* document = context.active_document();
//FIXME: This should not be here, as we're expected to have a document at this point. // FIXME: This should not be here, as we're expected to have a document at this point.
if (!document) if (!document)
return nullptr; return nullptr;

View file

@ -21,10 +21,10 @@ public:
const DOM::Document* content_document() const; const DOM::Document* content_document() const;
DOM::Document const* content_document_without_origin_check() const; DOM::Document const* content_document_without_origin_check() const;
virtual void inserted() override;
virtual void removed_from(Node*) override;
protected: protected:
void create_new_nested_browsing_context();
void discard_nested_browsing_context();
RefPtr<BrowsingContext> m_nested_browsing_context; RefPtr<BrowsingContext> m_nested_browsing_context;
private: private:

View file

@ -32,11 +32,28 @@ void HTMLIFrameElement::parse_attribute(const FlyString& name, const String& val
load_src(value); load_src(value);
} }
// https://html.spec.whatwg.org/multipage/iframe-embed-object.html#the-iframe-element:the-iframe-element-6
void HTMLIFrameElement::inserted() void HTMLIFrameElement::inserted()
{ {
BrowsingContextContainer::inserted(); HTMLElement::inserted();
if (is_connected())
load_src(attribute(HTML::AttributeNames::src)); if (!is_connected())
return;
// 1. Create a new nested browsing context for element.
create_new_nested_browsing_context();
// 2. FIXME: If element has a sandbox attribute, then parse the sandboxing directive given the attribute's value and element's iframe sandboxing flag set.
// 3. Process the iframe attributes for element, with initialInsertion set to true.
load_src(attribute(HTML::AttributeNames::src));
}
// https://html.spec.whatwg.org/multipage/iframe-embed-object.html#the-iframe-element:the-iframe-element-7
void HTMLIFrameElement::removed_from(DOM::Node* node)
{
HTMLElement::removed_from(node);
discard_nested_browsing_context();
} }
void HTMLIFrameElement::load_src(const String& value) void HTMLIFrameElement::load_src(const String& value)

View file

@ -21,6 +21,7 @@ public:
private: private:
virtual void inserted() override; virtual void inserted() override;
virtual void removed_from(Node*) override;
virtual void parse_attribute(const FlyString& name, const String& value) override; virtual void parse_attribute(const FlyString& name, const String& value) override;
void load_src(const String&); void load_src(const String&);