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>
2021-09-26 02:25:02 +02:00
# include <LibWeb/DOM/Event.h>
2021-11-18 15:01:28 +01:00
# include <LibWeb/HTML/BrowsingContext.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>
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
2022-02-18 21:00:52 +01:00
HTMLIFrameElement : : HTMLIFrameElement ( DOM : : Document & document , DOM : : QualifiedName qualified_name )
2021-05-31 13:59:28 +01:00
: BrowsingContextContainer ( document , move ( qualified_name ) )
2020-06-05 23:36:02 +02:00
{
}
2022-03-14 13:21:51 -06:00
HTMLIFrameElement : : ~ HTMLIFrameElement ( ) = default ;
2020-06-05 23:36:02 +02:00
2022-02-05 13:17:01 +01:00
RefPtr < Layout : : Node > HTMLIFrameElement : : create_layout_node ( NonnullRefPtr < CSS : : StyleProperties > style )
2020-06-05 23:36:02 +02:00
{
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
}
2022-04-01 20:58:27 +03:00
void HTMLIFrameElement : : parse_attribute ( FlyString const & name , String const & 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
}
2022-03-23 20:13:34 -04:00
// https://html.spec.whatwg.org/multipage/iframe-embed-object.html#the-iframe-element:the-iframe-element-6
2021-04-06 17:58:20 +01:00
void HTMLIFrameElement : : inserted ( )
2021-04-03 16:45:14 +02:00
{
2022-03-23 20:13:34 -04:00
HTMLElement : : inserted ( ) ;
if ( ! is_connected ( ) )
return ;
// 1. Create a new nested browsing context for element.
create_new_nested_browsing_context ( ) ;
// 2. FIXME: If element has a sandbox attribute, then parse the sandboxing directive given the attribute's value and element's iframe sandboxing flag set.
// 3. Process the iframe attributes for element, with initialInsertion set to true.
load_src ( attribute ( HTML : : AttributeNames : : src ) ) ;
}
// https://html.spec.whatwg.org/multipage/iframe-embed-object.html#the-iframe-element:the-iframe-element-7
void HTMLIFrameElement : : removed_from ( DOM : : Node * node )
{
HTMLElement : : removed_from ( node ) ;
discard_nested_browsing_context ( ) ;
2021-04-03 16:45:14 +02:00
}
2022-04-01 20:58:27 +03:00
void HTMLIFrameElement : : load_src ( String const & value )
2020-06-05 23:36:02 +02:00
{
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
}
2021-09-26 02:25:02 +02: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 23:36:02 +02:00
}