2020-06-05 23:36:02 +02:00
/*
2024-10-04 13:19:50 +02:00
* Copyright ( c ) 2020 - 2021 , Andreas Kling < andreas @ ladybird . org >
2026-06-11 15:24:47 +01:00
* Copyright ( c ) 2023 - 2026 , Sam Atkins < sam @ ladybird . 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
*/
2026-04-18 10:54:06 +02:00
# include <LibWeb/Bindings/HTMLIFrameElement.h>
2025-02-18 09:19:56 +01:00
# include <LibWeb/CSS/ComputedProperties.h>
2026-04-29 12:31:50 +02:00
# include <LibWeb/CSS/Invalidation/EmbeddedContentInvalidator.h>
2024-11-08 20:14:37 +08:00
# include <LibWeb/CSS/StyleValues/DisplayStyleValue.h>
2025-03-14 16:58:10 +00:00
# include <LibWeb/CSS/StyleValues/LengthStyleValue.h>
2024-11-18 07:16:26 +13:00
# include <LibWeb/DOM/DOMTokenList.h>
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>
2023-04-13 18:50:09 +03:00
# include <LibWeb/HTML/Navigable.h>
2025-03-14 16:58:10 +00:00
# include <LibWeb/HTML/Numbers.h>
2022-10-10 17:22:30 +01:00
# include <LibWeb/HTML/Parser/HTMLParser.h>
2025-02-27 21:36:33 +01:00
# include <LibWeb/HTML/TraversableNavigable.h>
2024-11-26 12:00:15 +01:00
# include <LibWeb/Layout/NavigableContainerViewport.h>
2026-06-11 15:24:47 +01:00
# include <LibWeb/ResourceTiming/PerformanceResourceTiming.h>
2025-10-31 11:51:57 +00:00
# include <LibWeb/TrustedTypes/RequireTrustedTypesForDirective.h>
2025-10-31 12:30:47 +00:00
# include <LibWeb/TrustedTypes/TrustedTypePolicy.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
2024-11-15 04:01:23 +13:00
GC_DEFINE_ALLOCATOR ( HTMLIFrameElement ) ;
2023-11-19 19:47:52 +01: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
{
2024-03-16 13:13:08 +01:00
WEB_SET_PROTOTYPE_FOR_INTERFACE ( HTMLIFrameElement ) ;
2025-04-20 16:22:57 +02:00
Base : : initialize ( realm ) ;
2023-01-10 06:28:20 -05:00
}
LibWeb: Make layout nodes refcounted
Move the layout tree from GC allocation to refcounted ownership so
removed layout and paint subtrees are destroyed synchronously instead
of waiting for the next GC sweep. This dramatically reduces GC memory
usage peaks after layout tree churn and makes it easier for memory use
to fall back after large document updates.
Update layout factories, tree traversal, SVG layout node creation,
paintable back-pointers, and pseudo-element layout links to use RefPtr
ownership.
Make display: contents follow the same shape as Blink and WebKit: the
element itself does not create a layout node, and its children are
flattened into the nearest layout parent. Wrap direct non-whitespace
text in an anonymous inline node when the boxless element contributes
inherited style to that text.
Use an internal inline wrapper for display: contents pseudo-elements
so generated content can still participate in layout, painting, hit
testing, and pseudo-element queries. Keep CSSOM reporting the computed
display value from the pseudo style, not the internal wrapper.
Remove the retained out-of-tree layout node list and its testing hook,
since the flattened model does not need a side owner for boxless
elements. Add coverage for inherited text style, dynamic insertion
order, pseudo-element hit testing, and computed style queries.
2026-06-07 17:50:33 +02:00
RefPtr < Layout : : Node > HTMLIFrameElement : : create_layout_node ( CSS : : ComputedProperties const & style )
2020-06-05 23:36:02 +02:00
{
LibWeb: Make layout nodes refcounted
Move the layout tree from GC allocation to refcounted ownership so
removed layout and paint subtrees are destroyed synchronously instead
of waiting for the next GC sweep. This dramatically reduces GC memory
usage peaks after layout tree churn and makes it easier for memory use
to fall back after large document updates.
Update layout factories, tree traversal, SVG layout node creation,
paintable back-pointers, and pseudo-element layout links to use RefPtr
ownership.
Make display: contents follow the same shape as Blink and WebKit: the
element itself does not create a layout node, and its children are
flattened into the nearest layout parent. Wrap direct non-whitespace
text in an anonymous inline node when the boxless element contributes
inherited style to that text.
Use an internal inline wrapper for display: contents pseudo-elements
so generated content can still participate in layout, painting, hit
testing, and pseudo-element queries. Keep CSSOM reporting the computed
display value from the pseudo style, not the internal wrapper.
Remove the retained out-of-tree layout node list and its testing hook,
since the flattened model does not need a side owner for boxless
elements. Add coverage for inherited text style, dynamic insertion
order, pseudo-element hit testing, and computed style queries.
2026-06-07 17:50:33 +02:00
return make_ref_counted < Layout : : NavigableContainerViewport > ( document ( ) , * this , style ) ;
2020-06-05 23:36:02 +02:00
}
2024-12-20 11:32:17 +01:00
void HTMLIFrameElement : : adjust_computed_style ( CSS : : ComputedProperties & style )
2024-11-08 20:14:37 +08:00
{
// https://drafts.csswg.org/css-display-3/#unbox
if ( style . display ( ) . is_contents ( ) )
style . set_property ( CSS : : PropertyID : : Display , CSS : : DisplayStyleValue : : create ( CSS : : Display : : from_short ( CSS : : Display : : Short : : None ) ) ) ;
}
2024-11-14 08:14:16 -05:00
void HTMLIFrameElement : : attribute_changed ( FlyString const & name , Optional < String > const & old_value , Optional < String > const & value , Optional < FlyString > const & namespace_ )
2020-06-06 15:08:36 +02:00
{
2024-11-14 08:14:16 -05:00
Base : : attribute_changed ( name , old_value , value , namespace_ ) ;
2024-01-01 16:31:14 +00:00
2024-12-06 14:53:03 +00:00
if ( name = = HTML : : AttributeNames : : sandbox ) {
if ( m_sandbox )
m_sandbox - > associated_attribute_changed ( value . value_or ( String { } ) ) ;
}
2024-01-01 16:31:14 +00:00
// https://html.spec.whatwg.org/multipage/iframe-embed-object.html#the-iframe-element:process-the-iframe-attributes-2
// https://html.spec.whatwg.org/multipage/iframe-embed-object.html#the-iframe-element:process-the-iframe-attributes-3
// Whenever an iframe element with a non-null content navigable has its srcdoc attribute set, changed, or removed,
// the user agent must process the iframe attributes.
// Similarly, whenever an iframe element with a non-null content navigable but with no srcdoc attribute specified
// has its src attribute set, changed, or removed, the user agent must process the iframe attributes.
if ( m_content_navigable ) {
if ( name = = AttributeNames : : srcdoc | | ( name = = AttributeNames : : src & & ! has_attribute ( AttributeNames : : srcdoc ) ) )
process_the_iframe_attributes ( ) ;
2024-12-06 14:53:03 +00:00
// https://html.spec.whatwg.org/multipage/iframe-embed-object.html#the-iframe-element:iframe-sandboxing-flag-set-2
// https://html.spec.whatwg.org/multipage/iframe-embed-object.html#the-iframe-element:iframe-sandboxing-flag-set-3
// When an iframe element's sandbox attribute is set or changed while it has a non-null content navigable, the
// user agent must parse the sandboxing directive given the attribute's value and the iframe element's iframe
// sandboxing flag set.
// When an iframe element's sandbox attribute is removed while it has a non-null content navigable, the user
// agent must empty the iframe element's iframe sandboxing flag set.
if ( name = = AttributeNames : : sandbox ) {
if ( value . has_value ( ) ) {
m_iframe_sandboxing_flag_set = parse_a_sandboxing_directive ( value . value ( ) ) ;
} else {
m_iframe_sandboxing_flag_set = { } ;
}
}
2024-01-01 16:31:14 +00:00
}
2024-12-23 17:51:10 +01:00
2026-04-29 12:31:50 +02:00
if ( name = = HTML : : AttributeNames : : width | | name = = HTML : : AttributeNames : : height )
CSS : : Invalidation : : invalidate_style_after_embedded_content_geometry_change ( * this ) ;
2025-02-22 14:55:07 +01:00
if ( name = = HTML : : AttributeNames : : marginwidth | | name = = HTML : : AttributeNames : : marginheight ) {
if ( auto * document = this - > content_document_without_origin_check ( ) ) {
if ( auto * body_element = document - > body ( ) )
const_cast < HTMLElement * > ( body_element ) - > set_needs_style_update ( true ) ;
}
}
2020-06-05 23:36:02 +02:00
}
2024-12-15 02:59:23 +13:00
// https://html.spec.whatwg.org/multipage/iframe-embed-object.html#the-iframe-element:html-element-post-connection-steps
void HTMLIFrameElement : : post_connection ( )
2021-04-03 16:45:14 +02:00
{
2025-01-21 09:12:05 -05:00
DOM : : Document & document = as < DOM : : Document > ( shadow_including_root ( ) ) ;
2024-11-12 18:16:08 +00:00
// NOTE: The check for "not fully active" is to prevent a crash on the dom/nodes/node-appendchild-crash.html WPT test.
if ( ! document . browsing_context ( ) | | ! document . is_fully_active ( ) )
return ;
2026-04-12 14:04:20 +02:00
// 1. If insertedNode has a sandbox attribute, then parse the sandboxing directive given the attribute's
2026-03-29 12:06:39 +02:00
// value and insertedNode's iframe sandboxing flag set.
2026-03-30 21:30:32 +02:00
if ( auto sandbox = attribute ( AttributeNames : : sandbox ) ; sandbox . has_value ( ) )
m_iframe_sandboxing_flag_set = parse_a_sandboxing_directive ( sandbox . value ( ) ) ;
2024-11-12 18:16:08 +00:00
2026-04-12 14:04:20 +02:00
// 2. Create a new child navigable for insertedNode.
create_new_child_navigable ( ) ;
2026-03-29 12:06:39 +02:00
// 3. Process the iframe attributes for insertedNode, with initialInsertion set to true.
process_the_iframe_attributes ( InitialInsertion : : Yes ) ;
2022-03-23 20:13:34 -04:00
}
2022-09-19 13:34:36 +02:00
// https://html.spec.whatwg.org/multipage/iframe-embed-object.html#process-the-iframe-attributes
2025-05-15 12:28:53 +01:00
void HTMLIFrameElement : : process_the_iframe_attributes ( InitialInsertion initial_insertion )
2022-09-19 13:34:36 +02:00
{
2023-04-13 18:50:09 +03:00
if ( ! content_navigable ( ) )
return ;
2022-09-19 13:34:36 +02:00
// 1. If element's srcdoc attribute is specified, then:
if ( has_attribute ( HTML : : AttributeNames : : srcdoc ) ) {
2023-04-13 18:50:09 +03:00
// 1. Set element's current navigation was lazy loaded boolean to false.
2023-11-24 15:54:57 +00:00
set_current_navigation_was_lazy_loaded ( false ) ;
2022-09-19 13:34:36 +02:00
2023-04-13 18:50:09 +03:00
// 2. If the will lazy load element steps given element return true, then:
2022-09-19 13:34:36 +02:00
if ( will_lazy_load_element ( ) ) {
2023-11-21 18:54:36 +00:00
// 1. Set element's lazy load resumption steps to the rest of this algorithm starting with the step labeled navigate to the srcdoc resource.
set_lazy_load_resumption_steps ( [ this ] ( ) {
// 3. Navigate to the srcdoc resource: navigate an iframe or frame given element, about:srcdoc, the empty string, and the value of element's srcdoc attribute.
2025-02-15 23:51:45 +13:00
navigate_an_iframe_or_frame ( URL : : about_srcdoc ( ) , ReferrerPolicy : : ReferrerPolicy : : EmptyString , get_attribute ( HTML : : AttributeNames : : srcdoc ) ) ;
2023-11-21 18:54:36 +00:00
// FIXME: The resulting Document must be considered an iframe srcdoc document.
} ) ;
// 2. Set element's current navigation was lazy loaded boolean to true.
2023-11-24 15:54:57 +00:00
set_current_navigation_was_lazy_loaded ( true ) ;
2023-11-21 18:54:36 +00:00
// 3. Start intersection-observing a lazy loading element for element.
document ( ) . start_intersection_observing_a_lazy_loading_element ( * this ) ;
// 4. Return.
return ;
2022-09-19 13:34:36 +02:00
}
2023-04-13 18:50:09 +03:00
// 3. Navigate to the srcdoc resource: navigate an iframe or frame given element, about:srcdoc, the empty string, and the value of element's srcdoc attribute.
2025-02-15 23:51:45 +13:00
navigate_an_iframe_or_frame ( URL : : about_srcdoc ( ) , ReferrerPolicy : : ReferrerPolicy : : EmptyString , get_attribute ( HTML : : AttributeNames : : srcdoc ) ) ;
2022-09-19 13:34:36 +02:00
// FIXME: The resulting Document must be considered an iframe srcdoc document.
return ;
}
2023-04-13 18:50:09 +03:00
// 1. Let url be the result of running the shared attribute processing steps for iframe and frame elements given element and initialInsertion.
auto url = shared_attribute_processing_steps_for_iframe_and_frame ( initial_insertion ) ;
// 2. If url is null, then return.
if ( ! url . has_value ( ) ) {
return ;
}
// 3. If url matches about:blank and initialInsertion is true, then:
2025-05-15 12:28:53 +01:00
if ( url_matches_about_blank ( * url ) & & initial_insertion = = InitialInsertion : : Yes ) {
2023-04-13 18:50:09 +03:00
// 1. Run the iframe load event steps given element.
run_iframe_load_event_steps ( * this ) ;
// 2. Return.
return ;
}
2024-05-31 21:24:43 +01:00
// 4. Let referrerPolicy be the current state of element's referrerpolicy content attribute.
auto referrer_policy = ReferrerPolicy : : from_string ( get_attribute_value ( HTML : : AttributeNames : : referrerpolicy ) ) . value_or ( ReferrerPolicy : : ReferrerPolicy : : EmptyString ) ;
2023-04-13 18:50:09 +03:00
// 5. Set element's current navigation was lazy loaded boolean to false.
2023-11-24 15:54:57 +00:00
set_current_navigation_was_lazy_loaded ( false ) ;
2023-04-13 18:50:09 +03:00
// 6. If the will lazy load element steps given element return true, then:
if ( will_lazy_load_element ( ) ) {
2023-11-21 18:54:36 +00:00
// 1. Set element's lazy load resumption steps to the rest of this algorithm starting with the step labeled navigate.
set_lazy_load_resumption_steps ( [ this , url , referrer_policy ] ( ) {
// 7. Navigate: navigate an iframe or frame given element, url, and referrerPolicy.
navigate_an_iframe_or_frame ( * url , referrer_policy ) ;
} ) ;
// 2. Set element's current navigation was lazy loaded boolean to true.
2023-11-24 15:54:57 +00:00
set_current_navigation_was_lazy_loaded ( true ) ;
2023-11-21 18:54:36 +00:00
// 3. Start intersection-observing a lazy loading element for element.
document ( ) . start_intersection_observing_a_lazy_loading_element ( * this ) ;
2023-04-13 18:50:09 +03:00
// 4. Return.
return ;
}
// 7. Navigate: navigate an iframe or frame given element, url, and referrerPolicy.
navigate_an_iframe_or_frame ( * url , referrer_policy ) ;
2022-09-19 13:34:36 +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-7
2026-04-16 20:04:54 +01:00
void HTMLIFrameElement : : removed_from ( IsSubtreeRoot is_subtree_root , DOM : : Node * old_ancestor , DOM : : Node & old_root )
2022-03-23 20:13:34 -04:00
{
2026-04-16 20:04:54 +01:00
HTMLElement : : removed_from ( is_subtree_root , old_ancestor , old_root ) ;
2022-09-20 21:44:42 +02:00
2023-04-13 18:50:09 +03:00
// When an iframe element is removed from a document, the user agent must destroy the nested navigable of the element.
destroy_the_child_navigable ( ) ;
2021-04-03 16:45:14 +02:00
}
2021-09-26 02:25:02 +02:00
// https://html.spec.whatwg.org/multipage/iframe-embed-object.html#iframe-load-event-steps
2026-06-11 15:24:47 +01:00
void run_iframe_load_event_steps ( HTMLIFrameElement & element )
2021-09-26 02:25:02 +02:00
{
2023-04-13 18:50:09 +03:00
// FIXME: 1. Assert: element's content navigable is not null.
if ( ! element . content_navigable ( ) ) {
2022-09-20 21:44:42 +02:00
// 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
2023-09-07 01:13:27 +02:00
// 2. Let childDocument be element's content navigable's active document.
[[maybe_unused]] auto child_document = element . content_navigable ( ) - > active_document ( ) ;
2021-09-26 02:25:02 +02:00
// FIXME: 3. If childDocument has its mute iframe load flag set, then return.
2026-06-11 15:24:47 +01:00
// 4. If element's pending resource-timing start time is not null:
if ( element . pending_resource_start_time ( ) . has_value ( ) ) {
// 1. Assert: element's pending resource-timing URL is not null.
VERIFY ( element . pending_resource_timing_url ( ) . has_value ( ) ) ;
// 2. Let global be element's node document's relevant global object.
auto & global = relevant_global_object ( element . document ( ) ) ;
// 3. Let fallbackTimingInfo be a new fetch timing info whose start time is element's pending resource-timing
// start time and whose response end time is the current high resolution time given global.
auto fallback_timing_info = Fetch : : Infrastructure : : FetchTimingInfo : : create ( element . vm ( ) ) ;
fallback_timing_info - > set_start_time ( element . pending_resource_start_time ( ) . value ( ) ) ;
fallback_timing_info - > set_end_time ( HighResolutionTime : : current_high_resolution_time ( global ) ) ;
// 4. Mark resource timing given fallbackTimingInfo, the result of parsing element's pending resource-timing
// URL, "iframe", global, the empty string, a new response body info, and 0.
// FIXME: Our URL is already parsed, how are we supposed to parse it?
ResourceTiming : : PerformanceResourceTiming : : mark_resource_timing (
fallback_timing_info ,
element . pending_resource_timing_url ( ) - > to_string ( ) ,
" iframe " _fly_string ,
global ,
Optional < Fetch : : Infrastructure : : Response : : CacheState > { } ,
Fetch : : Infrastructure : : Response : : BodyInfo { } ,
0 ) ;
// 5. Set element's pending resource-timing start time to null.
element . set_pending_resource_start_time ( { } ) ;
// 6. Set element's pending resource-timing URL to null.
element . set_pending_resource_timing_url ( { } ) ;
}
// FIXME: 5. Set childDocument's iframe load in progress flag.
2021-09-26 02:25:02 +02:00
2026-06-11 15:24:47 +01:00
// 6. 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
2026-06-11 15:24:47 +01:00
// FIXME: 7. Unset childDocument's iframe load in progress flag.
2021-09-26 02:25:02 +02:00
}
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 ;
}
2025-03-14 16:58:10 +00:00
bool HTMLIFrameElement : : is_presentational_hint ( FlyString const & name ) const
{
if ( Base : : is_presentational_hint ( name ) )
return true ;
return name = = HTML : : AttributeNames : : frameborder ;
}
2026-04-30 10:44:26 +01:00
void HTMLIFrameElement : : apply_presentational_hints ( Vector < CSS : : StyleProperty > & properties ) const
2025-03-14 16:58:10 +00:00
{
2026-04-30 10:44:26 +01:00
Base : : apply_presentational_hints ( properties ) ;
2025-03-14 16:58:10 +00:00
// https://html.spec.whatwg.org/multipage/rendering.html#attributes-for-embedded-content-and-images:attr-iframe-frameborder
// When an iframe element has a frameborder attribute whose value, when parsed using the rules for parsing integers,
// is zero or an error, the user agent is expected to have presentational hints setting the element's
// 'border-top-width', 'border-right-width', 'border-bottom-width', and 'border-left-width' properties to zero.
if ( auto frameborder_attribute = get_attribute ( HTML : : AttributeNames : : frameborder ) ; frameborder_attribute . has_value ( ) ) {
auto frameborder = parse_integer ( * frameborder_attribute ) ;
if ( ! frameborder . has_value ( ) | | frameborder = = 0 ) {
auto zero = CSS : : LengthStyleValue : : create ( CSS : : Length : : make_px ( 0 ) ) ;
2026-04-30 10:44:26 +01:00
properties . append ( { . property_id = CSS : : PropertyID : : BorderTopWidth , . value = zero } ) ;
properties . append ( { . property_id = CSS : : PropertyID : : BorderRightWidth , . value = zero } ) ;
properties . append ( { . property_id = CSS : : PropertyID : : BorderBottomWidth , . value = zero } ) ;
properties . append ( { . property_id = CSS : : PropertyID : : BorderLeftWidth , . value = zero } ) ;
2025-03-14 16:58:10 +00:00
}
}
}
2024-11-18 07:16:26 +13:00
// https://html.spec.whatwg.org/multipage/iframe-embed-object.html#dom-iframe-sandbox
GC : : Ref < DOM : : DOMTokenList > HTMLIFrameElement : : sandbox ( )
{
// The sandbox IDL attribute must reflect the sandbox content attribute.
if ( ! m_sandbox )
m_sandbox = DOM : : DOMTokenList : : create ( * this , HTML : : AttributeNames : : sandbox ) ;
return * m_sandbox ;
}
2023-11-21 18:52:33 +00:00
void HTMLIFrameElement : : visit_edges ( Cell : : Visitor & visitor )
{
Base : : visit_edges ( visitor ) ;
visit_lazy_loading_element ( visitor ) ;
2024-11-18 07:16:26 +13:00
visitor . visit ( m_sandbox ) ;
2023-11-21 18:52:33 +00:00
}
2023-11-24 15:54:57 +00:00
void HTMLIFrameElement : : set_current_navigation_was_lazy_loaded ( bool value )
{
m_current_navigation_was_lazy_loaded = value ;
// An iframe element whose current navigation was lazy loaded boolean is false potentially delays the load event.
// https://html.spec.whatwg.org/multipage/iframe-embed-object.html#the-iframe-element:potentially-delays-the-load-event
set_potentially_delays_the_load_event ( ! value ) ;
}
2025-10-31 11:51:57 +00:00
// https://html.spec.whatwg.org/multipage/iframe-embed-object.html#dom-iframe-srcdoc
TrustedTypes : : TrustedHTMLOrString HTMLIFrameElement : : srcdoc ( )
{
// 1. Let attribute be the result of running get an attribute by namespace and local name given null, srcdoc's
// local name, and this.
// 2. If attribute is null, then return the empty string.
// 3. Return attribute's value.
return Utf16String : : from_utf8 ( get_attribute_value ( AttributeNames : : srcdoc ) ) ;
}
// https://html.spec.whatwg.org/multipage/iframe-embed-object.html#dom-iframe-srcdoc
WebIDL : : ExceptionOr < void > HTMLIFrameElement : : set_srcdoc ( TrustedTypes : : TrustedHTMLOrString const & value )
{
// 1. Let compliantString be the result of invoking the Get Trusted Type compliant string algorithm with
// TrustedHTML, this's relevant global object, the given value, "HTMLIFrameElement srcdoc", and "script".
auto const compliant_string = TRY ( TrustedTypes : : get_trusted_type_compliant_string (
TrustedTypes : : TrustedTypeName : : TrustedHTML ,
HTML : : relevant_global_object ( * this ) ,
value ,
2025-11-04 15:27:46 +00:00
TrustedTypes : : InjectionSink : : HTMLIFrameElement_srcdoc ,
2025-10-31 11:51:57 +00:00
TrustedTypes : : Script . to_string ( ) ) ) ;
// 2. Set an attribute value given this, srcdoc's local name, and compliantString.
set_attribute_value ( AttributeNames : : srcdoc , compliant_string . to_utf8_but_should_be_ported_to_utf16 ( ) ) ;
return { } ;
}
2026-06-11 12:18:41 +01:00
// https://html.spec.whatwg.org/multipage/browsers.html#determining-the-iframe-element-referrer-policy
ReferrerPolicy : : ReferrerPolicy determine_iframe_element_referrer_policy ( GC : : Ptr < DOM : : Element > embedder )
{
// 1. If embedder is an iframe element, then return embedder's referrerpolicy attribute's state's corresponding
// keyword.
if ( auto * iframe = as_if < HTMLIFrameElement > ( embedder . ptr ( ) ) ) {
return ReferrerPolicy : : from_string ( iframe - > get_attribute_value ( HTML : : AttributeNames : : referrerpolicy ) ) . value_or ( ReferrerPolicy : : ReferrerPolicy : : EmptyString ) ;
}
// 2. Return the empty string.
return ReferrerPolicy : : ReferrerPolicy : : EmptyString ;
}
2020-06-05 23:36:02 +02:00
}