2013-05-21 20:14:00 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim:set ts=2 sw=2 et tw=78: */
|
|
|
|
/* 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/. */
|
|
|
|
|
2016-03-02 21:34:02 +03:00
|
|
|
#include "mozilla/AsyncEventDispatcher.h"
|
2013-05-21 20:14:00 +04:00
|
|
|
#include "mozilla/dom/TextTrack.h"
|
|
|
|
#include "mozilla/dom/TextTrackBinding.h"
|
2014-01-27 22:10:06 +04:00
|
|
|
#include "mozilla/dom/TextTrackList.h"
|
2013-06-15 00:10:36 +04:00
|
|
|
#include "mozilla/dom/TextTrackCue.h"
|
2013-09-06 00:25:17 +04:00
|
|
|
#include "mozilla/dom/TextTrackCueList.h"
|
2013-09-14 03:44:33 +04:00
|
|
|
#include "mozilla/dom/TextTrackRegion.h"
|
2013-06-15 00:10:36 +04:00
|
|
|
#include "mozilla/dom/HTMLMediaElement.h"
|
2013-10-25 08:14:36 +04:00
|
|
|
#include "mozilla/dom/HTMLTrackElement.h"
|
2013-05-21 20:14:00 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2014-04-25 20:49:00 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_INHERITED(TextTrack,
|
|
|
|
DOMEventTargetHelper,
|
|
|
|
mCueList,
|
|
|
|
mActiveCueList,
|
|
|
|
mTextTrackList,
|
|
|
|
mTrackElement)
|
2013-05-21 20:14:00 +04:00
|
|
|
|
2014-04-01 10:13:50 +04:00
|
|
|
NS_IMPL_ADDREF_INHERITED(TextTrack, DOMEventTargetHelper)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(TextTrack, DOMEventTargetHelper)
|
2013-05-21 20:14:00 +04:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(TextTrack)
|
2014-04-01 10:13:50 +04:00
|
|
|
NS_INTERFACE_MAP_END_INHERITING(DOMEventTargetHelper)
|
2013-05-21 20:14:00 +04:00
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
TextTrack::TextTrack(nsPIDOMWindowInner* aOwnerWindow,
|
2014-01-28 00:17:20 +04:00
|
|
|
TextTrackKind aKind,
|
|
|
|
const nsAString& aLabel,
|
2014-02-27 21:47:23 +04:00
|
|
|
const nsAString& aLanguage,
|
2014-03-13 21:18:06 +04:00
|
|
|
TextTrackMode aMode,
|
2014-03-13 22:41:21 +04:00
|
|
|
TextTrackReadyState aReadyState,
|
2014-02-27 21:47:23 +04:00
|
|
|
TextTrackSource aTextTrackSource)
|
2014-04-07 21:58:38 +04:00
|
|
|
: DOMEventTargetHelper(aOwnerWindow)
|
2014-03-13 22:58:08 +04:00
|
|
|
, mKind(aKind)
|
|
|
|
, mLabel(aLabel)
|
|
|
|
, mLanguage(aLanguage)
|
|
|
|
, mMode(aMode)
|
|
|
|
, mReadyState(aReadyState)
|
2014-02-27 21:47:23 +04:00
|
|
|
, mTextTrackSource(aTextTrackSource)
|
2013-06-15 00:10:36 +04:00
|
|
|
{
|
|
|
|
SetDefaultSettings();
|
|
|
|
}
|
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
TextTrack::TextTrack(nsPIDOMWindowInner* aOwnerWindow,
|
2014-01-28 00:17:20 +04:00
|
|
|
TextTrackList* aTextTrackList,
|
2013-05-21 20:14:00 +04:00
|
|
|
TextTrackKind aKind,
|
|
|
|
const nsAString& aLabel,
|
2014-02-27 21:47:23 +04:00
|
|
|
const nsAString& aLanguage,
|
2014-03-13 21:18:06 +04:00
|
|
|
TextTrackMode aMode,
|
2014-03-13 22:41:21 +04:00
|
|
|
TextTrackReadyState aReadyState,
|
2014-02-27 21:47:23 +04:00
|
|
|
TextTrackSource aTextTrackSource)
|
2014-04-07 21:58:38 +04:00
|
|
|
: DOMEventTargetHelper(aOwnerWindow)
|
2014-01-28 00:17:20 +04:00
|
|
|
, mTextTrackList(aTextTrackList)
|
2014-03-13 22:58:08 +04:00
|
|
|
, mKind(aKind)
|
|
|
|
, mLabel(aLabel)
|
|
|
|
, mLanguage(aLanguage)
|
|
|
|
, mMode(aMode)
|
|
|
|
, mReadyState(aReadyState)
|
2014-02-27 21:47:23 +04:00
|
|
|
, mTextTrackSource(aTextTrackSource)
|
2013-05-21 20:14:00 +04:00
|
|
|
{
|
2013-06-15 00:10:36 +04:00
|
|
|
SetDefaultSettings();
|
2013-05-21 20:14:00 +04:00
|
|
|
}
|
|
|
|
|
2014-06-15 06:53:52 +04:00
|
|
|
TextTrack::~TextTrack()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-06-15 00:10:36 +04:00
|
|
|
void
|
|
|
|
TextTrack::SetDefaultSettings()
|
2013-05-21 20:14:00 +04:00
|
|
|
{
|
2016-01-30 20:05:36 +03:00
|
|
|
nsPIDOMWindowInner* ownerWindow = GetOwner();
|
2014-04-07 21:58:38 +04:00
|
|
|
mCueList = new TextTrackCueList(ownerWindow);
|
|
|
|
mActiveCueList = new TextTrackCueList(ownerWindow);
|
2013-06-15 00:10:36 +04:00
|
|
|
mCuePos = 0;
|
|
|
|
mDirty = false;
|
2013-05-21 20:14:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
JSObject*
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 17:13:33 +03:00
|
|
|
TextTrack::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
2013-05-21 20:14:00 +04:00
|
|
|
{
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 17:13:33 +03:00
|
|
|
return TextTrackBinding::Wrap(aCx, this, aGivenProto);
|
2013-05-21 20:14:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TextTrack::SetMode(TextTrackMode aValue)
|
|
|
|
{
|
2013-12-18 09:19:09 +04:00
|
|
|
if (mMode != aValue) {
|
|
|
|
mMode = aValue;
|
2014-01-28 00:17:20 +04:00
|
|
|
if (mTextTrackList) {
|
|
|
|
mTextTrackList->CreateAndDispatchChangeEvent();
|
2013-12-18 09:19:09 +04:00
|
|
|
}
|
|
|
|
}
|
2013-05-21 20:14:00 +04:00
|
|
|
}
|
|
|
|
|
2014-03-19 19:27:39 +04:00
|
|
|
void
|
|
|
|
TextTrack::GetId(nsAString& aId) const
|
|
|
|
{
|
|
|
|
// If the track has a track element then its id should be the same as the
|
|
|
|
// track element's id.
|
|
|
|
if (mTrackElement) {
|
|
|
|
mTrackElement->GetAttribute(NS_LITERAL_STRING("id"), aId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-21 20:14:00 +04:00
|
|
|
void
|
|
|
|
TextTrack::AddCue(TextTrackCue& aCue)
|
|
|
|
{
|
|
|
|
mCueList->AddCue(aCue);
|
2014-04-02 20:16:00 +04:00
|
|
|
aCue.SetTrack(this);
|
2014-01-28 00:17:20 +04:00
|
|
|
if (mTextTrackList) {
|
|
|
|
HTMLMediaElement* mediaElement = mTextTrackList->GetMediaElement();
|
|
|
|
if (mediaElement) {
|
|
|
|
mediaElement->AddCue(aCue);
|
|
|
|
}
|
2014-01-15 20:30:58 +04:00
|
|
|
}
|
2013-06-15 00:10:36 +04:00
|
|
|
SetDirty();
|
2013-05-21 20:14:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-06-28 21:31:43 +04:00
|
|
|
TextTrack::RemoveCue(TextTrackCue& aCue, ErrorResult& aRv)
|
2013-05-21 20:14:00 +04:00
|
|
|
{
|
2013-06-28 21:31:43 +04:00
|
|
|
mCueList->RemoveCue(aCue, aRv);
|
2013-06-15 00:10:36 +04:00
|
|
|
SetDirty();
|
2013-05-21 20:14:00 +04:00
|
|
|
}
|
|
|
|
|
2014-04-07 23:42:33 +04:00
|
|
|
void
|
|
|
|
TextTrack::SetCuesDirty()
|
|
|
|
{
|
|
|
|
for (uint32_t i = 0; i < mCueList->Length(); i++) {
|
|
|
|
((*mCueList)[i])->Reset();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-12 19:57:21 +04:00
|
|
|
void
|
|
|
|
TextTrack::UpdateActiveCueList()
|
2013-06-15 00:10:36 +04:00
|
|
|
{
|
2014-02-07 22:59:26 +04:00
|
|
|
if (!mTextTrackList) {
|
2014-01-28 00:17:20 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
HTMLMediaElement* mediaElement = mTextTrackList->GetMediaElement();
|
|
|
|
if (!mediaElement) {
|
2013-12-12 19:57:21 +04:00
|
|
|
return;
|
2013-06-15 00:10:36 +04:00
|
|
|
}
|
|
|
|
|
2016-03-02 21:34:02 +03:00
|
|
|
// Flag that indicates whether or not this call of UpdateActiveCueList has
|
|
|
|
// changed the activeCueList.
|
|
|
|
bool hasChanged = false;
|
|
|
|
|
2013-06-15 00:10:36 +04:00
|
|
|
// If we are dirty, i.e. an event happened that may cause the sorted mCueList
|
|
|
|
// to have changed like a seek or an insert for a cue, than we need to rebuild
|
|
|
|
// the active cue list from scratch.
|
|
|
|
if (mDirty) {
|
|
|
|
mCuePos = 0;
|
2013-12-13 19:09:33 +04:00
|
|
|
mDirty = false;
|
2013-06-15 00:10:36 +04:00
|
|
|
mActiveCueList->RemoveAll();
|
|
|
|
}
|
|
|
|
|
2014-01-28 00:17:20 +04:00
|
|
|
double playbackTime = mediaElement->CurrentTime();
|
2013-06-15 00:10:36 +04:00
|
|
|
// Remove all the cues from the active cue list whose end times now occur
|
2013-12-13 19:09:33 +04:00
|
|
|
// earlier then the current playback time.
|
|
|
|
for (uint32_t i = mActiveCueList->Length(); i > 0; i--) {
|
|
|
|
if ((*mActiveCueList)[i - 1]->EndTime() < playbackTime) {
|
|
|
|
mActiveCueList->RemoveCueAt(i - 1);
|
2016-03-02 21:34:02 +03:00
|
|
|
hasChanged = true;
|
2013-12-13 19:09:33 +04:00
|
|
|
}
|
2013-06-15 00:10:36 +04:00
|
|
|
}
|
|
|
|
// Add all the cues, starting from the position of the last cue that was
|
|
|
|
// added, that have valid start and end times for the current playback time.
|
|
|
|
// We can stop iterating safely once we encounter a cue that does not have
|
2013-12-13 19:09:33 +04:00
|
|
|
// a valid start time as the cue list is sorted.
|
|
|
|
for (; mCuePos < mCueList->Length() &&
|
|
|
|
(*mCueList)[mCuePos]->StartTime() <= playbackTime; mCuePos++) {
|
|
|
|
if ((*mCueList)[mCuePos]->EndTime() >= playbackTime) {
|
|
|
|
mActiveCueList->AddCue(*(*mCueList)[mCuePos]);
|
2016-03-02 21:34:02 +03:00
|
|
|
hasChanged = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hasChanged) {
|
|
|
|
RefPtr<AsyncEventDispatcher> asyncDispatcher =
|
|
|
|
new AsyncEventDispatcher(this, NS_LITERAL_STRING("cuechange"), false);
|
|
|
|
asyncDispatcher->PostDOMEvent();
|
|
|
|
if (mTrackElement) {
|
|
|
|
mTrackElement->DispatchTrackRunnable(NS_LITERAL_STRING("cuechange"));
|
2013-06-15 00:10:36 +04:00
|
|
|
}
|
|
|
|
}
|
2013-12-12 19:57:21 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
TextTrackCueList*
|
|
|
|
TextTrack::GetActiveCues() {
|
2014-02-07 22:59:26 +04:00
|
|
|
if (mMode != TextTrackMode::Disabled) {
|
|
|
|
UpdateActiveCueList();
|
|
|
|
return mActiveCueList;
|
|
|
|
}
|
|
|
|
return nullptr;
|
2013-06-15 00:10:36 +04:00
|
|
|
}
|
|
|
|
|
2013-12-12 19:57:21 +04:00
|
|
|
void
|
2015-10-18 08:24:48 +03:00
|
|
|
TextTrack::GetActiveCueArray(nsTArray<RefPtr<TextTrackCue> >& aCues)
|
2013-12-12 19:57:21 +04:00
|
|
|
{
|
2014-02-07 22:59:26 +04:00
|
|
|
if (mMode != TextTrackMode::Disabled) {
|
|
|
|
UpdateActiveCueList();
|
|
|
|
mActiveCueList->GetArray(aCues);
|
|
|
|
}
|
2013-12-12 19:57:21 +04:00
|
|
|
}
|
|
|
|
|
2014-03-13 22:29:32 +04:00
|
|
|
TextTrackReadyState
|
2013-10-25 08:14:36 +04:00
|
|
|
TextTrack::ReadyState() const
|
|
|
|
{
|
|
|
|
return mReadyState;
|
|
|
|
}
|
|
|
|
|
2014-03-14 20:13:41 +04:00
|
|
|
void
|
|
|
|
TextTrack::SetReadyState(uint32_t aReadyState)
|
|
|
|
{
|
|
|
|
if (aReadyState <= TextTrackReadyState::FailedToLoad) {
|
|
|
|
SetReadyState(static_cast<TextTrackReadyState>(aReadyState));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-25 08:14:36 +04:00
|
|
|
void
|
2014-03-13 22:29:32 +04:00
|
|
|
TextTrack::SetReadyState(TextTrackReadyState aState)
|
2013-10-25 08:14:36 +04:00
|
|
|
{
|
|
|
|
mReadyState = aState;
|
2014-01-28 00:17:20 +04:00
|
|
|
|
|
|
|
if (!mTextTrackList) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
HTMLMediaElement* mediaElement = mTextTrackList->GetMediaElement();
|
2014-03-13 22:29:32 +04:00
|
|
|
if (mediaElement && (mReadyState == TextTrackReadyState::Loaded||
|
|
|
|
mReadyState == TextTrackReadyState::FailedToLoad)) {
|
2014-01-28 00:17:20 +04:00
|
|
|
mediaElement->RemoveTextTrack(this, true);
|
2013-10-25 08:14:36 +04:00
|
|
|
}
|
2013-10-25 08:14:36 +04:00
|
|
|
}
|
|
|
|
|
2014-01-27 22:10:06 +04:00
|
|
|
TextTrackList*
|
|
|
|
TextTrack::GetTextTrackList()
|
|
|
|
{
|
|
|
|
return mTextTrackList;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TextTrack::SetTextTrackList(TextTrackList* aTextTrackList)
|
|
|
|
{
|
|
|
|
mTextTrackList = aTextTrackList;
|
|
|
|
}
|
|
|
|
|
2014-02-27 23:07:39 +04:00
|
|
|
HTMLTrackElement*
|
|
|
|
TextTrack::GetTrackElement() {
|
|
|
|
return mTrackElement;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TextTrack::SetTrackElement(HTMLTrackElement* aTrackElement) {
|
|
|
|
mTrackElement = aTrackElement;
|
|
|
|
}
|
|
|
|
|
2013-05-21 20:14:00 +04:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|