mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-17 15:25:52 +00:00
servo: Merge #8454 - Implement basic <media> infrastructure (from jdm:media); r=KiChjang
This gets us to the point where we can start playing with actually integrating rust-media to process the data received by the network request, as currently it's just ignored. Source-Repo: https://github.com/servo/servo Source-Revision: f9d9cd3aaed3326e8935f710f800288a50156c71
This commit is contained in:
parent
da31a4c64f
commit
1379121bd9
@ -21,6 +21,7 @@ pub enum LoadType {
|
|||||||
Subframe(Url),
|
Subframe(Url),
|
||||||
Stylesheet(Url),
|
Stylesheet(Url),
|
||||||
PageSource(Url),
|
PageSource(Url),
|
||||||
|
Media(Url),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LoadType {
|
impl LoadType {
|
||||||
@ -30,6 +31,7 @@ impl LoadType {
|
|||||||
LoadType::Script(ref url) |
|
LoadType::Script(ref url) |
|
||||||
LoadType::Subframe(ref url) |
|
LoadType::Subframe(ref url) |
|
||||||
LoadType::Stylesheet(ref url) |
|
LoadType::Stylesheet(ref url) |
|
||||||
|
LoadType::Media(ref url) |
|
||||||
LoadType::PageSource(ref url) => url,
|
LoadType::PageSource(ref url) => url,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -39,7 +41,8 @@ impl LoadType {
|
|||||||
LoadType::Image(_) => LoadContext::Image,
|
LoadType::Image(_) => LoadContext::Image,
|
||||||
LoadType::Script(_) => LoadContext::Script,
|
LoadType::Script(_) => LoadContext::Script,
|
||||||
LoadType::Subframe(_) | LoadType::PageSource(_) => LoadContext::Browsing,
|
LoadType::Subframe(_) | LoadType::PageSource(_) => LoadContext::Browsing,
|
||||||
LoadType::Stylesheet(_) => LoadContext::Style
|
LoadType::Stylesheet(_) => LoadContext::Style,
|
||||||
|
LoadType::Media(_) => LoadContext::AudioVideo,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,14 +2,182 @@
|
|||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
use document_loader::LoadType;
|
||||||
|
use dom::attr::Attr;
|
||||||
|
use dom::bindings::cell::DOMRefCell;
|
||||||
|
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::MediaErrorBinding::MediaErrorConstants::*;
|
||||||
|
use dom::bindings::codegen::Bindings::MediaErrorBinding::MediaErrorMethods;
|
||||||
|
use dom::bindings::global::GlobalRef;
|
||||||
|
use dom::bindings::inheritance::Castable;
|
||||||
|
use dom::bindings::js::{Root, MutNullableHeap, JS};
|
||||||
|
use dom::bindings::refcounted::Trusted;
|
||||||
use dom::document::Document;
|
use dom::document::Document;
|
||||||
|
use dom::element::{Element, AttributeMutation};
|
||||||
|
use dom::event::{Event, EventBubbles, EventCancelable};
|
||||||
use dom::htmlelement::HTMLElement;
|
use dom::htmlelement::HTMLElement;
|
||||||
|
use dom::htmlsourceelement::HTMLSourceElement;
|
||||||
|
use dom::mediaerror::MediaError;
|
||||||
|
use dom::node::{window_from_node, document_from_node, Node, UnbindContext};
|
||||||
|
use dom::virtualmethods::VirtualMethods;
|
||||||
|
use ipc_channel::ipc;
|
||||||
|
use ipc_channel::router::ROUTER;
|
||||||
|
use net_traits::{AsyncResponseListener, AsyncResponseTarget, Metadata, NetworkError};
|
||||||
|
use network_listener::{NetworkListener, PreInvoke};
|
||||||
|
use script_runtime::ScriptChan;
|
||||||
|
use script_thread::{Runnable, ScriptThread};
|
||||||
|
use std::cell::Cell;
|
||||||
|
use std::sync::{Arc, Mutex};
|
||||||
use string_cache::Atom;
|
use string_cache::Atom;
|
||||||
|
use task_source::TaskSource;
|
||||||
|
use task_source::dom_manipulation::DOMManipulationTask;
|
||||||
|
use time::{self, Timespec, Duration};
|
||||||
|
use url::Url;
|
||||||
use util::str::DOMString;
|
use util::str::DOMString;
|
||||||
|
|
||||||
|
struct HTMLMediaElementContext {
|
||||||
|
/// The element that initiated the request.
|
||||||
|
elem: Trusted<HTMLMediaElement>,
|
||||||
|
/// The response body received to date.
|
||||||
|
data: Vec<u8>,
|
||||||
|
/// The response metadata received to date.
|
||||||
|
metadata: Option<Metadata>,
|
||||||
|
/// The generation of the media element when this fetch started.
|
||||||
|
generation_id: u32,
|
||||||
|
/// Time of last progress notification.
|
||||||
|
next_progress_event: Timespec,
|
||||||
|
/// Url of resource requested.
|
||||||
|
url: Url,
|
||||||
|
/// Whether the media metadata has been completely received.
|
||||||
|
have_metadata: bool,
|
||||||
|
/// True if this response is invalid and should be ignored.
|
||||||
|
ignore_response: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl AsyncResponseListener for HTMLMediaElementContext {
|
||||||
|
// https://html.spec.whatwg.org/multipage/#media-data-processing-steps-list
|
||||||
|
fn headers_available(&mut self, metadata: Result<Metadata, NetworkError>) {
|
||||||
|
self.metadata = metadata.ok();
|
||||||
|
|
||||||
|
// => "If the media data cannot be fetched at all..."
|
||||||
|
let is_failure = self.metadata
|
||||||
|
.as_ref()
|
||||||
|
.and_then(|m| m.status
|
||||||
|
.as_ref()
|
||||||
|
.map(|s| s.0 < 200 || s.0 >= 300))
|
||||||
|
.unwrap_or(false);
|
||||||
|
if is_failure {
|
||||||
|
// Ensure that the element doesn't receive any further notifications
|
||||||
|
// of the aborted fetch. The dedicated failure steps will be executed
|
||||||
|
// when response_complete runs.
|
||||||
|
self.ignore_response = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn data_available(&mut self, payload: Vec<u8>) {
|
||||||
|
if self.ignore_response {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut payload = payload;
|
||||||
|
self.data.append(&mut payload);
|
||||||
|
|
||||||
|
let elem = self.elem.root();
|
||||||
|
|
||||||
|
// https://html.spec.whatwg.org/multipage/#media-data-processing-steps-list
|
||||||
|
// => "Once enough of the media data has been fetched to determine the duration..."
|
||||||
|
if !self.have_metadata {
|
||||||
|
//TODO: actually check if the payload contains the full metadata
|
||||||
|
|
||||||
|
// Step 6
|
||||||
|
elem.change_ready_state(HAVE_METADATA);
|
||||||
|
self.have_metadata = true;
|
||||||
|
} else {
|
||||||
|
elem.change_ready_state(HAVE_CURRENT_DATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://html.spec.whatwg.org/multipage/#concept-media-load-resource step 4,
|
||||||
|
// => "If mode is remote" step 2
|
||||||
|
if time::get_time() > self.next_progress_event {
|
||||||
|
elem.queue_fire_simple_event("progress");
|
||||||
|
self.next_progress_event = time::get_time() + Duration::milliseconds(350);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://html.spec.whatwg.org/multipage/#media-data-processing-steps-list
|
||||||
|
fn response_complete(&mut self, status: Result<(), NetworkError>) {
|
||||||
|
let elem = self.elem.root();
|
||||||
|
|
||||||
|
// => "Once the entire media resource has been fetched..."
|
||||||
|
if status.is_ok() {
|
||||||
|
elem.change_ready_state(HAVE_ENOUGH_DATA);
|
||||||
|
|
||||||
|
elem.fire_simple_event("progress");
|
||||||
|
|
||||||
|
elem.network_state.set(NETWORK_IDLE);
|
||||||
|
|
||||||
|
elem.fire_simple_event("suspend");
|
||||||
|
}
|
||||||
|
// => "If the connection is interrupted after some media data has been received..."
|
||||||
|
else if elem.ready_state.get() != HAVE_NOTHING {
|
||||||
|
// Step 2
|
||||||
|
elem.error.set(Some(&*MediaError::new(&*window_from_node(&*elem),
|
||||||
|
MEDIA_ERR_NETWORK)));
|
||||||
|
|
||||||
|
// Step 3
|
||||||
|
elem.network_state.set(NETWORK_IDLE);
|
||||||
|
|
||||||
|
// TODO: Step 4 - update delay load flag
|
||||||
|
|
||||||
|
// Step 5
|
||||||
|
elem.fire_simple_event("error");
|
||||||
|
}
|
||||||
|
// => "If the media data cannot be fetched at all..."
|
||||||
|
else {
|
||||||
|
elem.queue_dedicated_media_source_failure_steps();
|
||||||
|
}
|
||||||
|
|
||||||
|
let document = document_from_node(&*elem);
|
||||||
|
document.finish_load(LoadType::Media(self.url.clone()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl PreInvoke for HTMLMediaElementContext {
|
||||||
|
fn should_invoke(&self) -> bool {
|
||||||
|
//TODO: finish_load needs to run at some point if the generation changes.
|
||||||
|
self.elem.root().generation_id.get() == self.generation_id
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl HTMLMediaElementContext {
|
||||||
|
fn new(elem: &HTMLMediaElement, url: Url) -> HTMLMediaElementContext {
|
||||||
|
HTMLMediaElementContext {
|
||||||
|
elem: Trusted::new(elem),
|
||||||
|
data: vec![],
|
||||||
|
metadata: None,
|
||||||
|
generation_id: elem.generation_id.get(),
|
||||||
|
next_progress_event: time::get_time() + Duration::milliseconds(350),
|
||||||
|
url: url,
|
||||||
|
have_metadata: false,
|
||||||
|
ignore_response: false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[dom_struct]
|
#[dom_struct]
|
||||||
pub struct HTMLMediaElement {
|
pub struct HTMLMediaElement {
|
||||||
htmlelement: HTMLElement,
|
htmlelement: HTMLElement,
|
||||||
|
network_state: Cell<u16>,
|
||||||
|
ready_state: Cell<u16>,
|
||||||
|
current_src: DOMRefCell<String>,
|
||||||
|
generation_id: Cell<u32>,
|
||||||
|
first_data_load: Cell<bool>,
|
||||||
|
error: MutNullableHeap<JS<MediaError>>,
|
||||||
|
paused: Cell<bool>,
|
||||||
|
autoplaying: Cell<bool>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl HTMLMediaElement {
|
impl HTMLMediaElement {
|
||||||
@ -18,7 +186,15 @@ impl HTMLMediaElement {
|
|||||||
-> HTMLMediaElement {
|
-> HTMLMediaElement {
|
||||||
HTMLMediaElement {
|
HTMLMediaElement {
|
||||||
htmlelement:
|
htmlelement:
|
||||||
HTMLElement::new_inherited(tag_name, prefix, document)
|
HTMLElement::new_inherited(tag_name, prefix, document),
|
||||||
|
network_state: Cell::new(NETWORK_EMPTY),
|
||||||
|
ready_state: Cell::new(HAVE_NOTHING),
|
||||||
|
current_src: DOMRefCell::new("".to_owned()),
|
||||||
|
generation_id: Cell::new(0),
|
||||||
|
first_data_load: Cell::new(true),
|
||||||
|
error: Default::default(),
|
||||||
|
paused: Cell::new(true),
|
||||||
|
autoplaying: Cell::new(true),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -26,4 +202,614 @@ impl HTMLMediaElement {
|
|||||||
pub fn htmlelement(&self) -> &HTMLElement {
|
pub fn htmlelement(&self) -> &HTMLElement {
|
||||||
&self.htmlelement
|
&self.htmlelement
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://html.spec.whatwg.org/multipage/#internal-pause-steps
|
||||||
|
fn internal_pause_steps(&self) {
|
||||||
|
// Step 1
|
||||||
|
self.autoplaying.set(false);
|
||||||
|
|
||||||
|
// Step 2
|
||||||
|
if !self.Paused() {
|
||||||
|
// 2.1
|
||||||
|
self.paused.set(true);
|
||||||
|
|
||||||
|
// 2.2
|
||||||
|
self.queue_internal_pause_steps_task();
|
||||||
|
|
||||||
|
// TODO 2.3 (official playback position)
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO step 3 (media controller)
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://html.spec.whatwg.org/multipage/#notify-about-playing
|
||||||
|
fn notify_about_playing(&self) {
|
||||||
|
// Step 1
|
||||||
|
self.fire_simple_event("playing");
|
||||||
|
// TODO Step 2
|
||||||
|
}
|
||||||
|
|
||||||
|
fn queue_notify_about_playing(&self) {
|
||||||
|
struct Task {
|
||||||
|
elem: Trusted<HTMLMediaElement>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Runnable for Task {
|
||||||
|
fn handler(self: Box<Task>) {
|
||||||
|
self.elem.root().notify_about_playing();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let task = Task {
|
||||||
|
elem: Trusted::new(self),
|
||||||
|
};
|
||||||
|
let win = window_from_node(self);
|
||||||
|
let _ = win.dom_manipulation_task_source().queue(DOMManipulationTask::MediaTask(box task));
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://html.spec.whatwg.org/multipage/#internal-pause-steps step 2.2
|
||||||
|
fn queue_internal_pause_steps_task(&self) {
|
||||||
|
struct Task {
|
||||||
|
elem: Trusted<HTMLMediaElement>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Runnable for Task {
|
||||||
|
fn handler(self: Box<Task>) {
|
||||||
|
let elem = self.elem.root();
|
||||||
|
// 2.2.1
|
||||||
|
elem.fire_simple_event("timeupdate");
|
||||||
|
// 2.2.2
|
||||||
|
elem.fire_simple_event("pause");
|
||||||
|
// TODO 2.2.3
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let task = Task {
|
||||||
|
elem: Trusted::new(self),
|
||||||
|
};
|
||||||
|
let win = window_from_node(self);
|
||||||
|
let _ = win.dom_manipulation_task_source().queue(DOMManipulationTask::MediaTask(box task));
|
||||||
|
}
|
||||||
|
|
||||||
|
fn queue_fire_simple_event(&self, type_: &'static str) {
|
||||||
|
let win = window_from_node(self);
|
||||||
|
let task = FireSimpleEventTask::new(self, type_);
|
||||||
|
let _ = win.dom_manipulation_task_source().queue(DOMManipulationTask::MediaTask(box task));
|
||||||
|
}
|
||||||
|
|
||||||
|
fn fire_simple_event(&self, type_: &str) {
|
||||||
|
let window = window_from_node(self);
|
||||||
|
let event = Event::new(GlobalRef::Window(&*window),
|
||||||
|
Atom::from(type_),
|
||||||
|
EventBubbles::DoesNotBubble,
|
||||||
|
EventCancelable::NotCancelable);
|
||||||
|
event.fire(self.upcast());
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://html.spec.whatwg.org/multipage/#ready-states
|
||||||
|
fn change_ready_state(&self, ready_state: u16) {
|
||||||
|
let old_ready_state = self.ready_state.get();
|
||||||
|
self.ready_state.set(ready_state);
|
||||||
|
|
||||||
|
if self.network_state.get() == NETWORK_EMPTY {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Step 1
|
||||||
|
match (old_ready_state, ready_state) {
|
||||||
|
// previous ready state was HAVE_NOTHING, and the new ready state is
|
||||||
|
// HAVE_METADATA
|
||||||
|
(HAVE_NOTHING, HAVE_METADATA) => {
|
||||||
|
self.queue_fire_simple_event("loadedmetadata");
|
||||||
|
}
|
||||||
|
|
||||||
|
// previous ready state was HAVE_METADATA and the new ready state is
|
||||||
|
// HAVE_CURRENT_DATA or greater
|
||||||
|
(HAVE_METADATA, HAVE_CURRENT_DATA) |
|
||||||
|
(HAVE_METADATA, HAVE_FUTURE_DATA) |
|
||||||
|
(HAVE_METADATA, HAVE_ENOUGH_DATA) => {
|
||||||
|
if self.first_data_load.get() {
|
||||||
|
self.first_data_load.set(false);
|
||||||
|
self.queue_fire_simple_event("loadeddata");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// previous ready state was HAVE_FUTURE_DATA or more, and the new ready
|
||||||
|
// state is HAVE_CURRENT_DATA or less
|
||||||
|
(HAVE_FUTURE_DATA, HAVE_CURRENT_DATA) |
|
||||||
|
(HAVE_ENOUGH_DATA, HAVE_CURRENT_DATA) |
|
||||||
|
(HAVE_FUTURE_DATA, HAVE_METADATA) |
|
||||||
|
(HAVE_ENOUGH_DATA, HAVE_METADATA) |
|
||||||
|
(HAVE_FUTURE_DATA, HAVE_NOTHING) |
|
||||||
|
(HAVE_ENOUGH_DATA, HAVE_NOTHING) => {
|
||||||
|
// TODO: timeupdate event logic + waiting
|
||||||
|
}
|
||||||
|
|
||||||
|
_ => (),
|
||||||
|
}
|
||||||
|
|
||||||
|
// Step 1
|
||||||
|
// If the new ready state is HAVE_FUTURE_DATA or HAVE_ENOUGH_DATA,
|
||||||
|
// then the relevant steps below must then be run also.
|
||||||
|
match (old_ready_state, ready_state) {
|
||||||
|
// previous ready state was HAVE_CURRENT_DATA or less, and the new ready
|
||||||
|
// state is HAVE_FUTURE_DATA
|
||||||
|
(HAVE_CURRENT_DATA, HAVE_FUTURE_DATA) |
|
||||||
|
(HAVE_METADATA, HAVE_FUTURE_DATA) |
|
||||||
|
(HAVE_NOTHING, HAVE_FUTURE_DATA) => {
|
||||||
|
self.queue_fire_simple_event("canplay");
|
||||||
|
|
||||||
|
if !self.Paused() {
|
||||||
|
self.queue_notify_about_playing();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// new ready state is HAVE_ENOUGH_DATA
|
||||||
|
(_, HAVE_ENOUGH_DATA) => {
|
||||||
|
if old_ready_state <= HAVE_CURRENT_DATA {
|
||||||
|
self.queue_fire_simple_event("canplay");
|
||||||
|
|
||||||
|
if !self.Paused() {
|
||||||
|
self.queue_notify_about_playing();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//TODO: check sandboxed automatic features browsing context flag
|
||||||
|
if self.autoplaying.get() &&
|
||||||
|
self.Paused() &&
|
||||||
|
self.Autoplay() {
|
||||||
|
// Step 1
|
||||||
|
self.paused.set(false);
|
||||||
|
// TODO step 2: show poster
|
||||||
|
// Step 3
|
||||||
|
self.queue_fire_simple_event("play");
|
||||||
|
// Step 4
|
||||||
|
self.queue_notify_about_playing();
|
||||||
|
// Step 5
|
||||||
|
self.autoplaying.set(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
self.queue_fire_simple_event("canplaythrough");
|
||||||
|
}
|
||||||
|
|
||||||
|
_ => (),
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO Step 2: media controller
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://html.spec.whatwg.org/multipage/#concept-media-load-algorithm
|
||||||
|
fn invoke_resource_selection_algorithm(&self) {
|
||||||
|
// Step 1
|
||||||
|
self.network_state.set(NETWORK_NO_SOURCE);
|
||||||
|
|
||||||
|
// TODO step 2 (show poster)
|
||||||
|
// TODO step 3 (delay load event)
|
||||||
|
|
||||||
|
// Step 4
|
||||||
|
let doc = document_from_node(self);
|
||||||
|
ScriptThread::await_stable_state(ResourceSelectionTask::new(self, doc.base_url()));
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://html.spec.whatwg.org/multipage/#concept-media-load-algorithm
|
||||||
|
fn resource_selection_algorithm_sync(&self, base_url: Url) {
|
||||||
|
// TODO step 5 (populate pending text tracks)
|
||||||
|
|
||||||
|
// Step 6
|
||||||
|
let mode = if false {
|
||||||
|
// TODO media provider object
|
||||||
|
ResourceSelectionMode::Object
|
||||||
|
} else if let Some(attr) = self.upcast::<Element>().get_attribute(&ns!(), &atom!("src")) {
|
||||||
|
ResourceSelectionMode::Attribute(attr.Value().to_string())
|
||||||
|
} else if false {
|
||||||
|
// TODO <source> child
|
||||||
|
ResourceSelectionMode::Children(panic!())
|
||||||
|
} else {
|
||||||
|
self.network_state.set(NETWORK_EMPTY);
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Step 7
|
||||||
|
self.network_state.set(NETWORK_LOADING);
|
||||||
|
|
||||||
|
// Step 8
|
||||||
|
self.queue_fire_simple_event("loadstart");
|
||||||
|
|
||||||
|
// Step 9
|
||||||
|
match mode {
|
||||||
|
ResourceSelectionMode::Object => {
|
||||||
|
// Step 1
|
||||||
|
*self.current_src.borrow_mut() = "".to_owned();
|
||||||
|
|
||||||
|
// Step 4
|
||||||
|
self.resource_fetch_algorithm(Resource::Object);
|
||||||
|
}
|
||||||
|
|
||||||
|
ResourceSelectionMode::Attribute(src) => {
|
||||||
|
// Step 1
|
||||||
|
if src.is_empty() {
|
||||||
|
self.queue_dedicated_media_source_failure_steps();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Step 2
|
||||||
|
let absolute_url = base_url.join(&src).map_err(|_| ());
|
||||||
|
|
||||||
|
// Step 3
|
||||||
|
if let Ok(url) = absolute_url {
|
||||||
|
*self.current_src.borrow_mut() = url.as_str().into();
|
||||||
|
// Step 4
|
||||||
|
self.resource_fetch_algorithm(Resource::Url(url));
|
||||||
|
} else {
|
||||||
|
self.queue_dedicated_media_source_failure_steps();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ResourceSelectionMode::Children(_child) => {
|
||||||
|
// TODO
|
||||||
|
self.queue_dedicated_media_source_failure_steps()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://html.spec.whatwg.org/multipage/#concept-media-load-resource
|
||||||
|
fn resource_fetch_algorithm(&self, resource: Resource) {
|
||||||
|
// TODO step 3 (remove text tracks)
|
||||||
|
|
||||||
|
// Step 4
|
||||||
|
if let Resource::Url(url) = resource {
|
||||||
|
// 4.1
|
||||||
|
if self.Preload() == "none" && !self.autoplaying.get() {
|
||||||
|
// 4.1.1
|
||||||
|
self.network_state.set(NETWORK_IDLE);
|
||||||
|
|
||||||
|
// 4.1.2
|
||||||
|
self.queue_fire_simple_event("suspend");
|
||||||
|
|
||||||
|
// TODO 4.1.3 (delay load flag)
|
||||||
|
|
||||||
|
// TODO 4.1.5-7 (state for load that initiates later)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 4.2
|
||||||
|
let context = Arc::new(Mutex::new(HTMLMediaElementContext::new(self, url.clone())));
|
||||||
|
let (action_sender, action_receiver) = ipc::channel().unwrap();
|
||||||
|
let script_chan = window_from_node(self).networking_task_source();
|
||||||
|
let listener = box NetworkListener {
|
||||||
|
context: context,
|
||||||
|
script_chan: script_chan,
|
||||||
|
};
|
||||||
|
|
||||||
|
let response_target = AsyncResponseTarget {
|
||||||
|
sender: action_sender,
|
||||||
|
};
|
||||||
|
ROUTER.add_route(action_receiver.to_opaque(), box move |message| {
|
||||||
|
listener.notify(message.to().unwrap());
|
||||||
|
});
|
||||||
|
|
||||||
|
// FIXME: we're supposed to block the load event much earlier than now
|
||||||
|
let doc = document_from_node(self);
|
||||||
|
doc.load_async(LoadType::Media(url), response_target);
|
||||||
|
} else {
|
||||||
|
// TODO local resource fetch
|
||||||
|
self.queue_dedicated_media_source_failure_steps();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn queue_dedicated_media_source_failure_steps(&self) {
|
||||||
|
let _ = window_from_node(self).dom_manipulation_task_source().queue(
|
||||||
|
DOMManipulationTask::MediaTask(box DedicatedMediaSourceFailureTask::new(self)));
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://html.spec.whatwg.org/multipage/#dedicated-media-source-failure-steps
|
||||||
|
fn dedicated_media_source_failure(&self) {
|
||||||
|
// Step 1
|
||||||
|
self.error.set(Some(&*MediaError::new(&*window_from_node(self),
|
||||||
|
MEDIA_ERR_SRC_NOT_SUPPORTED)));
|
||||||
|
|
||||||
|
// TODO step 2 (forget resource tracks)
|
||||||
|
|
||||||
|
// Step 3
|
||||||
|
self.network_state.set(NETWORK_NO_SOURCE);
|
||||||
|
|
||||||
|
// TODO step 4 (show poster)
|
||||||
|
|
||||||
|
// Step 5
|
||||||
|
self.fire_simple_event("error");
|
||||||
|
|
||||||
|
// TODO step 6 (resolve pending play promises)
|
||||||
|
// TODO step 7 (delay load event)
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://html.spec.whatwg.org/multipage/#media-element-load-algorithm
|
||||||
|
fn media_element_load_algorithm(&self) {
|
||||||
|
self.first_data_load.set(true);
|
||||||
|
|
||||||
|
// TODO Step 1 (abort resource selection algorithm instances)
|
||||||
|
|
||||||
|
// Step 2
|
||||||
|
self.generation_id.set(self.generation_id.get() + 1);
|
||||||
|
// TODO reject pending play promises
|
||||||
|
|
||||||
|
// Step 3
|
||||||
|
let network_state = self.NetworkState();
|
||||||
|
if network_state == NETWORK_LOADING || network_state == NETWORK_IDLE {
|
||||||
|
self.queue_fire_simple_event("abort");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Step 4
|
||||||
|
if network_state != NETWORK_EMPTY {
|
||||||
|
// 4.1
|
||||||
|
self.queue_fire_simple_event("emptied");
|
||||||
|
|
||||||
|
// TODO 4.2 (abort in-progress fetch)
|
||||||
|
|
||||||
|
// TODO 4.3 (detach media provider object)
|
||||||
|
// TODO 4.4 (forget resource tracks)
|
||||||
|
|
||||||
|
// 4.5
|
||||||
|
if self.ready_state.get() != HAVE_NOTHING {
|
||||||
|
self.change_ready_state(HAVE_NOTHING);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 4.6
|
||||||
|
if !self.Paused() {
|
||||||
|
self.paused.set(true);
|
||||||
|
}
|
||||||
|
// TODO 4.7 (seeking)
|
||||||
|
// TODO 4.8 (playback position)
|
||||||
|
// TODO 4.9 (timeline offset)
|
||||||
|
// TODO 4.10 (duration)
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO step 5 (playback rate)
|
||||||
|
// Step 6
|
||||||
|
self.error.set(None);
|
||||||
|
self.autoplaying.set(true);
|
||||||
|
|
||||||
|
// Step 7
|
||||||
|
self.invoke_resource_selection_algorithm();
|
||||||
|
|
||||||
|
// TODO step 8 (stop previously playing resource)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl HTMLMediaElementMethods for HTMLMediaElement {
|
||||||
|
// https://html.spec.whatwg.org/multipage/#dom-media-networkstate
|
||||||
|
fn NetworkState(&self) -> u16 {
|
||||||
|
self.network_state.get()
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://html.spec.whatwg.org/multipage/#dom-media-readystate
|
||||||
|
fn ReadyState(&self) -> u16 {
|
||||||
|
self.ready_state.get()
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://html.spec.whatwg.org/multipage/#dom-media-autoplay
|
||||||
|
make_bool_getter!(Autoplay, "autoplay");
|
||||||
|
// https://html.spec.whatwg.org/multipage/#dom-media-autoplay
|
||||||
|
make_bool_setter!(SetAutoplay, "autoplay");
|
||||||
|
|
||||||
|
// https://html.spec.whatwg.org/multipage/#dom-media-src
|
||||||
|
make_url_getter!(Src, "src");
|
||||||
|
// https://html.spec.whatwg.org/multipage/#dom-media-src
|
||||||
|
make_setter!(SetSrc, "src");
|
||||||
|
|
||||||
|
// https://html.spec.whatwg.org/multipage/#attr-media-preload
|
||||||
|
// Missing value default is user-agent defined.
|
||||||
|
make_enumerated_getter!(Preload, "preload", "", ("none") | ("metadata") | ("auto"));
|
||||||
|
// https://html.spec.whatwg.org/multipage/#attr-media-preload
|
||||||
|
make_setter!(SetPreload, "preload");
|
||||||
|
|
||||||
|
// https://html.spec.whatwg.org/multipage/#dom-media-currentsrc
|
||||||
|
fn CurrentSrc(&self) -> DOMString {
|
||||||
|
DOMString::from(self.current_src.borrow().clone())
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://html.spec.whatwg.org/multipage/#dom-media-load
|
||||||
|
fn Load(&self) {
|
||||||
|
self.media_element_load_algorithm();
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://html.spec.whatwg.org/multipage/#dom-navigator-canplaytype
|
||||||
|
fn CanPlayType(&self, _type_: DOMString) -> CanPlayTypeResult {
|
||||||
|
// TODO: application/octet-stream
|
||||||
|
CanPlayTypeResult::Maybe
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://html.spec.whatwg.org/multipage/#dom-media-error
|
||||||
|
fn GetError(&self) -> Option<Root<MediaError>> {
|
||||||
|
self.error.get()
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://html.spec.whatwg.org/multipage/#dom-media-play
|
||||||
|
fn Play(&self) {
|
||||||
|
// TODO step 1
|
||||||
|
|
||||||
|
// Step 2
|
||||||
|
if self.error.get().map_or(false, |e| e.Code() == MEDIA_ERR_SRC_NOT_SUPPORTED) {
|
||||||
|
// TODO return rejected promise
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO step 3
|
||||||
|
|
||||||
|
// Step 4
|
||||||
|
if self.network_state.get() == NETWORK_EMPTY {
|
||||||
|
self.invoke_resource_selection_algorithm();
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO step 5 (seek backwards)
|
||||||
|
|
||||||
|
// TODO step 6 (media controller)
|
||||||
|
|
||||||
|
let state = self.ready_state.get();
|
||||||
|
|
||||||
|
// Step 7
|
||||||
|
if self.Paused() {
|
||||||
|
// 7.1
|
||||||
|
self.paused.set(false);
|
||||||
|
|
||||||
|
// TODO 7.2 (show poster)
|
||||||
|
|
||||||
|
// 7.3
|
||||||
|
self.queue_fire_simple_event("play");
|
||||||
|
|
||||||
|
// 7.4
|
||||||
|
if state == HAVE_NOTHING ||
|
||||||
|
state == HAVE_METADATA ||
|
||||||
|
state == HAVE_CURRENT_DATA {
|
||||||
|
self.queue_fire_simple_event("waiting");
|
||||||
|
} else {
|
||||||
|
self.queue_notify_about_playing();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Step 8
|
||||||
|
else if state == HAVE_FUTURE_DATA || state == HAVE_ENOUGH_DATA {
|
||||||
|
// TODO resolve pending play promises
|
||||||
|
}
|
||||||
|
|
||||||
|
// Step 9
|
||||||
|
self.autoplaying.set(false);
|
||||||
|
|
||||||
|
// TODO step 10 (media controller)
|
||||||
|
|
||||||
|
// TODO return promise
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://html.spec.whatwg.org/multipage/#dom-media-pause
|
||||||
|
fn Pause(&self) {
|
||||||
|
// Step 1
|
||||||
|
if self.network_state.get() == NETWORK_EMPTY {
|
||||||
|
self.invoke_resource_selection_algorithm();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Step 2
|
||||||
|
self.internal_pause_steps();
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://html.spec.whatwg.org/multipage/#dom-media-paused
|
||||||
|
fn Paused(&self) -> bool {
|
||||||
|
self.paused.get()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl VirtualMethods for HTMLMediaElement {
|
||||||
|
fn super_type(&self) -> Option<&VirtualMethods> {
|
||||||
|
Some(self.upcast::<HTMLElement>() as &VirtualMethods)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn attribute_mutated(&self, attr: &Attr, mutation: AttributeMutation) {
|
||||||
|
self.super_type().unwrap().attribute_mutated(attr, mutation);
|
||||||
|
|
||||||
|
match attr.local_name() {
|
||||||
|
&atom!("src") => {
|
||||||
|
if mutation.new_value(attr).is_some() {
|
||||||
|
self.media_element_load_algorithm();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => (),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://html.spec.whatwg.org/multipage/#playing-the-media-resource:remove-an-element-from-a-document
|
||||||
|
fn unbind_from_tree(&self, context: &UnbindContext) {
|
||||||
|
self.super_type().unwrap().unbind_from_tree(context);
|
||||||
|
|
||||||
|
if context.tree_in_doc {
|
||||||
|
ScriptThread::await_stable_state(PauseIfNotInDocumentTask::new(self));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct FireSimpleEventTask {
|
||||||
|
elem: Trusted<HTMLMediaElement>,
|
||||||
|
type_: &'static str,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl FireSimpleEventTask {
|
||||||
|
fn new(target: &HTMLMediaElement, type_: &'static str) -> FireSimpleEventTask {
|
||||||
|
FireSimpleEventTask {
|
||||||
|
elem: Trusted::new(target),
|
||||||
|
type_: type_,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Runnable for FireSimpleEventTask {
|
||||||
|
fn handler(self: Box<FireSimpleEventTask>) {
|
||||||
|
let elem = self.elem.root();
|
||||||
|
elem.fire_simple_event(self.type_);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct ResourceSelectionTask {
|
||||||
|
elem: Trusted<HTMLMediaElement>,
|
||||||
|
base_url: Url,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ResourceSelectionTask {
|
||||||
|
fn new(elem: &HTMLMediaElement, url: Url) -> ResourceSelectionTask {
|
||||||
|
ResourceSelectionTask {
|
||||||
|
elem: Trusted::new(elem),
|
||||||
|
base_url: url,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Runnable for ResourceSelectionTask {
|
||||||
|
fn handler(self: Box<ResourceSelectionTask>) {
|
||||||
|
self.elem.root().resource_selection_algorithm_sync(self.base_url);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct DedicatedMediaSourceFailureTask {
|
||||||
|
elem: Trusted<HTMLMediaElement>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl DedicatedMediaSourceFailureTask {
|
||||||
|
fn new(elem: &HTMLMediaElement) -> DedicatedMediaSourceFailureTask {
|
||||||
|
DedicatedMediaSourceFailureTask {
|
||||||
|
elem: Trusted::new(elem),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Runnable for DedicatedMediaSourceFailureTask {
|
||||||
|
fn handler(self: Box<DedicatedMediaSourceFailureTask>) {
|
||||||
|
self.elem.root().dedicated_media_source_failure();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct PauseIfNotInDocumentTask {
|
||||||
|
elem: Trusted<HTMLMediaElement>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl PauseIfNotInDocumentTask {
|
||||||
|
fn new(elem: &HTMLMediaElement) -> PauseIfNotInDocumentTask {
|
||||||
|
PauseIfNotInDocumentTask {
|
||||||
|
elem: Trusted::new(elem),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Runnable for PauseIfNotInDocumentTask {
|
||||||
|
fn handler(self: Box<PauseIfNotInDocumentTask>) {
|
||||||
|
let elem = self.elem.root();
|
||||||
|
if !elem.upcast::<Node>().is_in_doc() {
|
||||||
|
elem.internal_pause_steps();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
enum ResourceSelectionMode {
|
||||||
|
Object,
|
||||||
|
Attribute(String),
|
||||||
|
Children(Root<HTMLSourceElement>),
|
||||||
|
}
|
||||||
|
|
||||||
|
enum Resource {
|
||||||
|
Object,
|
||||||
|
Url(Url),
|
||||||
}
|
}
|
||||||
|
@ -347,17 +347,30 @@ macro_rules! global_event_handlers(
|
|||||||
|
|
||||||
);
|
);
|
||||||
(NoOnload) => (
|
(NoOnload) => (
|
||||||
|
event_handler!(abort, GetOnabort, SetOnabort);
|
||||||
|
event_handler!(canplay, GetOncanplay, SetOncanplay);
|
||||||
|
event_handler!(canplaythrough, GetOncanplaythrough, SetOncanplaythrough);
|
||||||
event_handler!(change, GetOnchange, SetOnchange);
|
event_handler!(change, GetOnchange, SetOnchange);
|
||||||
event_handler!(click, GetOnclick, SetOnclick);
|
event_handler!(click, GetOnclick, SetOnclick);
|
||||||
event_handler!(dblclick, GetOndblclick, SetOndblclick);
|
event_handler!(dblclick, GetOndblclick, SetOndblclick);
|
||||||
|
event_handler!(emptied, GetOnemptied, SetOnemptied);
|
||||||
error_event_handler!(error, GetOnerror, SetOnerror);
|
error_event_handler!(error, GetOnerror, SetOnerror);
|
||||||
event_handler!(input, GetOninput, SetOninput);
|
event_handler!(input, GetOninput, SetOninput);
|
||||||
event_handler!(keydown, GetOnkeydown, SetOnkeydown);
|
event_handler!(keydown, GetOnkeydown, SetOnkeydown);
|
||||||
event_handler!(keypress, GetOnkeypress, SetOnkeypress);
|
event_handler!(keypress, GetOnkeypress, SetOnkeypress);
|
||||||
event_handler!(keyup, GetOnkeyup, SetOnkeyup);
|
event_handler!(keyup, GetOnkeyup, SetOnkeyup);
|
||||||
|
event_handler!(loadeddata, GetOnloadeddata, SetOnloadeddata);
|
||||||
|
event_handler!(loadedmetata, GetOnloadedmetadata, SetOnloadedmetadata);
|
||||||
event_handler!(mouseover, GetOnmouseover, SetOnmouseover);
|
event_handler!(mouseover, GetOnmouseover, SetOnmouseover);
|
||||||
|
event_handler!(pause, GetOnpause, SetOnpause);
|
||||||
|
event_handler!(play, GetOnplay, SetOnplay);
|
||||||
|
event_handler!(playing, GetOnplaying, SetOnplaying);
|
||||||
|
event_handler!(progress, GetOnprogress, SetOnprogress);
|
||||||
event_handler!(reset, GetOnreset, SetOnreset);
|
event_handler!(reset, GetOnreset, SetOnreset);
|
||||||
event_handler!(submit, GetOnsubmit, SetOnsubmit);
|
event_handler!(submit, GetOnsubmit, SetOnsubmit);
|
||||||
|
event_handler!(suspend, GetOnsuspend, SetOnsuspend);
|
||||||
|
event_handler!(timeupdate, GetOntimeupdate, SetOntimeupdate);
|
||||||
event_handler!(toggle, GetOntoggle, SetOntoggle);
|
event_handler!(toggle, GetOntoggle, SetOntoggle);
|
||||||
|
event_handler!(waiting, GetOnwaiting, SetOnwaiting);
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
37
servo/components/script/dom/mediaerror.rs
Normal file
37
servo/components/script/dom/mediaerror.rs
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
use dom::bindings::codegen::Bindings::MediaErrorBinding::{self, MediaErrorMethods};
|
||||||
|
use dom::bindings::global::GlobalRef;
|
||||||
|
use dom::bindings::js::Root;
|
||||||
|
use dom::bindings::reflector::{Reflector, reflect_dom_object};
|
||||||
|
use dom::window::Window;
|
||||||
|
|
||||||
|
#[dom_struct]
|
||||||
|
pub struct MediaError {
|
||||||
|
reflector_: Reflector,
|
||||||
|
code: u16,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl MediaError {
|
||||||
|
fn new_inherited(code: u16) -> MediaError {
|
||||||
|
MediaError {
|
||||||
|
reflector_: Reflector::new(),
|
||||||
|
code: code,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn new(window: &Window, code: u16) -> Root<MediaError> {
|
||||||
|
reflect_dom_object(box MediaError::new_inherited(code),
|
||||||
|
GlobalRef::Window(window),
|
||||||
|
MediaErrorBinding::Wrap)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl MediaErrorMethods for MediaError {
|
||||||
|
// https://html.spec.whatwg.org/multipage/#dom-mediaerror-code
|
||||||
|
fn Code(&self) -> u16 {
|
||||||
|
self.code
|
||||||
|
}
|
||||||
|
}
|
@ -339,6 +339,7 @@ pub mod htmlvideoelement;
|
|||||||
pub mod imagedata;
|
pub mod imagedata;
|
||||||
pub mod keyboardevent;
|
pub mod keyboardevent;
|
||||||
pub mod location;
|
pub mod location;
|
||||||
|
pub mod mediaerror;
|
||||||
pub mod messageevent;
|
pub mod messageevent;
|
||||||
pub mod mimetype;
|
pub mod mimetype;
|
||||||
pub mod mimetypearray;
|
pub mod mimetypearray;
|
||||||
|
@ -29,6 +29,7 @@ use dom::htmlimageelement::HTMLImageElement;
|
|||||||
use dom::htmlinputelement::HTMLInputElement;
|
use dom::htmlinputelement::HTMLInputElement;
|
||||||
use dom::htmllabelelement::HTMLLabelElement;
|
use dom::htmllabelelement::HTMLLabelElement;
|
||||||
use dom::htmllinkelement::HTMLLinkElement;
|
use dom::htmllinkelement::HTMLLinkElement;
|
||||||
|
use dom::htmlmediaelement::HTMLMediaElement;
|
||||||
use dom::htmlmetaelement::HTMLMetaElement;
|
use dom::htmlmetaelement::HTMLMetaElement;
|
||||||
use dom::htmlobjectelement::HTMLObjectElement;
|
use dom::htmlobjectelement::HTMLObjectElement;
|
||||||
use dom::htmloptgroupelement::HTMLOptGroupElement;
|
use dom::htmloptgroupelement::HTMLOptGroupElement;
|
||||||
@ -181,6 +182,9 @@ pub fn vtable_for(node: &Node) -> &VirtualMethods {
|
|||||||
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLLinkElement)) => {
|
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLLinkElement)) => {
|
||||||
node.downcast::<HTMLLinkElement>().unwrap() as &VirtualMethods
|
node.downcast::<HTMLLinkElement>().unwrap() as &VirtualMethods
|
||||||
}
|
}
|
||||||
|
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLMediaElement(_))) => {
|
||||||
|
node.downcast::<HTMLMediaElement>().unwrap() as &VirtualMethods
|
||||||
|
}
|
||||||
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLMetaElement)) => {
|
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLMetaElement)) => {
|
||||||
node.downcast::<HTMLMetaElement>().unwrap() as &VirtualMethods
|
node.downcast::<HTMLMetaElement>().unwrap() as &VirtualMethods
|
||||||
}
|
}
|
||||||
|
@ -20,26 +20,40 @@ callback OnErrorEventHandlerNonNull = any ((Event or DOMString) event, optional
|
|||||||
optional any error);
|
optional any error);
|
||||||
typedef OnErrorEventHandlerNonNull? OnErrorEventHandler;
|
typedef OnErrorEventHandlerNonNull? OnErrorEventHandler;
|
||||||
|
|
||||||
|
// https://html.spec.whatwg.org/multipage/#globaleventhandlers
|
||||||
[NoInterfaceObject]
|
[NoInterfaceObject]
|
||||||
interface GlobalEventHandlers {
|
interface GlobalEventHandlers {
|
||||||
|
attribute EventHandler onabort;
|
||||||
attribute EventHandler onblur;
|
attribute EventHandler onblur;
|
||||||
|
attribute EventHandler oncanplay;
|
||||||
|
attribute EventHandler oncanplaythrough;
|
||||||
attribute EventHandler onchange;
|
attribute EventHandler onchange;
|
||||||
attribute EventHandler onclick;
|
attribute EventHandler onclick;
|
||||||
attribute EventHandler ondblclick;
|
attribute EventHandler ondblclick;
|
||||||
|
attribute EventHandler onemptied;
|
||||||
attribute OnErrorEventHandler onerror;
|
attribute OnErrorEventHandler onerror;
|
||||||
attribute EventHandler oninput;
|
attribute EventHandler oninput;
|
||||||
attribute EventHandler onkeydown;
|
attribute EventHandler onkeydown;
|
||||||
attribute EventHandler onkeypress;
|
attribute EventHandler onkeypress;
|
||||||
attribute EventHandler onkeyup;
|
attribute EventHandler onkeyup;
|
||||||
attribute EventHandler onload;
|
attribute EventHandler onload;
|
||||||
|
attribute EventHandler onloadeddata;
|
||||||
|
attribute EventHandler onloadedmetadata;
|
||||||
attribute EventHandler onmouseover;
|
attribute EventHandler onmouseover;
|
||||||
|
attribute EventHandler onpause;
|
||||||
|
attribute EventHandler onplay;
|
||||||
|
attribute EventHandler onplaying;
|
||||||
|
attribute EventHandler onprogress;
|
||||||
attribute EventHandler onreset;
|
attribute EventHandler onreset;
|
||||||
attribute EventHandler onresize;
|
attribute EventHandler onresize;
|
||||||
attribute EventHandler onsubmit;
|
attribute EventHandler onsubmit;
|
||||||
|
attribute EventHandler onsuspend;
|
||||||
|
attribute EventHandler ontimeupdate;
|
||||||
attribute EventHandler ontoggle;
|
attribute EventHandler ontoggle;
|
||||||
|
attribute EventHandler onwaiting;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// https://html.spec.whatwg.org/multipage/#windoweventhandlers
|
||||||
[NoInterfaceObject]
|
[NoInterfaceObject]
|
||||||
interface WindowEventHandlers {
|
interface WindowEventHandlers {
|
||||||
attribute EventHandler onunload;
|
attribute EventHandler onunload;
|
||||||
|
@ -3,34 +3,34 @@
|
|||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#htmlmediaelement
|
// https://html.spec.whatwg.org/multipage/#htmlmediaelement
|
||||||
//enum CanPlayTypeResult { "" /* empty string */, "maybe", "probably" };
|
enum CanPlayTypeResult { "" /* empty string */, "maybe", "probably" };
|
||||||
[Abstract]
|
[Abstract]
|
||||||
interface HTMLMediaElement : HTMLElement {
|
interface HTMLMediaElement : HTMLElement {
|
||||||
|
|
||||||
// error state
|
// error state
|
||||||
//readonly attribute MediaError? error;
|
readonly attribute MediaError? error;
|
||||||
|
|
||||||
// network state
|
// network state
|
||||||
// attribute DOMString src;
|
attribute DOMString src;
|
||||||
//readonly attribute DOMString currentSrc;
|
readonly attribute DOMString currentSrc;
|
||||||
// attribute DOMString crossOrigin;
|
// attribute DOMString crossOrigin;
|
||||||
//const unsigned short NETWORK_EMPTY = 0;
|
const unsigned short NETWORK_EMPTY = 0;
|
||||||
//const unsigned short NETWORK_IDLE = 1;
|
const unsigned short NETWORK_IDLE = 1;
|
||||||
//const unsigned short NETWORK_LOADING = 2;
|
const unsigned short NETWORK_LOADING = 2;
|
||||||
//const unsigned short NETWORK_NO_SOURCE = 3;
|
const unsigned short NETWORK_NO_SOURCE = 3;
|
||||||
//readonly attribute unsigned short networkState;
|
readonly attribute unsigned short networkState;
|
||||||
// attribute DOMString preload;
|
attribute DOMString preload;
|
||||||
//readonly attribute TimeRanges buffered;
|
//readonly attribute TimeRanges buffered;
|
||||||
//void load();
|
void load();
|
||||||
//CanPlayTypeResult canPlayType(DOMString type);
|
CanPlayTypeResult canPlayType(DOMString type);
|
||||||
|
|
||||||
// ready state
|
// ready state
|
||||||
//const unsigned short HAVE_NOTHING = 0;
|
const unsigned short HAVE_NOTHING = 0;
|
||||||
//const unsigned short HAVE_METADATA = 1;
|
const unsigned short HAVE_METADATA = 1;
|
||||||
//const unsigned short HAVE_CURRENT_DATA = 2;
|
const unsigned short HAVE_CURRENT_DATA = 2;
|
||||||
//const unsigned short HAVE_FUTURE_DATA = 3;
|
const unsigned short HAVE_FUTURE_DATA = 3;
|
||||||
//const unsigned short HAVE_ENOUGH_DATA = 4;
|
const unsigned short HAVE_ENOUGH_DATA = 4;
|
||||||
//readonly attribute unsigned short readyState;
|
readonly attribute unsigned short readyState;
|
||||||
//readonly attribute boolean seeking;
|
//readonly attribute boolean seeking;
|
||||||
|
|
||||||
// playback state
|
// playback state
|
||||||
@ -38,16 +38,16 @@ interface HTMLMediaElement : HTMLElement {
|
|||||||
//void fastSeek(double time);
|
//void fastSeek(double time);
|
||||||
//readonly attribute unrestricted double duration;
|
//readonly attribute unrestricted double duration;
|
||||||
//Date getStartDate();
|
//Date getStartDate();
|
||||||
//readonly attribute boolean paused;
|
readonly attribute boolean paused;
|
||||||
// attribute double defaultPlaybackRate;
|
// attribute double defaultPlaybackRate;
|
||||||
// attribute double playbackRate;
|
// attribute double playbackRate;
|
||||||
//readonly attribute TimeRanges played;
|
//readonly attribute TimeRanges played;
|
||||||
//readonly attribute TimeRanges seekable;
|
//readonly attribute TimeRanges seekable;
|
||||||
//readonly attribute boolean ended;
|
//readonly attribute boolean ended;
|
||||||
// attribute boolean autoplay;
|
attribute boolean autoplay;
|
||||||
// attribute boolean loop;
|
// attribute boolean loop;
|
||||||
//void play();
|
void play();
|
||||||
//void pause();
|
void pause();
|
||||||
|
|
||||||
// media controller
|
// media controller
|
||||||
// attribute DOMString mediaGroup;
|
// attribute DOMString mediaGroup;
|
||||||
|
13
servo/components/script/dom/webidls/MediaError.webidl
Normal file
13
servo/components/script/dom/webidls/MediaError.webidl
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
// https://html.spec.whatwg.org/multipage/#mediaerror
|
||||||
|
|
||||||
|
interface MediaError {
|
||||||
|
const unsigned short MEDIA_ERR_ABORTED = 1;
|
||||||
|
const unsigned short MEDIA_ERR_NETWORK = 2;
|
||||||
|
const unsigned short MEDIA_ERR_DECODE = 3;
|
||||||
|
const unsigned short MEDIA_ERR_SRC_NOT_SUPPORTED = 4;
|
||||||
|
readonly attribute unsigned short code;
|
||||||
|
};
|
@ -505,6 +505,19 @@ impl ScriptThread {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://html.spec.whatwg.org/multipage/#await-a-stable-state
|
||||||
|
pub fn await_stable_state<T: Runnable + Send + 'static>(task: T) {
|
||||||
|
//TODO use microtasks when they exist
|
||||||
|
SCRIPT_THREAD_ROOT.with(|root| {
|
||||||
|
if let Some(script_thread) = *root.borrow() {
|
||||||
|
let script_thread = unsafe { &*script_thread };
|
||||||
|
let _ = script_thread.chan.send(CommonScriptMsg::RunnableMsg(
|
||||||
|
ScriptThreadEventCategory::DomEvent,
|
||||||
|
box task));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/// Creates a new script thread.
|
/// Creates a new script thread.
|
||||||
pub fn new(state: InitialScriptState,
|
pub fn new(state: InitialScriptState,
|
||||||
port: Receiver<MainThreadScriptMsg>,
|
port: Receiver<MainThreadScriptMsg>,
|
||||||
|
@ -33,6 +33,8 @@ pub enum DOMManipulationTask {
|
|||||||
FireSimpleEvent(Atom, Trusted<EventTarget>),
|
FireSimpleEvent(Atom, Trusted<EventTarget>),
|
||||||
// https://html.spec.whatwg.org/multipage/#details-notification-task-steps
|
// https://html.spec.whatwg.org/multipage/#details-notification-task-steps
|
||||||
FireToggleEvent(Box<Runnable + Send>),
|
FireToggleEvent(Box<Runnable + Send>),
|
||||||
|
// Placeholder until there's a real media element task queue implementation
|
||||||
|
MediaTask(Box<Runnable + Send>),
|
||||||
// https://html.spec.whatwg.org/multipage/#planned-navigation
|
// https://html.spec.whatwg.org/multipage/#planned-navigation
|
||||||
PlannedNavigation(Box<Runnable + Send>),
|
PlannedNavigation(Box<Runnable + Send>),
|
||||||
// https://html.spec.whatwg.org/multipage/#send-a-storage-notification
|
// https://html.spec.whatwg.org/multipage/#send-a-storage-notification
|
||||||
@ -54,6 +56,7 @@ impl DOMManipulationTask {
|
|||||||
target.fire_simple_event(&*name);
|
target.fire_simple_event(&*name);
|
||||||
}
|
}
|
||||||
FireToggleEvent(runnable) => runnable.handler(),
|
FireToggleEvent(runnable) => runnable.handler(),
|
||||||
|
MediaTask(runnable) => runnable.handler(),
|
||||||
PlannedNavigation(runnable) => runnable.handler(),
|
PlannedNavigation(runnable) => runnable.handler(),
|
||||||
SendStorageNotification(runnable) => runnable.handler(script_thread)
|
SendStorageNotification(runnable) => runnable.handler(script_thread)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user