servo: Merge #19337 - Implement HTMLMediaElement::canPlayType using gecko-media (from philn:gecko-canPlayType); r=nox

<!-- Please describe your changes on the following line: -->

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [ ] These changes fix #__ (github issue number if applicable).

<!-- Either: -->
- [x] There are tests for these changes

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

Source-Repo: https://github.com/servo/servo
Source-Revision: c5b446a5731f41d06a250f7a8222a43c49dd33a9

--HG--
extra : subtree_source : https%3A//hg.mozilla.org/projects/converted-servo-linear
extra : subtree_revision : 311eb7174241447dac85a1e0a7974dc18cf5727e
This commit is contained in:
Philippe Normand 2017-11-23 06:52:27 -06:00
parent 02cab34d1b
commit c5440617e9

View File

@ -31,10 +31,13 @@ use dom::node::{window_from_node, document_from_node, Node, UnbindContext};
use dom::promise::Promise;
use dom::virtualmethods::VirtualMethods;
use dom_struct::dom_struct;
#[cfg(all(any(target_os = "macos", target_os = "linux"), not(any(target_arch = "arm", target_arch = "aarch64"))))]
use gecko_media::{CanPlayType, GeckoMedia};
use html5ever::{LocalName, Prefix};
use ipc_channel::ipc;
use ipc_channel::router::ROUTER;
use microtask::{Microtask, MicrotaskRunnable};
#[allow(unused_imports)]
use mime::{Mime, SubLevel, TopLevel};
use net_traits::{FetchResponseListener, FetchMetadata, Metadata, NetworkError};
use net_traits::request::{CredentialsMode, Destination, RequestInit};
@ -869,6 +872,20 @@ impl HTMLMediaElementMethods for HTMLMediaElement {
// https://html.spec.whatwg.org/multipage/#dom-navigator-canplaytype
fn CanPlayType(&self, type_: DOMString) -> CanPlayTypeResult {
#[cfg(all(
any(target_os = "macos", target_os = "linux"),
not(any(target_arch = "arm", target_arch = "aarch64"))))]
{
let gecko_media = match GeckoMedia::get() {
Ok(gecko_media) => gecko_media,
Err(_error) => return CanPlayTypeResult::_empty,
};
return match gecko_media.can_play_type(&type_) {
CanPlayType::No => CanPlayTypeResult::_empty,
CanPlayType::Maybe => CanPlayTypeResult::Maybe,
CanPlayType::Probably => CanPlayTypeResult::Probably
};
}
match type_.parse::<Mime>() {
Ok(Mime(TopLevel::Application, SubLevel::OctetStream, _)) |
Err(_) => {