2022-09-19 12:28:46 +02:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
2022-10-17 11:06:50 +02:00
|
|
|
#include <LibWeb/Bindings/MainThreadVM.h>
|
2022-09-19 12:28:46 +02:00
|
|
|
#include <LibWeb/HTML/BrowsingContext.h>
|
|
|
|
#include <LibWeb/HTML/BrowsingContextGroup.h>
|
2023-09-19 19:16:50 +02:00
|
|
|
#include <LibWeb/Page/Page.h>
|
2022-09-19 12:28:46 +02:00
|
|
|
|
|
|
|
namespace Web::HTML {
|
|
|
|
|
2023-11-19 19:47:52 +01:00
|
|
|
JS_DEFINE_ALLOCATOR(BrowsingContextGroup);
|
|
|
|
|
2022-09-19 12:28:46 +02:00
|
|
|
// https://html.spec.whatwg.org/multipage/browsers.html#browsing-context-group-set
|
2023-04-20 16:45:28 +01:00
|
|
|
static HashTable<JS::NonnullGCPtr<BrowsingContextGroup>>& user_agent_browsing_context_group_set()
|
2022-09-19 12:28:46 +02:00
|
|
|
{
|
2023-04-20 16:45:28 +01:00
|
|
|
static HashTable<JS::NonnullGCPtr<BrowsingContextGroup>> set;
|
2022-09-19 12:28:46 +02:00
|
|
|
return set;
|
|
|
|
}
|
|
|
|
|
2023-12-03 16:56:04 +13:00
|
|
|
BrowsingContextGroup::BrowsingContextGroup(JS::NonnullGCPtr<Web::Page> page)
|
2022-09-19 12:28:46 +02:00
|
|
|
: m_page(page)
|
|
|
|
{
|
2023-04-20 16:45:28 +01:00
|
|
|
user_agent_browsing_context_group_set().set(*this);
|
2022-09-19 12:28:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
BrowsingContextGroup::~BrowsingContextGroup()
|
|
|
|
{
|
2023-04-20 16:45:28 +01:00
|
|
|
user_agent_browsing_context_group_set().remove(*this);
|
2022-09-19 12:28:46 +02:00
|
|
|
}
|
|
|
|
|
2022-10-17 11:06:50 +02:00
|
|
|
void BrowsingContextGroup::visit_edges(Cell::Visitor& visitor)
|
|
|
|
{
|
|
|
|
Base::visit_edges(visitor);
|
2023-06-26 06:56:54 +02:00
|
|
|
visitor.visit(m_page);
|
2024-04-15 13:58:21 +02:00
|
|
|
visitor.visit(m_browsing_context_set);
|
2022-10-17 11:06:50 +02:00
|
|
|
}
|
|
|
|
|
2022-12-17 14:26:48 +01:00
|
|
|
// https://html.spec.whatwg.org/multipage/document-sequences.html#creating-a-new-browsing-context-group-and-document
|
2023-12-03 16:56:04 +13:00
|
|
|
auto BrowsingContextGroup::create_a_new_browsing_context_group_and_document(JS::NonnullGCPtr<Page> page) -> WebIDL::ExceptionOr<BrowsingContextGroupAndDocument>
|
2022-12-17 14:26:48 +01:00
|
|
|
{
|
|
|
|
// 1. Let group be a new browsing context group.
|
|
|
|
// 2. Append group to the user agent's browsing context group set.
|
|
|
|
auto group = Bindings::main_thread_vm().heap().allocate_without_realm<BrowsingContextGroup>(page);
|
|
|
|
|
|
|
|
// 3. Let browsingContext and document be the result of creating a new browsing context and document with null, null, and group.
|
|
|
|
auto [browsing_context, document] = TRY(BrowsingContext::create_a_new_browsing_context_and_document(page, nullptr, nullptr, group));
|
|
|
|
|
|
|
|
// 4. Append browsingContext to group.
|
|
|
|
group->append(browsing_context);
|
|
|
|
|
|
|
|
// 5. Return group and document.
|
|
|
|
return BrowsingContextGroupAndDocument { group, document };
|
|
|
|
}
|
|
|
|
|
2022-09-19 12:28:46 +02:00
|
|
|
// https://html.spec.whatwg.org/multipage/browsers.html#bcg-append
|
|
|
|
void BrowsingContextGroup::append(BrowsingContext& browsing_context)
|
|
|
|
{
|
|
|
|
VERIFY(browsing_context.is_top_level());
|
|
|
|
|
|
|
|
// 1. Append browsingContext to group's browsing context set.
|
2023-04-20 16:44:54 +01:00
|
|
|
m_browsing_context_set.set(browsing_context);
|
2022-09-19 12:28:46 +02:00
|
|
|
|
|
|
|
// 2. Set browsingContext's group to group.
|
|
|
|
browsing_context.set_group(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|