Document.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. *
  8. * 1. Redistributions of source code must retain the above copyright notice, this
  9. * list of conditions and the following disclaimer.
  10. *
  11. * 2. Redistributions in binary form must reproduce the above copyright notice,
  12. * this list of conditions and the following disclaimer in the documentation
  13. * and/or other materials provided with the distribution.
  14. *
  15. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  16. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  17. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  18. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  19. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  20. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  21. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  22. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  23. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  24. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25. */
  26. #include <AK/StringBuilder.h>
  27. #include <AK/Utf8View.h>
  28. #include <LibCore/Timer.h>
  29. #include <LibGUI/Application.h>
  30. #include <LibGUI/DisplayLink.h>
  31. #include <LibGUI/MessageBox.h>
  32. #include <LibJS/Interpreter.h>
  33. #include <LibJS/Parser.h>
  34. #include <LibJS/Runtime/Function.h>
  35. #include <LibWeb/Bindings/DocumentWrapper.h>
  36. #include <LibWeb/Bindings/WindowObject.h>
  37. #include <LibWeb/CSS/StyleResolver.h>
  38. #include <LibWeb/DOM/Comment.h>
  39. #include <LibWeb/DOM/Document.h>
  40. #include <LibWeb/DOM/DocumentFragment.h>
  41. #include <LibWeb/DOM/DocumentType.h>
  42. #include <LibWeb/DOM/Element.h>
  43. #include <LibWeb/DOM/ElementFactory.h>
  44. #include <LibWeb/DOM/Event.h>
  45. #include <LibWeb/DOM/Text.h>
  46. #include <LibWeb/DOM/Window.h>
  47. #include <LibWeb/Dump.h>
  48. #include <LibWeb/HTML/AttributeNames.h>
  49. #include <LibWeb/HTML/EventNames.h>
  50. #include <LibWeb/HTML/HTMLBodyElement.h>
  51. #include <LibWeb/HTML/HTMLFrameSetElement.h>
  52. #include <LibWeb/HTML/HTMLHeadElement.h>
  53. #include <LibWeb/HTML/HTMLHtmlElement.h>
  54. #include <LibWeb/HTML/HTMLScriptElement.h>
  55. #include <LibWeb/HTML/HTMLTitleElement.h>
  56. #include <LibWeb/InProcessWebView.h>
  57. #include <LibWeb/Layout/BlockFormattingContext.h>
  58. #include <LibWeb/Layout/InitialContainingBlockBox.h>
  59. #include <LibWeb/Layout/TreeBuilder.h>
  60. #include <LibWeb/Namespace.h>
  61. #include <LibWeb/Origin.h>
  62. #include <LibWeb/Page/Frame.h>
  63. #include <LibWeb/SVG/TagNames.h>
  64. #include <ctype.h>
  65. #include <stdio.h>
  66. namespace Web::DOM {
  67. Document::Document(const URL& url)
  68. : ParentNode(*this, NodeType::DOCUMENT_NODE)
  69. , m_style_resolver(make<CSS::StyleResolver>(*this))
  70. , m_style_sheets(CSS::StyleSheetList::create(*this))
  71. , m_url(url)
  72. , m_window(Window::create_with_document(*this))
  73. , m_implementation(DOMImplementation::create(*this))
  74. {
  75. m_style_update_timer = Core::Timer::create_single_shot(0, [this] {
  76. update_style();
  77. });
  78. }
  79. Document::~Document()
  80. {
  81. }
  82. void Document::removed_last_ref()
  83. {
  84. ASSERT(!ref_count());
  85. ASSERT(!m_deletion_has_begun);
  86. if (m_referencing_node_count) {
  87. // The document has reached ref_count==0 but still has nodes keeping it alive.
  88. // At this point, sever all the node links we control.
  89. // If nodes remain elsewhere (e.g JS wrappers), they will keep the document alive.
  90. // NOTE: This makes sure we stay alive across for the duration of the cleanup below.
  91. increment_referencing_node_count();
  92. m_focused_element = nullptr;
  93. m_hovered_node = nullptr;
  94. m_pending_parsing_blocking_script = nullptr;
  95. m_inspected_node = nullptr;
  96. m_scripts_to_execute_when_parsing_has_finished.clear();
  97. m_scripts_to_execute_as_soon_as_possible.clear();
  98. m_associated_inert_template_document = nullptr;
  99. m_interpreter = nullptr;
  100. {
  101. // Gather up all the descendants of this document and prune them from the tree.
  102. // FIXME: This could definitely be more elegant.
  103. NonnullRefPtrVector<Node> descendants;
  104. for_each_in_subtree([&](auto& node) {
  105. if (&node != this)
  106. descendants.append(node);
  107. return IterationDecision::Continue;
  108. });
  109. for (auto& node : descendants) {
  110. ASSERT(&node.document() == this);
  111. ASSERT(!node.is_document());
  112. if (node.parent())
  113. node.parent()->remove_child(node);
  114. }
  115. }
  116. m_in_removed_last_ref = false;
  117. decrement_referencing_node_count();
  118. return;
  119. }
  120. m_in_removed_last_ref = false;
  121. m_deletion_has_begun = true;
  122. delete this;
  123. }
  124. Origin Document::origin() const
  125. {
  126. if (!m_url.is_valid())
  127. return {};
  128. return { m_url.protocol(), m_url.host(), m_url.port() };
  129. }
  130. void Document::set_origin(const Origin& origin)
  131. {
  132. m_url.set_protocol(origin.protocol());
  133. m_url.set_host(origin.host());
  134. m_url.set_port(origin.port());
  135. }
  136. void Document::schedule_style_update()
  137. {
  138. if (m_style_update_timer->is_active())
  139. return;
  140. m_style_update_timer->start();
  141. }
  142. bool Document::is_child_allowed(const Node& node) const
  143. {
  144. switch (node.type()) {
  145. case NodeType::DOCUMENT_NODE:
  146. case NodeType::TEXT_NODE:
  147. return false;
  148. case NodeType::COMMENT_NODE:
  149. return true;
  150. case NodeType::DOCUMENT_TYPE_NODE:
  151. return !first_child_of_type<DocumentType>();
  152. case NodeType::ELEMENT_NODE:
  153. return !first_child_of_type<Element>();
  154. default:
  155. return false;
  156. }
  157. }
  158. const Element* Document::document_element() const
  159. {
  160. return first_child_of_type<Element>();
  161. }
  162. const HTML::HTMLHtmlElement* Document::html_element() const
  163. {
  164. auto* html = document_element();
  165. if (is<HTML::HTMLHtmlElement>(html))
  166. return downcast<HTML::HTMLHtmlElement>(html);
  167. return nullptr;
  168. }
  169. const HTML::HTMLHeadElement* Document::head() const
  170. {
  171. auto* html = html_element();
  172. if (!html)
  173. return nullptr;
  174. return html->first_child_of_type<HTML::HTMLHeadElement>();
  175. }
  176. const HTML::HTMLElement* Document::body() const
  177. {
  178. auto* html = html_element();
  179. if (!html)
  180. return nullptr;
  181. auto* first_body = html->first_child_of_type<HTML::HTMLBodyElement>();
  182. if (first_body)
  183. return first_body;
  184. auto* first_frameset = html->first_child_of_type<HTML::HTMLFrameSetElement>();
  185. if (first_frameset)
  186. return first_frameset;
  187. return nullptr;
  188. }
  189. void Document::set_body(HTML::HTMLElement& new_body)
  190. {
  191. if (!is<HTML::HTMLBodyElement>(new_body) && !is<HTML::HTMLFrameSetElement>(new_body)) {
  192. // FIXME: throw a "HierarchyRequestError" DOMException.
  193. return;
  194. }
  195. auto* existing_body = body();
  196. if (existing_body) {
  197. TODO();
  198. return;
  199. }
  200. auto* html = document_element();
  201. if (!html) {
  202. // FIXME: throw a "HierarchyRequestError" DOMException.
  203. return;
  204. }
  205. // FIXME: Implement this once there's a non-const first_child_of_type:
  206. // "Otherwise, the body element is null, but there's a document element. Append the new value to the document element."
  207. TODO();
  208. }
  209. String Document::title() const
  210. {
  211. auto* head_element = head();
  212. if (!head_element)
  213. return {};
  214. auto* title_element = head_element->first_child_of_type<HTML::HTMLTitleElement>();
  215. if (!title_element)
  216. return {};
  217. auto raw_title = title_element->text_content();
  218. StringBuilder builder;
  219. bool last_was_space = false;
  220. for (auto code_point : Utf8View(raw_title)) {
  221. if (isspace(code_point)) {
  222. last_was_space = true;
  223. } else {
  224. if (last_was_space && !builder.is_empty())
  225. builder.append(' ');
  226. builder.append_code_point(code_point);
  227. last_was_space = false;
  228. }
  229. }
  230. return builder.to_string();
  231. }
  232. void Document::set_title(const String& title)
  233. {
  234. auto* head_element = const_cast<HTML::HTMLHeadElement*>(head());
  235. if (!head_element)
  236. return;
  237. RefPtr<HTML::HTMLTitleElement> title_element = head_element->first_child_of_type<HTML::HTMLTitleElement>();
  238. if (!title_element) {
  239. title_element = static_ptr_cast<HTML::HTMLTitleElement>(create_element(HTML::TagNames::title));
  240. head_element->append_child(*title_element);
  241. }
  242. while (RefPtr<Node> child = title_element->first_child())
  243. title_element->remove_child(child.release_nonnull());
  244. title_element->append_child(adopt(*new Text(*this, title)));
  245. if (auto* page = this->page())
  246. page->client().page_did_change_title(title);
  247. }
  248. void Document::attach_to_frame(Badge<Frame>, Frame& frame)
  249. {
  250. m_frame = frame;
  251. for_each_in_subtree([&](auto& node) {
  252. node.document_did_attach_to_frame(frame);
  253. return IterationDecision::Continue;
  254. });
  255. layout();
  256. }
  257. void Document::detach_from_frame(Badge<Frame>, Frame& frame)
  258. {
  259. for_each_in_subtree([&](auto& node) {
  260. node.document_will_detach_from_frame(frame);
  261. return IterationDecision::Continue;
  262. });
  263. tear_down_layout_tree();
  264. m_frame = nullptr;
  265. }
  266. void Document::tear_down_layout_tree()
  267. {
  268. if (!m_layout_root)
  269. return;
  270. // Gather up all the layout nodes in a vector and detach them from parents
  271. // while the vector keeps them alive.
  272. NonnullRefPtrVector<Layout::Node> layout_nodes;
  273. m_layout_root->for_each_in_subtree([&](auto& layout_node) {
  274. layout_nodes.append(layout_node);
  275. return IterationDecision::Continue;
  276. });
  277. for (auto& layout_node : layout_nodes) {
  278. if (layout_node.parent())
  279. layout_node.parent()->remove_child(layout_node);
  280. }
  281. m_layout_root = nullptr;
  282. }
  283. Color Document::background_color(const Palette& palette) const
  284. {
  285. auto default_color = palette.base();
  286. auto* body_element = body();
  287. if (!body_element)
  288. return default_color;
  289. auto* body_layout_node = body_element->layout_node();
  290. if (!body_layout_node)
  291. return default_color;
  292. auto background_color = body_layout_node->specified_style().property(CSS::PropertyID::BackgroundColor);
  293. if (!background_color.has_value() || !background_color.value()->is_color())
  294. return default_color;
  295. return background_color.value()->to_color(*this);
  296. }
  297. RefPtr<Gfx::Bitmap> Document::background_image() const
  298. {
  299. auto* body_element = body();
  300. if (!body_element)
  301. return {};
  302. auto* body_layout_node = body_element->layout_node();
  303. if (!body_layout_node)
  304. return {};
  305. auto background_image = body_layout_node->specified_style().property(CSS::PropertyID::BackgroundImage);
  306. if (!background_image.has_value() || !background_image.value()->is_image())
  307. return {};
  308. auto& image_value = static_cast<const CSS::ImageStyleValue&>(*background_image.value());
  309. if (!image_value.bitmap())
  310. return {};
  311. return *image_value.bitmap();
  312. }
  313. URL Document::complete_url(const String& string) const
  314. {
  315. return m_url.complete_url(string);
  316. }
  317. void Document::invalidate_layout()
  318. {
  319. tear_down_layout_tree();
  320. }
  321. void Document::force_layout()
  322. {
  323. invalidate_layout();
  324. layout();
  325. }
  326. void Document::layout()
  327. {
  328. if (!frame())
  329. return;
  330. if (!m_layout_root) {
  331. Layout::TreeBuilder tree_builder;
  332. m_layout_root = static_ptr_cast<Layout::InitialContainingBlockBox>(tree_builder.build(*this));
  333. }
  334. Layout::BlockFormattingContext root_formatting_context(*m_layout_root, nullptr);
  335. root_formatting_context.run(*m_layout_root, Layout::LayoutMode::Default);
  336. m_layout_root->set_needs_display();
  337. if (frame()->is_main_frame()) {
  338. if (auto* page = this->page())
  339. page->client().page_did_layout();
  340. }
  341. }
  342. void Document::update_style()
  343. {
  344. for_each_in_subtree_of_type<Element>([&](auto& element) {
  345. if (element.needs_style_update())
  346. element.recompute_style();
  347. return IterationDecision::Continue;
  348. });
  349. update_layout();
  350. }
  351. void Document::update_layout()
  352. {
  353. if (!frame())
  354. return;
  355. layout();
  356. }
  357. RefPtr<Layout::Node> Document::create_layout_node(const CSS::StyleProperties*)
  358. {
  359. return adopt(*new Layout::InitialContainingBlockBox(*this, CSS::StyleProperties::create()));
  360. }
  361. void Document::set_link_color(Color color)
  362. {
  363. m_link_color = color;
  364. }
  365. void Document::set_active_link_color(Color color)
  366. {
  367. m_active_link_color = color;
  368. }
  369. void Document::set_visited_link_color(Color color)
  370. {
  371. m_visited_link_color = color;
  372. }
  373. const Layout::InitialContainingBlockBox* Document::layout_node() const
  374. {
  375. return static_cast<const Layout::InitialContainingBlockBox*>(Node::layout_node());
  376. }
  377. Layout::InitialContainingBlockBox* Document::layout_node()
  378. {
  379. return static_cast<Layout::InitialContainingBlockBox*>(Node::layout_node());
  380. }
  381. void Document::set_inspected_node(Node* node)
  382. {
  383. if (m_inspected_node == node)
  384. return;
  385. if (m_inspected_node && m_inspected_node->layout_node())
  386. m_inspected_node->layout_node()->set_needs_display();
  387. m_inspected_node = node;
  388. if (m_inspected_node && m_inspected_node->layout_node())
  389. m_inspected_node->layout_node()->set_needs_display();
  390. }
  391. void Document::set_hovered_node(Node* node)
  392. {
  393. if (m_hovered_node == node)
  394. return;
  395. RefPtr<Node> old_hovered_node = move(m_hovered_node);
  396. m_hovered_node = node;
  397. invalidate_style();
  398. }
  399. NonnullRefPtrVector<Element> Document::get_elements_by_name(const String& name) const
  400. {
  401. NonnullRefPtrVector<Element> elements;
  402. for_each_in_subtree_of_type<Element>([&](auto& element) {
  403. if (element.attribute(HTML::AttributeNames::name) == name)
  404. elements.append(element);
  405. return IterationDecision::Continue;
  406. });
  407. return elements;
  408. }
  409. NonnullRefPtrVector<Element> Document::get_elements_by_tag_name(const FlyString& tag_name) const
  410. {
  411. NonnullRefPtrVector<Element> elements;
  412. for_each_in_subtree_of_type<Element>([&](auto& element) {
  413. if (element.local_name() == tag_name)
  414. elements.append(element);
  415. return IterationDecision::Continue;
  416. });
  417. return elements;
  418. }
  419. NonnullRefPtrVector<Element> Document::get_elements_by_class_name(const FlyString& class_name) const
  420. {
  421. NonnullRefPtrVector<Element> elements;
  422. for_each_in_subtree_of_type<Element>([&](auto& element) {
  423. if (element.has_class(class_name))
  424. elements.append(element);
  425. return IterationDecision::Continue;
  426. });
  427. return elements;
  428. }
  429. Color Document::link_color() const
  430. {
  431. if (m_link_color.has_value())
  432. return m_link_color.value();
  433. if (!page())
  434. return Color::Blue;
  435. return page()->palette().link();
  436. }
  437. Color Document::active_link_color() const
  438. {
  439. if (m_active_link_color.has_value())
  440. return m_active_link_color.value();
  441. if (!page())
  442. return Color::Red;
  443. return page()->palette().active_link();
  444. }
  445. Color Document::visited_link_color() const
  446. {
  447. if (m_visited_link_color.has_value())
  448. return m_visited_link_color.value();
  449. if (!page())
  450. return Color::Magenta;
  451. return page()->palette().visited_link();
  452. }
  453. static JS::VM& main_thread_vm()
  454. {
  455. static RefPtr<JS::VM> vm;
  456. if (!vm) {
  457. vm = JS::VM::create();
  458. vm->set_should_log_exceptions(true);
  459. }
  460. return *vm;
  461. }
  462. JS::Interpreter& Document::interpreter()
  463. {
  464. if (!m_interpreter)
  465. m_interpreter = JS::Interpreter::create<Bindings::WindowObject>(main_thread_vm(), *m_window);
  466. return *m_interpreter;
  467. }
  468. JS::Value Document::run_javascript(const StringView& source)
  469. {
  470. auto parser = JS::Parser(JS::Lexer(source));
  471. auto program = parser.parse_program();
  472. if (parser.has_errors()) {
  473. parser.print_errors();
  474. return JS::js_undefined();
  475. }
  476. auto& interpreter = document().interpreter();
  477. auto result = interpreter.run(interpreter.global_object(), *program);
  478. if (interpreter.exception())
  479. interpreter.vm().clear_exception();
  480. return result;
  481. }
  482. NonnullRefPtr<Element> Document::create_element(const String& tag_name)
  483. {
  484. // FIXME: Let namespace be the HTML namespace, if this is an HTML document or this’s content type is "application/xhtml+xml", and null otherwise.
  485. return DOM::create_element(*this, tag_name, Namespace::HTML);
  486. }
  487. NonnullRefPtr<DocumentFragment> Document::create_document_fragment()
  488. {
  489. return adopt(*new DocumentFragment(*this));
  490. }
  491. NonnullRefPtr<Text> Document::create_text_node(const String& data)
  492. {
  493. return adopt(*new Text(*this, data));
  494. }
  495. NonnullRefPtr<Comment> Document::create_comment(const String& data)
  496. {
  497. return adopt(*new Comment(*this, data));
  498. }
  499. void Document::set_pending_parsing_blocking_script(Badge<HTML::HTMLScriptElement>, HTML::HTMLScriptElement* script)
  500. {
  501. m_pending_parsing_blocking_script = script;
  502. }
  503. NonnullRefPtr<HTML::HTMLScriptElement> Document::take_pending_parsing_blocking_script(Badge<HTML::HTMLDocumentParser>)
  504. {
  505. return m_pending_parsing_blocking_script.release_nonnull();
  506. }
  507. void Document::add_script_to_execute_when_parsing_has_finished(Badge<HTML::HTMLScriptElement>, HTML::HTMLScriptElement& script)
  508. {
  509. m_scripts_to_execute_when_parsing_has_finished.append(script);
  510. }
  511. NonnullRefPtrVector<HTML::HTMLScriptElement> Document::take_scripts_to_execute_when_parsing_has_finished(Badge<HTML::HTMLDocumentParser>)
  512. {
  513. return move(m_scripts_to_execute_when_parsing_has_finished);
  514. }
  515. void Document::add_script_to_execute_as_soon_as_possible(Badge<HTML::HTMLScriptElement>, HTML::HTMLScriptElement& script)
  516. {
  517. m_scripts_to_execute_as_soon_as_possible.append(script);
  518. }
  519. NonnullRefPtrVector<HTML::HTMLScriptElement> Document::take_scripts_to_execute_as_soon_as_possible(Badge<HTML::HTMLDocumentParser>)
  520. {
  521. return move(m_scripts_to_execute_as_soon_as_possible);
  522. }
  523. void Document::adopt_node(Node& subtree_root)
  524. {
  525. subtree_root.for_each_in_subtree([&](auto& node) {
  526. node.set_document({}, *this);
  527. return IterationDecision::Continue;
  528. });
  529. }
  530. const DocumentType* Document::doctype() const
  531. {
  532. return first_child_of_type<DocumentType>();
  533. }
  534. const String& Document::compat_mode() const
  535. {
  536. static String back_compat = "BackCompat";
  537. static String css1_compat = "CSS1Compat";
  538. if (m_quirks_mode == QuirksMode::Yes)
  539. return back_compat;
  540. return css1_compat;
  541. }
  542. bool Document::is_editable() const
  543. {
  544. return m_editable;
  545. }
  546. void Document::set_focused_element(Element* element)
  547. {
  548. if (m_focused_element == element)
  549. return;
  550. m_focused_element = element;
  551. if (m_layout_root)
  552. m_layout_root->set_needs_display();
  553. }
  554. void Document::set_ready_state(const String& ready_state)
  555. {
  556. m_ready_state = ready_state;
  557. dispatch_event(Event::create(HTML::EventNames::readystatechange));
  558. }
  559. Page* Document::page()
  560. {
  561. return m_frame ? m_frame->page() : nullptr;
  562. }
  563. const Page* Document::page() const
  564. {
  565. return m_frame ? m_frame->page() : nullptr;
  566. }
  567. EventTarget* Document::get_parent(const Event& event)
  568. {
  569. if (event.type() == HTML::EventNames::load)
  570. return nullptr;
  571. return &window();
  572. }
  573. void Document::completely_finish_loading()
  574. {
  575. // FIXME: This needs to handle iframes.
  576. dispatch_event(DOM::Event::create(HTML::EventNames::load));
  577. }
  578. }