Document.h 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597
  1. /*
  2. * Copyright (c) 2018-2022, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/FlyString.h>
  8. #include <AK/Function.h>
  9. #include <AK/HashMap.h>
  10. #include <AK/NonnullRefPtrVector.h>
  11. #include <AK/OwnPtr.h>
  12. #include <AK/String.h>
  13. #include <AK/URL.h>
  14. #include <AK/Vector.h>
  15. #include <AK/WeakPtr.h>
  16. #include <LibCore/Forward.h>
  17. #include <LibJS/Forward.h>
  18. #include <LibWeb/CSS/CSSStyleSheet.h>
  19. #include <LibWeb/CSS/StyleComputer.h>
  20. #include <LibWeb/CSS/StyleSheetList.h>
  21. #include <LibWeb/Cookie/Cookie.h>
  22. #include <LibWeb/DOM/NonElementParentNode.h>
  23. #include <LibWeb/DOM/ParentNode.h>
  24. #include <LibWeb/HTML/BrowsingContext.h>
  25. #include <LibWeb/HTML/CrossOrigin/CrossOriginOpenerPolicy.h>
  26. #include <LibWeb/HTML/DocumentReadyState.h>
  27. #include <LibWeb/HTML/HTMLScriptElement.h>
  28. #include <LibWeb/HTML/History.h>
  29. #include <LibWeb/HTML/Origin.h>
  30. #include <LibWeb/HTML/SandboxingFlagSet.h>
  31. #include <LibWeb/HTML/Scripting/Environments.h>
  32. #include <LibWeb/HTML/VisibilityState.h>
  33. #include <LibWeb/HTML/Window.h>
  34. #include <LibWeb/WebIDL/ExceptionOr.h>
  35. namespace Web::DOM {
  36. enum class QuirksMode {
  37. No,
  38. Limited,
  39. Yes
  40. };
  41. // https://html.spec.whatwg.org/multipage/dom.html#document-load-timing-info
  42. struct DocumentLoadTimingInfo {
  43. // https://html.spec.whatwg.org/multipage/dom.html#navigation-start-time
  44. double navigation_start_time { 0 };
  45. // https://html.spec.whatwg.org/multipage/dom.html#dom-interactive-time
  46. double dom_interactive_time { 0 };
  47. // https://html.spec.whatwg.org/multipage/dom.html#dom-content-loaded-event-start-time
  48. double dom_content_loaded_event_start_time { 0 };
  49. // https://html.spec.whatwg.org/multipage/dom.html#dom-content-loaded-event-end-time
  50. double dom_content_loaded_event_end_time { 0 };
  51. // https://html.spec.whatwg.org/multipage/dom.html#dom-complete-time
  52. double dom_complete_time { 0 };
  53. // https://html.spec.whatwg.org/multipage/dom.html#load-event-start-time
  54. double load_event_start_time { 0 };
  55. // https://html.spec.whatwg.org/multipage/dom.html#load-event-end-time
  56. double load_event_end_time { 0 };
  57. };
  58. // https://html.spec.whatwg.org/multipage/dom.html#document-unload-timing-info
  59. struct DocumentUnloadTimingInfo {
  60. // https://html.spec.whatwg.org/multipage/dom.html#unload-event-start-time
  61. double unload_event_start_time { 0 };
  62. // https://html.spec.whatwg.org/multipage/dom.html#unload-event-end-time
  63. double unload_event_end_time { 0 };
  64. };
  65. class Document
  66. : public ParentNode
  67. , public NonElementParentNode<Document>
  68. , public HTML::GlobalEventHandlers {
  69. WEB_PLATFORM_OBJECT(Document, ParentNode);
  70. public:
  71. enum class Type {
  72. XML,
  73. HTML
  74. };
  75. static JS::NonnullGCPtr<Document> create_and_initialize(Type, String content_type, HTML::NavigationParams);
  76. static JS::NonnullGCPtr<Document> create(JS::Realm&, AK::URL const& url = "about:blank"sv);
  77. static JS::NonnullGCPtr<Document> construct_impl(JS::Realm&);
  78. virtual ~Document() override;
  79. size_t next_layout_node_serial_id(Badge<Layout::Node>) { return m_next_layout_node_serial_id++; }
  80. size_t layout_node_count() const { return m_next_layout_node_serial_id; }
  81. String cookie(Cookie::Source = Cookie::Source::NonHttp);
  82. void set_cookie(String const&, Cookie::Source = Cookie::Source::NonHttp);
  83. String referrer() const;
  84. void set_referrer(String);
  85. bool should_invalidate_styles_on_attribute_changes() const { return m_should_invalidate_styles_on_attribute_changes; }
  86. void set_should_invalidate_styles_on_attribute_changes(bool b) { m_should_invalidate_styles_on_attribute_changes = b; }
  87. void set_url(const AK::URL& url) { m_url = url; }
  88. AK::URL url() const { return m_url; }
  89. AK::URL fallback_base_url() const;
  90. AK::URL base_url() const;
  91. JS::GCPtr<HTML::HTMLBaseElement> first_base_element_with_href_in_tree_order() const;
  92. String url_string() const { return m_url.to_string(); }
  93. String document_uri() const { return m_url.to_string(); }
  94. HTML::Origin origin() const;
  95. void set_origin(HTML::Origin const& origin);
  96. HTML::CrossOriginOpenerPolicy const& cross_origin_opener_policy() const { return m_cross_origin_opener_policy; }
  97. void set_cross_origin_opener_policy(HTML::CrossOriginOpenerPolicy policy) { m_cross_origin_opener_policy = move(policy); }
  98. AK::URL parse_url(String const&) const;
  99. CSS::StyleComputer& style_computer() { return *m_style_computer; }
  100. const CSS::StyleComputer& style_computer() const { return *m_style_computer; }
  101. CSS::StyleSheetList& style_sheets();
  102. CSS::StyleSheetList const& style_sheets() const;
  103. CSS::StyleSheetList* style_sheets_for_bindings() { return &style_sheets(); }
  104. virtual FlyString node_name() const override { return "#document"; }
  105. void set_hovered_node(Node*);
  106. Node* hovered_node() { return m_hovered_node.ptr(); }
  107. Node const* hovered_node() const { return m_hovered_node.ptr(); }
  108. void set_inspected_node(Node*);
  109. Node* inspected_node() { return m_inspected_node.ptr(); }
  110. Node const* inspected_node() const { return m_inspected_node.ptr(); }
  111. Element* document_element();
  112. Element const* document_element() const;
  113. HTML::HTMLHtmlElement* html_element();
  114. HTML::HTMLHeadElement* head();
  115. HTML::HTMLElement* body();
  116. const HTML::HTMLHtmlElement* html_element() const
  117. {
  118. return const_cast<Document*>(this)->html_element();
  119. }
  120. const HTML::HTMLHeadElement* head() const
  121. {
  122. return const_cast<Document*>(this)->head();
  123. }
  124. const HTML::HTMLElement* body() const
  125. {
  126. return const_cast<Document*>(this)->body();
  127. }
  128. WebIDL::ExceptionOr<void> set_body(HTML::HTMLElement* new_body);
  129. String title() const;
  130. void set_title(String const&);
  131. HTML::BrowsingContext* browsing_context() { return m_browsing_context.ptr(); }
  132. HTML::BrowsingContext const* browsing_context() const { return m_browsing_context.ptr(); }
  133. void set_browsing_context(HTML::BrowsingContext*);
  134. Page* page();
  135. Page const* page() const;
  136. Color background_color(Gfx::Palette const&) const;
  137. Vector<CSS::BackgroundLayerData> const* background_layers() const;
  138. Color link_color() const;
  139. void set_link_color(Color);
  140. Color active_link_color() const;
  141. void set_active_link_color(Color);
  142. Color visited_link_color() const;
  143. void set_visited_link_color(Color);
  144. void force_layout();
  145. void update_style();
  146. void update_layout();
  147. void set_needs_layout();
  148. void invalidate_layout();
  149. void invalidate_stacking_context_tree();
  150. virtual bool is_child_allowed(Node const&) const override;
  151. Layout::InitialContainingBlock const* layout_node() const;
  152. Layout::InitialContainingBlock* layout_node();
  153. void schedule_style_update();
  154. void schedule_layout_update();
  155. JS::NonnullGCPtr<HTMLCollection> get_elements_by_name(String const&);
  156. JS::NonnullGCPtr<HTMLCollection> get_elements_by_class_name(FlyString const&);
  157. JS::NonnullGCPtr<HTMLCollection> applets();
  158. JS::NonnullGCPtr<HTMLCollection> anchors();
  159. JS::NonnullGCPtr<HTMLCollection> images();
  160. JS::NonnullGCPtr<HTMLCollection> embeds();
  161. JS::NonnullGCPtr<HTMLCollection> plugins();
  162. JS::NonnullGCPtr<HTMLCollection> links();
  163. JS::NonnullGCPtr<HTMLCollection> forms();
  164. JS::NonnullGCPtr<HTMLCollection> scripts();
  165. JS::NonnullGCPtr<HTMLCollection> all();
  166. String const& source() const { return m_source; }
  167. void set_source(String const& source) { m_source = source; }
  168. HTML::EnvironmentSettingsObject& relevant_settings_object();
  169. JS::Value run_javascript(StringView source, StringView filename = "(unknown)"sv);
  170. WebIDL::ExceptionOr<JS::NonnullGCPtr<Element>> create_element(FlyString const& local_name);
  171. WebIDL::ExceptionOr<JS::NonnullGCPtr<Element>> create_element_ns(String const& namespace_, String const& qualified_name);
  172. JS::NonnullGCPtr<DocumentFragment> create_document_fragment();
  173. JS::NonnullGCPtr<Text> create_text_node(String const& data);
  174. JS::NonnullGCPtr<Comment> create_comment(String const& data);
  175. WebIDL::ExceptionOr<JS::NonnullGCPtr<Event>> create_event(String const& interface);
  176. JS::NonnullGCPtr<Range> create_range();
  177. void set_pending_parsing_blocking_script(Badge<HTML::HTMLScriptElement>, HTML::HTMLScriptElement*);
  178. HTML::HTMLScriptElement* pending_parsing_blocking_script() { return m_pending_parsing_blocking_script.ptr(); }
  179. JS::NonnullGCPtr<HTML::HTMLScriptElement> take_pending_parsing_blocking_script(Badge<HTML::HTMLParser>);
  180. void add_script_to_execute_when_parsing_has_finished(Badge<HTML::HTMLScriptElement>, HTML::HTMLScriptElement&);
  181. Vector<JS::Handle<HTML::HTMLScriptElement>> take_scripts_to_execute_when_parsing_has_finished(Badge<HTML::HTMLParser>);
  182. Vector<JS::Handle<HTML::HTMLScriptElement>>& scripts_to_execute_when_parsing_has_finished() { return m_scripts_to_execute_when_parsing_has_finished; }
  183. void add_script_to_execute_as_soon_as_possible(Badge<HTML::HTMLScriptElement>, HTML::HTMLScriptElement&);
  184. Vector<JS::Handle<HTML::HTMLScriptElement>> take_scripts_to_execute_as_soon_as_possible(Badge<HTML::HTMLParser>);
  185. Vector<JS::Handle<HTML::HTMLScriptElement>>& scripts_to_execute_as_soon_as_possible() { return m_scripts_to_execute_as_soon_as_possible; }
  186. void add_script_to_execute_in_order_as_soon_as_possible(Badge<HTML::HTMLScriptElement>, HTML::HTMLScriptElement&);
  187. Vector<JS::Handle<HTML::HTMLScriptElement>> take_scripts_to_execute_in_order_as_soon_as_possible(Badge<HTML::HTMLParser>);
  188. 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; }
  189. QuirksMode mode() const { return m_quirks_mode; }
  190. bool in_quirks_mode() const { return m_quirks_mode == QuirksMode::Yes; }
  191. void set_quirks_mode(QuirksMode mode) { m_quirks_mode = mode; }
  192. Type document_type() const { return m_type; }
  193. void set_document_type(Type type) { m_type = type; }
  194. // https://dom.spec.whatwg.org/#xml-document
  195. bool is_xml_document() const { return m_type == Type::XML; }
  196. WebIDL::ExceptionOr<JS::NonnullGCPtr<Node>> import_node(JS::NonnullGCPtr<Node> node, bool deep);
  197. void adopt_node(Node&);
  198. WebIDL::ExceptionOr<JS::NonnullGCPtr<Node>> adopt_node_binding(JS::NonnullGCPtr<Node>);
  199. DocumentType const* doctype() const;
  200. String const& compat_mode() const;
  201. void set_editable(bool editable) { m_editable = editable; }
  202. virtual bool is_editable() const final;
  203. Element* focused_element() { return m_focused_element.ptr(); }
  204. Element const* focused_element() const { return m_focused_element.ptr(); }
  205. void set_focused_element(Element*);
  206. Element const* active_element() const { return m_active_element.ptr(); }
  207. void set_active_element(Element*);
  208. bool created_for_appropriate_template_contents() const { return m_created_for_appropriate_template_contents; }
  209. void set_created_for_appropriate_template_contents(bool value) { m_created_for_appropriate_template_contents = value; }
  210. Document* associated_inert_template_document() { return m_associated_inert_template_document.ptr(); }
  211. Document const* associated_inert_template_document() const { return m_associated_inert_template_document.ptr(); }
  212. void set_associated_inert_template_document(Document& document) { m_associated_inert_template_document = &document; }
  213. String ready_state() const;
  214. void update_readiness(HTML::DocumentReadyState);
  215. HTML::Window& window() const { return const_cast<HTML::Window&>(*m_window); }
  216. void set_window(Badge<HTML::BrowsingContext>, HTML::Window&);
  217. WebIDL::ExceptionOr<void> write(Vector<String> const& strings);
  218. WebIDL::ExceptionOr<void> writeln(Vector<String> const& strings);
  219. WebIDL::ExceptionOr<Document*> open(String const& = "", String const& = "");
  220. WebIDL::ExceptionOr<void> close();
  221. HTML::Window* default_view() { return m_window.ptr(); }
  222. String const& content_type() const { return m_content_type; }
  223. void set_content_type(String const& content_type) { m_content_type = content_type; }
  224. bool has_encoding() const { return m_encoding.has_value(); }
  225. Optional<String> const& encoding() const { return m_encoding; }
  226. String encoding_or_default() const { return m_encoding.value_or("UTF-8"); }
  227. void set_encoding(Optional<String> const& encoding) { m_encoding = encoding; }
  228. // NOTE: These are intended for the JS bindings
  229. String character_set() const { return encoding_or_default(); }
  230. String charset() const { return encoding_or_default(); }
  231. String input_encoding() const { return encoding_or_default(); }
  232. bool ready_for_post_load_tasks() const { return m_ready_for_post_load_tasks; }
  233. void set_ready_for_post_load_tasks(bool ready) { m_ready_for_post_load_tasks = ready; }
  234. void completely_finish_loading();
  235. DOMImplementation* implementation();
  236. JS::GCPtr<HTML::HTMLScriptElement> current_script() const { return m_current_script.ptr(); }
  237. void set_current_script(Badge<HTML::HTMLScriptElement>, JS::GCPtr<HTML::HTMLScriptElement> script) { m_current_script = move(script); }
  238. u32 ignore_destructive_writes_counter() const { return m_ignore_destructive_writes_counter; }
  239. void increment_ignore_destructive_writes_counter() { m_ignore_destructive_writes_counter++; }
  240. void decrement_ignore_destructive_writes_counter() { m_ignore_destructive_writes_counter--; }
  241. virtual EventTarget* get_parent(Event const&) override;
  242. String dump_dom_tree_as_json() const;
  243. bool has_a_style_sheet_that_is_blocking_scripts() const;
  244. bool is_fully_active() const;
  245. bool is_active() const;
  246. JS::NonnullGCPtr<HTML::History> history();
  247. Bindings::LocationObject* location();
  248. size_t number_of_things_delaying_the_load_event() { return m_number_of_things_delaying_the_load_event; }
  249. void increment_number_of_things_delaying_the_load_event(Badge<DocumentLoadEventDelayer>);
  250. void decrement_number_of_things_delaying_the_load_event(Badge<DocumentLoadEventDelayer>);
  251. bool page_showing() const { return m_page_showing; }
  252. void set_page_showing(bool value) { m_page_showing = value; }
  253. bool hidden() const;
  254. String visibility_state() const;
  255. // https://html.spec.whatwg.org/multipage/interaction.html#update-the-visibility-state
  256. void update_the_visibility_state(HTML::VisibilityState);
  257. // NOTE: This does not fire any events, unlike update_the_visibility_state().
  258. void set_visibility_state(Badge<HTML::BrowsingContext>, HTML::VisibilityState);
  259. void run_the_resize_steps();
  260. void run_the_scroll_steps();
  261. void evaluate_media_queries_and_report_changes();
  262. void add_media_query_list(JS::NonnullGCPtr<CSS::MediaQueryList>);
  263. bool has_focus() const;
  264. void set_parser(Badge<HTML::HTMLParser>, HTML::HTMLParser&);
  265. void detach_parser(Badge<HTML::HTMLParser>);
  266. static bool is_valid_name(String const&);
  267. struct PrefixAndTagName {
  268. FlyString prefix;
  269. FlyString tag_name;
  270. };
  271. static WebIDL::ExceptionOr<PrefixAndTagName> validate_qualified_name(JS::Realm&, String const& qualified_name);
  272. JS::NonnullGCPtr<NodeIterator> create_node_iterator(Node& root, unsigned what_to_show, JS::GCPtr<NodeFilter>);
  273. JS::NonnullGCPtr<TreeWalker> create_tree_walker(Node& root, unsigned what_to_show, JS::GCPtr<NodeFilter>);
  274. void register_node_iterator(Badge<NodeIterator>, NodeIterator&);
  275. void unregister_node_iterator(Badge<NodeIterator>, NodeIterator&);
  276. template<typename Callback>
  277. void for_each_node_iterator(Callback callback)
  278. {
  279. for (auto& node_iterator : m_node_iterators)
  280. callback(*node_iterator);
  281. }
  282. bool needs_full_style_update() const { return m_needs_full_style_update; }
  283. void set_needs_full_style_update(bool b) { m_needs_full_style_update = b; }
  284. bool has_active_favicon() const { return m_active_favicon; }
  285. void check_favicon_after_loading_link_resource();
  286. // https://html.spec.whatwg.org/multipage/dom.html#is-initial-about:blank
  287. bool is_initial_about_blank() const { return m_is_initial_about_blank; }
  288. void set_is_initial_about_blank(bool b) { m_is_initial_about_blank = b; }
  289. String domain() const;
  290. void set_domain(String const& domain);
  291. auto& pending_scroll_event_targets() { return m_pending_scroll_event_targets; }
  292. auto& pending_scrollend_event_targets() { return m_pending_scrollend_event_targets; }
  293. // https://html.spec.whatwg.org/#completely-loaded
  294. bool is_completely_loaded() const;
  295. // https://html.spec.whatwg.org/multipage/dom.html#concept-document-navigation-id
  296. Optional<String> navigation_id() const;
  297. void set_navigation_id(Optional<String>);
  298. // https://html.spec.whatwg.org/multipage/origin.html#active-sandboxing-flag-set
  299. HTML::SandboxingFlagSet active_sandboxing_flag_set() const;
  300. // https://html.spec.whatwg.org/multipage/dom.html#concept-document-policy-container
  301. HTML::PolicyContainer policy_container() const;
  302. // https://html.spec.whatwg.org/multipage/browsers.html#list-of-the-descendant-browsing-contexts
  303. Vector<NonnullRefPtr<HTML::BrowsingContext>> list_of_descendant_browsing_contexts() const;
  304. // https://html.spec.whatwg.org/multipage/window-object.html#discard-a-document
  305. void discard();
  306. // https://html.spec.whatwg.org/multipage/browsing-the-web.html#abort-a-document
  307. void abort();
  308. // https://html.spec.whatwg.org/multipage/browsing-the-web.html#unload-a-document
  309. void unload(bool recursive_flag = false, Optional<DocumentUnloadTimingInfo> = {});
  310. // https://html.spec.whatwg.org/multipage/dom.html#active-parser
  311. RefPtr<HTML::HTMLParser> active_parser();
  312. // https://html.spec.whatwg.org/multipage/dom.html#load-timing-info
  313. DocumentLoadTimingInfo& load_timing_info() { return m_load_timing_info; }
  314. DocumentLoadTimingInfo const& load_timing_info() const { return m_load_timing_info; }
  315. void set_load_timing_info(DocumentLoadTimingInfo const& load_timing_info) { m_load_timing_info = load_timing_info; }
  316. // https://html.spec.whatwg.org/multipage/dom.html#previous-document-unload-timing
  317. DocumentUnloadTimingInfo& previous_document_unload_timing() { return m_previous_document_unload_timing; }
  318. DocumentUnloadTimingInfo const& previous_document_unload_timing() const { return m_previous_document_unload_timing; }
  319. void set_previous_document_unload_timing(DocumentUnloadTimingInfo const& previous_document_unload_timing) { m_previous_document_unload_timing = previous_document_unload_timing; }
  320. protected:
  321. virtual void visit_edges(Cell::Visitor&) override;
  322. private:
  323. Document(JS::Realm&, AK::URL const&);
  324. // ^HTML::GlobalEventHandlers
  325. virtual EventTarget& global_event_handlers_to_event_target(FlyString const&) final { return *this; }
  326. void tear_down_layout_tree();
  327. void evaluate_media_rules();
  328. WebIDL::ExceptionOr<void> run_the_document_write_steps(String);
  329. size_t m_next_layout_node_serial_id { 0 };
  330. OwnPtr<CSS::StyleComputer> m_style_computer;
  331. JS::GCPtr<CSS::StyleSheetList> m_style_sheets;
  332. JS::GCPtr<Node> m_hovered_node;
  333. JS::GCPtr<Node> m_inspected_node;
  334. JS::GCPtr<Node> m_active_favicon;
  335. WeakPtr<HTML::BrowsingContext> m_browsing_context;
  336. AK::URL m_url;
  337. JS::GCPtr<HTML::Window> m_window;
  338. RefPtr<Layout::InitialContainingBlock> m_layout_root;
  339. Optional<Color> m_link_color;
  340. Optional<Color> m_active_link_color;
  341. Optional<Color> m_visited_link_color;
  342. RefPtr<Platform::Timer> m_style_update_timer;
  343. RefPtr<Platform::Timer> m_layout_update_timer;
  344. RefPtr<HTML::HTMLParser> m_parser;
  345. bool m_active_parser_was_aborted { false };
  346. String m_source;
  347. JS::GCPtr<HTML::HTMLScriptElement> m_pending_parsing_blocking_script;
  348. Vector<JS::Handle<HTML::HTMLScriptElement>> m_scripts_to_execute_when_parsing_has_finished;
  349. // https://html.spec.whatwg.org/multipage/scripting.html#list-of-scripts-that-will-execute-in-order-as-soon-as-possible
  350. Vector<JS::Handle<HTML::HTMLScriptElement>> m_scripts_to_execute_in_order_as_soon_as_possible;
  351. // https://html.spec.whatwg.org/multipage/scripting.html#set-of-scripts-that-will-execute-as-soon-as-possible
  352. Vector<JS::Handle<HTML::HTMLScriptElement>> m_scripts_to_execute_as_soon_as_possible;
  353. QuirksMode m_quirks_mode { QuirksMode::No };
  354. // https://dom.spec.whatwg.org/#concept-document-type
  355. Type m_type { Type::HTML };
  356. bool m_editable { false };
  357. JS::GCPtr<Element> m_focused_element;
  358. JS::GCPtr<Element> m_active_element;
  359. bool m_created_for_appropriate_template_contents { false };
  360. JS::GCPtr<Document> m_associated_inert_template_document;
  361. HTML::DocumentReadyState m_readiness { HTML::DocumentReadyState::Loading };
  362. String m_content_type { "application/xml" };
  363. Optional<String> m_encoding;
  364. bool m_ready_for_post_load_tasks { false };
  365. JS::GCPtr<DOMImplementation> m_implementation;
  366. JS::GCPtr<HTML::HTMLScriptElement> m_current_script;
  367. bool m_should_invalidate_styles_on_attribute_changes { true };
  368. u32 m_ignore_destructive_writes_counter { 0 };
  369. // https://html.spec.whatwg.org/multipage/browsing-the-web.html#unload-counter
  370. u32 m_unload_counter { 0 };
  371. // https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#throw-on-dynamic-markup-insertion-counter
  372. u32 m_throw_on_dynamic_markup_insertion_counter { 0 };
  373. // https://html.spec.whatwg.org/multipage/semantics.html#script-blocking-style-sheet-counter
  374. u32 m_script_blocking_style_sheet_counter { 0 };
  375. JS::GCPtr<HTML::History> m_history;
  376. size_t m_number_of_things_delaying_the_load_event { 0 };
  377. // https://html.spec.whatwg.org/multipage/browsing-the-web.html#concept-document-salvageable
  378. bool m_salvageable { true };
  379. // https://html.spec.whatwg.org/#page-showing
  380. bool m_page_showing { false };
  381. // Used by run_the_resize_steps().
  382. Gfx::IntSize m_last_viewport_size;
  383. // https://w3c.github.io/csswg-drafts/cssom-view-1/#document-pending-scroll-event-targets
  384. Vector<JS::NonnullGCPtr<EventTarget>> m_pending_scroll_event_targets;
  385. // https://w3c.github.io/csswg-drafts/cssom-view-1/#document-pending-scrollend-event-targets
  386. Vector<JS::NonnullGCPtr<EventTarget>> m_pending_scrollend_event_targets;
  387. // Used by evaluate_media_queries_and_report_changes().
  388. Vector<WeakPtr<CSS::MediaQueryList>> m_media_query_lists;
  389. bool m_needs_layout { false };
  390. bool m_needs_full_style_update { false };
  391. HashTable<NodeIterator*> m_node_iterators;
  392. // https://html.spec.whatwg.org/multipage/dom.html#is-initial-about:blank
  393. bool m_is_initial_about_blank { false };
  394. // https://html.spec.whatwg.org/multipage/dom.html#concept-document-coop
  395. HTML::CrossOriginOpenerPolicy m_cross_origin_opener_policy;
  396. // https://html.spec.whatwg.org/multipage/dom.html#the-document's-referrer
  397. String m_referrer { "" };
  398. // https://dom.spec.whatwg.org/#concept-document-origin
  399. HTML::Origin m_origin;
  400. JS::GCPtr<HTMLCollection> m_applets;
  401. JS::GCPtr<HTMLCollection> m_anchors;
  402. JS::GCPtr<HTMLCollection> m_images;
  403. JS::GCPtr<HTMLCollection> m_embeds;
  404. JS::GCPtr<HTMLCollection> m_links;
  405. JS::GCPtr<HTMLCollection> m_forms;
  406. JS::GCPtr<HTMLCollection> m_scripts;
  407. JS::GCPtr<HTMLCollection> m_all;
  408. // https://html.spec.whatwg.org/#completely-loaded-time
  409. Optional<AK::Time> m_completely_loaded_time;
  410. // https://html.spec.whatwg.org/multipage/dom.html#concept-document-navigation-id
  411. Optional<String> m_navigation_id;
  412. // https://html.spec.whatwg.org/multipage/origin.html#active-sandboxing-flag-set
  413. HTML::SandboxingFlagSet m_active_sandboxing_flag_set;
  414. // https://html.spec.whatwg.org/multipage/dom.html#concept-document-policy-container
  415. HTML::PolicyContainer m_policy_container;
  416. // https://html.spec.whatwg.org/multipage/interaction.html#visibility-state
  417. HTML::VisibilityState m_visibility_state { HTML::VisibilityState::Hidden };
  418. // https://html.spec.whatwg.org/multipage/dom.html#load-timing-info
  419. DocumentLoadTimingInfo m_load_timing_info;
  420. // https://html.spec.whatwg.org/multipage/dom.html#previous-document-unload-timing
  421. DocumentUnloadTimingInfo m_previous_document_unload_timing;
  422. };
  423. }