summaryrefslogtreecommitdiff
path: root/Userland/Libraries
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2022-09-19 13:34:36 +0200
committerAndreas Kling <kling@serenityos.org>2022-09-20 10:32:12 +0200
commit03375a3dc9e0cef259b8d8154b7a28a41d60aba8 (patch)
treec5c62a1a8da16752992ce6dc7b3bd1b04882df56 /Userland/Libraries
parent0810e77d77407943674ba154ea5579a9ca03239f (diff)
downloadserenity-03375a3dc9e0cef259b8d8154b7a28a41d60aba8.zip
LibWeb: Implement more spec-compliant iframe/frame attribute processing
We're still missing the lazy loading attribute handling, and once we hit the navigation step, we fall back to totally ad-hoc behavior instead of going all the way with a Fetch Request.
Diffstat (limited to 'Userland/Libraries')
-rw-r--r--Userland/Libraries/LibWeb/HTML/BrowsingContextContainer.cpp111
-rw-r--r--Userland/Libraries/LibWeb/HTML/BrowsingContextContainer.h6
-rw-r--r--Userland/Libraries/LibWeb/HTML/HTMLIFrameElement.cpp41
-rw-r--r--Userland/Libraries/LibWeb/HTML/HTMLIFrameElement.h11
4 files changed, 168 insertions, 1 deletions
diff --git a/Userland/Libraries/LibWeb/HTML/BrowsingContextContainer.cpp b/Userland/Libraries/LibWeb/HTML/BrowsingContextContainer.cpp
index 62e97996af..dec0c33b80 100644
--- a/Userland/Libraries/LibWeb/HTML/BrowsingContextContainer.cpp
+++ b/Userland/Libraries/LibWeb/HTML/BrowsingContextContainer.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2020-2021, Andreas Kling <kling@serenityos.org>
+ * Copyright (c) 2020-2022, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2022, Linus Groh <linusg@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
@@ -7,9 +7,12 @@
#include <LibWeb/DOM/Document.h>
#include <LibWeb/DOM/Event.h>
+#include <LibWeb/Fetch/Infrastructure/HTTP/Requests.h>
#include <LibWeb/HTML/BrowsingContext.h>
#include <LibWeb/HTML/BrowsingContextContainer.h>
#include <LibWeb/HTML/BrowsingContextGroup.h>
+#include <LibWeb/HTML/HTMLIFrameElement.h>
+#include <LibWeb/HTML/NavigationParams.h>
#include <LibWeb/HTML/Origin.h>
#include <LibWeb/Page/Page.h>
@@ -114,4 +117,110 @@ HTML::Window* BrowsingContextContainer::content_window() const
return const_cast<HTML::Window*>(&document->window());
}
+// https://html.spec.whatwg.org/multipage/urls-and-fetching.html#matches-about:blank
+static bool url_matches_about_blank(AK::URL const& url)
+{
+ // A URL matches about:blank if its scheme is "about", its path contains a single string "blank", its username and password are the empty string, and its host is null.
+ return url.scheme() == "about"sv
+ && url.path() == "blank"sv
+ && url.username().is_empty()
+ && url.password().is_empty()
+ && url.host().is_null();
+}
+
+// https://html.spec.whatwg.org/multipage/iframe-embed-object.html#shared-attribute-processing-steps-for-iframe-and-frame-elements
+void BrowsingContextContainer::shared_attribute_processing_steps_for_iframe_and_frame(bool initial_insertion)
+{
+ // 1. Let url be the URL record about:blank.
+ auto url = AK::URL("about:blank");
+
+ // 2. If element has a src attribute specified, and its value is not the empty string,
+ // then parse the value of that attribute relative to element's node document.
+ // If this is successful, then set url to the resulting URL record.
+ auto src_attribute_value = attribute(HTML::AttributeNames::src);
+ if (!src_attribute_value.is_null() && !src_attribute_value.is_empty()) {
+ auto parsed_src = document().parse_url(src_attribute_value);
+ if (parsed_src.is_valid())
+ url = parsed_src;
+ }
+
+ // 3. If there exists an ancestor browsing context of element's nested browsing context
+ // whose active document's URL, ignoring fragments, is equal to url, then return.
+ if (m_nested_browsing_context) {
+ for (auto* ancestor = m_nested_browsing_context->parent(); ancestor; ancestor = ancestor->parent()) {
+ VERIFY(ancestor->active_document());
+ if (ancestor->active_document()->url().equals(url, AK::URL::ExcludeFragment::Yes))
+ return;
+ }
+ }
+
+ // 4. If url matches about:blank and initialInsertion is true, then:
+ if (url_matches_about_blank(url) && initial_insertion) {
+ // FIXME: 1. Perform the URL and history update steps given element's nested browsing context's active document and url.
+
+ // 2. Run the iframe load event steps given element.
+ // FIXME: The spec doesn't check frame vs iframe here. Bug: https://github.com/whatwg/html/issues/8295
+ if (is<HTMLIFrameElement>(*this)) {
+ run_iframe_load_event_steps(static_cast<HTMLIFrameElement&>(*this));
+ }
+
+ // 3. Return.
+ }
+
+ // 5. Let resource be a new request whose URL is url and whose referrer policy is the current state of element's referrerpolicy content attribute.
+ auto resource = Fetch::Infrastructure::Request();
+ resource.set_url(url);
+ // FIXME: Set the referrer policy.
+
+ // AD-HOC:
+ if (url.protocol() == "file" && document().origin().protocol() != "file") {
+ dbgln("iframe failed to load URL: Security violation: {} may not load {}", document().url(), url);
+ return;
+ }
+
+ // 6. If element is an iframe element, then set element's current navigation was lazy loaded boolean to false.
+ if (is<HTMLIFrameElement>(*this)) {
+ static_cast<HTMLIFrameElement&>(*this).set_current_navigation_was_lazy_loaded(false);
+ }
+
+ // 7. If element is an iframe element, and the will lazy load element steps given element return true, then:
+ if (is<HTMLIFrameElement>(*this) && static_cast<HTMLIFrameElement&>(*this).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 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.
+ }
+
+ // 8. Navigate to the resource: navigate an iframe or frame given element and resource.
+ navigate_an_iframe_or_frame(move(resource));
+}
+
+// https://html.spec.whatwg.org/multipage/iframe-embed-object.html#navigate-an-iframe-or-frame
+void BrowsingContextContainer::navigate_an_iframe_or_frame(Fetch::Infrastructure::Request resource)
+{
+ // 1. Let historyHandling be "default".
+ auto history_handling = HistoryHandlingBehavior::Default;
+
+ // 2. If element's nested browsing context's active document is not completely loaded, then set historyHandling to "replace".
+ VERIFY(m_nested_browsing_context);
+ VERIFY(m_nested_browsing_context->active_document());
+ if (!m_nested_browsing_context->active_document()->is_completely_loaded()) {
+ history_handling = HistoryHandlingBehavior::Replace;
+ }
+
+ // FIXME: 3. Let reportFrameTiming be the following step given response response:
+ // queue an element task on the networking task source
+ // given element's node document's relevant global object
+ // to finalize and report timing given response, element's node document's relevant global object, and element's local name.
+
+ // FIXME: 4. Navigate element's nested browsing context to resource,
+ // with historyHandling set to historyHandling,
+ // the source browsing context set to element's node document's browsing context,
+ // and processResponseEndOfBody set to reportFrameTiming.
+ (void)history_handling;
+
+ // AD-HOC:
+ m_nested_browsing_context->loader().load(resource.url(), FrameLoader::Type::IFrame);
+}
+
}
diff --git a/Userland/Libraries/LibWeb/HTML/BrowsingContextContainer.h b/Userland/Libraries/LibWeb/HTML/BrowsingContextContainer.h
index 80228438ac..7009a3867a 100644
--- a/Userland/Libraries/LibWeb/HTML/BrowsingContextContainer.h
+++ b/Userland/Libraries/LibWeb/HTML/BrowsingContextContainer.h
@@ -29,6 +29,12 @@ public:
protected:
BrowsingContextContainer(DOM::Document&, DOM::QualifiedName);
+ // https://html.spec.whatwg.org/multipage/iframe-embed-object.html#shared-attribute-processing-steps-for-iframe-and-frame-elements
+ void shared_attribute_processing_steps_for_iframe_and_frame(bool initial_insertion);
+
+ // https://html.spec.whatwg.org/multipage/iframe-embed-object.html#navigate-an-iframe-or-frame
+ void navigate_an_iframe_or_frame(Fetch::Infrastructure::Request);
+
void create_new_nested_browsing_context();
void discard_nested_browsing_context();
diff --git a/Userland/Libraries/LibWeb/HTML/HTMLIFrameElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLIFrameElement.cpp
index 5d5d0eae12..771e6fa05e 100644
--- a/Userland/Libraries/LibWeb/HTML/HTMLIFrameElement.cpp
+++ b/Userland/Libraries/LibWeb/HTML/HTMLIFrameElement.cpp
@@ -46,10 +46,51 @@ void HTMLIFrameElement::inserted()
// 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.
// 3. Process the iframe attributes for element, with initialInsertion set to true.
+ process_the_iframe_attributes(true);
load_src(attribute(HTML::AttributeNames::src));
}
}
+// 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);
+}
+
// https://html.spec.whatwg.org/multipage/iframe-embed-object.html#the-iframe-element:the-iframe-element-7
void HTMLIFrameElement::removed_from(DOM::Node* node)
{
diff --git a/Userland/Libraries/LibWeb/HTML/HTMLIFrameElement.h b/Userland/Libraries/LibWeb/HTML/HTMLIFrameElement.h
index f9728145e5..a5416ce885 100644
--- a/Userland/Libraries/LibWeb/HTML/HTMLIFrameElement.h
+++ b/Userland/Libraries/LibWeb/HTML/HTMLIFrameElement.h
@@ -18,6 +18,11 @@ public:
virtual RefPtr<Layout::Node> create_layout_node(NonnullRefPtr<CSS::StyleProperties>) override;
+ // https://html.spec.whatwg.org/multipage/urls-and-fetching.html#will-lazy-load-element-steps
+ bool will_lazy_load_element() const;
+
+ void set_current_navigation_was_lazy_loaded(bool value) { m_current_navigation_was_lazy_loaded = value; }
+
private:
HTMLIFrameElement(DOM::Document&, DOM::QualifiedName);
@@ -25,7 +30,13 @@ private:
virtual void removed_from(Node*) override;
virtual void parse_attribute(FlyString const& name, String const& value) override;
+ // https://html.spec.whatwg.org/multipage/iframe-embed-object.html#process-the-iframe-attributes
+ void process_the_iframe_attributes(bool initial_insertion = false);
+
void load_src(String const&);
+
+ // https://html.spec.whatwg.org/multipage/iframe-embed-object.html#current-navigation-was-lazy-loaded
+ bool m_current_navigation_was_lazy_loaded { false };
};
void run_iframe_load_event_steps(HTML::HTMLIFrameElement&);