servo: Merge #18804 - Another couple of low-key media improvements πŸ‘ΆπŸ‘£ (from servo:media); r=emilio

Source-Repo: https://github.com/servo/servo
Source-Revision: 826352ab4cae13f5154d13ab53885d80a8057337

--HG--
extra : subtree_source : https%3A//hg.mozilla.org/projects/converted-servo-linear
extra : subtree_revision : 76086eaff3ce8c62041c2ffadfb24cbd7d9b9183
This commit is contained in:
Anthony Ramine 2017-10-10 06:17:15 -05:00
Π ΠΎΠ΄ΠΈΡ‚Π΅Π»ΡŒ 880fdf7f5e
ΠšΠΎΠΌΠΌΠΈΡ‚ 1200f0d0cb
2 ΠΈΠ·ΠΌΠ΅Π½Ρ‘Π½Π½Ρ‹Ρ… Ρ„Π°ΠΉΠ»ΠΎΠ²: 45 Π΄ΠΎΠ±Π°Π²Π»Π΅Π½ΠΈΠΉ ΠΈ 35 ΡƒΠ΄Π°Π»Π΅Π½ΠΈΠΉ

ΠŸΡ€ΠΎΡΠΌΠΎΡ‚Ρ€Π΅Ρ‚ΡŒ Ρ„Π°ΠΉΠ»

