From 8524093d1f91bc769a98ac5b5abef5889769ee2e Mon Sep 17 00:00:00 2001 From: Rick Eyre Date: Mon, 24 Mar 2014 11:48:37 -0400 Subject: [PATCH] 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. --- .../html/content/public/HTMLMediaElement.h | 10 ++++--- content/html/content/src/HTMLMediaElement.cpp | 27 +++++++++++-------- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/content/html/content/public/HTMLMediaElement.h b/content/html/content/public/HTMLMediaElement.h index 70bf44954d92..2888fdf0255d 100644 --- a/content/html/content/public/HTMLMediaElement.h +++ b/content/html/content/public/HTMLMediaElement.h @@ -518,16 +518,14 @@ public: AudioChannel MozAudioChannelType() const; void SetMozAudioChannelType(AudioChannel aValue, ErrorResult& aRv); - TextTrackList* TextTracks() const; + TextTrackList* TextTracks(); already_AddRefed 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 mDecoder; diff --git a/content/html/content/src/HTMLMediaElement.cpp b/content/html/content/src/HTMLMediaElement.cpp index 43f30c7e7552..78c8e9fccf86 100644 --- a/content/html/content/src/HTMLMediaElement.cpp +++ b/content/html/content/src/HTMLMediaElement.cpp @@ -2040,8 +2040,6 @@ HTMLMediaElement::HTMLMediaElement(already_AddRefed& 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 @@ -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 {