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>
2022-07-12 20:37:43 +01:00
# include <LibWeb/HTML/Origin.h>
2022-10-10 17:22:30 +01:00
# include <LibWeb/HTML/Parser/HTMLParser.h>
2020-11-22 15:53:01 +01:00
# include <LibWeb/Layout/FrameBox.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 )
2022-12-12 12:20:02 +01:00
: NavigableContainer ( 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
2023-08-07 08:41:28 +02:00
void HTMLIFrameElement : : initialize ( JS : : Realm & realm )
2023-01-10 06:28:20 -05:00
{
2023-08-07 08:41:28 +02:00
Base : : initialize ( realm ) ;
2023-01-10 06:28:20 -05:00
set_prototype ( & Bindings : : ensure_web_prototype < Bindings : : HTMLIFrameElementPrototype > ( realm , " HTMLIFrameElement " ) ) ;
}
2022-10-17 14:41:50 +02:00
JS : : GCPtr < Layout : : Node > HTMLIFrameElement : : create_layout_node ( NonnullRefPtr < CSS : : StyleProperties > style )
2020-06-05 23:36:02 +02:00
{
2022-10-17 14:41:50 +02:00
return heap ( ) . allocate_without_realm < Layout : : FrameBox > ( document ( ) , * this , move ( style ) ) ;
2020-06-05 23:36:02 +02:00
}
2023-07-03 17:08:37 +02:00
void HTMLIFrameElement : : attribute_changed ( DeprecatedFlyString const & name , DeprecatedString const & value )
2020-06-06 15:08:36 +02:00
{
2023-07-03 17:08:37 +02:00
HTMLElement : : attribute_changed ( name , value ) ;
2023-08-25 13:39:32 +02:00
if ( m_nested_browsing_context )
process_the_iframe_attributes ( ) ;
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 ( ) ;
2022-09-19 12:33:05 +02:00
// When an iframe element element is inserted into a document whose browsing context is non-null, the user agent must run these steps:
if ( document ( ) . browsing_context ( ) ) {
// 1. Create a new nested browsing context for element.
create_new_nested_browsing_context ( ) ;
2022-03-23 20:13:34 -04:00
2022-09-19 12:33:05 +02:00
// FIXME: 2. If element has a sandbox attribute, then parse the sandboxing directive given the attribute's value and element's iframe sandboxing flag set.
2022-03-23 20:13:34 -04:00
2022-09-19 12:33:05 +02:00
// 3. Process the iframe attributes for element, with initialInsertion set to true.
2022-09-19 13:34:36 +02:00
process_the_iframe_attributes ( true ) ;
2022-09-19 12:33:05 +02:00
}
2022-03-23 20:13:34 -04:00
}
2022-09-19 13:34:36 +02:00
// https://html.spec.whatwg.org/multipage/urls-and-fetching.html#will-lazy-load-element-steps
bool HTMLIFrameElement : : will_lazy_load_element ( ) const
{
// 1. If scripting is disabled for element, then return false.
if ( document ( ) . is_scripting_disabled ( ) )
return false ;
// FIXME: 2. If element's lazy loading attribute is in the Lazy state, then return true.
// 3. Return false.
return false ;
}
// https://html.spec.whatwg.org/multipage/iframe-embed-object.html#process-the-iframe-attributes
void HTMLIFrameElement : : process_the_iframe_attributes ( bool initial_insertion )
{
// 1. If element's srcdoc attribute is specified, then:
if ( has_attribute ( HTML : : AttributeNames : : srcdoc ) ) {
// 2. Set element's current navigation was lazy loaded boolean to false.
m_current_navigation_was_lazy_loaded = false ;
// 3. If the will lazy load element steps given element return true, then:
if ( will_lazy_load_element ( ) ) {
// FIXME: 1. Set element's lazy load resumption steps to the rest of this algorithm starting with the step labeled navigate to the srcdoc resource.
// FIXME: 2. Set element's current navigation was lazy loaded boolean to true.
// FIXME: 3. Start intersection-observing a lazy loading element for element.
// FIXME: 4. Return.
}
// FIXME: 4. Navigate to the srcdoc resource: navigate an iframe or frame given element and a new response whose URL list is « about:srcdoc », header list is « (`Content-Type`, `text/html`) », and body is the value of element's srcdoc attribute.
// FIXME: The resulting Document must be considered an iframe srcdoc document.
return ;
}
// 2. Otherwise, run the shared attribute processing steps for iframe and frame elements given element and initialInsertion.
shared_attribute_processing_steps_for_iframe_and_frame ( initial_insertion ) ;
}
2022-03-23 20:13:34 -04:00
// 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 ) ;
2022-09-20 21:44:42 +02:00
// When an iframe element is removed from a document, the user agent must discard the element's nested browsing context,
// if it is not null, and then set the element's nested browsing context to null.
if ( m_nested_browsing_context ) {
m_nested_browsing_context - > discard ( ) ;
m_nested_browsing_context = nullptr ;
}
2021-04-03 16:45:14 +02:00
}
2022-10-10 17:22:30 +01:00
// https://html.spec.whatwg.org/multipage/rendering.html#attributes-for-embedded-content-and-images
void HTMLIFrameElement : : apply_presentational_hints ( CSS : : StyleProperties & style ) const
{
for_each_attribute ( [ & ] ( auto & name , auto & value ) {
if ( name = = HTML : : AttributeNames : : width ) {
if ( auto parsed_value = parse_dimension_value ( value ) )
style . set_property ( CSS : : PropertyID : : Width , parsed_value . release_nonnull ( ) ) ;
} else if ( name = = HTML : : AttributeNames : : height ) {
if ( auto parsed_value = parse_dimension_value ( value ) )
style . set_property ( CSS : : PropertyID : : Height , parsed_value . release_nonnull ( ) ) ;
}
} ) ;
}
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 )
{
2022-09-20 21:44:42 +02:00
// FIXME: 1. Assert: element's nested browsing context is not null.
if ( ! element . nested_browsing_context ( ) ) {
// FIXME: For some reason, we sometimes end up here in the middle of SunSpider.
dbgln ( " FIXME: run_iframe_load_event_steps called with null nested browsing context " ) ;
return ;
}
2021-09-26 02:25:02 +02:00
// 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.
2023-08-13 13:05:26 +02:00
element . dispatch_event ( DOM : : Event : : create ( element . realm ( ) , HTML : : EventNames : : load ) ) ;
2021-09-26 02:25:02 +02:00
// FIXME: 6. Unset childDocument's iframe load in progress flag.
}
2022-11-05 03:58:14 +00:00
// https://html.spec.whatwg.org/multipage/interaction.html#dom-tabindex
i32 HTMLIFrameElement : : default_tab_index_value ( ) const
{
// See the base function for the spec comments.
return 0 ;
}
2020-06-05 23:36:02 +02:00
}