summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Wilde <lukew@serenityos.org>2023-04-12 00:09:44 +0100
committerLinus Groh <mail@linusgroh.de>2023-04-12 01:47:58 +0200
commit8fa9ca8b7f8a5dbbcae85e878ee8fc81e35ea958 (patch)
treee6d0757a9d3187436632b8fce3efe110cdf91eb0
parent819b6332d13b38521f21fcdf848fb794027ad59d (diff)
downloadserenity-8fa9ca8b7f8a5dbbcae85e878ee8fc81e35ea958.zip
LibWeb: Create a video document for `video/` MIME types on navigation
-rw-r--r--Userland/Libraries/LibWeb/Loader/FrameLoader.cpp22
1 files changed, 22 insertions, 0 deletions
diff --git a/Userland/Libraries/LibWeb/Loader/FrameLoader.cpp b/Userland/Libraries/LibWeb/Loader/FrameLoader.cpp
index c87217d728..ff4b9c7554 100644
--- a/Userland/Libraries/LibWeb/Loader/FrameLoader.cpp
+++ b/Userland/Libraries/LibWeb/Loader/FrameLoader.cpp
@@ -184,6 +184,26 @@ static bool build_xml_document(DOM::Document& document, ByteBuffer const& data)
return !result.is_error() && !builder.has_error();
}
+static bool build_video_document(DOM::Document& document)
+{
+ auto html_element = DOM::create_element(document, HTML::TagNames::html, Namespace::HTML).release_value_but_fixme_should_propagate_errors();
+ MUST(document.append_child(html_element));
+
+ auto head_element = DOM::create_element(document, HTML::TagNames::head, Namespace::HTML).release_value_but_fixme_should_propagate_errors();
+ MUST(html_element->append_child(head_element));
+
+ auto body_element = DOM::create_element(document, HTML::TagNames::body, Namespace::HTML).release_value_but_fixme_should_propagate_errors();
+ MUST(html_element->append_child(body_element));
+
+ auto video_element = DOM::create_element(document, HTML::TagNames::video, Namespace::HTML).release_value_but_fixme_should_propagate_errors();
+ MUST(video_element->set_attribute(HTML::AttributeNames::src, document.url().to_deprecated_string()));
+ MUST(video_element->set_attribute(HTML::AttributeNames::autoplay, DeprecatedString::empty()));
+ MUST(video_element->set_attribute(HTML::AttributeNames::controls, DeprecatedString::empty()));
+ MUST(body_element->append_child(video_element));
+
+ return true;
+}
+
bool FrameLoader::parse_document(DOM::Document& document, ByteBuffer const& data)
{
auto& mime_type = document.content_type();
@@ -196,6 +216,8 @@ bool FrameLoader::parse_document(DOM::Document& document, ByteBuffer const& data
return build_xml_document(document, data);
if (mime_type.starts_with("image/"sv))
return build_image_document(document, data);
+ if (mime_type.starts_with("video/"sv))
+ return build_video_document(document);
if (mime_type == "text/plain" || mime_type == "application/json")
return build_text_document(document, data);
if (mime_type == "text/markdown")