HTMLMediaElement.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. * Copyright (c) 2020, the SerenityOS developers.
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/ByteBuffer.h>
  8. #include <AK/Variant.h>
  9. #include <LibJS/SafeFunction.h>
  10. #include <LibWeb/HTML/EventLoop/Task.h>
  11. #include <LibWeb/HTML/HTMLElement.h>
  12. namespace Web::HTML {
  13. class HTMLMediaElement : public HTMLElement {
  14. WEB_PLATFORM_OBJECT(HTMLMediaElement, HTMLElement);
  15. public:
  16. virtual ~HTMLMediaElement() override;
  17. void queue_a_media_element_task(JS::SafeFunction<void()> steps);
  18. enum class NetworkState : u16 {
  19. Empty,
  20. Idle,
  21. Loading,
  22. NoSource,
  23. };
  24. NetworkState network_state() const { return m_network_state; }
  25. Bindings::CanPlayTypeResult can_play_type(DeprecatedString const& type) const;
  26. void load() const;
  27. void pause() const;
  28. JS::NonnullGCPtr<VideoTrackList> video_tracks() const { return *m_video_tracks; }
  29. protected:
  30. HTMLMediaElement(DOM::Document&, DOM::QualifiedName);
  31. virtual JS::ThrowCompletionOr<void> initialize(JS::Realm&) override;
  32. virtual void visit_edges(Cell::Visitor&) override;
  33. private:
  34. struct EntireResource { };
  35. using ByteRange = Variant<EntireResource>; // FIXME: This will need to include "until end" and an actual byte range.
  36. virtual void parse_attribute(DeprecatedFlyString const& name, DeprecatedString const& value) override;
  37. Task::Source media_element_event_task_source() const { return m_media_element_event_task_source.source; }
  38. WebIDL::ExceptionOr<void> load_element();
  39. WebIDL::ExceptionOr<void> select_resource();
  40. WebIDL::ExceptionOr<void> fetch_resource(AK::URL const&, Function<void()> failure_callback);
  41. static bool verify_response(JS::NonnullGCPtr<Fetch::Infrastructure::Response>, ByteRange const&);
  42. WebIDL::ExceptionOr<void> process_media_data(Function<void()> failure_callback);
  43. WebIDL::ExceptionOr<void> handle_media_source_failure();
  44. void forget_media_resource_specific_tracks();
  45. // https://html.spec.whatwg.org/multipage/media.html#media-element-event-task-source
  46. UniqueTaskSource m_media_element_event_task_source {};
  47. // https://html.spec.whatwg.org/multipage/media.html#dom-media-networkstate
  48. NetworkState m_network_state { NetworkState::Empty };
  49. // https://html.spec.whatwg.org/multipage/media.html#dom-media-videotracks
  50. JS::GCPtr<VideoTrackList> m_video_tracks;
  51. // https://html.spec.whatwg.org/multipage/media.html#media-data
  52. ByteBuffer m_media_data;
  53. JS::GCPtr<Fetch::Infrastructure::FetchController> m_fetch_controller;
  54. };
  55. }