Serenity Operating System
at master 624 lines 26 kB view raw
1/* 2 * Copyright (c) 2018-2023, Andreas Kling <kling@serenityos.org> 3 * Copyright (c) 2021-2023, Linus Groh <linusg@serenityos.org> 4 * 5 * SPDX-License-Identifier: BSD-2-Clause 6 */ 7 8#pragma once 9 10#include <AK/DeprecatedFlyString.h> 11#include <AK/DeprecatedString.h> 12#include <AK/Function.h> 13#include <AK/HashMap.h> 14#include <AK/OwnPtr.h> 15#include <AK/URL.h> 16#include <AK/Vector.h> 17#include <AK/WeakPtr.h> 18#include <LibCore/Forward.h> 19#include <LibJS/Forward.h> 20#include <LibWeb/CSS/CSSStyleSheet.h> 21#include <LibWeb/CSS/StyleComputer.h> 22#include <LibWeb/CSS/StyleSheetList.h> 23#include <LibWeb/Cookie/Cookie.h> 24#include <LibWeb/DOM/NonElementParentNode.h> 25#include <LibWeb/DOM/ParentNode.h> 26#include <LibWeb/HTML/BrowsingContext.h> 27#include <LibWeb/HTML/CrossOrigin/CrossOriginOpenerPolicy.h> 28#include <LibWeb/HTML/DocumentReadyState.h> 29#include <LibWeb/HTML/HTMLScriptElement.h> 30#include <LibWeb/HTML/History.h> 31#include <LibWeb/HTML/Origin.h> 32#include <LibWeb/HTML/SandboxingFlagSet.h> 33#include <LibWeb/HTML/Scripting/Environments.h> 34#include <LibWeb/HTML/VisibilityState.h> 35#include <LibWeb/HTML/Window.h> 36#include <LibWeb/HTML/WindowProxy.h> 37#include <LibWeb/WebIDL/ExceptionOr.h> 38 39namespace Web::DOM { 40 41enum class QuirksMode { 42 No, 43 Limited, 44 Yes 45}; 46 47// https://html.spec.whatwg.org/multipage/dom.html#document-load-timing-info 48struct DocumentLoadTimingInfo { 49 // https://html.spec.whatwg.org/multipage/dom.html#navigation-start-time 50 double navigation_start_time { 0 }; 51 // https://html.spec.whatwg.org/multipage/dom.html#dom-interactive-time 52 double dom_interactive_time { 0 }; 53 // https://html.spec.whatwg.org/multipage/dom.html#dom-content-loaded-event-start-time 54 double dom_content_loaded_event_start_time { 0 }; 55 // https://html.spec.whatwg.org/multipage/dom.html#dom-content-loaded-event-end-time 56 double dom_content_loaded_event_end_time { 0 }; 57 // https://html.spec.whatwg.org/multipage/dom.html#dom-complete-time 58 double dom_complete_time { 0 }; 59 // https://html.spec.whatwg.org/multipage/dom.html#load-event-start-time 60 double load_event_start_time { 0 }; 61 // https://html.spec.whatwg.org/multipage/dom.html#load-event-end-time 62 double load_event_end_time { 0 }; 63}; 64 65// https://html.spec.whatwg.org/multipage/dom.html#document-unload-timing-info 66struct DocumentUnloadTimingInfo { 67 // https://html.spec.whatwg.org/multipage/dom.html#unload-event-start-time 68 double unload_event_start_time { 0 }; 69 // https://html.spec.whatwg.org/multipage/dom.html#unload-event-end-time 70 double unload_event_end_time { 0 }; 71}; 72 73class Document 74 : public ParentNode 75 , public NonElementParentNode<Document> 76 , public HTML::GlobalEventHandlers { 77 WEB_PLATFORM_OBJECT(Document, ParentNode); 78 79public: 80 enum class Type { 81 XML, 82 HTML 83 }; 84 85 static WebIDL::ExceptionOr<JS::NonnullGCPtr<Document>> create_and_initialize(Type, DeprecatedString content_type, HTML::NavigationParams); 86 87 static WebIDL::ExceptionOr<JS::NonnullGCPtr<Document>> create(JS::Realm&, AK::URL const& url = "about:blank"sv); 88 static WebIDL::ExceptionOr<JS::NonnullGCPtr<Document>> construct_impl(JS::Realm&); 89 virtual ~Document() override; 90 91 JS::GCPtr<Selection::Selection> get_selection() const; 92 93 size_t next_layout_node_serial_id(Badge<Layout::Node>) { return m_next_layout_node_serial_id++; } 94 size_t layout_node_count() const { return m_next_layout_node_serial_id; } 95 96 DeprecatedString cookie(Cookie::Source = Cookie::Source::NonHttp); 97 void set_cookie(DeprecatedString const&, Cookie::Source = Cookie::Source::NonHttp); 98 99 DeprecatedString referrer() const; 100 void set_referrer(DeprecatedString); 101 102 void set_url(const AK::URL& url) { m_url = url; } 103 AK::URL url() const { return m_url; } 104 AK::URL fallback_base_url() const; 105 AK::URL base_url() const; 106 107 void update_base_element(Badge<HTML::HTMLBaseElement>); 108 JS::GCPtr<HTML::HTMLBaseElement const> first_base_element_with_href_in_tree_order() const; 109 110 DeprecatedString url_string() const { return m_url.to_deprecated_string(); } 111 DeprecatedString document_uri() const { return m_url.to_deprecated_string(); } 112 113 HTML::Origin origin() const; 114 void set_origin(HTML::Origin const& origin); 115 116 HTML::CrossOriginOpenerPolicy const& cross_origin_opener_policy() const { return m_cross_origin_opener_policy; } 117 void set_cross_origin_opener_policy(HTML::CrossOriginOpenerPolicy policy) { m_cross_origin_opener_policy = move(policy); } 118 119 AK::URL parse_url(DeprecatedString const&) const; 120 121 CSS::StyleComputer& style_computer() { return *m_style_computer; } 122 const CSS::StyleComputer& style_computer() const { return *m_style_computer; } 123 124 CSS::StyleSheetList& style_sheets(); 125 CSS::StyleSheetList const& style_sheets() const; 126 127 CSS::StyleSheetList* style_sheets_for_bindings() { return &style_sheets(); } 128 129 virtual DeprecatedFlyString node_name() const override { return "#document"; } 130 131 void set_hovered_node(Node*); 132 Node* hovered_node() { return m_hovered_node.ptr(); } 133 Node const* hovered_node() const { return m_hovered_node.ptr(); } 134 135 void set_inspected_node(Node*); 136 Node* inspected_node() { return m_inspected_node.ptr(); } 137 Node const* inspected_node() const { return m_inspected_node.ptr(); } 138 139 Element* document_element(); 140 Element const* document_element() const; 141 142 HTML::HTMLHtmlElement* html_element(); 143 HTML::HTMLHeadElement* head(); 144 HTML::HTMLElement* body(); 145 146 const HTML::HTMLHtmlElement* html_element() const 147 { 148 return const_cast<Document*>(this)->html_element(); 149 } 150 151 const HTML::HTMLHeadElement* head() const 152 { 153 return const_cast<Document*>(this)->head(); 154 } 155 156 const HTML::HTMLElement* body() const 157 { 158 return const_cast<Document*>(this)->body(); 159 } 160 161 WebIDL::ExceptionOr<void> set_body(HTML::HTMLElement* new_body); 162 163 DeprecatedString title() const; 164 void set_title(DeprecatedString const&); 165 166 HTML::BrowsingContext* browsing_context() { return m_browsing_context.ptr(); } 167 HTML::BrowsingContext const* browsing_context() const { return m_browsing_context.ptr(); } 168 169 void set_browsing_context(HTML::BrowsingContext*); 170 171 Page* page(); 172 Page const* page() const; 173 174 Color background_color(Gfx::Palette const&) const; 175 Vector<CSS::BackgroundLayerData> const* background_layers() const; 176 177 Color link_color() const; 178 void set_link_color(Color); 179 180 Color active_link_color() const; 181 void set_active_link_color(Color); 182 183 Color visited_link_color() const; 184 void set_visited_link_color(Color); 185 186 void force_layout(); 187 188 void update_style(); 189 void update_layout(); 190 191 void set_needs_layout(); 192 193 void invalidate_layout(); 194 void invalidate_stacking_context_tree(); 195 196 virtual bool is_child_allowed(Node const&) const override; 197 198 Layout::Viewport const* layout_node() const; 199 Layout::Viewport* layout_node(); 200 201 void schedule_style_update(); 202 void schedule_layout_update(); 203 204 JS::NonnullGCPtr<HTMLCollection> get_elements_by_name(DeprecatedString const&); 205 JS::NonnullGCPtr<HTMLCollection> get_elements_by_class_name(DeprecatedFlyString const&); 206 207 JS::NonnullGCPtr<HTMLCollection> applets(); 208 JS::NonnullGCPtr<HTMLCollection> anchors(); 209 JS::NonnullGCPtr<HTMLCollection> images(); 210 JS::NonnullGCPtr<HTMLCollection> embeds(); 211 JS::NonnullGCPtr<HTMLCollection> plugins(); 212 JS::NonnullGCPtr<HTMLCollection> links(); 213 JS::NonnullGCPtr<HTMLCollection> forms(); 214 JS::NonnullGCPtr<HTMLCollection> scripts(); 215 JS::NonnullGCPtr<HTMLCollection> all(); 216 217 DeprecatedString const& source() const { return m_source; } 218 void set_source(DeprecatedString source) { m_source = move(source); } 219 220 HTML::EnvironmentSettingsObject& relevant_settings_object(); 221 222 JS::Value run_javascript(StringView source, StringView filename = "(unknown)"sv); 223 224 WebIDL::ExceptionOr<JS::NonnullGCPtr<Element>> create_element(DeprecatedFlyString const& local_name); 225 WebIDL::ExceptionOr<JS::NonnullGCPtr<Element>> create_element_ns(DeprecatedString const& namespace_, DeprecatedString const& qualified_name); 226 JS::NonnullGCPtr<DocumentFragment> create_document_fragment(); 227 JS::NonnullGCPtr<Text> create_text_node(DeprecatedString const& data); 228 JS::NonnullGCPtr<Comment> create_comment(DeprecatedString const& data); 229 WebIDL::ExceptionOr<JS::NonnullGCPtr<ProcessingInstruction>> create_processing_instruction(DeprecatedString const& target, DeprecatedString const& data); 230 231 WebIDL::ExceptionOr<JS::NonnullGCPtr<Attr>> create_attribute(DeprecatedString const& local_name); 232 WebIDL::ExceptionOr<JS::NonnullGCPtr<Attr>> create_attribute_ns(DeprecatedString const& namespace_, DeprecatedString const& qualified_name); 233 234 WebIDL::ExceptionOr<JS::NonnullGCPtr<Event>> create_event(DeprecatedString const& interface); 235 JS::NonnullGCPtr<Range> create_range(); 236 237 void set_pending_parsing_blocking_script(Badge<HTML::HTMLScriptElement>, HTML::HTMLScriptElement*); 238 HTML::HTMLScriptElement* pending_parsing_blocking_script() { return m_pending_parsing_blocking_script.ptr(); } 239 JS::NonnullGCPtr<HTML::HTMLScriptElement> take_pending_parsing_blocking_script(Badge<HTML::HTMLParser>); 240 241 void add_script_to_execute_when_parsing_has_finished(Badge<HTML::HTMLScriptElement>, HTML::HTMLScriptElement&); 242 Vector<JS::Handle<HTML::HTMLScriptElement>> take_scripts_to_execute_when_parsing_has_finished(Badge<HTML::HTMLParser>); 243 Vector<JS::Handle<HTML::HTMLScriptElement>>& scripts_to_execute_when_parsing_has_finished() { return m_scripts_to_execute_when_parsing_has_finished; } 244 245 void add_script_to_execute_as_soon_as_possible(Badge<HTML::HTMLScriptElement>, HTML::HTMLScriptElement&); 246 Vector<JS::Handle<HTML::HTMLScriptElement>> take_scripts_to_execute_as_soon_as_possible(Badge<HTML::HTMLParser>); 247 Vector<JS::Handle<HTML::HTMLScriptElement>>& scripts_to_execute_as_soon_as_possible() { return m_scripts_to_execute_as_soon_as_possible; } 248 249 void add_script_to_execute_in_order_as_soon_as_possible(Badge<HTML::HTMLScriptElement>, HTML::HTMLScriptElement&); 250 Vector<JS::Handle<HTML::HTMLScriptElement>> take_scripts_to_execute_in_order_as_soon_as_possible(Badge<HTML::HTMLParser>); 251 Vector<JS::Handle<HTML::HTMLScriptElement>>& scripts_to_execute_in_order_as_soon_as_possible() { return m_scripts_to_execute_in_order_as_soon_as_possible; } 252 253 QuirksMode mode() const { return m_quirks_mode; } 254 bool in_quirks_mode() const { return m_quirks_mode == QuirksMode::Yes; } 255 void set_quirks_mode(QuirksMode mode) { m_quirks_mode = mode; } 256 257 Type document_type() const { return m_type; } 258 void set_document_type(Type type) { m_type = type; } 259 260 // https://dom.spec.whatwg.org/#html-document 261 bool is_html_document() const { return m_type == Type::HTML; } 262 263 // https://dom.spec.whatwg.org/#xml-document 264 bool is_xml_document() const { return m_type == Type::XML; } 265 266 WebIDL::ExceptionOr<JS::NonnullGCPtr<Node>> import_node(JS::NonnullGCPtr<Node> node, bool deep); 267 void adopt_node(Node&); 268 WebIDL::ExceptionOr<JS::NonnullGCPtr<Node>> adopt_node_binding(JS::NonnullGCPtr<Node>); 269 270 DocumentType const* doctype() const; 271 DeprecatedString const& compat_mode() const; 272 273 void set_editable(bool editable) { m_editable = editable; } 274 virtual bool is_editable() const final; 275 276 Element* focused_element() { return m_focused_element.ptr(); } 277 Element const* focused_element() const { return m_focused_element.ptr(); } 278 279 void set_focused_element(Element*); 280 281 Element const* active_element() const { return m_active_element.ptr(); } 282 283 void set_active_element(Element*); 284 285 bool created_for_appropriate_template_contents() const { return m_created_for_appropriate_template_contents; } 286 287 JS::NonnullGCPtr<Document> appropriate_template_contents_owner_document(); 288 289 DeprecatedString ready_state() const; 290 HTML::DocumentReadyState readiness() const { return m_readiness; }; 291 void update_readiness(HTML::DocumentReadyState); 292 293 HTML::Window& window() const { return const_cast<HTML::Window&>(*m_window); } 294 295 void set_window(Badge<HTML::BrowsingContext>, HTML::Window&); 296 297 WebIDL::ExceptionOr<void> write(Vector<DeprecatedString> const& strings); 298 WebIDL::ExceptionOr<void> writeln(Vector<DeprecatedString> const& strings); 299 300 WebIDL::ExceptionOr<Document*> open(DeprecatedString const& = "", DeprecatedString const& = ""); 301 WebIDL::ExceptionOr<JS::GCPtr<HTML::WindowProxy>> open(DeprecatedString const& url, DeprecatedString const& name, DeprecatedString const& features); 302 WebIDL::ExceptionOr<void> close(); 303 304 HTML::Window* default_view() { return m_window.ptr(); } 305 HTML::Window const* default_view() const { return m_window.ptr(); } 306 307 DeprecatedString const& content_type() const { return m_content_type; } 308 void set_content_type(DeprecatedString const& content_type) { m_content_type = content_type; } 309 310 bool has_encoding() const { return m_encoding.has_value(); } 311 Optional<DeprecatedString> const& encoding() const { return m_encoding; } 312 DeprecatedString encoding_or_default() const { return m_encoding.value_or("UTF-8"); } 313 void set_encoding(Optional<DeprecatedString> const& encoding) { m_encoding = encoding; } 314 315 // NOTE: These are intended for the JS bindings 316 DeprecatedString character_set() const { return encoding_or_default(); } 317 DeprecatedString charset() const { return encoding_or_default(); } 318 DeprecatedString input_encoding() const { return encoding_or_default(); } 319 320 bool ready_for_post_load_tasks() const { return m_ready_for_post_load_tasks; } 321 void set_ready_for_post_load_tasks(bool ready) { m_ready_for_post_load_tasks = ready; } 322 323 void completely_finish_loading(); 324 325 DOMImplementation* implementation(); 326 327 JS::GCPtr<HTML::HTMLScriptElement> current_script() const { return m_current_script.ptr(); } 328 void set_current_script(Badge<HTML::HTMLScriptElement>, JS::GCPtr<HTML::HTMLScriptElement> script) { m_current_script = move(script); } 329 330 u32 ignore_destructive_writes_counter() const { return m_ignore_destructive_writes_counter; } 331 void increment_ignore_destructive_writes_counter() { m_ignore_destructive_writes_counter++; } 332 void decrement_ignore_destructive_writes_counter() { m_ignore_destructive_writes_counter--; } 333 334 virtual EventTarget* get_parent(Event const&) override; 335 336 DeprecatedString dump_dom_tree_as_json() const; 337 338 bool has_a_style_sheet_that_is_blocking_scripts() const; 339 340 bool is_fully_active() const; 341 bool is_active() const; 342 343 JS::NonnullGCPtr<HTML::History> history(); 344 JS::NonnullGCPtr<HTML::History> history() const; 345 346 WebIDL::ExceptionOr<JS::GCPtr<HTML::Location>> location(); 347 348 size_t number_of_things_delaying_the_load_event() { return m_number_of_things_delaying_the_load_event; } 349 void increment_number_of_things_delaying_the_load_event(Badge<DocumentLoadEventDelayer>); 350 void decrement_number_of_things_delaying_the_load_event(Badge<DocumentLoadEventDelayer>); 351 352 bool page_showing() const { return m_page_showing; } 353 void set_page_showing(bool value) { m_page_showing = value; } 354 355 bool hidden() const; 356 DeprecatedString visibility_state() const; 357 358 // https://html.spec.whatwg.org/multipage/interaction.html#update-the-visibility-state 359 void update_the_visibility_state(HTML::VisibilityState); 360 361 // NOTE: This does not fire any events, unlike update_the_visibility_state(). 362 void set_visibility_state(Badge<HTML::BrowsingContext>, HTML::VisibilityState); 363 364 void run_the_resize_steps(); 365 void run_the_scroll_steps(); 366 367 void evaluate_media_queries_and_report_changes(); 368 void add_media_query_list(JS::NonnullGCPtr<CSS::MediaQueryList>); 369 370 bool has_focus() const; 371 372 void set_parser(Badge<HTML::HTMLParser>, HTML::HTMLParser&); 373 void detach_parser(Badge<HTML::HTMLParser>); 374 375 static bool is_valid_name(DeprecatedString const&); 376 377 struct PrefixAndTagName { 378 DeprecatedFlyString prefix; 379 DeprecatedFlyString tag_name; 380 }; 381 static WebIDL::ExceptionOr<PrefixAndTagName> validate_qualified_name(JS::Realm&, DeprecatedString const& qualified_name); 382 383 JS::NonnullGCPtr<NodeIterator> create_node_iterator(Node& root, unsigned what_to_show, JS::GCPtr<NodeFilter>); 384 JS::NonnullGCPtr<TreeWalker> create_tree_walker(Node& root, unsigned what_to_show, JS::GCPtr<NodeFilter>); 385 386 void register_node_iterator(Badge<NodeIterator>, NodeIterator&); 387 void unregister_node_iterator(Badge<NodeIterator>, NodeIterator&); 388 389 template<typename Callback> 390 void for_each_node_iterator(Callback callback) 391 { 392 for (auto& node_iterator : m_node_iterators) 393 callback(*node_iterator); 394 } 395 396 bool needs_full_style_update() const { return m_needs_full_style_update; } 397 void set_needs_full_style_update(bool b) { m_needs_full_style_update = b; } 398 399 bool has_active_favicon() const { return m_active_favicon; } 400 void check_favicon_after_loading_link_resource(); 401 402 // https://html.spec.whatwg.org/multipage/dom.html#is-initial-about:blank 403 bool is_initial_about_blank() const { return m_is_initial_about_blank; } 404 void set_is_initial_about_blank(bool b) { m_is_initial_about_blank = b; } 405 406 DeprecatedString domain() const; 407 void set_domain(DeprecatedString const& domain); 408 409 auto& pending_scroll_event_targets() { return m_pending_scroll_event_targets; } 410 auto& pending_scrollend_event_targets() { return m_pending_scrollend_event_targets; } 411 412 // https://html.spec.whatwg.org/#completely-loaded 413 bool is_completely_loaded() const; 414 415 // https://html.spec.whatwg.org/multipage/dom.html#concept-document-navigation-id 416 Optional<DeprecatedString> navigation_id() const; 417 void set_navigation_id(Optional<DeprecatedString>); 418 419 // https://html.spec.whatwg.org/multipage/origin.html#active-sandboxing-flag-set 420 HTML::SandboxingFlagSet active_sandboxing_flag_set() const; 421 422 // https://html.spec.whatwg.org/multipage/dom.html#concept-document-policy-container 423 HTML::PolicyContainer policy_container() const; 424 425 // https://html.spec.whatwg.org/multipage/browsers.html#list-of-the-descendant-browsing-contexts 426 Vector<JS::Handle<HTML::BrowsingContext>> list_of_descendant_browsing_contexts() const; 427 428 // https://html.spec.whatwg.org/multipage/window-object.html#discard-a-document 429 void discard(); 430 431 // https://html.spec.whatwg.org/multipage/browsing-the-web.html#abort-a-document 432 void abort(); 433 434 // https://html.spec.whatwg.org/multipage/browsing-the-web.html#unload-a-document 435 void unload(bool recursive_flag = false, Optional<DocumentUnloadTimingInfo> = {}); 436 437 // https://html.spec.whatwg.org/multipage/dom.html#active-parser 438 JS::GCPtr<HTML::HTMLParser> active_parser(); 439 440 // https://html.spec.whatwg.org/multipage/dom.html#load-timing-info 441 DocumentLoadTimingInfo& load_timing_info() { return m_load_timing_info; } 442 DocumentLoadTimingInfo const& load_timing_info() const { return m_load_timing_info; } 443 void set_load_timing_info(DocumentLoadTimingInfo const& load_timing_info) { m_load_timing_info = load_timing_info; } 444 445 // https://html.spec.whatwg.org/multipage/dom.html#previous-document-unload-timing 446 DocumentUnloadTimingInfo& previous_document_unload_timing() { return m_previous_document_unload_timing; } 447 DocumentUnloadTimingInfo const& previous_document_unload_timing() const { return m_previous_document_unload_timing; } 448 void set_previous_document_unload_timing(DocumentUnloadTimingInfo const& previous_document_unload_timing) { m_previous_document_unload_timing = previous_document_unload_timing; } 449 450 void did_stop_being_active_document_in_browsing_context(Badge<HTML::BrowsingContext>); 451 452 bool query_command_supported(DeprecatedString const&) const; 453 454 DeprecatedString dump_accessibility_tree_as_json(); 455 456protected: 457 virtual JS::ThrowCompletionOr<void> initialize(JS::Realm&) override; 458 virtual void visit_edges(Cell::Visitor&) override; 459 460private: 461 Document(JS::Realm&, AK::URL const&); 462 463 // ^HTML::GlobalEventHandlers 464 virtual EventTarget& global_event_handlers_to_event_target(DeprecatedFlyString const&) final { return *this; } 465 466 void tear_down_layout_tree(); 467 468 void evaluate_media_rules(); 469 470 WebIDL::ExceptionOr<void> run_the_document_write_steps(DeprecatedString); 471 472 size_t m_next_layout_node_serial_id { 0 }; 473 474 OwnPtr<CSS::StyleComputer> m_style_computer; 475 JS::GCPtr<CSS::StyleSheetList> m_style_sheets; 476 JS::GCPtr<Node> m_hovered_node; 477 JS::GCPtr<Node> m_inspected_node; 478 JS::GCPtr<Node> m_active_favicon; 479 WeakPtr<HTML::BrowsingContext> m_browsing_context; 480 AK::URL m_url; 481 482 JS::GCPtr<HTML::Window> m_window; 483 484 JS::GCPtr<Layout::Viewport> m_layout_root; 485 486 Optional<Color> m_link_color; 487 Optional<Color> m_active_link_color; 488 Optional<Color> m_visited_link_color; 489 490 RefPtr<Platform::Timer> m_style_update_timer; 491 RefPtr<Platform::Timer> m_layout_update_timer; 492 493 JS::GCPtr<HTML::HTMLParser> m_parser; 494 bool m_active_parser_was_aborted { false }; 495 496 DeprecatedString m_source; 497 498 JS::GCPtr<HTML::HTMLScriptElement> m_pending_parsing_blocking_script; 499 500 Vector<JS::Handle<HTML::HTMLScriptElement>> m_scripts_to_execute_when_parsing_has_finished; 501 502 // https://html.spec.whatwg.org/multipage/scripting.html#list-of-scripts-that-will-execute-in-order-as-soon-as-possible 503 Vector<JS::Handle<HTML::HTMLScriptElement>> m_scripts_to_execute_in_order_as_soon_as_possible; 504 505 // https://html.spec.whatwg.org/multipage/scripting.html#set-of-scripts-that-will-execute-as-soon-as-possible 506 Vector<JS::Handle<HTML::HTMLScriptElement>> m_scripts_to_execute_as_soon_as_possible; 507 508 QuirksMode m_quirks_mode { QuirksMode::No }; 509 510 // https://dom.spec.whatwg.org/#concept-document-type 511 Type m_type { Type::HTML }; 512 513 bool m_editable { false }; 514 515 JS::GCPtr<Element> m_focused_element; 516 JS::GCPtr<Element> m_active_element; 517 518 bool m_created_for_appropriate_template_contents { false }; 519 JS::GCPtr<Document> m_associated_inert_template_document; 520 JS::GCPtr<Document> m_appropriate_template_contents_owner_document; 521 522 HTML::DocumentReadyState m_readiness { HTML::DocumentReadyState::Loading }; 523 DeprecatedString m_content_type { "application/xml" }; 524 Optional<DeprecatedString> m_encoding; 525 526 bool m_ready_for_post_load_tasks { false }; 527 528 JS::GCPtr<DOMImplementation> m_implementation; 529 JS::GCPtr<HTML::HTMLScriptElement> m_current_script; 530 531 bool m_should_invalidate_styles_on_attribute_changes { true }; 532 533 u32 m_ignore_destructive_writes_counter { 0 }; 534 535 // https://html.spec.whatwg.org/multipage/browsing-the-web.html#unload-counter 536 u32 m_unload_counter { 0 }; 537 538 // https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#throw-on-dynamic-markup-insertion-counter 539 u32 m_throw_on_dynamic_markup_insertion_counter { 0 }; 540 541 // https://html.spec.whatwg.org/multipage/semantics.html#script-blocking-style-sheet-counter 542 u32 m_script_blocking_style_sheet_counter { 0 }; 543 544 JS::GCPtr<HTML::History> m_history; 545 546 size_t m_number_of_things_delaying_the_load_event { 0 }; 547 548 // https://html.spec.whatwg.org/multipage/browsing-the-web.html#concept-document-salvageable 549 bool m_salvageable { true }; 550 551 // https://html.spec.whatwg.org/#page-showing 552 bool m_page_showing { false }; 553 554 // Used by run_the_resize_steps(). 555 Gfx::IntSize m_last_viewport_size; 556 557 // https://w3c.github.io/csswg-drafts/cssom-view-1/#document-pending-scroll-event-targets 558 Vector<JS::NonnullGCPtr<EventTarget>> m_pending_scroll_event_targets; 559 560 // https://w3c.github.io/csswg-drafts/cssom-view-1/#document-pending-scrollend-event-targets 561 Vector<JS::NonnullGCPtr<EventTarget>> m_pending_scrollend_event_targets; 562 563 // Used by evaluate_media_queries_and_report_changes(). 564 Vector<WeakPtr<CSS::MediaQueryList>> m_media_query_lists; 565 566 bool m_needs_layout { false }; 567 568 bool m_needs_full_style_update { false }; 569 570 HashTable<NodeIterator*> m_node_iterators; 571 572 // https://html.spec.whatwg.org/multipage/dom.html#is-initial-about:blank 573 bool m_is_initial_about_blank { false }; 574 575 // https://html.spec.whatwg.org/multipage/dom.html#concept-document-coop 576 HTML::CrossOriginOpenerPolicy m_cross_origin_opener_policy; 577 578 // https://html.spec.whatwg.org/multipage/dom.html#the-document's-referrer 579 DeprecatedString m_referrer { "" }; 580 581 // https://dom.spec.whatwg.org/#concept-document-origin 582 HTML::Origin m_origin; 583 584 JS::GCPtr<HTMLCollection> m_applets; 585 JS::GCPtr<HTMLCollection> m_anchors; 586 JS::GCPtr<HTMLCollection> m_images; 587 JS::GCPtr<HTMLCollection> m_embeds; 588 JS::GCPtr<HTMLCollection> m_links; 589 JS::GCPtr<HTMLCollection> m_forms; 590 JS::GCPtr<HTMLCollection> m_scripts; 591 JS::GCPtr<HTMLCollection> m_all; 592 593 // https://html.spec.whatwg.org/#completely-loaded-time 594 Optional<AK::Time> m_completely_loaded_time; 595 596 // https://html.spec.whatwg.org/multipage/dom.html#concept-document-navigation-id 597 Optional<DeprecatedString> m_navigation_id; 598 599 // https://html.spec.whatwg.org/multipage/origin.html#active-sandboxing-flag-set 600 HTML::SandboxingFlagSet m_active_sandboxing_flag_set; 601 602 // https://html.spec.whatwg.org/multipage/dom.html#concept-document-policy-container 603 HTML::PolicyContainer m_policy_container; 604 605 // https://html.spec.whatwg.org/multipage/interaction.html#visibility-state 606 HTML::VisibilityState m_visibility_state { HTML::VisibilityState::Hidden }; 607 608 // https://html.spec.whatwg.org/multipage/dom.html#load-timing-info 609 DocumentLoadTimingInfo m_load_timing_info; 610 611 // https://html.spec.whatwg.org/multipage/dom.html#previous-document-unload-timing 612 DocumentUnloadTimingInfo m_previous_document_unload_timing; 613 614 // https://w3c.github.io/selection-api/#dfn-selection 615 JS::GCPtr<Selection::Selection> m_selection; 616 617 // NOTE: This is a cache to make finding the first <base href> element O(1). 618 JS::GCPtr<HTML::HTMLBaseElement const> m_first_base_element_with_href_in_tree_order; 619}; 620 621template<> 622inline bool Node::fast_is<Document>() const { return is_document(); } 623 624}