HTMLMediaElement.cpp 2.2 KB

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