HTMLIFrameElement.cpp 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*
  2. * Copyright (c) 2020-2021, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibWeb/DOM/Document.h>
  7. #include <LibWeb/DOM/Event.h>
  8. #include <LibWeb/HTML/BrowsingContext.h>
  9. #include <LibWeb/HTML/HTMLIFrameElement.h>
  10. #include <LibWeb/Layout/FrameBox.h>
  11. #include <LibWeb/Origin.h>
  12. namespace Web::HTML {
  13. HTMLIFrameElement::HTMLIFrameElement(DOM::Document& document, QualifiedName qualified_name)
  14. : BrowsingContextContainer(document, move(qualified_name))
  15. {
  16. }
  17. HTMLIFrameElement::~HTMLIFrameElement()
  18. {
  19. }
  20. RefPtr<Layout::Node> HTMLIFrameElement::create_layout_node()
  21. {
  22. auto style = document().style_computer().compute_style(*this);
  23. return adopt_ref(*new Layout::FrameBox(document(), *this, move(style)));
  24. }
  25. void HTMLIFrameElement::parse_attribute(const FlyString& name, const String& value)
  26. {
  27. HTMLElement::parse_attribute(name, value);
  28. if (name == HTML::AttributeNames::src)
  29. load_src(value);
  30. }
  31. void HTMLIFrameElement::inserted()
  32. {
  33. BrowsingContextContainer::inserted();
  34. if (is_connected())
  35. load_src(attribute(HTML::AttributeNames::src));
  36. }
  37. void HTMLIFrameElement::load_src(const String& value)
  38. {
  39. if (!m_nested_browsing_context)
  40. return;
  41. if (value.is_null())
  42. return;
  43. auto url = document().parse_url(value);
  44. if (!url.is_valid()) {
  45. dbgln("iframe failed to load URL: Invalid URL: {}", value);
  46. return;
  47. }
  48. if (url.protocol() == "file" && document().origin().protocol() != "file") {
  49. dbgln("iframe failed to load URL: Security violation: {} may not load {}", document().url(), url);
  50. return;
  51. }
  52. dbgln("Loading iframe document from {}", value);
  53. m_nested_browsing_context->loader().load(url, FrameLoader::Type::IFrame);
  54. }
  55. // https://html.spec.whatwg.org/multipage/iframe-embed-object.html#iframe-load-event-steps
  56. void run_iframe_load_event_steps(HTML::HTMLIFrameElement& element)
  57. {
  58. // 1. Assert: element's nested browsing context is not null.
  59. VERIFY(element.nested_browsing_context());
  60. // 2. Let childDocument be the active document of element's nested browsing context.
  61. [[maybe_unused]] auto* child_document = element.nested_browsing_context()->active_document();
  62. // FIXME: 3. If childDocument has its mute iframe load flag set, then return.
  63. // FIXME: 4. Set childDocument's iframe load in progress flag.
  64. // 5. Fire an event named load at element.
  65. element.dispatch_event(DOM::Event::create(HTML::EventNames::load));
  66. // FIXME: 6. Unset childDocument's iframe load in progress flag.
  67. }
  68. }