Serenity Operating System
1/*
2 * Copyright (c) 2020, the SerenityOS developers.
3 *
4 * SPDX-License-Identifier: BSD-2-Clause
5 */
6
7#include <LibWeb/Bindings/HTMLMediaElementPrototype.h>
8#include <LibWeb/Bindings/Intrinsics.h>
9#include <LibWeb/HTML/HTMLMediaElement.h>
10
11namespace Web::HTML {
12
13HTMLMediaElement::HTMLMediaElement(DOM::Document& document, DOM::QualifiedName qualified_name)
14 : HTMLElement(document, move(qualified_name))
15{
16}
17
18HTMLMediaElement::~HTMLMediaElement() = default;
19
20JS::ThrowCompletionOr<void> HTMLMediaElement::initialize(JS::Realm& realm)
21{
22 MUST_OR_THROW_OOM(Base::initialize(realm));
23 set_prototype(&Bindings::ensure_web_prototype<Bindings::HTMLMediaElementPrototype>(realm, "HTMLMediaElement"));
24
25 return {};
26}
27
28// https://html.spec.whatwg.org/multipage/media.html#dom-navigator-canplaytype
29Bindings::CanPlayTypeResult HTMLMediaElement::can_play_type(DeprecatedString const& type) const
30{
31 // The canPlayType(type) method must:
32 // - return the empty string if type is a type that the user agent knows it cannot render or is the type "application/octet-stream"
33 // - return "probably" if the user agent is confident that the type represents a media resource that it can render if used in with this audio or video element
34 // - return "maybe" otherwise. Implementers are encouraged to return "maybe" unless the type can be confidently established as being supported or not
35 // Generally, a user agent should never return "probably" for a type that allows the codecs parameter if that parameter is not present.
36 if (type == "application/octet-stream"sv)
37 return Bindings::CanPlayTypeResult::Empty;
38 // FIXME: Eventually we should return `Maybe` here, but for now `Empty` is our best bet :^)
39 // Being honest here leads to some apps and frameworks skipping things like audio loading,
40 // which for the time being would create more issues than it solves - e.g. endless waiting
41 // for audio that will never load.
42 return Bindings::CanPlayTypeResult::Empty;
43}
44
45// https://html.spec.whatwg.org/multipage/media.html#dom-media-load
46void HTMLMediaElement::load() const
47{
48 dbgln("(STUBBED) HTMLMediaElement::load()");
49}
50
51// https://html.spec.whatwg.org/multipage/media.html#dom-media-pause
52void HTMLMediaElement::pause() const
53{
54 dbgln("(STUBBED) HTMLMediaElement::pause()");
55}
56
57}