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