2015-05-03 19:32:37 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2013-05-21 16:14:00 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#ifndef mozilla_dom_HTMLTrackElement_h
|
|
|
|
#define mozilla_dom_HTMLTrackElement_h
|
|
|
|
|
2013-05-29 20:43:41 +00:00
|
|
|
#include "mozilla/Attributes.h"
|
2013-05-21 16:14:00 +00:00
|
|
|
#include "mozilla/dom/HTMLMediaElement.h"
|
|
|
|
#include "mozilla/dom/TextTrack.h"
|
|
|
|
#include "nsCycleCollectionParticipant.h"
|
|
|
|
#include "nsGenericHTMLElement.h"
|
|
|
|
#include "nsGkAtoms.h"
|
|
|
|
|
2014-08-18 14:44:50 +00:00
|
|
|
class nsIContent;
|
|
|
|
|
2013-05-21 16:14:00 +00:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2013-09-19 15:26:00 +00:00
|
|
|
class WebVTTListener;
|
2016-08-05 07:13:36 +00:00
|
|
|
class WindowDestroyObserver;
|
2019-12-02 19:13:11 +00:00
|
|
|
enum class TextTrackReadyState : uint8_t;
|
2013-06-10 15:30:00 +00:00
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
class HTMLTrackElement final : public nsGenericHTMLElement {
|
2013-05-21 16:14:00 +00:00
|
|
|
public:
|
2018-09-21 20:45:49 +00:00
|
|
|
explicit HTMLTrackElement(
|
|
|
|
already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo);
|
2013-05-21 16:14:00 +00:00
|
|
|
|
|
|
|
// nsISupports
|
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(HTMLTrackElement,
|
|
|
|
nsGenericHTMLElement)
|
|
|
|
|
|
|
|
// HTMLTrackElement WebIDL
|
2013-07-04 18:16:05 +00:00
|
|
|
void GetKind(DOMString& aKind) const;
|
|
|
|
void SetKind(const nsAString& aKind, ErrorResult& aError) {
|
|
|
|
SetHTMLAttr(nsGkAtoms::kind, aKind, aError);
|
|
|
|
}
|
2013-05-21 16:14:00 +00:00
|
|
|
|
|
|
|
void GetSrc(DOMString& aSrc) const { GetHTMLURIAttr(nsGkAtoms::src, aSrc); }
|
2016-07-21 08:49:24 +00:00
|
|
|
|
|
|
|
void SetSrc(const nsAString& aSrc, ErrorResult& aError);
|
2013-05-21 16:14:00 +00:00
|
|
|
|
|
|
|
void GetSrclang(DOMString& aSrclang) const {
|
|
|
|
GetHTMLAttr(nsGkAtoms::srclang, aSrclang);
|
|
|
|
}
|
2016-06-30 05:36:31 +00:00
|
|
|
void GetSrclang(nsAString& aSrclang) const {
|
2013-05-24 02:57:00 +00:00
|
|
|
GetHTMLAttr(nsGkAtoms::srclang, aSrclang);
|
|
|
|
}
|
2013-05-21 16:14:00 +00:00
|
|
|
void SetSrclang(const nsAString& aSrclang, ErrorResult& aError) {
|
|
|
|
SetHTMLAttr(nsGkAtoms::srclang, aSrclang, aError);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GetLabel(DOMString& aLabel) const {
|
|
|
|
GetHTMLAttr(nsGkAtoms::label, aLabel);
|
|
|
|
}
|
2016-06-30 05:36:31 +00:00
|
|
|
void GetLabel(nsAString& aLabel) const {
|
2013-05-24 02:57:00 +00:00
|
|
|
GetHTMLAttr(nsGkAtoms::label, aLabel);
|
|
|
|
}
|
2013-05-21 16:14:00 +00:00
|
|
|
void SetLabel(const nsAString& aLabel, ErrorResult& aError) {
|
|
|
|
SetHTMLAttr(nsGkAtoms::label, aLabel, aError);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Default() const { return GetBoolAttr(nsGkAtoms::_default); }
|
|
|
|
void SetDefault(bool aDefault, ErrorResult& aError) {
|
|
|
|
SetHTMLBoolAttr(nsGkAtoms::_default, aDefault, aError);
|
|
|
|
}
|
|
|
|
|
2019-12-02 19:13:11 +00:00
|
|
|
TextTrackReadyState ReadyState() const;
|
|
|
|
uint16_t ReadyStateForBindings() const {
|
|
|
|
return static_cast<uint16_t>(ReadyState());
|
|
|
|
}
|
|
|
|
void SetReadyState(TextTrackReadyState);
|
2013-05-21 16:14:00 +00:00
|
|
|
|
2014-04-07 17:58:38 +00:00
|
|
|
TextTrack* GetTrack();
|
2013-05-21 16:14:00 +00:00
|
|
|
|
2018-08-08 23:58:44 +00:00
|
|
|
virtual nsresult Clone(dom::NodeInfo*, nsINode** aResult) const override;
|
2013-05-21 16:14:00 +00:00
|
|
|
|
|
|
|
// Override ParseAttribute() to convert kind strings to enum values.
|
|
|
|
virtual bool ParseAttribute(int32_t aNamespaceID, nsAtom* aAttribute,
|
|
|
|
const nsAString& aValue,
|
2017-11-02 03:35:52 +00:00
|
|
|
nsIPrincipal* aMaybeScriptedPrincipal,
|
2015-03-21 16:28:04 +00:00
|
|
|
nsAttrValue& aResult) override;
|
2013-05-21 16:14:00 +00:00
|
|
|
|
|
|
|
// Override BindToTree() so that we can trigger a load when we become
|
|
|
|
// the child of a media element.
|
Bug 1555216 - Change the signature of BindToTree to be (BindContext&, nsINode& aParentNode). r=bzbarsky
BindContext was going to have way more information at first, but then I realized
that most of the things I wanted to know were basically a flag away using the
parent node.
Still I think it's worth it, now experimenting with BindToTree will only mean
adding a field to a struct that's included from a couple cpp files, instead of a
massive pain.
I also think this is clearer, and doing this highlights quite a few
inconsistencies in our code which I've left untouched, but commented with
FIXMEs.
Steps are:
$ for file in $(rg 'nsresult BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#nsresult BindToTree(Document\* aDocument, nsIContent\* aParent,#nsresult BindToTree(BindContext\&, nsINode\& aParent)#g' $file; done
$ for file in $(rg 'nsresult BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's# nsIContent\* aBindingParent) override#override#g' $file; done
$ for file in $(rg '::BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#::BindToTree(Document\* aDocument, nsIContent\* aParent,#::BindToTree(BindContext\& aContext, nsINode\& aParent)#g' $file; done
$ for file in $(rg '::BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#nsIContent\* aBindingParent)##g' $file; done
$ for file in $(rg '::BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#::BindToTree(aDocument, aParent, aBindingParent)#::BindToTree(aContext, aParent)#g' $file; done
$ ./mach clang-format
Then manual fixups.
Depends on D32948
Differential Revision: https://phabricator.services.mozilla.com/D32949
2019-05-29 04:27:04 +00:00
|
|
|
virtual nsresult BindToTree(BindContext&, nsINode& aParent) override;
|
2019-05-28 22:47:08 +00:00
|
|
|
virtual void UnbindFromTree(bool aNullParent) override;
|
2013-05-21 16:14:00 +00:00
|
|
|
|
2019-05-24 00:41:29 +00:00
|
|
|
virtual nsresult AfterSetAttr(int32_t aNameSpaceID, nsAtom* aName,
|
|
|
|
const nsAttrValue* aValue,
|
|
|
|
const nsAttrValue* aOldValue,
|
|
|
|
nsIPrincipal* aMaybeScriptedPrincipal,
|
|
|
|
bool aNotify) override;
|
|
|
|
|
2014-03-14 16:13:41 +00:00
|
|
|
void DispatchTrackRunnable(const nsString& aEventName);
|
|
|
|
void DispatchTrustedEvent(const nsAString& aName);
|
2019-07-03 23:28:31 +00:00
|
|
|
void DispatchTestEvent(const nsAString& aName);
|
2014-06-18 20:10:24 +00:00
|
|
|
|
2019-07-03 23:27:12 +00:00
|
|
|
void CancelChannelAndListener();
|
2016-08-05 07:13:36 +00:00
|
|
|
|
2019-05-24 00:41:40 +00:00
|
|
|
// Only load resource for the non-disabled track with media parent.
|
|
|
|
void MaybeDispatchLoadResource();
|
|
|
|
|
2013-05-21 16:14:00 +00:00
|
|
|
protected:
|
2014-07-08 21:23:16 +00:00
|
|
|
virtual ~HTMLTrackElement();
|
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual JSObject* WrapNode(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aGivenProto) override;
|
2013-06-10 15:30:00 +00:00
|
|
|
void OnChannelRedirect(nsIChannel* aChannel, nsIChannel* aNewChannel,
|
|
|
|
uint32_t aFlags);
|
|
|
|
|
|
|
|
friend class TextTrackCue;
|
2013-09-19 15:26:00 +00:00
|
|
|
friend class WebVTTListener;
|
2013-05-21 16:14:00 +00:00
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<TextTrack> mTrack;
|
2013-05-21 16:14:00 +00:00
|
|
|
nsCOMPtr<nsIChannel> mChannel;
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<HTMLMediaElement> mMediaParent;
|
|
|
|
RefPtr<WebVTTListener> mListener;
|
2013-05-21 16:14:00 +00:00
|
|
|
|
|
|
|
void CreateTextTrack();
|
2016-07-21 08:49:24 +00:00
|
|
|
|
|
|
|
private:
|
2018-12-13 20:06:02 +00:00
|
|
|
// Open a new channel to the HTMLTrackElement's src attribute and call
|
|
|
|
// mListener's LoadResource().
|
|
|
|
void LoadResource(RefPtr<WebVTTListener>&& aWebVTTListener);
|
2016-07-21 08:49:24 +00:00
|
|
|
bool mLoadResourceDispatched;
|
2016-08-05 07:13:36 +00:00
|
|
|
|
2019-05-24 00:41:29 +00:00
|
|
|
void MaybeClearAllCues();
|
|
|
|
|
2016-08-05 07:13:36 +00:00
|
|
|
RefPtr<WindowDestroyObserver> mWindowDestroyObserver;
|
2013-05-21 16:14:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_dom_HTMLTrackElement_h
|