LibWeb: Update HTMLIFrameElement to use navigables

This commit is contained in:
Aliaksandr Kalenik 2023-04-13 18:50:09 +03:00 committed by Andreas Kling
parent 623d1a78da
commit 912cf89727
Notes: sideshowbarker 2024-07-17 08:42:05 +09:00
3 changed files with 99 additions and 131 deletions

View file

@ -8,6 +8,7 @@
#include <LibWeb/DOM/Event.h>
#include <LibWeb/HTML/BrowsingContext.h>
#include <LibWeb/HTML/HTMLIFrameElement.h>
#include <LibWeb/HTML/Navigable.h>
#include <LibWeb/HTML/Origin.h>
#include <LibWeb/HTML/Parser/HTMLParser.h>
#include <LibWeb/Layout/FrameBox.h>
@ -35,7 +36,7 @@ JS::GCPtr<Layout::Node> HTMLIFrameElement::create_layout_node(NonnullRefPtr<CSS:
void HTMLIFrameElement::attribute_changed(DeprecatedFlyString const& name, DeprecatedString const& value)
{
HTMLElement::attribute_changed(name, value);
if (m_nested_browsing_context)
if (m_content_navigable)
process_the_iframe_attributes();
}
@ -46,8 +47,8 @@ void HTMLIFrameElement::inserted()
// 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();
// 1. Create a new child navigable for element.
MUST(create_new_child_navigable());
// 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.
@ -72,12 +73,15 @@ bool HTMLIFrameElement::will_lazy_load_element() const
// https://html.spec.whatwg.org/multipage/iframe-embed-object.html#process-the-iframe-attributes
void HTMLIFrameElement::process_the_iframe_attributes(bool initial_insertion)
{
if (!content_navigable())
return;
// 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.
// 1. 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:
// 2. 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.
@ -85,15 +89,48 @@ void HTMLIFrameElement::process_the_iframe_attributes(bool initial_insertion)
// 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.
// 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.
navigate_an_iframe_or_frame(AK::URL("about:srcdoc"sv), ReferrerPolicy::ReferrerPolicy::EmptyString, String::from_deprecated_string(get_attribute(HTML::AttributeNames::srcdoc)).release_value_but_fixme_should_propagate_errors());
// 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);
// 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:
if (url_matches_about_blank(*url) && initial_insertion) {
// 1. Run the iframe load event steps given element.
run_iframe_load_event_steps(*this);
// 2. Return.
return;
}
// FIXME: 4. Let referrerPolicy be the current state of element's referrerpolicy content attribute.
auto referrer_policy = ReferrerPolicy::ReferrerPolicy::EmptyString;
// 5. Set element's current navigation was lazy loaded boolean to false.
m_current_navigation_was_lazy_loaded = false;
// 6. 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.
// FIXME: 2. Set element's current navigation was lazy loaded boolean to true.
// FIXME: 3. Start intersection-observing a lazy loading element for element.
// 4. Return.
return;
}
// 7. Navigate: navigate an iframe or frame given element, url, and referrerPolicy.
navigate_an_iframe_or_frame(*url, referrer_policy);
}
// https://html.spec.whatwg.org/multipage/iframe-embed-object.html#the-iframe-element:the-iframe-element-7
@ -101,12 +138,8 @@ void HTMLIFrameElement::removed_from(DOM::Node* node)
{
HTMLElement::removed_from(node);
// 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;
}
// When an iframe element is removed from a document, the user agent must destroy the nested navigable of the element.
destroy_the_child_navigable();
}
// https://html.spec.whatwg.org/multipage/rendering.html#attributes-for-embedded-content-and-images
@ -126,8 +159,8 @@ void HTMLIFrameElement::apply_presentational_hints(CSS::StyleProperties& style)
// https://html.spec.whatwg.org/multipage/iframe-embed-object.html#iframe-load-event-steps
void run_iframe_load_event_steps(HTML::HTMLIFrameElement& element)
{
// FIXME: 1. Assert: element's nested browsing context is not null.
if (!element.nested_browsing_context()) {
// FIXME: 1. Assert: element's content navigable is not null.
if (!element.content_navigable()) {
// 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;