HTMLMediaElement.cpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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/HTML/HTMLMediaElement.h>
  8. #include <LibWeb/HTML/Window.h>
  9. namespace Web::HTML {
  10. HTMLMediaElement::HTMLMediaElement(DOM::Document& document, DOM::QualifiedName qualified_name)
  11. : HTMLElement(document, move(qualified_name))
  12. {
  13. set_prototype(&window().cached_web_prototype("HTMLMediaElement"));
  14. }
  15. HTMLMediaElement::~HTMLMediaElement() = default;
  16. // https://html.spec.whatwg.org/multipage/media.html#dom-navigator-canplaytype
  17. Bindings::CanPlayTypeResult HTMLMediaElement::can_play_type(String const& type) const
  18. {
  19. // The canPlayType(type) method must:
  20. // - return the empty string if type is a type that the user agent knows it cannot render or is the type "application/octet-stream"
  21. // - 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
  22. // - return "maybe" otherwise. Implementers are encouraged to return "maybe" unless the type can be confidently established as being supported or not
  23. // Generally, a user agent should never return "probably" for a type that allows the codecs parameter if that parameter is not present.
  24. if (type == "application/octet-stream"sv)
  25. return Bindings::CanPlayTypeResult::Empty;
  26. // FIXME: Eventually we should return `Maybe` here, but for now `Empty` is our best bet :^)
  27. // Being honest here leads to some apps and frameworks skipping things like audio loading,
  28. // which for the time being would create more issues than it solves - e.g. endless waiting
  29. // for audio that will never load.
  30. return Bindings::CanPlayTypeResult::Empty;
  31. }
  32. }