MediaSource.cpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * Copyright (c) 2024, Jelle Raaijmakers <jelle@ladybird.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibWeb/Bindings/Intrinsics.h>
  7. #include <LibWeb/Bindings/MediaSourcePrototype.h>
  8. #include <LibWeb/MediaSourceExtensions/EventNames.h>
  9. #include <LibWeb/MediaSourceExtensions/MediaSource.h>
  10. namespace Web::MediaSourceExtensions {
  11. GC_DEFINE_ALLOCATOR(MediaSource);
  12. WebIDL::ExceptionOr<GC::Ref<MediaSource>> MediaSource::construct_impl(JS::Realm& realm)
  13. {
  14. return realm.create<MediaSource>(realm);
  15. }
  16. MediaSource::MediaSource(JS::Realm& realm)
  17. : DOM::EventTarget(realm)
  18. {
  19. }
  20. MediaSource::~MediaSource() = default;
  21. void MediaSource::initialize(JS::Realm& realm)
  22. {
  23. Base::initialize(realm);
  24. WEB_SET_PROTOTYPE_FOR_INTERFACE(MediaSource);
  25. }
  26. // https://w3c.github.io/media-source/#dom-mediasource-onsourceopen
  27. void MediaSource::set_onsourceopen(GC::Ptr<WebIDL::CallbackType> event_handler)
  28. {
  29. set_event_handler_attribute(EventNames::sourceopen, event_handler);
  30. }
  31. // https://w3c.github.io/media-source/#dom-mediasource-onsourceopen
  32. GC::Ptr<WebIDL::CallbackType> MediaSource::onsourceopen()
  33. {
  34. return event_handler_attribute(EventNames::sourceopen);
  35. }
  36. // https://w3c.github.io/media-source/#dom-mediasource-onsourceended
  37. void MediaSource::set_onsourceended(GC::Ptr<WebIDL::CallbackType> event_handler)
  38. {
  39. set_event_handler_attribute(EventNames::sourceended, event_handler);
  40. }
  41. // https://w3c.github.io/media-source/#dom-mediasource-onsourceended
  42. GC::Ptr<WebIDL::CallbackType> MediaSource::onsourceended()
  43. {
  44. return event_handler_attribute(EventNames::sourceended);
  45. }
  46. // https://w3c.github.io/media-source/#dom-mediasource-onsourceclose
  47. void MediaSource::set_onsourceclose(GC::Ptr<WebIDL::CallbackType> event_handler)
  48. {
  49. set_event_handler_attribute(EventNames::sourceclose, event_handler);
  50. }
  51. // https://w3c.github.io/media-source/#dom-mediasource-onsourceclose
  52. GC::Ptr<WebIDL::CallbackType> MediaSource::onsourceclose()
  53. {
  54. return event_handler_attribute(EventNames::sourceclose);
  55. }
  56. }