Auto merge of #19337 - philn:gecko-canPlayType, r=nox

Implement HTMLMediaElement::canPlayType using gecko-media

<!-- 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. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/19337)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2017-11-23 06:52:27 -06:00 committed by GitHub
commit c5b446a573
2 changed files with 39 additions and 70 deletions

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(_) => {