2020-01-18 09:38:21 +01:00
|
|
|
/*
|
2022-08-01 16:34:56 +02:00
|
|
|
* Copyright (c) 2018-2022, Andreas Kling <kling@serenityos.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>
|
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-09-19 17:46:34 +02:00
|
|
|
#include <LibWeb/HTML/HistoryHandlingBehavior.h>
|
2022-12-12 12:20:02 +01:00
|
|
|
#include <LibWeb/HTML/NavigableContainer.h>
|
2022-08-05 10:55:47 +02:00
|
|
|
#include <LibWeb/HTML/Origin.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>
|
2020-07-28 19:27:41 +02:00
|
|
|
#include <LibWeb/Page/EventHandler.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-02-04 03:44:19 -07:00
|
|
|
class BrowsingContext final : public JS::Cell
|
2022-10-17 11:06:50 +02:00
|
|
|
, public Weakable<BrowsingContext> {
|
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> parent() const { return m_parent; }
|
|
|
|
|
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>
|
|
|
|
|
IterationDecision for_each_in_inclusive_subtree(Callback callback) const
|
|
|
|
|
{
|
|
|
|
|
if (callback(*this) == IterationDecision::Break)
|
|
|
|
|
return IterationDecision::Break;
|
|
|
|
|
for (auto child = first_child(); child; child = child->next_sibling()) {
|
|
|
|
|
if (child->for_each_in_inclusive_subtree(callback) == IterationDecision::Break)
|
|
|
|
|
return IterationDecision::Break;
|
|
|
|
|
}
|
|
|
|
|
return IterationDecision::Continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<typename Callback>
|
|
|
|
|
IterationDecision for_each_in_inclusive_subtree(Callback callback)
|
|
|
|
|
{
|
|
|
|
|
if (callback(*this) == IterationDecision::Break)
|
|
|
|
|
return IterationDecision::Break;
|
|
|
|
|
for (auto child = first_child(); child; child = child->next_sibling()) {
|
|
|
|
|
if (child->for_each_in_inclusive_subtree(callback) == IterationDecision::Break)
|
|
|
|
|
return IterationDecision::Break;
|
|
|
|
|
}
|
|
|
|
|
return IterationDecision::Continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<typename Callback>
|
|
|
|
|
IterationDecision for_each_in_subtree(Callback callback) const
|
|
|
|
|
{
|
|
|
|
|
for (auto child = first_child(); child; child = child->next_sibling()) {
|
|
|
|
|
if (child->for_each_in_inclusive_subtree(callback) == IterationDecision::Break)
|
|
|
|
|
return IterationDecision::Break;
|
|
|
|
|
}
|
|
|
|
|
return IterationDecision::Continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<typename Callback>
|
|
|
|
|
IterationDecision for_each_in_subtree(Callback callback)
|
|
|
|
|
{
|
|
|
|
|
for (auto child = first_child(); child; child = child->next_sibling()) {
|
|
|
|
|
if (child->for_each_in_inclusive_subtree(callback) == IterationDecision::Break)
|
|
|
|
|
return IterationDecision::Break;
|
|
|
|
|
}
|
|
|
|
|
return IterationDecision::Continue;
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-01 21:17:53 +00:00
|
|
|
bool is_top_level() const;
|
2021-05-30 12:36:53 +02:00
|
|
|
bool is_focused_context() const;
|
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
|
|
|
|
2021-11-18 15:01:28 +01:00
|
|
|
Web::EventHandler& event_handler() { return m_event_handler; }
|
|
|
|
|
Web::EventHandler const& event_handler() const { return m_event_handler; }
|
2020-06-07 14:40:38 +02:00
|
|
|
|
2023-09-04 15:33:08 +02:00
|
|
|
JS::GCPtr<BrowsingContext> top_level_browsing_context() const;
|
2020-06-06 15:08:36 +02:00
|
|
|
|
2023-09-26 19:34:21 +02:00
|
|
|
JS::GCPtr<DOM::Position> cursor_position() const { return m_cursor_position; }
|
|
|
|
|
void set_cursor_position(JS::NonnullGCPtr<DOM::Position>);
|
2021-05-18 22:01:12 +02:00
|
|
|
bool increment_cursor_position_offset();
|
|
|
|
|
bool decrement_cursor_position_offset();
|
2020-08-02 11:52:35 +02:00
|
|
|
|
|
|
|
|
bool cursor_blink_state() const { return m_cursor_blink_state; }
|
|
|
|
|
|
2023-12-24 15:49:57 +13:00
|
|
|
String selected_text() const;
|
2021-07-14 08:38:10 -04:00
|
|
|
void select_all();
|
2020-08-06 19:21:59 +02:00
|
|
|
|
2021-01-04 20:48:27 +01:00
|
|
|
void did_edit(Badge<EditEventHandler>);
|
|
|
|
|
|
2022-08-28 13:42:07 +02:00
|
|
|
JS::GCPtr<DOM::Node> currently_focused_area();
|
2022-02-06 18:45:29 +01: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;
|
|
|
|
|
|
2021-02-09 21:23:50 +01:00
|
|
|
void reset_cursor_blink_cycle();
|
|
|
|
|
|
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
|
|
|
// FIXME: Move EventHandler to Navigable
|
2021-11-18 15:01:28 +01:00
|
|
|
Web::EventHandler m_event_handler;
|
2020-06-06 13:02:44 +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
|
|
|
|
|
Optional<HTML::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-02-11 20:15:39 +13:00
|
|
|
Optional<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
|
|
|
|
2024-02-04 03:56:00 -07:00
|
|
|
// FIXME: Move cursor tracking to Navigable
|
2023-09-26 19:34:21 +02:00
|
|
|
JS::GCPtr<DOM::Position> m_cursor_position;
|
2023-08-19 16:19:52 +02:00
|
|
|
RefPtr<Core::Timer> m_cursor_blink_timer;
|
2020-08-02 11:52:35 +02:00
|
|
|
bool m_cursor_blink_state { false };
|
2021-01-30 12:25:33 +01: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_parent;
|
|
|
|
|
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-02-11 20:15:39 +13:00
|
|
|
HTML::Origin determine_the_origin(URL const& url, SandboxingFlagSet sandbox_flags, Optional<HTML::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-02-11 20:15:39 +13:00
|
|
|
bool url_matches_about_blank(URL const& url);
|
|
|
|
|
bool url_matches_about_srcdoc(URL const& url);
|
2023-08-28 17:41:09 +02:00
|
|
|
|
2020-03-07 10:27:02 +01:00
|
|
|
}
|