2013-05-21 20:14:00 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 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/TextTrackList.h"
|
|
|
|
#include "mozilla/dom/TextTrackListBinding.h"
|
2013-10-04 22:28:25 +04:00
|
|
|
#include "mozilla/dom/TrackEvent.h"
|
|
|
|
#include "nsThreadUtils.h"
|
2013-12-12 19:57:21 +04:00
|
|
|
#include "mozilla/dom/TextTrackCue.h"
|
2014-01-27 23:51:28 +04:00
|
|
|
#include "mozilla/dom/TextTrackManager.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(TextTrackList,
|
|
|
|
DOMEventTargetHelper,
|
|
|
|
mTextTracks,
|
|
|
|
mTextTrackManager)
|
2013-05-21 20:14:00 +04:00
|
|
|
|
2014-04-01 10:13:50 +04:00
|
|
|
NS_IMPL_ADDREF_INHERITED(TextTrackList, DOMEventTargetHelper)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(TextTrackList, DOMEventTargetHelper)
|
2013-05-21 20:14:00 +04:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(TextTrackList)
|
2014-04-01 10:13:50 +04:00
|
|
|
NS_INTERFACE_MAP_END_INHERITING(DOMEventTargetHelper)
|
2013-05-21 20:14:00 +04:00
|
|
|
|
2014-04-07 21:58:38 +04:00
|
|
|
TextTrackList::TextTrackList(nsPIDOMWindow* aOwnerWindow)
|
|
|
|
: DOMEventTargetHelper(aOwnerWindow)
|
2013-05-21 20:14:00 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-04-07 21:58:38 +04:00
|
|
|
TextTrackList::TextTrackList(nsPIDOMWindow* aOwnerWindow,
|
|
|
|
TextTrackManager* aTextTrackManager)
|
|
|
|
: DOMEventTargetHelper(aOwnerWindow)
|
2014-01-27 23:51:28 +04:00
|
|
|
, mTextTrackManager(aTextTrackManager)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-06-24 18:20:54 +04:00
|
|
|
TextTrackList::~TextTrackList()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-12-12 19:57:21 +04:00
|
|
|
void
|
2014-02-27 19:02:40 +04:00
|
|
|
TextTrackList::UpdateAndGetShowingCues(nsTArray<nsRefPtr<TextTrackCue> >& aCues)
|
2013-12-12 19:57:21 +04:00
|
|
|
{
|
|
|
|
nsTArray< nsRefPtr<TextTrackCue> > cues;
|
|
|
|
for (uint32_t i = 0; i < Length(); i++) {
|
2014-02-27 19:02:40 +04:00
|
|
|
TextTrackMode mode = mTextTracks[i]->Mode();
|
|
|
|
// If the mode is hidden then we just need to update the active cue list,
|
|
|
|
// we don't need to show it on the video.
|
|
|
|
if (mode == TextTrackMode::Hidden) {
|
|
|
|
mTextTracks[i]->UpdateActiveCueList();
|
|
|
|
} else if (mode == TextTrackMode::Showing) {
|
|
|
|
// If the mode is showing then we need to update the cue list and show it
|
|
|
|
// on the video. GetActiveCueArray() calls UpdateActiveCueList() so we
|
|
|
|
// don't need to call it explicitly.
|
2013-12-12 19:57:21 +04:00
|
|
|
mTextTracks[i]->GetActiveCueArray(cues);
|
|
|
|
aCues.AppendElements(cues);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
TextTrackList::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 TextTrackListBinding::Wrap(aCx, this, aGivenProto);
|
2013-05-21 20:14:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
TextTrack*
|
|
|
|
TextTrackList::IndexedGetter(uint32_t aIndex, bool& aFound)
|
|
|
|
{
|
|
|
|
aFound = aIndex < mTextTracks.Length();
|
|
|
|
return aFound ? mTextTracks[aIndex] : nullptr;
|
|
|
|
}
|
|
|
|
|
2014-03-01 00:40:00 +04:00
|
|
|
TextTrack*
|
|
|
|
TextTrackList::operator[](uint32_t aIndex)
|
|
|
|
{
|
|
|
|
return mTextTracks.SafeElementAt(aIndex, nullptr);
|
|
|
|
}
|
|
|
|
|
2013-05-21 20:14:00 +04:00
|
|
|
already_AddRefed<TextTrack>
|
2014-01-28 00:17:20 +04:00
|
|
|
TextTrackList::AddTextTrack(TextTrackKind aKind,
|
2013-05-21 20:14:00 +04:00
|
|
|
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,
|
|
|
|
const CompareTextTracks& aCompareTT)
|
2013-05-21 20:14:00 +04:00
|
|
|
{
|
2014-04-07 21:58:38 +04:00
|
|
|
nsRefPtr<TextTrack> track = new TextTrack(GetOwner(), this, aKind, aLabel,
|
2014-03-13 22:41:21 +04:00
|
|
|
aLanguage, aMode, aReadyState,
|
|
|
|
aTextTrackSource);
|
2014-02-27 21:47:23 +04:00
|
|
|
AddTextTrack(track, aCompareTT);
|
2013-05-21 20:14:00 +04:00
|
|
|
return track.forget();
|
|
|
|
}
|
|
|
|
|
2014-02-13 22:28:21 +04:00
|
|
|
void
|
2014-02-27 21:47:23 +04:00
|
|
|
TextTrackList::AddTextTrack(TextTrack* aTextTrack,
|
|
|
|
const CompareTextTracks& aCompareTT)
|
2014-02-13 22:28:21 +04:00
|
|
|
{
|
2014-02-27 21:47:23 +04:00
|
|
|
if (mTextTracks.InsertElementSorted(aTextTrack, aCompareTT)) {
|
2014-02-13 22:28:21 +04:00
|
|
|
aTextTrack->SetTextTrackList(this);
|
|
|
|
CreateAndDispatchTrackEventRunner(aTextTrack, NS_LITERAL_STRING("addtrack"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-09 19:44:35 +04:00
|
|
|
TextTrack*
|
|
|
|
TextTrackList::GetTrackById(const nsAString& aId)
|
|
|
|
{
|
|
|
|
nsAutoString id;
|
|
|
|
for (uint32_t i = 0; i < Length(); i++) {
|
|
|
|
mTextTracks[i]->GetId(id);
|
|
|
|
if (aId.Equals(id)) {
|
|
|
|
return mTextTracks[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2013-05-21 20:14:00 +04:00
|
|
|
void
|
2013-10-21 18:15:00 +04:00
|
|
|
TextTrackList::RemoveTextTrack(TextTrack* aTrack)
|
2013-05-21 20:14:00 +04:00
|
|
|
{
|
2013-10-21 18:15:00 +04:00
|
|
|
if (mTextTracks.RemoveElement(aTrack)) {
|
|
|
|
CreateAndDispatchTrackEventRunner(aTrack, NS_LITERAL_STRING("removetrack"));
|
2013-10-04 22:28:25 +04:00
|
|
|
}
|
2013-05-21 20:14:00 +04:00
|
|
|
}
|
|
|
|
|
2013-06-15 00:10:36 +04:00
|
|
|
void
|
|
|
|
TextTrackList::DidSeek()
|
|
|
|
{
|
|
|
|
for (uint32_t i = 0; i < mTextTracks.Length(); i++) {
|
|
|
|
mTextTracks[i]->SetDirty();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class TrackEventRunner final: public nsRunnable
|
2013-10-04 22:28:25 +04:00
|
|
|
{
|
|
|
|
public:
|
2013-12-18 09:19:09 +04:00
|
|
|
TrackEventRunner(TextTrackList* aList, nsIDOMEvent* aEvent)
|
2013-10-04 22:28:25 +04:00
|
|
|
: mList(aList)
|
|
|
|
, mEvent(aEvent)
|
|
|
|
{}
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
NS_IMETHOD Run() override
|
2013-10-04 22:28:25 +04:00
|
|
|
{
|
|
|
|
return mList->DispatchTrackEvent(mEvent);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsRefPtr<TextTrackList> mList;
|
2013-12-18 09:19:09 +04:00
|
|
|
nsRefPtr<nsIDOMEvent> mEvent;
|
2013-10-04 22:28:25 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
nsresult
|
2013-12-18 09:19:09 +04:00
|
|
|
TextTrackList::DispatchTrackEvent(nsIDOMEvent* aEvent)
|
2013-10-04 22:28:25 +04:00
|
|
|
{
|
|
|
|
return DispatchTrustedEvent(aEvent);
|
|
|
|
}
|
|
|
|
|
2013-12-18 09:19:09 +04:00
|
|
|
void
|
|
|
|
TextTrackList::CreateAndDispatchChangeEvent()
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDOMEvent> event;
|
|
|
|
nsresult rv = NS_NewDOMEvent(getter_AddRefs(event), this, nullptr, nullptr);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
NS_WARNING("Failed to create the error event!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = event->InitEvent(NS_LITERAL_STRING("change"), false, false);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
NS_WARNING("Failed to init the change event!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
event->SetTrusted(true);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIRunnable> eventRunner = new TrackEventRunner(this, event);
|
2014-05-23 23:53:17 +04:00
|
|
|
NS_DispatchToMainThread(eventRunner);
|
2013-12-18 09:19:09 +04:00
|
|
|
}
|
|
|
|
|
2013-10-04 22:28:25 +04:00
|
|
|
void
|
|
|
|
TextTrackList::CreateAndDispatchTrackEventRunner(TextTrack* aTrack,
|
|
|
|
const nsAString& aEventName)
|
|
|
|
{
|
2013-10-09 20:05:22 +04:00
|
|
|
TrackEventInit eventInit;
|
2014-04-16 07:06:45 +04:00
|
|
|
eventInit.mTrack.SetValue().SetAsTextTrack() = aTrack;
|
2013-12-18 09:19:09 +04:00
|
|
|
nsRefPtr<TrackEvent> event =
|
2013-10-04 22:28:25 +04:00
|
|
|
TrackEvent::Constructor(this, aEventName, eventInit);
|
|
|
|
|
|
|
|
// Dispatch the TrackEvent asynchronously.
|
2013-12-18 09:19:09 +04:00
|
|
|
nsCOMPtr<nsIRunnable> eventRunner = new TrackEventRunner(this, event);
|
2014-05-23 23:53:17 +04:00
|
|
|
NS_DispatchToMainThread(eventRunner);
|
2013-10-04 22:28:25 +04:00
|
|
|
}
|
|
|
|
|
2014-01-27 23:51:28 +04:00
|
|
|
HTMLMediaElement*
|
|
|
|
TextTrackList::GetMediaElement()
|
|
|
|
{
|
|
|
|
if (mTextTrackManager) {
|
|
|
|
return mTextTrackManager->mMediaElement;
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TextTrackList::SetTextTrackManager(TextTrackManager* aTextTrackManager)
|
|
|
|
{
|
|
|
|
mTextTrackManager = aTextTrackManager;
|
|
|
|
}
|
|
|
|
|
2013-05-21 20:14:00 +04:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|