Line data Source code
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/. */
6 :
7 : #ifndef mozilla_dom_HTMLTrackElement_h
8 : #define mozilla_dom_HTMLTrackElement_h
9 :
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"
16 : #include "nsIDOMHTMLElement.h"
17 : #include "nsIDOMEventTarget.h"
18 : #include "nsIHttpChannel.h"
19 :
20 : class nsIContent;
21 : class nsIDocument;
22 :
23 : namespace mozilla {
24 : namespace dom {
25 :
26 : class WebVTTListener;
27 : class WindowDestroyObserver;
28 :
29 : class HTMLTrackElement final : public nsGenericHTMLElement
30 : {
31 : public:
32 : explicit HTMLTrackElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo);
33 :
34 : // nsISupports
35 : NS_DECL_ISUPPORTS_INHERITED
36 0 : NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(HTMLTrackElement,
37 : nsGenericHTMLElement)
38 :
39 : // HTMLTrackElement WebIDL
40 : void GetKind(DOMString& aKind) const;
41 0 : void SetKind(const nsAString& aKind, ErrorResult& aError)
42 : {
43 0 : SetHTMLAttr(nsGkAtoms::kind, aKind, aError);
44 0 : }
45 :
46 0 : void GetSrc(DOMString& aSrc) const
47 : {
48 0 : GetHTMLURIAttr(nsGkAtoms::src, aSrc);
49 0 : }
50 :
51 : void SetSrc(const nsAString& aSrc, ErrorResult& aError);
52 :
53 0 : void GetSrclang(DOMString& aSrclang) const
54 : {
55 0 : GetHTMLAttr(nsGkAtoms::srclang, aSrclang);
56 0 : }
57 0 : void GetSrclang(nsAString& aSrclang) const
58 : {
59 0 : GetHTMLAttr(nsGkAtoms::srclang, aSrclang);
60 0 : }
61 0 : void SetSrclang(const nsAString& aSrclang, ErrorResult& aError)
62 : {
63 0 : SetHTMLAttr(nsGkAtoms::srclang, aSrclang, aError);
64 0 : }
65 :
66 0 : void GetLabel(DOMString& aLabel) const
67 : {
68 0 : GetHTMLAttr(nsGkAtoms::label, aLabel);
69 0 : }
70 0 : void GetLabel(nsAString& aLabel) const
71 : {
72 0 : GetHTMLAttr(nsGkAtoms::label, aLabel);
73 0 : }
74 0 : void SetLabel(const nsAString& aLabel, ErrorResult& aError)
75 : {
76 0 : SetHTMLAttr(nsGkAtoms::label, aLabel, aError);
77 0 : }
78 :
79 0 : bool Default() const
80 : {
81 0 : return GetBoolAttr(nsGkAtoms::_default);
82 : }
83 0 : void SetDefault(bool aDefault, ErrorResult& aError)
84 : {
85 0 : SetHTMLBoolAttr(nsGkAtoms::_default, aDefault, aError);
86 0 : }
87 :
88 : uint16_t ReadyState() const;
89 : void SetReadyState(uint16_t aReadyState);
90 :
91 : TextTrack* GetTrack();
92 :
93 : virtual nsresult Clone(mozilla::dom::NodeInfo* aNodeInfo, nsINode** aResult,
94 : bool aPreallocateChildren) const override;
95 :
96 : // Override ParseAttribute() to convert kind strings to enum values.
97 : virtual bool ParseAttribute(int32_t aNamespaceID,
98 : nsIAtom* aAttribute,
99 : const nsAString& aValue,
100 : nsAttrValue& aResult) override;
101 :
102 : // Override BindToTree() so that we can trigger a load when we become
103 : // the child of a media element.
104 : virtual nsresult BindToTree(nsIDocument* aDocument,
105 : nsIContent* aParent,
106 : nsIContent* aBindingParent,
107 : bool aCompileEventHandlers) override;
108 : virtual void UnbindFromTree(bool aDeep, bool aNullParent) override;
109 :
110 : void DispatchTrackRunnable(const nsString& aEventName);
111 : void DispatchTrustedEvent(const nsAString& aName);
112 :
113 : void DropChannel();
114 :
115 : void NotifyShutdown();
116 :
117 : protected:
118 : virtual ~HTMLTrackElement();
119 :
120 : virtual JSObject* WrapNode(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
121 : void OnChannelRedirect(nsIChannel* aChannel, nsIChannel* aNewChannel,
122 : uint32_t aFlags);
123 : // Open a new channel to the HTMLTrackElement's src attribute and call
124 : // mListener's LoadResource().
125 : void LoadResource();
126 :
127 : friend class TextTrackCue;
128 : friend class WebVTTListener;
129 :
130 : RefPtr<TextTrack> mTrack;
131 : nsCOMPtr<nsIChannel> mChannel;
132 : RefPtr<HTMLMediaElement> mMediaParent;
133 : RefPtr<WebVTTListener> mListener;
134 :
135 : void CreateTextTrack();
136 :
137 : private:
138 : void DispatchLoadResource();
139 : bool mLoadResourceDispatched;
140 :
141 : RefPtr<WindowDestroyObserver> mWindowDestroyObserver;
142 : };
143 :
144 : } // namespace dom
145 : } // namespace mozilla
146 :
147 : #endif // mozilla_dom_HTMLTrackElement_h
|