@ -20,6 +20,7 @@ use dom::bindings::refcounted::Trusted;
use dom::bindings::reflector::DomObject;
use dom::bindings::root::{DomRoot, MutNullableDom};
use dom::bindings::str::DOMString;
use dom::blob::Blob;
use dom::document::Document;
use dom::element::{Element, AttributeMutation};
use dom::eventtarget::EventTarget;
@ -57,6 +58,8 @@ pub struct HTMLMediaElement {
network_state: Cell<NetworkState>,
/// https://html.spec.whatwg.org/multipage/#dom-media-readystate
ready_state: Cell<ReadyState>,
/// https://html.spec.whatwg.org/multipage/#dom-media-srcobject
src_object: MutNullableDom<Blob>,
/// https://html.spec.whatwg.org/multipage/#dom-media-currentsrc
current_src: DomRefCell<String>,
/// Incremented whenever tasks associated with this element are cancelled.
@ -112,6 +115,7 @@ impl HTMLMediaElement {
htmlelement: HTMLElement::new_inherited(tag_name, prefix, document),
network_state: Cell::new(NetworkState::Empty),
ready_state: Cell::new(ReadyState::HaveNothing),
src_object: Default::default(),
current_src: DomRefCell::new("".to_owned()),
generation_id: Cell::new(0),
fired_loadeddata_event: Cell::new(false),
@ -430,6 +434,7 @@ impl HTMLMediaElement {
let doc = document_from_node(self);
let task = MediaElementMicrotask::ResourceSelectionTask {
elem: DomRoot::from_ref(self),
generation_id: self.generation_id.get(),
base_url: doc.base_url()
};
@ -447,13 +452,14 @@ impl HTMLMediaElement {
// Step 6.
enum Mode {
// FIXME(nox): Support media object provider.
#[allow(dead_code)]
Object,
Attribute(String),
Children(DomRoot<HTMLSourceElement>),
}
fn mode(media: &HTMLMediaElement) -> Option<Mode> {
if media.src_object.get().is_some() {
return Some(Mode::Object);
}
if let Some(attr) = media.upcast::<Element>().get_attribute(&ns!(), &local_name!("src")) {
return Some(Mode::Attribute(attr.Value().into()));
}
@ -499,7 +505,6 @@ impl HTMLMediaElement {
// Step 9.obj.3.
// Note that the resource fetch algorithm itself takes care
// of the cleanup in case of failure itself.
// FIXME(nox): Pass the assigned media provider here.
self.resource_fetch_algorithm(Resource::Object);
},
Mode::Attribute(src) => {
@ -612,7 +617,7 @@ impl HTMLMediaElement {
document.loader().fetch_async_background(request, action_sender);
},
Resource::Object => {
// FIXME(nox): Use the current media resource.
// FIXME(nox): Actually do something with the object.
self.queue_dedicated_media_source_failure_steps();
},
}
@ -672,12 +677,10 @@ impl HTMLMediaElement {
// this invokation of the load algorithm.
self.fired_loadeddata_event.set(false);
// Step 1.
// FIXME(nox): Abort any already-running instance of the
// resource selection algorithm.
// Steps 2-4.
// Step 1-2.
self.generation_id.set(self.generation_id.get() + 1);
// Steps 3-4.
while !self.in_flight_play_promises_queue.borrow().is_empty() {
self.fulfill_in_flight_play_promises(|| ());
}
@ -837,6 +840,17 @@ impl HTMLMediaElementMethods for HTMLMediaElement {
// https://html.spec.whatwg.org/multipage/#dom-media-src
make_setter!(SetSrc, "src");
// https://html.spec.whatwg.org/multipage/#dom-media-srcobject
fn GetSrcObject(&self) -> Option<DomRoot<Blob>> {
self.src_object.get()
}
// https://html.spec.whatwg.org/multipage/#dom-media-srcobject
fn SetSrcObject(&self, value: Option<&Blob>) {
self.src_object.set(value);
self.media_element_load_algorithm();
}
// https://html.spec.whatwg.org/multipage/#attr-media-preload
// Missing value default is user-agent defined.
make_enumerated_getter!(Preload, "preload", "", "none" | "metadata" | "auto");
@ -929,7 +943,8 @@ impl VirtualMethods for HTMLMediaElement {
pub enum MediaElementMicrotask {
ResourceSelectionTask {
elem: DomRoot<HTMLMediaElement>,
base_url: ServoUrl
generation_id: u32,
base_url: ServoUrl,
},
PauseIfNotInDocumentTask {
elem: DomRoot<HTMLMediaElement>,
@ -939,8 +954,10 @@ pub enum MediaElementMicrotask {
impl MicrotaskRunnable for MediaElementMicrotask {
fn handler(&self) {
match self {
&MediaElementMicrotask::ResourceSelectionTask { ref elem, ref base_url } => {
elem.resource_selection_algorithm_sync(base_url.clone());
&MediaElementMicrotask::ResourceSelectionTask { ref elem, generation_id, ref base_url } => {
if generation_id == elem.generation_id.get() {
elem.resource_selection_algorithm_sync(base_url.clone());
}
},
&MediaElementMicrotask::PauseIfNotInDocumentTask { ref elem } => {
if !elem.upcast::<Node>().is_in_doc() {

ΠŸΡ€ΠΎΡΠΌΠΎΡ‚Ρ€Π΅Ρ‚ΡŒ Ρ„Π°ΠΉΠ»

@ -3,25 +3,26 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// https://html.spec.whatwg.org/multipage/#htmlmediaelement
enum CanPlayTypeResult { "" /* empty string */, "maybe", "probably" };
typedef /* (MediaStream or MediaSource or */ Blob /* ) */ MediaProvider;
[Abstract]
interface HTMLMediaElement : HTMLElement {
// error state
readonly attribute MediaError? error;
// network state
[CEReactions]
attribute DOMString src;
[CEReactions] attribute DOMString src;
attribute MediaProvider? srcObject;
readonly attribute DOMString currentSrc;
// [CEReactions]
// attribute DOMString crossOrigin;
// [CEReactions] attribute DOMString crossOrigin;
const unsigned short NETWORK_EMPTY = 0;
const unsigned short NETWORK_IDLE = 1;
const unsigned short NETWORK_LOADING = 2;
const unsigned short NETWORK_NO_SOURCE = 3;
readonly attribute unsigned short networkState;
[CEReactions]
attribute DOMString preload;
[CEReactions] attribute DOMString preload;
// readonly attribute TimeRanges buffered;
void load();
CanPlayTypeResult canPlayType(DOMString type);
@ -36,34 +37,26 @@ interface HTMLMediaElement : HTMLElement {
// readonly attribute boolean seeking;
// playback state
// attribute double currentTime;
// attribute double currentTime;
// void fastSeek(double time);
// readonly attribute unrestricted double duration;
// Date getStartDate();
readonly attribute boolean paused;
// attribute double defaultPlaybackRate;
// attribute double playbackRate;
// attribute double defaultPlaybackRate;
// attribute double playbackRate;
// readonly attribute TimeRanges played;
// readonly attribute TimeRanges seekable;
// readonly attribute boolean ended;
[CEReactions]
attribute boolean autoplay;
// [CEReactions]
// attribute boolean loop;
[CEReactions] attribute boolean autoplay;
// [CEReactions] attribute boolean loop;
Promise<void> play();
void pause();
// media controller
// attribute DOMString mediaGroup;
// attribute MediaController? controller;
// controls
// [CEReactions]
// attribute boolean controls;
// attribute double volume;
// attribute boolean muted;
// [CEReactions]
// attribute boolean defaultMuted;
// [CEReactions] attribute boolean controls;
// attribute double volume;
// attribute boolean muted;
// [CEReactions] attribute boolean defaultMuted;
// tracks
// readonly attribute AudioTrackList audioTracks;