2020-06-05 23:36:02 +02:00
|
|
|
/*
|
2021-04-03 11:43:08 +02:00
|
|
|
* Copyright (c) 2020-2021, Andreas Kling <kling@serenityos.org>
|
2020-06-05 23:36:02 +02:00
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-06-05 23:36:02 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <LibWeb/DOM/Document.h>
|
2020-07-26 15:08:16 +02:00
|
|
|
#include <LibWeb/HTML/HTMLIFrameElement.h>
|
2020-11-22 15:53:01 +01:00
|
|
|
#include <LibWeb/Layout/FrameBox.h>
|
2020-09-22 18:26:33 +02:00
|
|
|
#include <LibWeb/Origin.h>
|
2021-05-30 12:36:53 +02:00
|
|
|
#include <LibWeb/Page/BrowsingContext.h>
|
2020-06-05 23:36:02 +02:00
|
|
|
|
2020-07-28 18:20:36 +02:00
|
|
|
namespace Web::HTML {
|
2020-06-05 23:36:02 +02:00
|
|
|
|
2021-02-07 11:20:15 +01:00
|
|
|
HTMLIFrameElement::HTMLIFrameElement(DOM::Document& document, QualifiedName qualified_name)
|
2021-05-31 13:59:28 +01:00
|
|
|
: BrowsingContextContainer(document, move(qualified_name))
|
2020-06-05 23:36:02 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
HTMLIFrameElement::~HTMLIFrameElement()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-01-06 14:27:40 +01:00
|
|
|
RefPtr<Layout::Node> HTMLIFrameElement::create_layout_node()
|
2020-06-05 23:36:02 +02:00
|
|
|
{
|
2021-09-24 13:49:57 +02:00
|
|
|
auto style = document().style_computer().compute_style(*this);
|
2021-04-23 16:46:57 +02:00
|
|
|
return adopt_ref(*new Layout::FrameBox(document(), *this, move(style)));
|
2020-06-05 23:36:02 +02:00
|
|
|
}
|
|
|
|
|
2020-12-14 13:41:18 +01:00
|
|
|
void HTMLIFrameElement::parse_attribute(const FlyString& name, const String& value)
|
2020-06-06 15:08:36 +02:00
|
|
|
{
|
2020-12-14 13:41:18 +01:00
|
|
|
HTMLElement::parse_attribute(name, value);
|
|
|
|
if (name == HTML::AttributeNames::src)
|
|
|
|
load_src(value);
|
2020-06-05 23:36:02 +02:00
|
|
|
}
|
|
|
|
|
2021-04-06 17:58:20 +01:00
|
|
|
void HTMLIFrameElement::inserted()
|
2021-04-03 16:45:14 +02:00
|
|
|
{
|
2021-05-31 13:59:28 +01:00
|
|
|
BrowsingContextContainer::inserted();
|
2021-04-03 16:45:14 +02:00
|
|
|
if (is_connected())
|
|
|
|
load_src(attribute(HTML::AttributeNames::src));
|
|
|
|
}
|
|
|
|
|
2020-06-05 23:36:02 +02:00
|
|
|
void HTMLIFrameElement::load_src(const String& value)
|
|
|
|
{
|
2021-05-30 12:36:53 +02:00
|
|
|
if (!m_nested_browsing_context)
|
2021-04-03 16:45:14 +02:00
|
|
|
return;
|
|
|
|
|
2021-04-17 21:36:37 +02:00
|
|
|
if (value.is_null())
|
|
|
|
return;
|
|
|
|
|
2021-09-09 18:08:56 +02:00
|
|
|
auto url = document().parse_url(value);
|
2020-06-05 23:36:02 +02:00
|
|
|
if (!url.is_valid()) {
|
2021-01-17 16:57:17 +01:00
|
|
|
dbgln("iframe failed to load URL: Invalid URL: {}", value);
|
2020-11-07 09:51:22 +00:00
|
|
|
return;
|
|
|
|
}
|
2020-12-08 17:47:47 +01:00
|
|
|
if (url.protocol() == "file" && document().origin().protocol() != "file") {
|
2021-01-17 16:57:17 +01:00
|
|
|
dbgln("iframe failed to load URL: Security violation: {} may not load {}", document().url(), url);
|
2020-06-05 23:36:02 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-01-17 16:57:17 +01:00
|
|
|
dbgln("Loading iframe document from {}", value);
|
2021-05-30 12:36:53 +02:00
|
|
|
m_nested_browsing_context->loader().load(url, FrameLoader::Type::IFrame);
|
2020-06-05 23:36:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|