Bug 987076 - Construct HTMLMediaElement::mTextTrackManager lazily. r=roc

* Remove the TextTrackManager's initialization from the MediaElement's
ctor and add a getter that creates it if we don't have it yet. The public
functions exposed on the MediaElement's IDL now call this getter.
* Also remove the const qualifier from HTMLMediaElement::TextTracks()
as we don't really need it and this function now needs to call
GetOrCreateTextTrackManager() which is non-const.
This commit is contained in:
Rick Eyre 2014-03-24 11:48:37 -04:00
Родитель 1ff851fd6f
Коммит 8524093d1f
2 изменённых файлов: 22 добавлений и 15 удалений

Просмотреть файл

@ -518,16 +518,14 @@ public:
AudioChannel MozAudioChannelType() const;
void SetMozAudioChannelType(AudioChannel aValue, ErrorResult& aRv);
TextTrackList* TextTracks() const;
TextTrackList* TextTracks();
already_AddRefed<TextTrack> AddTextTrack(TextTrackKind aKind,
const nsAString& aLabel,
const nsAString& aLanguage);
void AddTextTrack(TextTrack* aTextTrack) {
if (mTextTrackManager) {
mTextTrackManager->AddTextTrack(aTextTrack);
}
GetOrCreateTextTrackManager()->AddTextTrack(aTextTrack);
}
void RemoveTextTrack(TextTrack* aTextTrack, bool aPendingListOnly = false) {
@ -871,6 +869,10 @@ protected:
// and whose text track readiness state is loading.
void PopulatePendingTextTrackList();
// Gets a reference to the MediaElement's TextTrackManager. If the
// MediaElement doesn't yet have one then it will create it.
TextTrackManager* GetOrCreateTextTrackManager();
// The current decoder. Load() has been called on this decoder.
// At most one of mDecoder and mSrcStream can be non-null.
nsRefPtr<MediaDecoder> mDecoder;

Просмотреть файл

@ -2040,8 +2040,6 @@ HTMLMediaElement::HTMLMediaElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
RegisterFreezableElement();
NotifyOwnerDocumentActivityChanged();
mTextTrackManager = new TextTrackManager(this);
}
HTMLMediaElement::~HTMLMediaElement()
@ -3963,9 +3961,9 @@ NS_IMETHODIMP HTMLMediaElement::WindowVolumeChanged()
/* readonly attribute TextTrackList textTracks; */
TextTrackList*
HTMLMediaElement::TextTracks() const
HTMLMediaElement::TextTracks()
{
return mTextTrackManager ? mTextTrackManager->TextTracks() : nullptr;
return GetOrCreateTextTrackManager()->TextTracks();
}
already_AddRefed<TextTrack>
@ -3973,13 +3971,11 @@ HTMLMediaElement::AddTextTrack(TextTrackKind aKind,
const nsAString& aLabel,
const nsAString& aLanguage)
{
if (mTextTrackManager) {
return mTextTrackManager->AddTextTrack(aKind, aLabel, aLanguage,
TextTrackMode::Hidden,
TextTrackReadyState::Loaded,
TextTrackSource::AddTextTrack);
}
return nullptr;
return
GetOrCreateTextTrackManager()->AddTextTrack(aKind, aLabel, aLanguage,
TextTrackMode::Hidden,
TextTrackReadyState::Loaded,
TextTrackSource::AddTextTrack);
}
void
@ -3990,6 +3986,15 @@ HTMLMediaElement::PopulatePendingTextTrackList()
}
}
TextTrackManager*
HTMLMediaElement::GetOrCreateTextTrackManager()
{
if (!mTextTrackManager) {
mTextTrackManager = new TextTrackManager(this);
}
return mTextTrackManager;
}
AudioChannel
HTMLMediaElement::MozAudioChannelType() const
{