mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 10:18: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:
parent
5608bc4eaf
commit
f733385cc4
4 changed files with 50 additions and 19 deletions
|
@ -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;
|
||||
|
||||
|
|
|
@ -21,10 +21,10 @@ public:
|
|||
const DOM::Document* content_document() const;
|
||||
DOM::Document const* content_document_without_origin_check() const;
|
||||
|
||||
virtual void inserted() override;
|
||||
virtual void removed_from(Node*) override;
|
||||
|
||||
protected:
|
||||
void create_new_nested_browsing_context();
|
||||
void discard_nested_browsing_context();
|
||||
|
||||
RefPtr<BrowsingContext> m_nested_browsing_context;
|
||||
|
||||
private:
|
||||
|
|
|
@ -32,11 +32,28 @@ void HTMLIFrameElement::parse_attribute(const FlyString& name, const String& val
|
|||
load_src(value);
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/iframe-embed-object.html#the-iframe-element:the-iframe-element-6
|
||||
void HTMLIFrameElement::inserted()
|
||||
{
|
||||
BrowsingContextContainer::inserted();
|
||||
if (is_connected())
|
||||
load_src(attribute(HTML::AttributeNames::src));
|
||||
HTMLElement::inserted();
|
||||
|
||||
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)
|
||||
|
|
|
@ -21,6 +21,7 @@ public:
|
|||
|
||||
private:
|
||||
virtual void inserted() override;
|
||||
virtual void removed_from(Node*) override;
|
||||
virtual void parse_attribute(const FlyString& name, const String& value) override;
|
||||
|
||||
void load_src(const String&);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue