2021-04-03 11:43:08 +02:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2020-2021, Andreas Kling <kling@serenityos.org>
|
2022-02-14 22:03:16 +00:00
|
|
|
* Copyright (c) 2022, Linus Groh <linusg@serenityos.org>
|
2021-04-03 11:43:08 +02:00
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2021-04-03 11:43:08 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <LibWeb/DOM/Document.h>
|
|
|
|
#include <LibWeb/DOM/Event.h>
|
2021-11-18 15:01:28 +01:00
|
|
|
#include <LibWeb/HTML/BrowsingContext.h>
|
2021-05-31 13:59:28 +01:00
|
|
|
#include <LibWeb/HTML/BrowsingContextContainer.h>
|
2021-04-03 11:43:08 +02:00
|
|
|
#include <LibWeb/Origin.h>
|
2021-09-12 02:10:43 +02:00
|
|
|
#include <LibWeb/Page/Page.h>
|
2021-04-03 11:43:08 +02:00
|
|
|
|
|
|
|
namespace Web::HTML {
|
|
|
|
|
2021-05-31 13:59:28 +01:00
|
|
|
BrowsingContextContainer::BrowsingContextContainer(DOM::Document& document, QualifiedName qualified_name)
|
2021-04-03 11:43:08 +02:00
|
|
|
: HTMLElement(document, move(qualified_name))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-05-31 13:59:28 +01:00
|
|
|
BrowsingContextContainer::~BrowsingContextContainer()
|
2021-04-03 11:43:08 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-05-31 13:59:28 +01:00
|
|
|
void BrowsingContextContainer::inserted()
|
2021-04-03 16:45:14 +02:00
|
|
|
{
|
2021-04-06 17:58:20 +01:00
|
|
|
HTMLElement::inserted();
|
2021-04-03 16:45:14 +02:00
|
|
|
if (!is_connected())
|
|
|
|
return;
|
2022-02-06 14:41:29 +01:00
|
|
|
if (auto* browsing_context = document().browsing_context()) {
|
|
|
|
VERIFY(browsing_context->page());
|
|
|
|
m_nested_browsing_context = BrowsingContext::create_nested(*browsing_context->page(), *this);
|
|
|
|
m_nested_browsing_context->set_frame_nesting_levels(browsing_context->frame_nesting_levels());
|
2021-05-30 12:36:53 +02:00
|
|
|
m_nested_browsing_context->register_frame_nesting(document().url());
|
2021-04-19 14:30:08 +02:00
|
|
|
}
|
2021-04-03 16:45:14 +02:00
|
|
|
}
|
|
|
|
|
2022-02-14 22:03:16 +00:00
|
|
|
// https://html.spec.whatwg.org/multipage/browsers.html#concept-bcc-content-document
|
|
|
|
const DOM::Document* BrowsingContextContainer::content_document() const
|
2021-04-03 11:43:08 +02:00
|
|
|
{
|
2022-02-14 22:03:16 +00:00
|
|
|
// 1. If container's nested browsing context is null, then return null.
|
|
|
|
if (m_nested_browsing_context == nullptr)
|
|
|
|
return nullptr;
|
2021-04-03 11:43:08 +02:00
|
|
|
|
2022-02-14 22:03:16 +00:00
|
|
|
// 2. Let context be container's nested browsing context.
|
|
|
|
auto const& context = *m_nested_browsing_context;
|
2021-04-03 11:43:08 +02:00
|
|
|
|
2022-02-14 22:03:16 +00:00
|
|
|
// 3. Let document be context's active document.
|
|
|
|
auto const* document = context.active_document();
|
|
|
|
|
|
|
|
VERIFY(document);
|
|
|
|
VERIFY(m_document);
|
|
|
|
|
|
|
|
// 4. If document's origin and container's node document's origin are not same origin-domain, then return null.
|
|
|
|
if (!document->origin().is_same_origin_domain(m_document->origin()))
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
// 5. Return document.
|
|
|
|
return document;
|
2021-04-03 11:43:08 +02:00
|
|
|
}
|
|
|
|
|
2022-02-16 22:51:25 +00:00
|
|
|
DOM::Document const* BrowsingContextContainer::content_document_without_origin_check() const
|
|
|
|
{
|
|
|
|
if (!m_nested_browsing_context)
|
|
|
|
return nullptr;
|
|
|
|
return m_nested_browsing_context->active_document();
|
|
|
|
}
|
|
|
|
|
2021-04-03 11:43:08 +02:00
|
|
|
}
|