2020-01-18 05:38:21 -03:00
|
|
|
/*
|
2024-10-04 08:19:50 -03:00
|
|
|
* Copyright (c) 2018-2022, Andreas Kling <andreas@ladybird.org>
|
2020-01-18 05:38:21 -03:00
|
|
|
*
|
2021-04-22 05:24:48 -03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 05:38:21 -03:00
|
|
|
*/
|
|
|
|
|
|
2019-10-04 10:50:04 -03:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <AK/Noncopyable.h>
|
2022-10-17 06:06:50 -03:00
|
|
|
#include <LibJS/Heap/Cell.h>
|
2024-10-04 23:33:34 -03:00
|
|
|
#include <LibURL/Origin.h>
|
2025-07-19 23:35:33 -03:00
|
|
|
#include <LibWeb/Export.h>
|
2022-12-12 08:20:02 -03:00
|
|
|
#include <LibWeb/HTML/NavigableContainer.h>
|
2023-08-28 12:41:09 -03:00
|
|
|
#include <LibWeb/HTML/SandboxingFlagSet.h>
|
2022-08-01 11:34:56 -03:00
|
|
|
#include <LibWeb/HTML/SessionHistoryEntry.h>
|
2023-03-21 07:52:29 -03:00
|
|
|
#include <LibWeb/HTML/TokenizedFeatures.h>
|
2019-10-04 10:50:04 -03:00
|
|
|
|
2021-11-18 11:01:28 -03:00
|
|
|
namespace Web::HTML {
|
2020-03-07 06:27:02 -03:00
|
|
|
|
2025-07-19 23:35:33 -03:00
|
|
|
class WEB_API BrowsingContext final : public JS::Cell {
|
2024-11-14 12:01:23 -03:00
|
|
|
GC_CELL(BrowsingContext, JS::Cell);
|
|
|
|
|
GC_DECLARE_ALLOCATOR(BrowsingContext);
|
2022-10-17 06:06:50 -03:00
|
|
|
|
2019-10-04 10:50:04 -03:00
|
|
|
public:
|
2023-04-23 13:31:46 -03:00
|
|
|
struct BrowsingContextAndDocument {
|
2024-11-14 12:01:23 -03:00
|
|
|
GC::Ref<BrowsingContext> browsing_context;
|
|
|
|
|
GC::Ref<DOM::Document> document;
|
2023-04-23 13:31:46 -03:00
|
|
|
};
|
|
|
|
|
|
2024-11-14 12:01:23 -03:00
|
|
|
static WebIDL::ExceptionOr<BrowsingContextAndDocument> create_a_new_browsing_context_and_document(GC::Ref<Page> page, GC::Ptr<DOM::Document> creator, GC::Ptr<DOM::Element> embedder, GC::Ref<BrowsingContextGroup> group);
|
|
|
|
|
static WebIDL::ExceptionOr<BrowsingContextAndDocument> create_a_new_auxiliary_browsing_context_and_document(GC::Ref<Page> page, GC::Ref<HTML::BrowsingContext> opener);
|
2023-04-23 13:31:46 -03:00
|
|
|
|
2023-03-14 06:40:03 -03:00
|
|
|
virtual ~BrowsingContext() override;
|
2019-10-04 10:50:04 -03:00
|
|
|
|
2025-02-17 19:57:52 -03:00
|
|
|
GC::Ref<TraversableNavigable> top_level_traversable() const;
|
2022-10-17 06:06:50 -03:00
|
|
|
|
|
|
|
|
bool is_ancestor_of(BrowsingContext const&) const;
|
2023-11-28 12:36:09 -03:00
|
|
|
bool is_familiar_with(BrowsingContext const&) const;
|
2022-10-17 06:06:50 -03:00
|
|
|
|
2022-03-01 18:17:53 -03:00
|
|
|
bool is_top_level() const;
|
2024-10-05 16:56:35 -03:00
|
|
|
bool is_auxiliary() const { return m_is_auxiliary; }
|
2020-06-06 11:33:04 -03:00
|
|
|
|
2022-08-28 08:42:07 -03:00
|
|
|
DOM::Document const* active_document() const;
|
|
|
|
|
DOM::Document* active_document();
|
2019-10-04 10:50:04 -03:00
|
|
|
|
2024-02-04 07:44:19 -03:00
|
|
|
HTML::WindowProxy* window_proxy();
|
|
|
|
|
HTML::WindowProxy const* window_proxy() const;
|
2022-11-14 20:58:26 -03:00
|
|
|
|
2024-11-14 12:01:23 -03:00
|
|
|
void set_window_proxy(GC::Ptr<WindowProxy>);
|
2023-04-23 13:31:46 -03:00
|
|
|
|
2022-09-19 12:46:34 -03:00
|
|
|
HTML::Window* active_window();
|
|
|
|
|
HTML::Window const* active_window() const;
|
|
|
|
|
|
2023-12-03 04:29:37 -03:00
|
|
|
Page& page() { return m_page; }
|
|
|
|
|
Page const& page() const { return m_page; }
|
2019-11-25 17:19:03 -03:00
|
|
|
|
2024-08-10 09:26:59 -03:00
|
|
|
u64 virtual_browsing_context_group_id() const { return m_virtual_browsing_context_group_id; }
|
|
|
|
|
|
2024-11-14 12:01:23 -03:00
|
|
|
GC::Ptr<BrowsingContext> top_level_browsing_context() const;
|
2020-06-06 10:08:36 -03:00
|
|
|
|
2022-09-19 07:28:46 -03:00
|
|
|
BrowsingContextGroup* group();
|
2024-10-24 14:23:38 -03:00
|
|
|
BrowsingContextGroup const* group() const;
|
2022-09-19 07:28:46 -03:00
|
|
|
void set_group(BrowsingContextGroup*);
|
|
|
|
|
|
|
|
|
|
// https://html.spec.whatwg.org/multipage/browsers.html#bcg-remove
|
|
|
|
|
void remove();
|
|
|
|
|
|
2022-09-19 12:46:34 -03:00
|
|
|
// https://html.spec.whatwg.org/multipage/origin.html#one-permitted-sandboxed-navigator
|
|
|
|
|
BrowsingContext const* the_one_permitted_sandboxed_navigator() const;
|
2024-11-25 14:06:54 -03:00
|
|
|
void set_the_one_permitted_sandboxed_navigator(BrowsingContext const*)
|
|
|
|
|
{
|
|
|
|
|
// FIXME: Implement this
|
|
|
|
|
}
|
2022-09-19 12:46:34 -03:00
|
|
|
|
2024-02-05 14:34:29 -03:00
|
|
|
bool has_navigable_been_destroyed() const;
|
2022-09-20 16:44:42 -03:00
|
|
|
|
2024-11-14 12:01:23 -03:00
|
|
|
GC::Ptr<BrowsingContext> opener_browsing_context() const { return m_opener_browsing_context; }
|
|
|
|
|
void set_opener_browsing_context(GC::Ptr<BrowsingContext> browsing_context) { m_opener_browsing_context = browsing_context; }
|
2023-02-21 14:08:01 -03:00
|
|
|
|
2024-02-04 07:44:19 -03:00
|
|
|
void set_is_popup(TokenizedFeature::Popup is_popup) { m_is_popup = is_popup; }
|
2025-03-04 18:51:08 -03:00
|
|
|
[[nodiscard]] TokenizedFeature::Popup is_popup() const { return m_is_popup; }
|
2024-02-04 07:44:19 -03:00
|
|
|
|
2024-11-25 14:06:54 -03:00
|
|
|
SandboxingFlagSet popup_sandboxing_flag_set() const { return m_popup_sandboxing_flag_set; }
|
|
|
|
|
void set_popup_sandboxing_flag_set(SandboxingFlagSet value) { m_popup_sandboxing_flag_set = value; }
|
|
|
|
|
|
2019-10-04 10:50:04 -03:00
|
|
|
private:
|
2024-11-14 12:01:23 -03:00
|
|
|
explicit BrowsingContext(GC::Ref<Page>);
|
2019-10-04 10:50:04 -03:00
|
|
|
|
2022-10-17 06:06:50 -03:00
|
|
|
virtual void visit_edges(Cell::Visitor&) override;
|
|
|
|
|
|
2024-11-14 12:01:23 -03:00
|
|
|
GC::Ref<Page> m_page;
|
2021-09-08 06:17:43 -03:00
|
|
|
|
2024-02-04 07:56:00 -03:00
|
|
|
// https://html.spec.whatwg.org/multipage/document-sequences.html#browsing-context
|
2025-02-17 19:57:52 -03:00
|
|
|
GC::Ptr<WindowProxy> m_window_proxy;
|
2020-08-02 06:52:35 -03:00
|
|
|
|
2024-02-04 07:56:00 -03:00
|
|
|
// https://html.spec.whatwg.org/multipage/browsers.html#opener-browsing-context
|
2024-11-14 12:01:23 -03:00
|
|
|
GC::Ptr<BrowsingContext> m_opener_browsing_context;
|
2023-03-13 10:49:07 -03:00
|
|
|
|
2024-02-04 07:56:00 -03:00
|
|
|
// https://html.spec.whatwg.org/multipage/document-sequences.html#opener-origin-at-creation
|
2024-10-04 23:33:34 -03:00
|
|
|
Optional<URL::Origin> m_opener_origin_at_creation;
|
2022-10-15 18:10:56 -03:00
|
|
|
|
2024-02-04 07:44:19 -03:00
|
|
|
// https://html.spec.whatwg.org/multipage/browsers.html#is-popup
|
|
|
|
|
TokenizedFeature::Popup m_is_popup { TokenizedFeature::Popup::No };
|
|
|
|
|
|
2024-11-25 14:06:54 -03:00
|
|
|
// https://html.spec.whatwg.org/multipage/browsers.html#popup-sandboxing-flag-set
|
|
|
|
|
SandboxingFlagSet m_popup_sandboxing_flag_set {};
|
|
|
|
|
|
2024-02-04 07:56:00 -03: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 00:22:27 -03:00
|
|
|
Optional<URL::URL> m_initial_url;
|
2024-02-04 07:44:19 -03:00
|
|
|
|
2024-02-04 07:56:00 -03: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 07:44:19 -03:00
|
|
|
|
2022-09-19 07:28:46 -03:00
|
|
|
// https://html.spec.whatwg.org/multipage/browsers.html#tlbc-group
|
2024-11-14 12:01:23 -03:00
|
|
|
GC::Ptr<BrowsingContextGroup> m_group;
|
2022-09-19 15:50:33 -03:00
|
|
|
|
2024-11-14 12:01:23 -03:00
|
|
|
GC::Ptr<BrowsingContext> m_first_child;
|
|
|
|
|
GC::Ptr<BrowsingContext> m_last_child;
|
|
|
|
|
GC::Ptr<BrowsingContext> m_next_sibling;
|
|
|
|
|
GC::Ptr<BrowsingContext> m_previous_sibling;
|
2019-10-04 10:50:04 -03:00
|
|
|
};
|
2020-03-07 06:27:02 -03:00
|
|
|
|
2024-11-15 11:17:18 -03:00
|
|
|
URL::Origin determine_the_origin(Optional<URL::URL const&>, SandboxingFlagSet, Optional<URL::Origin> source_origin);
|
2022-12-12 13:36:20 -03:00
|
|
|
|
2024-11-14 12:01:23 -03:00
|
|
|
SandboxingFlagSet determine_the_creation_sandboxing_flags(BrowsingContext const&, GC::Ptr<DOM::Element> embedder);
|
2023-08-28 12:44:50 -03:00
|
|
|
|
2024-02-04 07:41:07 -03:00
|
|
|
// FIXME: Find a better home for these
|
2025-07-19 23:35:33 -03:00
|
|
|
WEB_API bool url_matches_about_blank(URL::URL const& url);
|
2024-03-18 00:22:27 -03:00
|
|
|
bool url_matches_about_srcdoc(URL::URL const& url);
|
2023-08-28 12:41:09 -03:00
|
|
|
|
2020-03-07 06:27:02 -03:00
|
|
|
}
|