HTMLMediaElement.cpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. JS::ThrowCompletionOr<void> HTMLMediaElement::initialize(JS::Realm& realm)
  16. {
  17. MUST_OR_THROW_OOM(Base::initialize(realm));
  18. set_prototype(&Bindings::ensure_web_prototype<Bindings::HTMLMediaElementPrototype>(realm, "HTMLMediaElement"));
  19. return {};
  20. }
  21. // https://html.spec.whatwg.org/multipage/media.html#dom-navigator-canplaytype
  22. Bindings::CanPlayTypeResult HTMLMediaElement::can_play_type(DeprecatedString const& type) const
  23. {
  24. // The canPlayType(type) method must:
  25. // - return the empty string if type is a type that the user agent knows it cannot render or is the type "application/octet-stream"
  26. // - 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
  27. // - return "maybe" otherwise. Implementers are encouraged to return "maybe" unless the type can be confidently established as being supported or not
  28. // Generally, a user agent should never return "probably" for a type that allows the codecs parameter if that parameter is not present.
  29. if (type == "application/octet-stream"sv)
  30. return Bindings::CanPlayTypeResult::Empty;
  31. // FIXME: Eventually we should return `Maybe` here, but for now `Empty` is our best bet :^)
  32. // Being honest here leads to some apps and frameworks skipping things like audio loading,
  33. // which for the time being would create more issues than it solves - e.g. endless waiting
  34. // for audio that will never load.
  35. return Bindings::CanPlayTypeResult::Empty;
  36. }
  37. // https://html.spec.whatwg.org/multipage/media.html#dom-media-load
  38. void HTMLMediaElement::load() const
  39. {
  40. dbgln("(STUBBED) HTMLMediaElement::load()");
  41. }
  42. // https://html.spec.whatwg.org/multipage/media.html#dom-media-pause
  43. void HTMLMediaElement::pause() const
  44. {
  45. dbgln("(STUBBED) HTMLMediaElement::pause()");
  46. }
  47. }