Bug 882665 - Part a: Add readiness state attribute to text track. r= rillian, khuey
authorAndrew Quartey <andrew.quartey@gmail.com>
Fri, 25 Oct 2013 00:14:36 -0400
changeset 165943 2f3d1761b05915b2dd6713a5bcdee6548628a973
parent 165875 f030f97fcf107fbd5da84b1bea47a3580426bc29
child 165944 53dd3aa9be7e239e1a0cac0ad6262b182685b6bb
push id3066
push userakeybl@mozilla.com
push dateMon, 09 Dec 2013 19:58:46 +0000
treeherdermozilla-beta@a31a0dce83aa [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs882665
milestone27.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 882665 - Part a: Add readiness state attribute to text track. r= rillian, khuey
content/html/content/src/HTMLTrackElement.cpp
content/html/content/src/HTMLTrackElement.h
content/html/content/src/TextTrackManager.cpp
content/media/TextTrack.cpp
content/media/TextTrack.h
content/media/WebVTTListener.cpp
--- a/content/html/content/src/HTMLTrackElement.cpp
+++ b/content/html/content/src/HTMLTrackElement.cpp
@@ -62,17 +62,16 @@ namespace mozilla {
 namespace dom {
 
 // The default value for kKindTable is "subtitles"
 static const char* kKindTableDefaultString = kKindTable->tag;
 
 /** HTMLTrackElement */
 HTMLTrackElement::HTMLTrackElement(already_AddRefed<nsINodeInfo> aNodeInfo)
   : nsGenericHTMLElement(aNodeInfo)
-  , mReadyState(NONE)
 {
 #ifdef PR_LOGGING
   if (!gTrackElementLog) {
     gTrackElementLog = PR_NewLogModule("nsTrackElement");
   }
 #endif
 }
 
@@ -300,10 +299,20 @@ HTMLTrackElement::UnbindFromTree(bool aD
     if (aNullParent) {
       mMediaParent = nullptr;
     }
   }
 
   nsGenericHTMLElement::UnbindFromTree(aDeep, aNullParent);
 }
 
+uint16_t
+HTMLTrackElement::ReadyState() const
+{
+  if (!mTrack) {
+    return NONE;
+  }
+
+  return mTrack->ReadyState();
+}
+
 } // namespace dom
 } // namespace mozilla
--- a/content/html/content/src/HTMLTrackElement.h
+++ b/content/html/content/src/HTMLTrackElement.h
@@ -97,20 +97,17 @@ public:
 
   // Constants for numeric readyState property values.
   enum {
     NONE = 0U,
     LOADING = 1U,
     LOADED = 2U,
     ERROR = 3U
   };
-  uint16_t ReadyState() const
-  {
-    return mReadyState;
-  }
+  uint16_t ReadyState() const;
 
   TextTrack* Track();
 
   virtual nsresult Clone(nsINodeInfo* aNodeInfo, nsINode** aResult) const MOZ_OVERRIDE;
 
   // For Track, ItemValue reflects the src attribute
   virtual void GetItemValueText(nsAString& aText) MOZ_OVERRIDE
   {
@@ -152,17 +149,16 @@ protected:
 
   friend class TextTrackCue;
   friend class WebVTTListener;
 
   nsRefPtr<TextTrack> mTrack;
   nsCOMPtr<nsIChannel> mChannel;
   nsRefPtr<HTMLMediaElement> mMediaParent;
   nsRefPtr<WebVTTListener> mListener;
-  uint16_t mReadyState;
 
   void CreateTextTrack();
 };
 
 } // namespace dom
 } // namespace mozilla
 
 #endif // mozilla_dom_HTMLTrackElement_h
--- a/content/html/content/src/TextTrackManager.cpp
+++ b/content/html/content/src/TextTrackManager.cpp
@@ -2,16 +2,17 @@
 /* vim:set tw=80 expandtab softtabstop=2 ts=2 sw=2: */
 
 /* 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/. */
 
 #include "mozilla/dom/TextTrackManager.h"
 #include "mozilla/dom/HTMLMediaElement.h"
