forked from SerenityOS/serenity
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
LibWeb: Implement "browsing context group" concept from the HTML spec
- Loading branch information
1 parent
e36750d
commit 8ead228
Showing
9 changed files
with
163 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* Copyright (c) 2022, Andreas Kling <[email protected]> | ||
* | ||
* SPDX-License-Identifier: BSD-2-Clause | ||
*/ | ||
|
||
#include <LibWeb/HTML/BrowsingContext.h> | ||
#include <LibWeb/HTML/BrowsingContextGroup.h> | ||
|
||
namespace Web::HTML { | ||
|
||
// https://html.spec.whatwg.org/multipage/browsers.html#browsing-context-group-set | ||
static HashTable<BrowsingContextGroup*>& user_agent_browsing_context_group_set() | ||
{ | ||
static HashTable<BrowsingContextGroup*> set; | ||
return set; | ||
} | ||
|
||
BrowsingContextGroup::BrowsingContextGroup(Web::Page& page) | ||
: m_page(page) | ||
{ | ||
user_agent_browsing_context_group_set().set(this); | ||
} | ||
|
||
BrowsingContextGroup::~BrowsingContextGroup() | ||
{ | ||
user_agent_browsing_context_group_set().remove(this); | ||
} | ||
|
||
// https://html.spec.whatwg.org/multipage/browsers.html#creating-a-new-browsing-context-group | ||
NonnullRefPtr<BrowsingContextGroup> BrowsingContextGroup::create_a_new_browsing_context_group(Web::Page& page) | ||
{ | ||
// 1. Let group be a new browsing context group. | ||
// 2. Append group to the user agent's browsing context group set. | ||
auto group = adopt_ref(*new BrowsingContextGroup(page)); | ||
|
||
// 3. Let browsingContext be the result of creating a new browsing context with null, null, and group. | ||
auto browsing_context = BrowsingContext::create_a_new_browsing_context(page, nullptr, nullptr, group); | ||
|
||
// 4. Append browsingContext to group. | ||
group->append(move(browsing_context)); | ||
|
||
// 5. Return group. | ||
return group; | ||
} | ||
|
||
// 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. | ||
m_browsing_context_set.set(browsing_context); | ||
|
||
// 2. Set browsingContext's group to group. | ||
browsing_context.set_group(this); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright (c) 2022, Andreas Kling <[email protected]> | ||
* | ||
* SPDX-License-Identifier: BSD-2-Clause | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <AK/HashMap.h> | ||
#include <AK/NonnullRefPtr.h> | ||
#include <AK/RefCounted.h> | ||
#include <LibWeb/Forward.h> | ||
|
||
namespace Web::HTML { | ||
|
||
class BrowsingContextGroup : public RefCounted<BrowsingContextGroup> { | ||
public: | ||
static NonnullRefPtr<BrowsingContextGroup> create_a_new_browsing_context_group(Page&); | ||
~BrowsingContextGroup(); | ||
|
||
Page* page() { return m_page; } | ||
Page const* page() const { return m_page; } | ||
|
||
auto& browsing_context_set() { return m_browsing_context_set; } | ||
auto const& browsing_context_set() const { return m_browsing_context_set; } | ||
|
||
void append(BrowsingContext&); | ||
void remove(BrowsingContext&); | ||
|
||
private: | ||
explicit BrowsingContextGroup(Web::Page&); | ||
|
||
// https://html.spec.whatwg.org/multipage/browsers.html#browsing-context-group-set | ||
OrderedHashTable<NonnullRefPtr<BrowsingContext>> m_browsing_context_set; | ||
|
||
WeakPtr<Page> m_page; | ||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters