2020-01-18 09:38:21 +01:00
|
|
|
/*
|
2024-10-04 13:19:50 +02:00
|
|
|
* Copyright (c) 2018-2022, Andreas Kling <andreas@ladybird.org>
|
2020-01-18 09:38:21 +01:00
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 09:38:21 +01:00
|
|
|
*/
|
|
|
|
|
|
2019-10-04 15:50:04 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
2019-10-09 21:25:29 +02:00
|
|
|
#include <AK/Function.h>
|
2019-10-04 15:50:04 +02:00
|
|
|
#include <AK/Noncopyable.h>
|
|
|
|
|
#include <AK/RefPtr.h>
|
2019-11-25 21:19:03 +01:00
|
|
|
#include <AK/WeakPtr.h>
|
2020-06-06 13:02:44 +02:00
|
|
|
#include <LibGfx/Bitmap.h>
|
2020-02-06 12:04:00 +01:00
|
|
|
#include <LibGfx/Rect.h>
|
|
|
|
|
#include <LibGfx/Size.h>
|
2022-10-30 01:52:07 +00:00
|
|
|
#include <LibJS/Forward.h>
|
2022-10-17 11:06:50 +02:00
|
|
|
#include <LibJS/Heap/Cell.h>
|
2024-10-05 15:33:34 +13:00
|
|
|
#include <LibURL/Origin.h>
|
2020-08-02 11:52:35 +02:00
|
|
|
#include <LibWeb/DOM/Position.h>
|
2023-03-20 18:39:20 -04:00
|
|
|
#include <LibWeb/HTML/ActivateTab.h>
|
2022-12-12 12:20:02 +01:00
|
|
|
#include <LibWeb/HTML/NavigableContainer.h>
|
2023-08-28 17:41:09 +02:00
|
|
|
#include <LibWeb/HTML/SandboxingFlagSet.h>
|
2022-08-01 16:34:56 +02:00
|
|
|
#include <LibWeb/HTML/SessionHistoryEntry.h>
|
2023-03-21 06:52:29 -04:00
|
|
|
#include <LibWeb/HTML/TokenizedFeatures.h>
|
2022-09-19 20:50:33 +02:00
|
|
|
#include <LibWeb/HTML/VisibilityState.h>
|
2022-09-07 20:30:31 +02:00
|
|
|
#include <LibWeb/Platform/Timer.h>
|
2020-03-07 10:32:51 +01:00
|
|
|
#include <LibWeb/TreeNode.h>
|
2019-10-04 15:50:04 +02:00
|
|
|
|
2021-11-18 15:01:28 +01:00
|
|
|
namespace Web::HTML {
|
2020-03-07 10:27:02 +01:00
|
|
|
|
2024-05-02 10:24:23 +02:00
|
|
|
class BrowsingContext final : public JS::Cell {
|
2024-02-04 03:44:19 -07:00
|
|
|
JS_CELL(BrowsingContext, JS::Cell);
|
2023-11-19 19:47:52 +01:00
|
|
|
JS_DECLARE_ALLOCATOR(BrowsingContext);
|
2022-10-17 11:06:50 +02:00
|
|
|
|
2019-10-04 15:50:04 +02:00
|
|
|
public:
|
2023-04-23 19:31:46 +03:00
|
|
|
struct BrowsingContextAndDocument {
|
|
|
|
|
JS::NonnullGCPtr<BrowsingContext> browsing_context;
|
|
|
|
|
JS::NonnullGCPtr<DOM::Document> document;
|
|
|
|
|
};
|
|
|
|
|
|
2023-06-26 06:58:10 +02:00
|
|
|
static WebIDL::ExceptionOr<BrowsingContextAndDocument> create_a_new_browsing_context_and_document(JS::NonnullGCPtr<Page> page, JS::GCPtr<DOM::Document> creator, JS::GCPtr<DOM::Element> embedder, JS::NonnullGCPtr<BrowsingContextGroup> group);
|
|
|
|
|
static WebIDL::ExceptionOr<BrowsingContextAndDocument> create_a_new_auxiliary_browsing_context_and_document(JS::NonnullGCPtr<Page> page, JS::NonnullGCPtr<HTML::BrowsingContext> opener);
|
2023-04-23 19:31:46 +03:00
|
|
|
|
2023-03-14 12:40:03 +03:00
|
|
|
virtual ~BrowsingContext() override;
|
2019-10-04 15:50:04 +02:00
|
|
|
|
2022-12-17 13:35:20 +01:00
|
|
|
JS::NonnullGCPtr<HTML::TraversableNavigable> top_level_traversable() const;
|
|
|
|
|
|
2022-10-17 11:06:50 +02:00
|
|
|
JS::GCPtr<BrowsingContext> first_child() const;
|
|
|
|
|
JS::GCPtr<BrowsingContext> next_sibling() const;
|
|
|
|
|
|
|
|
|
|
bool is_ancestor_of(BrowsingContext const&) const;
|
2023-11-28 08:36:09 -07:00
|
|
|
bool is_familiar_with(BrowsingContext const&) const;
|
2022-10-17 11:06:50 +02:00
|
|
|
|
|
|
|
|
template<typename Callback>
|
2024-05-04 14:47:04 +01:00
|
|
|
TraversalDecision for_each_in_inclusive_subtree(Callback callback) const
|
2022-10-17 11:06:50 +02:00
|
|
|
{
|
2024-05-04 14:47:04 +01:00
|
|
|
if (callback(*this) == TraversalDecision::Break)
|
|
|
|
|
return TraversalDecision::Break;
|
2022-10-17 11:06:50 +02:00
|
|
|
for (auto child = first_child(); child; child = child->next_sibling()) {
|
2024-05-04 14:47:04 +01:00
|
|
|
if (child->for_each_in_inclusive_subtree(callback) == TraversalDecision::Break)
|
|
|
|
|
return TraversalDecision::Break;
|
2022-10-17 11:06:50 +02:00
|
|
|
}
|
2024-05-04 14:47:04 +01:00
|
|
|
return TraversalDecision::Continue;
|
2022-10-17 11:06:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<typename Callback>
|
2024-05-04 14:47:04 +01:00
|
|
|
TraversalDecision for_each_in_inclusive_subtree(Callback callback)
|
2022-10-17 11:06:50 +02:00
|
|
|
{
|
2024-05-04 14:47:04 +01:00
|
|
|
if (callback(*this) == TraversalDecision::Break)
|
|
|
|
|
return TraversalDecision::Break;
|
2022-10-17 11:06:50 +02:00
|
|
|
for (auto child = first_child(); child; child = child->next_sibling()) {
|
2024-05-04 14:47:04 +01:00
|
|
|
if (child->for_each_in_inclusive_subtree(callback) == TraversalDecision::Break)
|
|
|
|
|
return TraversalDecision::Break;
|
2022-10-17 11:06:50 +02:00
|
|
|
}
|
2024-05-04 14:47:04 +01:00
|
|
|
return TraversalDecision::Continue;
|
2022-10-17 11:06:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<typename Callback>
|
2024-05-04 14:47:04 +01:00
|
|
|
TraversalDecision for_each_in_subtree(Callback callback) const
|
2022-10-17 11:06:50 +02:00
|
|
|
{
|
|
|
|
|
for (auto child = first_child(); child; child = child->next_sibling()) {
|
2024-05-04 14:47:04 +01:00
|
|
|
if (child->for_each_in_inclusive_subtree(callback) == TraversalDecision::Break)
|
|
|
|
|
return TraversalDecision::Break;
|
2022-10-17 11:06:50 +02:00
|
|
|
}
|
2024-05-04 14:47:04 +01:00
|
|
|
return TraversalDecision::Continue;
|
2022-10-17 11:06:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<typename Callback>
|
2024-05-04 14:47:04 +01:00
|
|
|
TraversalDecision for_each_in_subtree(Callback callback)
|
2022-10-17 11:06:50 +02:00
|
|
|
{
|
|
|
|
|
for (auto child = first_child(); child; child = child->next_sibling()) {
|
2024-05-04 14:47:04 +01:00
|
|
|
if (child->for_each_in_inclusive_subtree(callback) == TraversalDecision::Break)
|
|
|
|
|
return TraversalDecision::Break;
|
2022-10-17 11:06:50 +02:00
|
|
|
}
|
2024-05-04 14:47:04 +01:00
|
|
|
return TraversalDecision::Continue;
|
2022-10-17 11:06:50 +02:00
|
|
|
}
|
|
|
|
|
|
2022-03-01 21:17:53 +00:00
|
|
|
bool is_top_level() const;
|
2024-10-05 15:56:35 -04:00
|
|
|
bool is_auxiliary() const { return m_is_auxiliary; }
|
2020-06-06 16:33:04 +02:00
|
|
|
|
2022-08-28 13:42:07 +02:00
|
|
|
DOM::Document const* active_document() const;
|
|
|
|
|
DOM::Document* active_document();
|
2019-10-04 15:50:04 +02:00
|
|
|
|
2024-02-04 03:44:19 -07:00
|
|
|
HTML::WindowProxy* window_proxy();
|
|
|
|
|
HTML::WindowProxy const* window_proxy() const;
|
2022-11-15 01:58:26 +02:00
|
|
|
|
2023-04-23 19:31:46 +03:00
|
|
|
void set_window_proxy(JS::GCPtr<WindowProxy>);
|
|
|
|
|
|
2022-09-19 17:46:34 +02:00
|
|
|
HTML::Window* active_window();
|
|
|
|
|
HTML::Window const* active_window() const;
|
|
|
|
|
|
2023-12-03 20:29:37 +13:00
|
|
|
Page& page() { return m_page; }
|
|
|
|
|
Page const& page() const { return m_page; }
|
2019-11-25 21:19:03 +01:00
|
|
|
|
2024-08-10 15:26:59 +03:00
|
|
|
u64 virtual_browsing_context_group_id() const { return m_virtual_browsing_context_group_id; }
|
|
|
|
|
|
2023-09-04 15:33:08 +02:00
|
|
|
JS::GCPtr<BrowsingContext> top_level_browsing_context() const;
|
2020-06-06 15:08:36 +02:00
|
|
|
|
2022-09-19 12:28:46 +02:00
|
|
|
BrowsingContextGroup* group();
|
|
|
|
|
void set_group(BrowsingContextGroup*);
|
|
|
|
|
|
|
|
|
|
// https://html.spec.whatwg.org/multipage/browsers.html#bcg-remove
|
|
|
|
|
void remove();
|
|
|
|
|
|
2022-09-19 17:46:34 +02:00
|
|
|
// https://html.spec.whatwg.org/multipage/origin.html#one-permitted-sandboxed-navigator
|
|
|
|
|
BrowsingContext const* the_one_permitted_sandboxed_navigator() const;
|
|
|
|
|
|
2024-02-05 12:34:29 -05:00
|
|
|
bool has_navigable_been_destroyed() const;
|
2022-09-20 21:44:42 +02:00
|
|
|
|
2024-02-04 03:44:19 -07:00
|
|
|
JS::GCPtr<BrowsingContext> opener_browsing_context() const { return m_opener_browsing_context; }
|
|
|
|
|
void set_opener_browsing_context(JS::GCPtr<BrowsingContext> browsing_context) { m_opener_browsing_context = browsing_context; }
|
2023-02-21 17:08:01 +00:00
|
|
|
|
2024-02-04 03:44:19 -07:00
|
|
|
void set_is_popup(TokenizedFeature::Popup is_popup) { m_is_popup = is_popup; }
|
|
|
|
|
|
2019-10-04 15:50:04 +02:00
|
|
|
private:
|
2024-02-04 03:56:00 -07:00
|
|
|
explicit BrowsingContext(JS::NonnullGCPtr<Page>);
|
2019-10-04 15:50:04 +02:00
|
|
|
|
2022-10-17 11:06:50 +02:00
|
|
|
virtual void visit_edges(Cell::Visitor&) override;
|
|
|
|
|
|
2023-06-26 06:58:10 +02:00
|
|
|
JS::NonnullGCPtr<Page> m_page;
|
2021-09-08 11:17:43 +02:00
|
|
|
|
2024-02-04 03:56:00 -07:00
|
|
|
// https://html.spec.whatwg.org/multipage/document-sequences.html#browsing-context
|
|
|
|
|
JS::GCPtr<HTML::WindowProxy> m_window_proxy;
|
2020-08-02 11:52:35 +02:00
|
|
|
|
2024-02-04 03:56:00 -07:00
|
|
|
// https://html.spec.whatwg.org/multipage/browsers.html#opener-browsing-context
|
|
|
|
|
JS::GCPtr<BrowsingContext> m_opener_browsing_context;
|
2023-03-13 16:49:07 +03:00
|
|
|
|
2024-02-04 03:56:00 -07:00
|
|
|
// https://html.spec.whatwg.org/multipage/document-sequences.html#opener-origin-at-creation
|
2024-10-05 15:33:34 +13:00
|
|
|
Optional<URL::Origin> m_opener_origin_at_creation;
|
2022-10-15 23:10:56 +02:00
|
|
|
|
2024-02-04 03:44:19 -07:00
|
|
|
// https://html.spec.whatwg.org/multipage/browsers.html#is-popup
|
|
|
|
|
TokenizedFeature::Popup m_is_popup { TokenizedFeature::Popup::No };
|
|
|
|
|
|
2024-02-04 03:56:00 -07:00
|
|
|
// https://html.spec.whatwg.org/multipage/document-sequences.html#is-auxiliary
|
|
|
|
|
bool m_is_auxiliary { false };
|
|
|
|
|
|
|
|
|
|
// https://html.spec.whatwg.org/multipage/document-sequences.html#browsing-context-initial-url
|
2024-03-18 16:22:27 +13:00
|
|
|
Optional<URL::URL> m_initial_url;
|
2024-02-04 03:44:19 -07:00
|
|
|
|
2024-02-04 03:56:00 -07:00
|
|
|
// https://html.spec.whatwg.org/multipage/document-sequences.html#virtual-browsing-context-group-id
|
|
|
|
|
u64 m_virtual_browsing_context_group_id = { 0 };
|
2024-02-04 03:44:19 -07:00
|
|
|
|
2022-09-19 12:28:46 +02:00
|
|
|
// https://html.spec.whatwg.org/multipage/browsers.html#tlbc-group
|
2022-10-17 11:06:50 +02:00
|
|
|
JS::GCPtr<BrowsingContextGroup> m_group;
|
2022-09-19 20:50:33 +02:00
|
|
|
|
2022-10-17 11:06:50 +02:00
|
|
|
JS::GCPtr<BrowsingContext> m_first_child;
|
|
|
|
|
JS::GCPtr<BrowsingContext> m_last_child;
|
|
|
|
|
JS::GCPtr<BrowsingContext> m_next_sibling;
|
|
|
|
|
JS::GCPtr<BrowsingContext> m_previous_sibling;
|
2019-10-04 15:50:04 +02:00
|
|
|
};
|
2020-03-07 10:27:02 +01:00
|
|
|
|
2024-10-05 15:33:34 +13:00
|
|
|
URL::Origin determine_the_origin(Optional<URL::URL> const&, SandboxingFlagSet, Optional<URL::Origin> source_origin);
|
2022-12-12 17:36:20 +01:00
|
|
|
|
2023-08-28 17:44:50 +02:00
|
|
|
SandboxingFlagSet determine_the_creation_sandboxing_flags(BrowsingContext const&, JS::GCPtr<DOM::Element> embedder);
|
|
|
|
|
|
2024-02-04 03:41:07 -07:00
|
|
|
// FIXME: Find a better home for these
|
2024-03-18 16:22:27 +13:00
|
|
|
bool url_matches_about_blank(URL::URL const& url);
|
|
|
|
|
bool url_matches_about_srcdoc(URL::URL const& url);
|
2023-08-28 17:41:09 +02:00
|
|
|
|
2020-03-07 10:27:02 +01:00
|
|
|
}
|