1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 05:38: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;
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();
if (!is_connected())
// 1. Let group be element's node document's browsing context's top-level browsing context's group.
// FIXME: We do not have a concept of "browsing context groups" yet.
auto* group = document().browsing_context();
if (!group)
return;
if (auto* browsing_context = document().browsing_context()) {
VERIFY(browsing_context->page());
m_nested_browsing_context = BrowsingContext::create_nested(*browsing_context->page(), *this);
browsing_context->append_child(*m_nested_browsing_context);
m_nested_browsing_context->set_frame_nesting_levels(browsing_context->frame_nesting_levels());
m_nested_browsing_context->register_frame_nesting(document().url());
}
VERIFY(group->page());
// 2. Let browsingContext be the result of creating a new browsing context with element's node document, element, and group.
// 3. Set element's nested browsing context to browsingContext.
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())
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
@ -55,7 +68,7 @@ const DOM::Document* BrowsingContextContainer::content_document() const
// 3. Let document be context's 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)
return nullptr;