From af0f7db909058e125f48b0580c7f5d7c95de36ab Mon Sep 17 00:00:00 2001 From: est31 Date: Thu, 11 Oct 2018 21:42:51 +0200 Subject: [PATCH] Implement basic support for HtmlMediaElement The spec has a complicated algorithm for selecting a element among multiple children of a HtmlMediaElement where it loops over all of them, tries each and takes the first where "everything works out". This commit implements a much simpler and restricted approach by just taking the first child, and if that fails, failing altogether, without looking at any further children. This is an improvement over the current status and makes gifv items on imgur playable, although it doesn't mean full support. --- components/script/dom/htmlmediaelement.rs | 25 ++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/components/script/dom/htmlmediaelement.rs b/components/script/dom/htmlmediaelement.rs index 3a1d439168c..6756e6838b0 100644 --- a/components/script/dom/htmlmediaelement.rs +++ b/components/script/dom/htmlmediaelement.rs @@ -9,6 +9,7 @@ use dom::bindings::codegen::Bindings::AttrBinding::AttrMethods; use dom::bindings::codegen::Bindings::HTMLMediaElementBinding::CanPlayTypeResult; use dom::bindings::codegen::Bindings::HTMLMediaElementBinding::HTMLMediaElementConstants; use dom::bindings::codegen::Bindings::HTMLMediaElementBinding::HTMLMediaElementMethods; +use dom::bindings::codegen::Bindings::HTMLSourceElementBinding::HTMLSourceElementMethods; use dom::bindings::codegen::Bindings::MediaErrorBinding::MediaErrorConstants::*; use dom::bindings::codegen::Bindings::MediaErrorBinding::MediaErrorMethods; use dom::bindings::codegen::InheritTypes::{ElementTypeId, HTMLElementTypeId}; @@ -633,10 +634,28 @@ impl HTMLMediaElement { // of the cleanup in case of failure itself. self.resource_fetch_algorithm(Resource::Url(url_record)); }, - Mode::Children(_source) => { - // Step 9.children. + // Step 9.children. + Mode::Children(source) => { + // This is only a partial implementation // FIXME: https://github.com/servo/servo/issues/21481 - self.queue_dedicated_media_source_failure_steps() + let src = source.Src(); + // Step 9.attr.2. + if src.is_empty() { + source.upcast::().fire_event(atom!("error")); + self.queue_dedicated_media_source_failure_steps(); + return; + } + // Step 9.attr.3. + let url_record = match base_url.join(&src) { + Ok(url) => url, + Err(_) => { + source.upcast::().fire_event(atom!("error")); + self.queue_dedicated_media_source_failure_steps(); + return; + }, + }; + // Step 9.attr.8. + self.resource_fetch_algorithm(Resource::Url(url_record)); }, } }