/src/serenity/Userland/Libraries/LibWeb/HTML/BrowsingContextGroup.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright (c) 2022, Andreas Kling <kling@serenityos.org> |
3 | | * |
4 | | * SPDX-License-Identifier: BSD-2-Clause |
5 | | */ |
6 | | |
7 | | #include <LibWeb/Bindings/MainThreadVM.h> |
8 | | #include <LibWeb/HTML/BrowsingContext.h> |
9 | | #include <LibWeb/HTML/BrowsingContextGroup.h> |
10 | | #include <LibWeb/Page/Page.h> |
11 | | |
12 | | namespace Web::HTML { |
13 | | |
14 | | JS_DEFINE_ALLOCATOR(BrowsingContextGroup); |
15 | | |
16 | | // https://html.spec.whatwg.org/multipage/browsers.html#browsing-context-group-set |
17 | | static HashTable<JS::NonnullGCPtr<BrowsingContextGroup>>& user_agent_browsing_context_group_set() |
18 | 0 | { |
19 | 0 | static HashTable<JS::NonnullGCPtr<BrowsingContextGroup>> set; |
20 | 0 | return set; |
21 | 0 | } |
22 | | |
23 | | BrowsingContextGroup::BrowsingContextGroup(JS::NonnullGCPtr<Web::Page> page) |
24 | 0 | : m_page(page) |
25 | 0 | { |
26 | 0 | user_agent_browsing_context_group_set().set(*this); |
27 | 0 | } |
28 | | |
29 | | BrowsingContextGroup::~BrowsingContextGroup() |
30 | 0 | { |
31 | 0 | user_agent_browsing_context_group_set().remove(*this); |
32 | 0 | } |
33 | | |
34 | | void BrowsingContextGroup::visit_edges(Cell::Visitor& visitor) |
35 | 0 | { |
36 | 0 | Base::visit_edges(visitor); |
37 | 0 | visitor.visit(m_page); |
38 | 0 | visitor.visit(m_browsing_context_set); |
39 | 0 | } |
40 | | |
41 | | // https://html.spec.whatwg.org/multipage/document-sequences.html#creating-a-new-browsing-context-group-and-document |
42 | | auto BrowsingContextGroup::create_a_new_browsing_context_group_and_document(JS::NonnullGCPtr<Page> page) -> WebIDL::ExceptionOr<BrowsingContextGroupAndDocument> |
43 | 0 | { |
44 | | // 1. Let group be a new browsing context group. |
45 | | // 2. Append group to the user agent's browsing context group set. |
46 | 0 | auto group = Bindings::main_thread_vm().heap().allocate_without_realm<BrowsingContextGroup>(page); |
47 | | |
48 | | // 3. Let browsingContext and document be the result of creating a new browsing context and document with null, null, and group. |
49 | 0 | auto [browsing_context, document] = TRY(BrowsingContext::create_a_new_browsing_context_and_document(page, nullptr, nullptr, group)); |
50 | | |
51 | | // 4. Append browsingContext to group. |
52 | 0 | group->append(browsing_context); |
53 | | |
54 | | // 5. Return group and document. |
55 | 0 | return BrowsingContextGroupAndDocument { group, document }; |
56 | 0 | } |
57 | | |
58 | | // https://html.spec.whatwg.org/multipage/browsers.html#bcg-append |
59 | | void BrowsingContextGroup::append(BrowsingContext& browsing_context) |
60 | 0 | { |
61 | 0 | VERIFY(browsing_context.is_top_level()); |
62 | | |
63 | | // 1. Append browsingContext to group's browsing context set. |
64 | 0 | m_browsing_context_set.set(browsing_context); |
65 | | |
66 | | // 2. Set browsingContext's group to group. |
67 | 0 | browsing_context.set_group(this); |
68 | 0 | } |
69 | | |
70 | | } |