HTMLIFrameElement.cpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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/HTML/HTMLIFrameElement.h>
  8. #include <LibWeb/Layout/FrameBox.h>
  9. #include <LibWeb/Origin.h>
  10. #include <LibWeb/Page/BrowsingContext.h>
  11. namespace Web::HTML {
  12. HTMLIFrameElement::HTMLIFrameElement(DOM::Document& document, QualifiedName qualified_name)
  13. : BrowsingContextContainer(document, move(qualified_name))
  14. {
  15. }
  16. HTMLIFrameElement::~HTMLIFrameElement()
  17. {
  18. }
  19. RefPtr<Layout::Node> HTMLIFrameElement::create_layout_node()
  20. {
  21. auto style = document().style_resolver().resolve_style(*this);
  22. return adopt_ref(*new Layout::FrameBox(document(), *this, move(style)));
  23. }
  24. void HTMLIFrameElement::parse_attribute(const FlyString& name, const String& value)
  25. {
  26. HTMLElement::parse_attribute(name, value);
  27. if (name == HTML::AttributeNames::src)
  28. load_src(value);
  29. }
  30. void HTMLIFrameElement::inserted()
  31. {
  32. BrowsingContextContainer::inserted();
  33. if (is_connected())
  34. load_src(attribute(HTML::AttributeNames::src));
  35. }
  36. void HTMLIFrameElement::load_src(const String& value)
  37. {
  38. if (!m_nested_browsing_context)
  39. return;
  40. if (value.is_null())
  41. return;
  42. auto url = document().parse_url(value);
  43. if (!url.is_valid()) {
  44. dbgln("iframe failed to load URL: Invalid URL: {}", value);
  45. return;
  46. }
  47. if (url.protocol() == "file" && document().origin().protocol() != "file") {
  48. dbgln("iframe failed to load URL: Security violation: {} may not load {}", document().url(), url);
  49. return;
  50. }
  51. dbgln("Loading iframe document from {}", value);
  52. m_nested_browsing_context->loader().load(url, FrameLoader::Type::IFrame);
  53. }
  54. }