HTMLIFrameElement.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * Copyright (c) 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 <LibCore/ElapsedTimer.h>
  27. #include <LibGUI/Button.h>
  28. #include <LibGUI/TextBox.h>
  29. #include <LibWeb/DOM/Document.h>
  30. #include <LibWeb/DOM/Event.h>
  31. #include <LibWeb/DOM/HTMLFormElement.h>
  32. #include <LibWeb/DOM/HTMLIFrameElement.h>
  33. #include <LibWeb/Dump.h>
  34. #include <LibWeb/Frame/Frame.h>
  35. #include <LibWeb/Layout/LayoutFrame.h>
  36. #include <LibWeb/Layout/LayoutWidget.h>
  37. #include <LibWeb/Loader/ResourceLoader.h>
  38. #include <LibWeb/PageView.h>
  39. #include <LibWeb/Parser/HTMLDocumentParser.h>
  40. namespace Web {
  41. HTMLIFrameElement::HTMLIFrameElement(Document& document, const FlyString& tag_name)
  42. : HTMLElement(document, tag_name)
  43. {
  44. }
  45. HTMLIFrameElement::~HTMLIFrameElement()
  46. {
  47. }
  48. RefPtr<LayoutNode> HTMLIFrameElement::create_layout_node(const StyleProperties* parent_style) const
  49. {
  50. auto style = document().style_resolver().resolve_style(*this, parent_style);
  51. return adopt(*new LayoutFrame(*this, move(style)));
  52. }
  53. void HTMLIFrameElement::document_did_attach_to_frame(Frame& frame)
  54. {
  55. ASSERT(!m_hosted_frame);
  56. m_hosted_frame = Frame::create_subframe(*this, frame.main_frame());
  57. auto src = attribute(HTML::AttributeNames::src);
  58. if (src.is_null())
  59. return;
  60. load_src(src);
  61. }
  62. void HTMLIFrameElement::document_will_detach_from_frame(Frame&)
  63. {
  64. }
  65. void HTMLIFrameElement::load_src(const String& value)
  66. {
  67. dbg() << "Loading iframe document from " << value;
  68. auto url = document().complete_url(value);
  69. if (!url.is_valid()) {
  70. dbg() << "Actually no I'm not, because the URL is not valid :(";
  71. return;
  72. }
  73. m_hosted_frame->loader().load(url);
  74. }
  75. const Document* HTMLIFrameElement::hosted_document() const
  76. {
  77. return m_hosted_frame ? m_hosted_frame->document() : nullptr;
  78. }
  79. }