1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_dom_HTMLTrackElement_h
8 #define mozilla_dom_HTMLTrackElement_h
10 #include "mozilla/Attributes.h"
11 #include "mozilla/dom/HTMLMediaElement.h"
12 #include "mozilla/dom/TextTrack.h"
13 #include "nsCycleCollectionParticipant.h"
14 #include "nsGenericHTMLElement.h"
15 #include "nsGkAtoms.h"
19 namespace mozilla::dom
{
22 class WindowDestroyObserver
;
23 enum class TextTrackReadyState
: uint8_t;
25 class HTMLTrackElement final
: public nsGenericHTMLElement
{
27 explicit HTMLTrackElement(
28 already_AddRefed
<mozilla::dom::NodeInfo
>&& aNodeInfo
);
31 NS_DECL_ISUPPORTS_INHERITED
32 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(HTMLTrackElement
,
35 // HTMLTrackElement WebIDL
36 void GetKind(DOMString
& aKind
) const;
37 void SetKind(const nsAString
& aKind
, ErrorResult
& aError
) {
38 SetHTMLAttr(nsGkAtoms::kind
, aKind
, aError
);
41 void GetSrc(DOMString
& aSrc
) const { GetHTMLURIAttr(nsGkAtoms::src
, aSrc
); }
43 void SetSrc(const nsAString
& aSrc
, ErrorResult
& aError
);
45 void GetSrclang(DOMString
& aSrclang
) const {
46 GetHTMLAttr(nsGkAtoms::srclang
, aSrclang
);
48 void GetSrclang(nsAString
& aSrclang
) const {
49 GetHTMLAttr(nsGkAtoms::srclang
, aSrclang
);
51 void SetSrclang(const nsAString
& aSrclang
, ErrorResult
& aError
) {
52 SetHTMLAttr(nsGkAtoms::srclang
, aSrclang
, aError
);
55 void GetLabel(DOMString
& aLabel
) const {
56 GetHTMLAttr(nsGkAtoms::label
, aLabel
);
58 void GetLabel(nsAString
& aLabel
) const {
59 GetHTMLAttr(nsGkAtoms::label
, aLabel
);
61 void SetLabel(const nsAString
& aLabel
, ErrorResult
& aError
) {
62 SetHTMLAttr(nsGkAtoms::label
, aLabel
, aError
);
65 bool Default() const { return GetBoolAttr(nsGkAtoms::_default
); }
66 void SetDefault(bool aDefault
, ErrorResult
& aError
) {
67 SetHTMLBoolAttr(nsGkAtoms::_default
, aDefault
, aError
);
70 TextTrackReadyState
ReadyState() const;
71 uint16_t ReadyStateForBindings() const {
72 return static_cast<uint16_t>(ReadyState());
74 void SetReadyState(TextTrackReadyState
);
76 TextTrack
* GetTrack();
78 virtual nsresult
Clone(dom::NodeInfo
*, nsINode
** aResult
) const override
;
80 // Override ParseAttribute() to convert kind strings to enum values.
81 virtual bool ParseAttribute(int32_t aNamespaceID
, nsAtom
* aAttribute
,
82 const nsAString
& aValue
,
83 nsIPrincipal
* aMaybeScriptedPrincipal
,
84 nsAttrValue
& aResult
) override
;
86 // Override BindToTree() so that we can trigger a load when we become
87 // the child of a media element.
88 virtual nsresult
BindToTree(BindContext
&, nsINode
& aParent
) override
;
89 virtual void UnbindFromTree(bool aNullParent
) override
;
91 virtual nsresult
AfterSetAttr(int32_t aNameSpaceID
, nsAtom
* aName
,
92 const nsAttrValue
* aValue
,
93 const nsAttrValue
* aOldValue
,
94 nsIPrincipal
* aMaybeScriptedPrincipal
,
95 bool aNotify
) override
;
97 void DispatchTrackRunnable(const nsString
& aEventName
);
98 void DispatchTrustedEvent(const nsAString
& aName
);
99 void DispatchTestEvent(const nsAString
& aName
);
101 void CancelChannelAndListener();
103 // Only load resource for the non-disabled track with media parent.
104 void MaybeDispatchLoadResource();
107 virtual ~HTMLTrackElement();
109 virtual JSObject
* WrapNode(JSContext
* aCx
,
110 JS::Handle
<JSObject
*> aGivenProto
) override
;
111 void OnChannelRedirect(nsIChannel
* aChannel
, nsIChannel
* aNewChannel
,
114 friend class TextTrackCue
;
115 friend class WebVTTListener
;
117 RefPtr
<TextTrack
> mTrack
;
118 nsCOMPtr
<nsIChannel
> mChannel
;
119 RefPtr
<HTMLMediaElement
> mMediaParent
;
120 RefPtr
<WebVTTListener
> mListener
;
122 void CreateTextTrack();
125 // Open a new channel to the HTMLTrackElement's src attribute and call
126 // mListener's LoadResource().
127 void LoadResource(RefPtr
<WebVTTListener
>&& aWebVTTListener
);
128 bool mLoadResourceDispatched
;
130 void MaybeClearAllCues();
132 RefPtr
<WindowDestroyObserver
> mWindowDestroyObserver
;
135 } // namespace mozilla::dom
137 #endif // mozilla_dom_HTMLTrackElement_h