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"
|
2017-06-01 23:41:18 +03:00
|
|
|
|
|
|
|
#include "mozilla/DebugOnly.h"
|
2018-04-20 19:55:30 +03:00
|
|
|
#include "mozilla/dom/Event.h"
|
2013-05-21 20:14:00 +04:00
|
|
|
#include "mozilla/dom/TextTrackListBinding.h"
|
2013-10-04 22:28:25 +04:00
|
|
|
#include "mozilla/dom/TrackEvent.h"
|
|
|
|
#include "nsThreadUtils.h"
|
2017-03-21 11:16:08 +03:00
|
|
|
#include "nsGlobalWindow.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)
|
2017-08-30 02:02:48 +03:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(TextTrackList)
|
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
|
|
|
TextTrackList::TextTrackList(nsPIDOMWindowInner* aOwnerWindow)
|
2014-04-07 21:58:38 +04:00
|
|
|
: DOMEventTargetHelper(aOwnerWindow) {}
|
2013-05-21 20:14:00 +04:00
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
TextTrackList::TextTrackList(nsPIDOMWindowInner* aOwnerWindow,
|
2014-04-07 21:58:38 +04:00
|
|
|
TextTrackManager* aTextTrackManager)
|
2016-09-21 11:01:22 +03:00
|
|
|
: DOMEventTargetHelper(aOwnerWindow),
|
|
|
|
mTextTrackManager(aTextTrackManager) {}
|
2014-01-27 23:51:28 +04:00
|
|
|
|
2020-03-04 18:39:20 +03:00
|
|
|
TextTrackList::~TextTrackList() = default;
|
2014-06-24 18:20:54 +04:00
|
|
|
|
2016-07-18 10:39:14 +03:00
|
|
|
void TextTrackList::GetShowingCues(nsTArray<RefPtr<TextTrackCue>>& aCues) {
|
2017-05-22 06:30:22 +03:00
|
|
|
// Only Subtitles and Captions can show on the screen.
|
2015-10-18 08:24:48 +03:00
|
|
|
nsTArray<RefPtr<TextTrackCue>> cues;
|
2013-12-12 19:57:21 +04:00
|
|
|
for (uint32_t i = 0; i < Length(); i++) {
|
2017-05-22 06:30:22 +03:00
|
|
|
if (mTextTracks[i]->Mode() == TextTrackMode::Showing &&
|
|
|
|
(mTextTracks[i]->Kind() == TextTrackKind::Subtitles ||
|
|
|
|
mTextTracks[i]->Kind() == TextTrackKind::Captions)) {
|
2013-12-12 19:57:21 +04:00
|
|
|
mTextTracks[i]->GetActiveCueArray(cues);
|
|
|
|
aCues.AppendElements(cues);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
JSObject* TextTrackList::WrapObject(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aGivenProto) {
|
2018-06-26 00:20:54 +03:00
|
|
|
return TextTrackList_Binding::Wrap(aCx, this, aGivenProto);
|
2013-05-21 20:14:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
TextTrack* TextTrackList::IndexedGetter(uint32_t aIndex, bool& aFound) {
|
|
|
|
aFound = aIndex < mTextTracks.Length();
|
2015-08-13 15:22:48 +03:00
|
|
|
if (!aFound) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return mTextTracks[aIndex];
|
2013-05-21 20:14:00 +04:00
|
|
|
}
|
|
|
|
|
2014-03-01 00:40:00 +04:00
|
|
|
TextTrack* TextTrackList::operator[](uint32_t aIndex) {
|
|
|
|
return mTextTracks.SafeElementAt(aIndex, nullptr);
|
|
|
|
}
|
|
|
|
|
2014-01-28 00:17:20 +04:00
|
|
|
already_AddRefed<TextTrack> TextTrackList::AddTextTrack(
|
2014-02-27 21:47:23 +04:00
|
|
|
TextTrackKind aKind, const nsAString& aLabel, const nsAString& aLanguage,
|
2014-03-13 22:41:21 +04:00
|
|
|
TextTrackMode aMode, TextTrackReadyState aReadyState,
|
2014-02-27 21:47:23 +04:00
|
|
|
TextTrackSource aTextTrackSource, const CompareTextTracks& aCompareTT) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<TextTrack> track =
|
|
|
|
new TextTrack(GetOwner(), this, aKind, aLabel, aLanguage, aMode,
|
2014-03-13 22:41:21 +04:00
|
|
|
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-27 21:47:23 +04:00
|
|
|
void TextTrackList::AddTextTrack(TextTrack* aTextTrack,
|
|
|
|
const CompareTextTracks& aCompareTT) {
|
2016-06-21 11:26:35 +03:00
|
|
|
if (mTextTracks.Contains(aTextTrack)) {
|
|
|
|
return;
|
|
|
|
}
|
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-10-21 18:15:00 +04:00
|
|
|
void TextTrackList::RemoveTextTrack(TextTrack* aTrack) {
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2016-09-21 11:01:22 +03:00
|
|
|
class TrackEventRunner : public Runnable {
|
2013-10-04 22:28:25 +04:00
|
|
|
public:
|
2018-04-20 19:55:30 +03:00
|
|
|
TrackEventRunner(TextTrackList* aList, Event* aEvent)
|
2017-06-12 22:34:10 +03:00
|
|
|
: Runnable("dom::TrackEventRunner"), mList(aList), mEvent(aEvent) {}
|
2018-11-19 16:25:37 +03:00
|
|
|
|
2013-10-04 22:28:25 +04:00
|
|
|
NS_IMETHOD Run() override { return mList->DispatchTrackEvent(mEvent); }
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<TextTrackList> mList;
|
2018-11-19 16:25:37 +03:00
|
|
|
|
2016-09-21 11:01:22 +03:00
|
|
|
private:
|
2018-04-20 19:55:30 +03:00
|
|
|
RefPtr<Event> mEvent;
|
2013-10-04 22:28:25 +04:00
|
|
|
};
|
|
|
|
|
2018-04-20 19:55:30 +03:00
|
|
|
nsresult TextTrackList::DispatchTrackEvent(Event* aEvent) {
|
2013-10-04 22:28:25 +04:00
|
|
|
return DispatchTrustedEvent(aEvent);
|
|
|
|
}
|
|
|
|
|
2013-12-18 09:19:09 +04:00
|
|
|
void TextTrackList::CreateAndDispatchChangeEvent() {
|
2016-09-21 11:01:22 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2019-03-12 03:32:21 +03:00
|
|
|
nsPIDOMWindowInner* win = GetOwner();
|
|
|
|
if (!win) {
|
|
|
|
return;
|
|
|
|
}
|
2017-03-21 11:16:08 +03:00
|
|
|
|
2019-03-12 03:32:21 +03:00
|
|
|
RefPtr<Event> event = NS_NewDOMEvent(this, nullptr, nullptr);
|
2013-12-18 09:19:09 +04:00
|
|
|
|
2019-03-12 03:32:21 +03:00
|
|
|
event->InitEvent(NS_LITERAL_STRING("change"), false, false);
|
|
|
|
event->SetTrusted(true);
|
2013-12-18 09:19:09 +04:00
|
|
|
|
2019-03-12 03:32:21 +03:00
|
|
|
nsCOMPtr<nsIRunnable> eventRunner = new TrackEventRunner(this, event);
|
|
|
|
nsGlobalWindowInner::Cast(win)->Dispatch(TaskCategory::Other,
|
|
|
|
eventRunner.forget());
|
2013-12-18 09:19:09 +04:00
|
|
|
}
|
|
|
|
|
2013-10-04 22:28:25 +04:00
|
|
|
void TextTrackList::CreateAndDispatchTrackEventRunner(
|
|
|
|
TextTrack* aTrack, const nsAString& aEventName) {
|
2017-06-01 23:41:18 +03:00
|
|
|
DebugOnly<nsresult> rv;
|
|
|
|
nsCOMPtr<nsIEventTarget> target = GetMainThreadEventTarget();
|
|
|
|
if (!target) {
|
2015-08-20 19:45:34 +03:00
|
|
|
// If we are not able to get the main-thread object we are shutting down.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-10-09 20:05:22 +04:00
|
|
|
TrackEventInit eventInit;
|
2014-04-16 07:06:45 +04:00
|
|
|
eventInit.mTrack.SetValue().SetAsTextTrack() = aTrack;
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<TrackEvent> event =
|
2013-10-04 22:28:25 +04:00
|
|
|
TrackEvent::Constructor(this, aEventName, eventInit);
|
|
|
|
|
|
|
|
// Dispatch the TrackEvent asynchronously.
|
2017-06-01 23:41:18 +03:00
|
|
|
rv = target->Dispatch(do_AddRef(new TrackEventRunner(this, event)),
|
2015-08-20 21:54:50 +03:00
|
|
|
NS_DISPATCH_NORMAL);
|
|
|
|
|
|
|
|
// If we are shutting down this can file but it's still ok.
|
2016-09-02 10:12:24 +03:00
|
|
|
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "Dispatch failed");
|
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;
|
|
|
|
}
|
|
|
|
|
2016-06-01 08:35:53 +03:00
|
|
|
void TextTrackList::SetCuesInactive() {
|
|
|
|
for (uint32_t i = 0; i < Length(); i++) {
|
|
|
|
mTextTracks[i]->SetCuesInactive();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-20 10:27:06 +03:00
|
|
|
bool TextTrackList::AreTextTracksLoaded() {
|
|
|
|
// Return false if any texttrack is not loaded.
|
|
|
|
for (uint32_t i = 0; i < Length(); i++) {
|
|
|
|
if (!mTextTracks[i]->IsLoaded()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-06-13 04:52:27 +03:00
|
|
|
nsTArray<RefPtr<TextTrack>>& TextTrackList::GetTextTrackArray() {
|
|
|
|
return mTextTracks;
|
|
|
|
}
|
|
|
|
|
2013-05-21 20:14:00 +04:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|