+#include "mozilla/dom/HTMLTrackElement.h"
 
 namespace mozilla {
 namespace dom {
 
 NS_IMPL_CYCLE_COLLECTION_1(TextTrackManager, mTextTracks)
 NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(TextTrackManager, AddRef)
 NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(TextTrackManager, Release)
 
@@ -32,17 +33,20 @@ TextTrackManager::TextTracks() const
 {
   return mTextTracks;
 }
 
 already_AddRefed<TextTrack>
 TextTrackManager::AddTextTrack(TextTrackKind aKind, const nsAString& aLabel,
                                const nsAString& aLanguage)
 {
-  return mTextTracks->AddTextTrack(mMediaElement, aKind, aLabel, aLanguage);
+  nsRefPtr<TextTrack> ttrack =
+    mTextTracks->AddTextTrack(mMediaElement, aKind, aLabel, aLanguage);
+  ttrack->SetReadyState(HTMLTrackElement::LOADED);
+  return ttrack.forget();
 }
 
 void
 TextTrackManager::AddTextTrack(TextTrack* aTextTrack)
 {
   mTextTracks->AddTextTrack(aTextTrack);
 }
 
--- a/content/media/TextTrack.cpp
+++ b/content/media/TextTrack.cpp
@@ -6,16 +6,17 @@
 
 #include "mozilla/dom/TextTrack.h"
 #include "mozilla/dom/TextTrackBinding.h"
 #include "mozilla/dom/TextTrackCue.h"
 #include "mozilla/dom/TextTrackCueList.h"
 #include "mozilla/dom/TextTrackRegion.h"
 #include "mozilla/dom/TextTrackRegionList.h"
 #include "mozilla/dom/HTMLMediaElement.h"
+#include "mozilla/dom/HTMLTrackElement.h"
 
 namespace mozilla {
 namespace dom {
 
 NS_IMPL_CYCLE_COLLECTION_INHERITED_5(TextTrack,
                                      nsDOMEventTargetHelper,
                                      mParent,
                                      mMediaElement,
@@ -63,16 +64,17 @@ TextTrack::SetDefaultSettings()
 {
   mKind = TextTrackKind::Subtitles;
   mMode = TextTrackMode::Hidden;
   mCueList = new TextTrackCueList(mParent);
   mActiveCueList = new TextTrackCueList(mParent);
   mRegionList = new TextTrackRegionList(mParent);
   mCuePos = 0;
   mDirty = false;
+  mReadyState = HTMLTrackElement::NONE;
 }
 
 void
 TextTrack::Update(double aTime)
 {
   mCueList->Update(aTime);
 }
 
@@ -165,10 +167,22 @@ TextTrack::GetActiveCues()
     if (cue->StartTime() > playbackTime || cue->EndTime() < playbackTime) {
       break;
     }
     mActiveCueList->AddCue(*cue);
   }
   return mActiveCueList;
 }
 
+uint16_t
+TextTrack::ReadyState() const
+{
+  return mReadyState;
+}
+
+void
+TextTrack::SetReadyState(uint16_t aState)
+{
+  mReadyState = aState;
+}
+
 } // namespace dom
 } // namespace mozilla
--- a/content/media/TextTrack.h
+++ b/content/media/TextTrack.h
@@ -87,16 +87,19 @@ public:
   TextTrackRegionList* GetRegions() const
   {
     if (mMode != TextTrackMode::Disabled) {
       return mRegionList;
     }
     return nullptr;
   }
 
+  uint16_t ReadyState() const;
+  void SetReadyState(uint16_t aState);
+
   void AddRegion(TextTrackRegion& aRegion);
   void RemoveRegion(const TextTrackRegion& aRegion, ErrorResult& aRv);
 
   // Time is in seconds.
   void Update(double aTime);
 
   void AddCue(TextTrackCue& aCue);
   void RemoveCue(TextTrackCue& aCue, ErrorResult& aRv);
@@ -116,15 +119,16 @@ private:
   nsString mId;
   TextTrackMode mMode;
 
   nsRefPtr<TextTrackCueList> mCueList;
   nsRefPtr<TextTrackCueList> mActiveCueList;
   nsRefPtr<TextTrackRegionList> mRegionList;
 
   uint32_t mCuePos;
+  uint16_t mReadyState;
   bool mDirty;
 };
 
 } // namespace dom
 } // namespace mozilla
 
 #endif // mozilla_dom_TextTrack_h
--- a/content/media/WebVTTListener.cpp
+++ b/content/media/WebVTTListener.cpp
@@ -73,17 +73,17 @@ WebVTTListener::LoadResource()
 
   nsPIDOMWindow* window = mElement->OwnerDoc()->GetWindow();
   rv = mParserWrapper->LoadParser(window);
   NS_ENSURE_SUCCESS(rv, rv);
 
   rv = mParserWrapper->Watch(this);
   NS_ENSURE_SUCCESS(rv, rv);
 
-  mElement->mReadyState = HTMLTrackElement::LOADING;
+  mElement->mTrack->SetReadyState(HTMLTrackElement::LOADING);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 WebVTTListener::AsyncOnChannelRedirect(nsIChannel* aOldChannel,
                                        nsIChannel* aNewChannel,
                                        uint32_t aFlags,
                                        nsIAsyncVerifyRedirectCallback* cb)
@@ -101,18 +101,18 @@ WebVTTListener::OnStartRequest(nsIReques
   return NS_OK;
 }
 
 NS_IMETHODIMP
 WebVTTListener::OnStopRequest(nsIRequest* aRequest,
                               nsISupports* aContext,
                               nsresult aStatus)
 {
-  if (mElement->mReadyState != HTMLTrackElement::ERROR) {
-    mElement->mReadyState = HTMLTrackElement::LOADED;
+  if (mElement->ReadyState() != HTMLTrackElement::ERROR) {
+    mElement->mTrack->SetReadyState(HTMLTrackElement::LOADED);
   }
   // Attempt to parse any final data the parser might still have.
   mParserWrapper->Flush();
   return NS_OK;
 }
 
 NS_METHOD
 WebVTTListener::ParseChunk(nsIInputStream* aInStream, void* aClosure,