Bug 881976 - Part 2: Expose TextTrackList's MediaElement to chrome JS. r=rillian, r=bz

Our JS WebVTT implementation (vtt.js) needs access to a TextTrackList's
MediaElement in order to compute a TextTrackCue's line position. Therefore,
we need to expose it to chrome JS.
This commit is contained in:
Rick Eyre 2014-01-27 14:51:28 -05:00
parent 14d26a8bdb
commit 3c33886b48
7 changed files with 74 additions and 5 deletions

View File

@ -32,9 +32,10 @@ TextTrackManager::TextTrackManager(HTMLMediaElement *aMediaElement)
{
MOZ_COUNT_CTOR(TextTrackManager);
mNewCues = new TextTrackCueList(mMediaElement->OwnerDoc()->GetParentObject());
mTextTracks = new TextTrackList(mMediaElement->OwnerDoc()->GetParentObject());
mTextTracks = new TextTrackList(mMediaElement->OwnerDoc()->GetParentObject(),
this);
mPendingTextTracks =
new TextTrackList(mMediaElement->OwnerDoc()->GetParentObject());
new TextTrackList(mMediaElement->OwnerDoc()->GetParentObject(), this);
if (!sParserWrapper) {
nsCOMPtr<nsIWebVTTParserWrapper> parserWrapper =

View File

@ -74,12 +74,12 @@ public:
void PopulatePendingList();
private:
// The HTMLMediaElement that this TextTrackManager manages the TextTracks of.
// This is a weak reference as the life time of TextTrackManager is dependent
// on the HTMLMediaElement, so it should not be trying to hold the
// HTMLMediaElement alive.
HTMLMediaElement* mMediaElement;
private:
// List of the TextTrackManager's owning HTMLMediaElement's TextTracks.
nsRefPtr<TextTrackList> mTextTracks;
// List of text track objects awaiting loading.

View File

@ -8,14 +8,16 @@
#include "mozilla/dom/TrackEvent.h"
#include "nsThreadUtils.h"
#include "mozilla/dom/TextTrackCue.h"
#include "mozilla/dom/TextTrackManager.h"
namespace mozilla {
namespace dom {
NS_IMPL_CYCLE_COLLECTION_INHERITED_2(TextTrackList,
NS_IMPL_CYCLE_COLLECTION_INHERITED_3(TextTrackList,
nsDOMEventTargetHelper,
mGlobal,
mTextTracks)
mTextTracks,
mTextTrackManager)
NS_IMPL_ADDREF_INHERITED(TextTrackList, nsDOMEventTargetHelper)
NS_IMPL_RELEASE_INHERITED(TextTrackList, nsDOMEventTargetHelper)
@ -27,6 +29,13 @@ TextTrackList::TextTrackList(nsISupports* aGlobal) : mGlobal(aGlobal)
SetIsDOMBinding();
}
TextTrackList::TextTrackList(nsISupports* aGlobal, TextTrackManager* aTextTrackManager)
: mGlobal(aGlobal)
, mTextTrackManager(aTextTrackManager)
{
SetIsDOMBinding();
}
void
TextTrackList::GetAllActiveCues(nsTArray<nsRefPtr<TextTrackCue> >& aCues)
{
@ -159,5 +168,20 @@ TextTrackList::CreateAndDispatchTrackEventRunner(TextTrack* aTrack,
NS_DispatchToMainThread(eventRunner, NS_DISPATCH_NORMAL);
}
HTMLMediaElement*
TextTrackList::GetMediaElement()
{
if (mTextTrackManager) {
return mTextTrackManager->mMediaElement;
}
return nullptr;
}
void
TextTrackList::SetTextTrackManager(TextTrackManager* aTextTrackManager)
{
mTextTrackManager = aTextTrackManager;
}
} // namespace dom
} // namespace mozilla

View File

@ -14,6 +14,8 @@
namespace mozilla {
namespace dom {
class HTMLMediaElement;
class TextTrackManager;
class TrackEvent;
class TrackEventRunner;
@ -24,6 +26,7 @@ public:
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(TextTrackList, nsDOMEventTargetHelper)
TextTrackList(nsISupports* aGlobal);
TextTrackList(nsISupports* aGlobal, TextTrackManager* aTextTrackManager);
virtual JSObject* WrapObject(JSContext* aCx,
JS::Handle<JSObject*> aScope) MOZ_OVERRIDE;
@ -57,6 +60,9 @@ public:
void RemoveTextTrack(TextTrack* aTrack);
void DidSeek();
HTMLMediaElement* GetMediaElement();
void SetTextTrackManager(TextTrackManager* aTextTrackManager);
nsresult DispatchTrackEvent(nsIDOMEvent* aEvent);
void CreateAndDispatchChangeEvent();
@ -67,6 +73,7 @@ public:
private:
nsCOMPtr<nsISupports> mGlobal;
nsTArray< nsRefPtr<TextTrack> > mTextTracks;
nsRefPtr<TextTrackManager> mTextTrackManager;
void CreateAndDispatchTrackEventRunner(TextTrack* aTrack,
const nsAString& aEventName);

View File

@ -6,3 +6,4 @@ support-files =
seek.webm
[test_texttrack_chrome.html]
[test_texttracklist_chrome.html]

View File

@ -0,0 +1,30 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=881976
-->
<head>
<meta charset='utf-8'>
<title>Test for Bug 881976 - TextTrackCue Computed Position</title>
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"/>
</head>
<body>
<p id="display"></p>
<div id="content">
</div>
<pre id="test">
<script class="testbody" type="text/javascript">
SimpleTest.waitForExplicitFinish();
SpecialPowers.pushPrefEnv({"set": [["media.webvtt.enabled", true]]},
function() {
var video = document.createElement("video");
is(video.textTracks.mediaElement, video, "Video's TextTrackList's MediaElement reference should be set to the video.");
SimpleTest.finish();
}
);
</script>
</pre>
</body>
</html>

View File

@ -17,3 +17,9 @@ interface TextTrackList : EventTarget {
attribute EventHandler onaddtrack;
attribute EventHandler onremovetrack;
};
// Mozilla extensions
partial interface TextTrackList {
[ChromeOnly]
readonly attribute HTMLMediaElement? mediaElement;
};