2021-04-03 06:43:08 -03:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2020-2021, Andreas Kling <kling@serenityos.org>
|
|
|
|
|
*
|
2021-04-22 05:24:48 -03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2021-04-03 06:43:08 -03:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <LibWeb/DOM/Document.h>
|
|
|
|
|
#include <LibWeb/DOM/Event.h>
|
2021-11-18 11:01:28 -03:00
|
|
|
#include <LibWeb/HTML/BrowsingContext.h>
|
2021-05-31 09:59:28 -03:00
|
|
|
#include <LibWeb/HTML/BrowsingContextContainer.h>
|
2021-04-03 06:43:08 -03:00
|
|
|
#include <LibWeb/Origin.h>
|
2021-09-11 21:10:43 -03:00
|
|
|
#include <LibWeb/Page/Page.h>
|
2021-04-03 06:43:08 -03:00
|
|
|
|
|
|
|
|
namespace Web::HTML {
|
|
|
|
|
|
2021-05-31 09:59:28 -03:00
|
|
|
BrowsingContextContainer::BrowsingContextContainer(DOM::Document& document, QualifiedName qualified_name)
|
2021-04-03 06:43:08 -03:00
|
|
|
: HTMLElement(document, move(qualified_name))
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-31 09:59:28 -03:00
|
|
|
BrowsingContextContainer::~BrowsingContextContainer()
|
2021-04-03 06:43:08 -03:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-31 09:59:28 -03:00
|
|
|
void BrowsingContextContainer::inserted()
|
2021-04-03 11:45:14 -03:00
|
|
|
{
|
2021-04-06 13:58:20 -03:00
|
|
|
HTMLElement::inserted();
|
2021-04-03 11:45:14 -03:00
|
|
|
if (!is_connected())
|
|
|
|
|
return;
|
2021-05-30 07:36:53 -03:00
|
|
|
if (auto* frame = document().browsing_context()) {
|
2021-09-09 20:51:09 -03:00
|
|
|
VERIFY(frame->page());
|
|
|
|
|
m_nested_browsing_context = BrowsingContext::create_nested(*frame->page(), *this);
|
2021-05-30 07:36:53 -03:00
|
|
|
m_nested_browsing_context->set_frame_nesting_levels(frame->frame_nesting_levels());
|
|
|
|
|
m_nested_browsing_context->register_frame_nesting(document().url());
|
2021-04-19 09:30:08 -03:00
|
|
|
}
|
2021-04-03 11:45:14 -03:00
|
|
|
}
|
|
|
|
|
|
2021-05-31 09:59:28 -03:00
|
|
|
Origin BrowsingContextContainer::content_origin() const
|
2021-04-03 06:43:08 -03:00
|
|
|
{
|
2021-09-09 08:14:32 -03:00
|
|
|
if (!m_nested_browsing_context || !m_nested_browsing_context->active_document())
|
2021-04-03 06:43:08 -03:00
|
|
|
return {};
|
2021-09-09 08:14:32 -03:00
|
|
|
return m_nested_browsing_context->active_document()->origin();
|
2021-04-03 06:43:08 -03:00
|
|
|
}
|
|
|
|
|
|
2021-05-31 09:59:28 -03:00
|
|
|
bool BrowsingContextContainer::may_access_from_origin(const Origin& origin) const
|
2021-04-03 06:43:08 -03:00
|
|
|
{
|
2021-09-11 21:10:43 -03:00
|
|
|
if (auto* page = document().page()) {
|
|
|
|
|
if (!page->is_same_origin_policy_enabled())
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2021-04-03 06:43:08 -03:00
|
|
|
return origin.is_same(content_origin());
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-31 09:59:28 -03:00
|
|
|
const DOM::Document* BrowsingContextContainer::content_document() const
|
2021-04-03 06:43:08 -03:00
|
|
|
{
|
2021-09-09 08:14:32 -03:00
|
|
|
return m_nested_browsing_context ? m_nested_browsing_context->active_document() : nullptr;
|
2021-04-03 06:43:08 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|