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