HTMLTrackElement.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. #ifndef mozilla_dom_HTMLTrackElement_h
  6. #define mozilla_dom_HTMLTrackElement_h
  7. #include "mozilla/Attributes.h"
  8. #include "mozilla/dom/HTMLMediaElement.h"
  9. #include "mozilla/dom/TextTrack.h"
  10. #include "nsCycleCollectionParticipant.h"
  11. #include "nsGenericHTMLElement.h"
  12. #include "nsGkAtoms.h"
  13. #include "nsIDOMHTMLElement.h"
  14. #include "nsIDOMEventTarget.h"
  15. #include "nsIHttpChannel.h"
  16. class nsIContent;
  17. class nsIDocument;
  18. namespace mozilla {
  19. namespace dom {
  20. class WebVTTListener;
  21. class WindowDestroyObserver;
  22. class HTMLTrackElement final : public nsGenericHTMLElement
  23. {
  24. public:
  25. explicit HTMLTrackElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo);
  26. // nsISupports
  27. NS_DECL_ISUPPORTS_INHERITED
  28. NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(HTMLTrackElement,
  29. nsGenericHTMLElement)
  30. // HTMLTrackElement WebIDL
  31. void GetKind(DOMString& aKind) const;
  32. void SetKind(const nsAString& aKind, ErrorResult& aError)
  33. {
  34. SetHTMLAttr(nsGkAtoms::kind, aKind, aError);
  35. }
  36. void GetSrc(DOMString& aSrc) const
  37. {
  38. GetHTMLURIAttr(nsGkAtoms::src, aSrc);
  39. }
  40. void SetSrc(const nsAString& aSrc, ErrorResult& aError);
  41. void GetSrclang(DOMString& aSrclang) const
  42. {
  43. GetHTMLAttr(nsGkAtoms::srclang, aSrclang);
  44. }
  45. void GetSrclang(nsAString& aSrclang) const
  46. {
  47. GetHTMLAttr(nsGkAtoms::srclang, aSrclang);
  48. }
  49. void SetSrclang(const nsAString& aSrclang, ErrorResult& aError)
  50. {
  51. SetHTMLAttr(nsGkAtoms::srclang, aSrclang, aError);
  52. }
  53. void GetLabel(DOMString& aLabel) const
  54. {
  55. GetHTMLAttr(nsGkAtoms::label, aLabel);
  56. }
  57. void GetLabel(nsAString& aLabel) const
  58. {
  59. GetHTMLAttr(nsGkAtoms::label, aLabel);
  60. }
  61. void SetLabel(const nsAString& aLabel, ErrorResult& aError)
  62. {
  63. SetHTMLAttr(nsGkAtoms::label, aLabel, aError);
  64. }
  65. bool Default() const
  66. {
  67. return GetBoolAttr(nsGkAtoms::_default);
  68. }
  69. void SetDefault(bool aDefault, ErrorResult& aError)
  70. {
  71. SetHTMLBoolAttr(nsGkAtoms::_default, aDefault, aError);
  72. }
  73. uint16_t ReadyState() const;
  74. void SetReadyState(uint16_t aReadyState);
  75. TextTrack* GetTrack();
  76. virtual nsresult Clone(mozilla::dom::NodeInfo* aNodeInfo, nsINode** aResult) const override;
  77. // Override ParseAttribute() to convert kind strings to enum values.
  78. virtual bool ParseAttribute(int32_t aNamespaceID,
  79. nsIAtom* aAttribute,
  80. const nsAString& aValue,
  81. nsAttrValue& aResult) override;
  82. // Override BindToTree() so that we can trigger a load when we become
  83. // the child of a media element.
  84. virtual nsresult BindToTree(nsIDocument* aDocument,
  85. nsIContent* aParent,
  86. nsIContent* aBindingParent,
  87. bool aCompileEventHandlers) override;
  88. virtual void UnbindFromTree(bool aDeep, bool aNullParent) override;
  89. void DispatchTrackRunnable(const nsString& aEventName);
  90. void DispatchTrustedEvent(const nsAString& aName);
  91. void DropChannel();
  92. void NotifyShutdown();
  93. protected:
  94. virtual ~HTMLTrackElement();
  95. virtual JSObject* WrapNode(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
  96. void OnChannelRedirect(nsIChannel* aChannel, nsIChannel* aNewChannel,
  97. uint32_t aFlags);
  98. // Open a new channel to the HTMLTrackElement's src attribute and call
  99. // mListener's LoadResource().
  100. void LoadResource();
  101. friend class TextTrackCue;
  102. friend class WebVTTListener;
  103. RefPtr<TextTrack> mTrack;
  104. nsCOMPtr<nsIChannel> mChannel;
  105. RefPtr<HTMLMediaElement> mMediaParent;
  106. RefPtr<WebVTTListener> mListener;
  107. void CreateTextTrack();
  108. private:
  109. void DispatchLoadResource();
  110. bool mLoadResourceDispatched;
  111. RefPtr<WindowDestroyObserver> mWindowDestroyObserver;
  112. };
  113. } // namespace dom
  114. } // namespace mozilla
  115. #endif // mozilla_dom_HTMLTrackElement_h