2015-05-03 22:32:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2013-10-23 22:45:00 +04:00
|
|
|
/* 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/. */
|
|
|
|
|
|
|
|
#ifndef mozilla_dom_TextTrackManager_h
|
|
|
|
#define mozilla_dom_TextTrackManager_h
|
|
|
|
|
|
|
|
#include "mozilla/dom/TextTrack.h"
|
|
|
|
#include "mozilla/dom/TextTrackList.h"
|
2014-01-06 22:03:50 +04:00
|
|
|
#include "mozilla/dom/TextTrackCueList.h"
|
2013-12-12 21:02:17 +04:00
|
|
|
#include "mozilla/StaticPtr.h"
|
2016-06-01 10:13:45 +03:00
|
|
|
#include "nsContentUtils.h"
|
2019-03-26 10:50:50 +03:00
|
|
|
#include "TimeUnits.h"
|
2013-12-12 21:02:17 +04:00
|
|
|
|
|
|
|
class nsIWebVTTParserWrapper;
|
2013-10-23 22:45:00 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
|
|
|
class HTMLMediaElement;
|
2014-02-27 21:47:23 +04:00
|
|
|
|
|
|
|
class CompareTextTracks {
|
|
|
|
private:
|
|
|
|
HTMLMediaElement* mMediaElement;
|
2016-06-01 08:35:56 +03:00
|
|
|
int32_t TrackChildPosition(TextTrack* aTrack) const;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-02-27 21:47:23 +04:00
|
|
|
public:
|
2014-09-02 04:49:25 +04:00
|
|
|
explicit CompareTextTracks(HTMLMediaElement* aMediaElement);
|
2014-02-27 21:47:23 +04:00
|
|
|
bool Equals(TextTrack* aOne, TextTrack* aTwo) const;
|
|
|
|
bool LessThan(TextTrack* aOne, TextTrack* aTwo) const;
|
|
|
|
};
|
|
|
|
|
2013-12-12 21:02:17 +04:00
|
|
|
class TextTrack;
|
|
|
|
class TextTrackCue;
|
2013-10-23 22:45:00 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class TextTrackManager final : public nsIDOMEventListener {
|
2014-06-25 06:09:15 +04:00
|
|
|
~TextTrackManager();
|
|
|
|
|
2013-10-23 22:45:00 +04:00
|
|
|
public:
|
2014-04-07 23:42:33 +04:00
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS(TextTrackManager)
|
|
|
|
|
|
|
|
NS_DECL_NSIDOMEVENTLISTENER
|
2013-10-23 22:45:00 +04:00
|
|
|
|
2014-09-02 04:49:25 +04:00
|
|
|
explicit TextTrackManager(HTMLMediaElement* aMediaElement);
|
2013-10-23 22:45:00 +04:00
|
|
|
|
2015-01-12 14:07:38 +03:00
|
|
|
TextTrackList* GetTextTracks() const;
|
2013-10-23 22:45:00 +04:00
|
|
|
already_AddRefed<TextTrack> AddTextTrack(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);
|
2013-10-23 22:45:00 +04:00
|
|
|
void AddTextTrack(TextTrack* aTextTrack);
|
2013-10-25 08:14:36 +04:00
|
|
|
void RemoveTextTrack(TextTrack* aTextTrack, bool aPendingListOnly);
|
2013-10-23 22:45:00 +04:00
|
|
|
void DidSeek();
|
|
|
|
|
2016-06-02 11:08:32 +03:00
|
|
|
void NotifyCueAdded(TextTrackCue& aCue);
|
2014-01-06 22:03:50 +04:00
|
|
|
void AddCues(TextTrack* aTextTrack);
|
2016-06-01 08:35:58 +03:00
|
|
|
void NotifyCueRemoved(TextTrackCue& aCue);
|
2013-12-12 21:02:17 +04:00
|
|
|
/**
|
|
|
|
* Overview of WebVTT cuetext and anonymous content setup.
|
|
|
|
*
|
|
|
|
* WebVTT nodes are the parsed version of WebVTT cuetext. WebVTT cuetext is
|
|
|
|
* the portion of a WebVTT cue that specifies what the caption will actually
|
|
|
|
* show up as on screen.
|
|
|
|
*
|
|
|
|
* WebVTT cuetext can contain markup that loosely relates to HTML markup. It
|
|
|
|
* can contain tags like <b>, <u>, <i>, <c>, <v>, <ruby>, <rt>, <lang>,
|
|
|
|
* including timestamp tags.
|
|
|
|
*
|
|
|
|
* When the caption is ready to be displayed the WebVTT nodes are converted
|
|
|
|
* over to anonymous DOM content. <i>, <u>, <b>, <ruby>, and <rt> all become
|
|
|
|
* HTMLElements of their corresponding HTML markup tags. <c> and <v> are
|
|
|
|
* converted to <span> tags. Timestamp tags are converted to XML processing
|
|
|
|
* instructions. Additionally, all cuetext tags support specifying of classes.
|
|
|
|
* This takes the form of <foo.class.subclass>. These classes are then parsed
|
|
|
|
* and set as the anonymous content's class attribute.
|
|
|
|
*
|
|
|
|
* Rules on constructing DOM objects from WebVTT nodes can be found here
|
|
|
|
* http://dev.w3.org/html5/webvtt/#webvtt-cue-text-dom-construction-rules.
|
|
|
|
* Current rules are taken from revision on April 15, 2013.
|
|
|
|
*/
|
|
|
|
|
2013-10-25 08:14:36 +04:00
|
|
|
void PopulatePendingList();
|
|
|
|
|
2014-04-07 23:42:33 +04:00
|
|
|
void AddListeners();
|
|
|
|
|
2013-10-23 22:45:00 +04:00
|
|
|
// The HTMLMediaElement that this TextTrackManager manages the TextTracks of.
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<HTMLMediaElement> mMediaElement;
|
2016-06-01 08:35:56 +03:00
|
|
|
|
|
|
|
void DispatchTimeMarchesOn();
|
2016-06-01 12:37:26 +03:00
|
|
|
void TimeMarchesOn();
|
2016-07-18 10:39:14 +03:00
|
|
|
void DispatchUpdateCueDisplay();
|
2016-06-01 08:35:56 +03:00
|
|
|
|
2016-06-01 10:13:45 +03:00
|
|
|
void NotifyShutdown() { mShutdown = true; }
|
|
|
|
|
2016-06-08 11:53:30 +03:00
|
|
|
void NotifyCueUpdated(TextTrackCue* aCue);
|
|
|
|
|
2016-06-20 10:58:58 +03:00
|
|
|
void NotifyReset();
|
|
|
|
|
2017-02-20 10:27:06 +03:00
|
|
|
bool IsLoaded();
|
|
|
|
|
2014-01-27 23:51:28 +04:00
|
|
|
private:
|
2016-06-01 12:37:26 +03:00
|
|
|
/**
|
|
|
|
* Converts the TextTrackCue's cuetext into a tree of DOM objects
|
|
|
|
* and attaches it to a div on its owning TrackElement's
|
|
|
|
* MediaElement's caption overlay.
|
|
|
|
*/
|
|
|
|
void UpdateCueDisplay();
|
2016-06-01 08:35:56 +03:00
|
|
|
|
2013-10-23 22:45:00 +04:00
|
|
|
// List of the TextTrackManager's owning HTMLMediaElement's TextTracks.
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<TextTrackList> mTextTracks;
|
2013-10-25 08:14:36 +04:00
|
|
|
// List of text track objects awaiting loading.
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<TextTrackList> mPendingTextTracks;
|
2014-01-06 22:03:50 +04:00
|
|
|
// List of newly introduced Text Track cues.
|
2016-06-01 08:35:56 +03:00
|
|
|
|
2016-06-08 11:53:30 +03:00
|
|
|
// Contain all cues for a MediaElement. Not sorted.
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<TextTrackCueList> mNewCues;
|
2016-06-01 08:35:56 +03:00
|
|
|
|
|
|
|
// True if the media player playback changed due to seeking prior to and
|
|
|
|
// during running the "Time Marches On" algorithm.
|
|
|
|
bool mHasSeeked;
|
|
|
|
// Playback position at the time of last "Time Marches On" call
|
2019-03-26 10:50:50 +03:00
|
|
|
media::TimeUnit mLastTimeMarchesOnCalled;
|
2016-06-01 08:35:56 +03:00
|
|
|
|
|
|
|
bool mTimeMarchesOnDispatched;
|
2016-07-18 10:39:14 +03:00
|
|
|
bool mUpdateCueDisplayDispatched;
|
2013-12-12 21:02:17 +04:00
|
|
|
|
|
|
|
static StaticRefPtr<nsIWebVTTParserWrapper> sParserWrapper;
|
2014-03-01 00:40:00 +04:00
|
|
|
|
|
|
|
bool performedTrackSelection;
|
|
|
|
|
|
|
|
// Runs the algorithm for performing automatic track selection.
|
|
|
|
void HonorUserPreferencesForTrackSelection();
|
|
|
|
// Performs track selection for a single TextTrackKind.
|
|
|
|
void PerformTrackSelection(TextTrackKind aTextTrackKind);
|
|
|
|
// Performs track selection for a set of TextTrackKinds, for example,
|
|
|
|
// 'subtitles' and 'captions' should be selected together.
|
|
|
|
void PerformTrackSelection(TextTrackKind aTextTrackKinds[], uint32_t size);
|
|
|
|
void GetTextTracksOfKinds(TextTrackKind aTextTrackKinds[], uint32_t size,
|
|
|
|
nsTArray<TextTrack*>& aTextTracks);
|
|
|
|
void GetTextTracksOfKind(TextTrackKind aTextTrackKind,
|
|
|
|
nsTArray<TextTrack*>& aTextTracks);
|
|
|
|
bool TrackIsDefault(TextTrack* aTextTrack);
|
2016-06-01 10:13:45 +03:00
|
|
|
|
2016-07-11 05:51:08 +03:00
|
|
|
void ReportTelemetryForTrack(TextTrack* aTextTrack) const;
|
|
|
|
|
2017-08-09 12:30:52 +03:00
|
|
|
bool IsShutdown() const;
|
2016-07-11 05:51:08 +03:00
|
|
|
|
2019-05-17 04:59:34 +03:00
|
|
|
// This function will check media element's show poster flag to decide whether
|
|
|
|
// we need to run `TimeMarchesOn`.
|
|
|
|
void MaybeRunTimeMarchesOn();
|
|
|
|
|
2016-06-01 10:13:45 +03:00
|
|
|
class ShutdownObserverProxy final : public nsIObserver {
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit ShutdownObserverProxy(TextTrackManager* aManager)
|
|
|
|
: mManager(aManager) {
|
|
|
|
nsContentUtils::RegisterShutdownObserver(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP Observe(nsISupports* aSubject, const char* aTopic,
|
|
|
|
const char16_t* aData) override {
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
if (strcmp(aTopic, NS_XPCOM_SHUTDOWN_OBSERVER_ID) == 0) {
|
2018-11-20 02:16:24 +03:00
|
|
|
if (mManager) {
|
|
|
|
mManager->NotifyShutdown();
|
|
|
|
}
|
|
|
|
Unregister();
|
2016-06-01 10:13:45 +03:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2018-11-20 02:16:24 +03:00
|
|
|
void Unregister();
|
|
|
|
|
2016-06-01 10:13:45 +03:00
|
|
|
private:
|
2020-02-20 19:19:15 +03:00
|
|
|
~ShutdownObserverProxy() = default;
|
|
|
|
|
2016-06-01 10:13:45 +03:00
|
|
|
TextTrackManager* mManager;
|
|
|
|
};
|
|
|
|
|
|
|
|
RefPtr<ShutdownObserverProxy> mShutdownProxy;
|
|
|
|
bool mShutdown;
|
2013-10-23 22:45:00 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_dom_TextTrackManager_h
|