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-05-21 20:14: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/. */
|
|
|
|
|
2018-12-13 23:06:02 +03:00
|
|
|
#include "mozilla/dom/HTMLTrackElement.h"
|
2013-05-21 20:14:00 +04:00
|
|
|
#include "mozilla/dom/Element.h"
|
|
|
|
#include "mozilla/dom/HTMLMediaElement.h"
|
2018-11-14 08:29:11 +03:00
|
|
|
#ifdef XP_WIN
|
|
|
|
// HTMLTrackElement.webidl defines ERROR, but so does windows.h:
|
|
|
|
#undef ERROR
|
|
|
|
#endif
|
2018-12-13 23:06:02 +03:00
|
|
|
#include "WebVTTListener.h"
|
|
|
|
#include "mozilla/LoadInfo.h"
|
2013-05-21 20:14:00 +04:00
|
|
|
#include "mozilla/dom/HTMLTrackElementBinding.h"
|
|
|
|
#include "mozilla/dom/HTMLUnknownElement.h"
|
|
|
|
#include "nsAttrValueInlines.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsContentPolicyUtils.h"
|
|
|
|
#include "nsContentUtils.h"
|
|
|
|
#include "nsCycleCollectionParticipant.h"
|
|
|
|
#include "nsGenericHTMLElement.h"
|
|
|
|
#include "nsGkAtoms.h"
|
|
|
|
#include "nsIAsyncVerifyRedirectCallback.h"
|
|
|
|
#include "nsICachingChannel.h"
|
|
|
|
#include "nsIChannelEventSink.h"
|
|
|
|
#include "nsIContentPolicy.h"
|
|
|
|
#include "nsIContentSecurityPolicy.h"
|
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsIHttpChannel.h"
|
|
|
|
#include "nsIInterfaceRequestor.h"
|
|
|
|
#include "nsILoadGroup.h"
|
|
|
|
#include "nsIObserver.h"
|
|
|
|
#include "nsIStreamListener.h"
|
|
|
|
#include "nsISupportsImpl.h"
|
2016-08-05 10:13:36 +03:00
|
|
|
#include "nsISupportsPrimitives.h"
|
2013-05-21 20:14:00 +04:00
|
|
|
#include "nsMappedAttributes.h"
|
|
|
|
#include "nsNetUtil.h"
|
|
|
|
#include "nsStyleConsts.h"
|
|
|
|
#include "nsThreadUtils.h"
|
|
|
|
#include "nsVideoFrame.h"
|
|
|
|
|
2015-11-23 22:09:25 +03:00
|
|
|
static mozilla::LazyLogModule gTrackElementLog("nsTrackElement");
|
2015-05-21 23:22:04 +03:00
|
|
|
#define LOG(type, msg) MOZ_LOG(gTrackElementLog, type, msg)
|
2013-05-21 20:14:00 +04:00
|
|
|
|
|
|
|
// Replace the usual NS_IMPL_NS_NEW_HTML_ELEMENT(Track) so
|
|
|
|
// we can return an UnknownElement instead when pref'd off.
|
2014-06-20 06:01:40 +04:00
|
|
|
nsGenericHTMLElement* NS_NewHTMLTrackElement(
|
|
|
|
already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo,
|
2013-05-21 20:14:00 +04:00
|
|
|
mozilla::dom::FromParser aFromParser) {
|
2018-09-21 23:45:49 +03:00
|
|
|
return new mozilla::dom::HTMLTrackElement(std::move(aNodeInfo));
|
2013-05-21 20:14:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2014-02-22 07:06:48 +04:00
|
|
|
// Map html attribute string values to TextTrackKind enums.
|
2016-07-09 00:39:53 +03:00
|
|
|
static constexpr nsAttrValue::EnumTable kKindTable[] = {
|
2014-02-22 07:06:48 +04:00
|
|
|
{"subtitles", static_cast<int16_t>(TextTrackKind::Subtitles)},
|
|
|
|
{"captions", static_cast<int16_t>(TextTrackKind::Captions)},
|
|
|
|
{"descriptions", static_cast<int16_t>(TextTrackKind::Descriptions)},
|
|
|
|
{"chapters", static_cast<int16_t>(TextTrackKind::Chapters)},
|
|
|
|
{"metadata", static_cast<int16_t>(TextTrackKind::Metadata)},
|
2016-09-07 05:20:17 +03:00
|
|
|
{nullptr, 0}};
|
2014-02-22 07:06:48 +04:00
|
|
|
|
2016-05-08 14:46:20 +03:00
|
|
|
// Invalid values are treated as "metadata" in ParseAttribute, but if no value
|
|
|
|
// at all is specified, it's treated as "subtitles" in GetKind
|
2017-10-15 04:09:05 +03:00
|
|
|
static const nsAttrValue::EnumTable* const kKindTableInvalidValueDefault =
|
|
|
|
&kKindTable[4];
|
2013-07-04 22:16:05 +04:00
|
|
|
|
2016-08-05 10:13:36 +03:00
|
|
|
class WindowDestroyObserver final : public nsIObserver {
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit WindowDestroyObserver(HTMLTrackElement* aElement, uint64_t aWinID)
|
|
|
|
: mTrackElement(aElement), mInnerID(aWinID) {
|
|
|
|
RegisterWindowDestroyObserver();
|
|
|
|
}
|
|
|
|
void RegisterWindowDestroyObserver() {
|
|
|
|
nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
|
|
|
|
if (obs) {
|
|
|
|
obs->AddObserver(this, "inner-window-destroyed", false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void UnRegisterWindowDestroyObserver() {
|
|
|
|
nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
|
|
|
|
if (obs) {
|
|
|
|
obs->RemoveObserver(this, "inner-window-destroyed");
|
|
|
|
}
|
|
|
|
mTrackElement = nullptr;
|
|
|
|
}
|
|
|
|
NS_IMETHODIMP Observe(nsISupports* aSubject, const char* aTopic,
|
|
|
|
const char16_t* aData) override {
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
if (strcmp(aTopic, "inner-window-destroyed") == 0) {
|
|
|
|
nsCOMPtr<nsISupportsPRUint64> wrapper = do_QueryInterface(aSubject);
|
|
|
|
NS_ENSURE_TRUE(wrapper, NS_ERROR_FAILURE);
|
|
|
|
uint64_t innerID;
|
|
|
|
nsresult rv = wrapper->GetData(&innerID);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
if (innerID == mInnerID) {
|
|
|
|
if (mTrackElement) {
|
|
|
|
mTrackElement->NotifyShutdown();
|
|
|
|
}
|
|
|
|
UnRegisterWindowDestroyObserver();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
~WindowDestroyObserver(){};
|
|
|
|
HTMLTrackElement* mTrackElement;
|
|
|
|
uint64_t mInnerID;
|
|
|
|
};
|
|
|
|
NS_IMPL_ISUPPORTS(WindowDestroyObserver, nsIObserver);
|
|
|
|
|
2013-05-21 20:14:00 +04:00
|
|
|
/** HTMLTrackElement */
|
2018-09-21 23:45:49 +03:00
|
|
|
HTMLTrackElement::HTMLTrackElement(
|
|
|
|
already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo)
|
|
|
|
: nsGenericHTMLElement(std::move(aNodeInfo)),
|
2016-07-21 11:49:24 +03:00
|
|
|
mLoadResourceDispatched(false),
|
2016-10-12 12:26:20 +03:00
|
|
|
mWindowDestroyObserver(nullptr) {
|
2016-08-17 04:11:42 +03:00
|
|
|
nsISupports* parentObject = OwnerDoc()->GetParentObject();
|
|
|
|
NS_ENSURE_TRUE_VOID(parentObject);
|
|
|
|
nsCOMPtr<nsPIDOMWindowInner> window = do_QueryInterface(parentObject);
|
2016-10-12 12:26:20 +03:00
|
|
|
if (window) {
|
|
|
|
mWindowDestroyObserver =
|
|
|
|
new WindowDestroyObserver(this, window->WindowID());
|
|
|
|
}
|
2013-05-21 20:14:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
HTMLTrackElement::~HTMLTrackElement() {
|
2016-08-05 10:13:36 +03:00
|
|
|
if (mWindowDestroyObserver) {
|
|
|
|
mWindowDestroyObserver->UnRegisterWindowDestroyObserver();
|
|
|
|
}
|
|
|
|
NotifyShutdown();
|
2013-05-21 20:14:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_ELEMENT_CLONE(HTMLTrackElement)
|
|
|
|
|
2014-04-25 20:49:00 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_INHERITED(HTMLTrackElement, nsGenericHTMLElement,
|
2014-06-19 00:10:24 +04:00
|
|
|
mTrack, mMediaParent, mListener)
|
2013-05-21 20:14:00 +04:00
|
|
|
|
2017-10-03 02:42:09 +03:00
|
|
|
NS_IMPL_ISUPPORTS_CYCLE_COLLECTION_INHERITED_0(HTMLTrackElement,
|
|
|
|
nsGenericHTMLElement)
|
2013-05-21 20:14:00 +04:00
|
|
|
|
2013-07-04 22:16:05 +04:00
|
|
|
void HTMLTrackElement::GetKind(DOMString& aKind) const {
|
2016-05-08 14:46:20 +03:00
|
|
|
GetEnumAttr(nsGkAtoms::kind, kKindTable[0].tag, aKind);
|
2013-07-04 22:16:05 +04:00
|
|
|
}
|
|
|
|
|
2013-06-10 19:30:00 +04:00
|
|
|
void HTMLTrackElement::OnChannelRedirect(nsIChannel* aChannel,
|
|
|
|
nsIChannel* aNewChannel,
|
|
|
|
uint32_t aFlags) {
|
|
|
|
NS_ASSERTION(aChannel == mChannel, "Channels should match!");
|
|
|
|
mChannel = aNewChannel;
|
|
|
|
}
|
|
|
|
|
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* HTMLTrackElement::WrapNode(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aGivenProto) {
|
2018-06-26 00:20:54 +03:00
|
|
|
return HTMLTrackElement_Binding::Wrap(aCx, this, aGivenProto);
|
2013-05-21 20:14:00 +04:00
|
|
|
}
|
|
|
|
|
2014-04-07 21:58:38 +04:00
|
|
|
TextTrack* HTMLTrackElement::GetTrack() {
|
2013-05-21 20:14:00 +04:00
|
|
|
if (!mTrack) {
|
2014-01-28 00:17:20 +04:00
|
|
|
CreateTextTrack();
|
2013-05-21 20:14:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return mTrack;
|
|
|
|
}
|
|
|
|
|
|
|
|
void HTMLTrackElement::CreateTextTrack() {
|
2013-05-24 06:57:00 +04:00
|
|
|
nsString label, srcLang;
|
2013-05-21 20:14:00 +04:00
|
|
|
GetSrclang(srcLang);
|
|
|
|
GetLabel(label);
|
|
|
|
|
2013-07-04 22:16:05 +04:00
|
|
|
TextTrackKind kind;
|
|
|
|
if (const nsAttrValue* value = GetParsedAttr(nsGkAtoms::kind)) {
|
|
|
|
kind = static_cast<TextTrackKind>(value->GetEnumValue());
|
|
|
|
} else {
|
|
|
|
kind = TextTrackKind::Subtitles;
|
2013-05-21 20:14:00 +04:00
|
|
|
}
|
|
|
|
|
2015-01-12 14:07:38 +03:00
|
|
|
nsISupports* parentObject = OwnerDoc()->GetParentObject();
|
2014-04-07 21:58:38 +04:00
|
|
|
|
2015-01-12 14:07:38 +03:00
|
|
|
NS_ENSURE_TRUE_VOID(parentObject);
|
2014-04-07 21:58:38 +04:00
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
nsCOMPtr<nsPIDOMWindowInner> window = do_QueryInterface(parentObject);
|
2014-04-07 21:58:38 +04:00
|
|
|
mTrack =
|
|
|
|
new TextTrack(window, kind, label, srcLang, TextTrackMode::Disabled,
|
2014-03-13 22:41:21 +04:00
|
|
|
TextTrackReadyState::NotLoaded, TextTrackSource::Track);
|
2014-02-27 23:07:39 +04:00
|
|
|
mTrack->SetTrackElement(this);
|
2013-05-21 20:14:00 +04:00
|
|
|
|
2013-07-04 22:16:05 +04:00
|
|
|
if (mMediaParent) {
|
|
|
|
mMediaParent->AddTextTrack(mTrack);
|
|
|
|
}
|
2013-05-21 20:14:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool HTMLTrackElement::ParseAttribute(int32_t aNamespaceID, nsAtom* aAttribute,
|
|
|
|
const nsAString& aValue,
|
2017-11-02 06:35:52 +03:00
|
|
|
nsIPrincipal* aMaybeScriptedPrincipal,
|
2013-05-21 20:14:00 +04:00
|
|
|
nsAttrValue& aResult) {
|
|
|
|
if (aNamespaceID == kNameSpaceID_None && aAttribute == nsGkAtoms::kind) {
|
|
|
|
// Case-insensitive lookup, with the first element as the default.
|
2016-05-08 14:46:20 +03:00
|
|
|
return aResult.ParseEnumValue(aValue, kKindTable, false,
|
|
|
|
kKindTableInvalidValueDefault);
|
2013-05-21 20:14:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise call the generic implementation.
|
|
|
|
return nsGenericHTMLElement::ParseAttribute(aNamespaceID, aAttribute, aValue,
|
2017-11-02 06:35:52 +03:00
|
|
|
aMaybeScriptedPrincipal, aResult);
|
2013-05-21 20:14:00 +04:00
|
|
|
}
|
|
|
|
|
2016-07-21 11:49:24 +03:00
|
|
|
void HTMLTrackElement::SetSrc(const nsAString& aSrc, ErrorResult& aError) {
|
|
|
|
SetHTMLAttr(nsGkAtoms::src, aSrc, aError);
|
|
|
|
uint16_t oldReadyState = ReadyState();
|
|
|
|
SetReadyState(TextTrackReadyState::NotLoaded);
|
|
|
|
if (!mMediaParent) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (mTrack && (oldReadyState != TextTrackReadyState::NotLoaded)) {
|
|
|
|
// Remove all the cues in MediaElement.
|
|
|
|
mMediaParent->RemoveTextTrack(mTrack);
|
|
|
|
// Recreate mTrack.
|
|
|
|
CreateTextTrack();
|
|
|
|
}
|
|
|
|
// Stop WebVTTListener.
|
|
|
|
mListener = nullptr;
|
|
|
|
if (mChannel) {
|
|
|
|
mChannel->Cancel(NS_BINDING_ABORTED);
|
|
|
|
mChannel = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
DispatchLoadResource();
|
|
|
|
}
|
|
|
|
|
|
|
|
void HTMLTrackElement::DispatchLoadResource() {
|
|
|
|
if (!mLoadResourceDispatched) {
|
2018-12-13 23:06:02 +03:00
|
|
|
RefPtr<WebVTTListener> listener = new WebVTTListener(this);
|
|
|
|
RefPtr<Runnable> r = NewRunnableMethod<RefPtr<WebVTTListener>>(
|
|
|
|
"dom::HTMLTrackElement::LoadResource", this,
|
|
|
|
&HTMLTrackElement::LoadResource, std::move(listener));
|
2016-07-21 11:49:24 +03:00
|
|
|
nsContentUtils::RunInStableState(r.forget());
|
|
|
|
mLoadResourceDispatched = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-13 23:06:02 +03:00
|
|
|
void HTMLTrackElement::LoadResource(RefPtr<WebVTTListener>&& aWebVTTListener) {
|
2016-07-21 11:49:24 +03:00
|
|
|
mLoadResourceDispatched = false;
|
|
|
|
|
2013-06-10 19:30:00 +04:00
|
|
|
// Find our 'src' url
|
|
|
|
nsAutoString src;
|
|
|
|
if (!GetAttr(kNameSpaceID_None, nsGkAtoms::src, src)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
nsresult rv = NewURIFromString(src, getter_AddRefs(uri));
|
|
|
|
NS_ENSURE_TRUE_VOID(NS_SUCCEEDED(rv));
|
2015-06-04 01:25:57 +03:00
|
|
|
LOG(LogLevel::Info, ("%p Trying to load from src=%s", this,
|
2013-06-10 19:30:00 +04:00
|
|
|
NS_ConvertUTF16toUTF8(src).get()));
|
|
|
|
|
|
|
|
if (mChannel) {
|
|
|
|
mChannel->Cancel(NS_BINDING_ABORTED);
|
|
|
|
mChannel = nullptr;
|
|
|
|
}
|
|
|
|
|
2017-02-14 06:47:14 +03:00
|
|
|
// According to
|
|
|
|
// https://www.w3.org/TR/html5/embedded-content-0.html#sourcing-out-of-band-text-tracks
|
|
|
|
//
|
|
|
|
// "8: If the track element's parent is a media element then let CORS mode
|
|
|
|
// be the state of the parent media element's crossorigin content attribute.
|
|
|
|
// Otherwise, let CORS mode be No CORS."
|
|
|
|
//
|
|
|
|
CORSMode corsMode = mMediaParent ? mMediaParent->GetCORSMode() : CORS_NONE;
|
|
|
|
|
|
|
|
// Determine the security flag based on corsMode.
|
|
|
|
nsSecurityFlags secFlags;
|
|
|
|
if (CORS_NONE == corsMode) {
|
|
|
|
// Same-origin is required for track element.
|
|
|
|
secFlags = nsILoadInfo::SEC_REQUIRE_SAME_ORIGIN_DATA_INHERITS;
|
|
|
|
} else {
|
|
|
|
secFlags = nsILoadInfo::SEC_REQUIRE_CORS_DATA_INHERITS;
|
|
|
|
if (CORS_ANONYMOUS == corsMode) {
|
|
|
|
secFlags |= nsILoadInfo::SEC_COOKIES_SAME_ORIGIN;
|
|
|
|
} else if (CORS_USE_CREDENTIALS == corsMode) {
|
|
|
|
secFlags |= nsILoadInfo::SEC_COOKIES_INCLUDE;
|
|
|
|
} else {
|
|
|
|
NS_WARNING("Unknown CORS mode.");
|
|
|
|
secFlags = nsILoadInfo::SEC_REQUIRE_SAME_ORIGIN_DATA_INHERITS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-13 23:06:02 +03:00
|
|
|
mListener = std::move(aWebVTTListener);
|
|
|
|
// This will do 6. Set the text track readiness state to loading.
|
2013-09-19 19:26:00 +04:00
|
|
|
rv = mListener->LoadResource();
|
2013-06-10 19:30:00 +04:00
|
|
|
NS_ENSURE_TRUE_VOID(NS_SUCCEEDED(rv));
|
2017-02-14 06:47:14 +03:00
|
|
|
|
2018-12-13 23:06:02 +03:00
|
|
|
nsIDocument* doc = OwnerDoc();
|
|
|
|
if (!doc) {
|
2017-02-14 06:47:14 +03:00
|
|
|
return;
|
|
|
|
}
|
2013-06-10 19:30:00 +04:00
|
|
|
|
2018-12-13 23:06:02 +03:00
|
|
|
// 9. End the synchronous section, continuing the remaining steps in parallel.
|
|
|
|
nsCOMPtr<nsIRunnable> runnable = NS_NewRunnableFunction(
|
|
|
|
"dom::HTMLTrackElement::LoadResource",
|
|
|
|
[ self = RefPtr<HTMLTrackElement>(this), uri, secFlags ]() {
|
|
|
|
nsCOMPtr<nsIChannel> channel;
|
|
|
|
nsCOMPtr<nsILoadGroup> loadGroup =
|
|
|
|
self->OwnerDoc()->GetDocumentLoadGroup();
|
|
|
|
nsresult rv = NS_NewChannel(
|
|
|
|
getter_AddRefs(channel), uri, static_cast<Element*>(self), secFlags,
|
|
|
|
nsIContentPolicy::TYPE_INTERNAL_TRACK,
|
|
|
|
nullptr, // PerformanceStorage
|
|
|
|
loadGroup,
|
|
|
|
nullptr, // aCallbacks
|
|
|
|
nsIRequest::LOAD_NORMAL | nsIChannel::LOAD_CLASSIFY_URI);
|
|
|
|
|
|
|
|
NS_ENSURE_TRUE_VOID(NS_SUCCEEDED(rv));
|
|
|
|
|
|
|
|
channel->SetNotificationCallbacks(self->mListener);
|
|
|
|
|
|
|
|
LOG(LogLevel::Debug, ("opening webvtt channel"));
|
|
|
|
rv = channel->AsyncOpen2(self->mListener);
|
|
|
|
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
self->SetReadyState(TextTrackReadyState::FailedToLoad);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
self->mChannel = channel;
|
|
|
|
});
|
|
|
|
doc->Dispatch(TaskCategory::Other, runnable.forget());
|
2013-06-10 19:30:00 +04:00
|
|
|
}
|
|
|
|
|
2013-05-21 20:14:00 +04:00
|
|
|
nsresult HTMLTrackElement::BindToTree(nsIDocument* aDocument,
|
|
|
|
nsIContent* aParent,
|
2018-07-31 21:18:38 +03:00
|
|
|
nsIContent* aBindingParent) {
|
2013-05-21 20:14:00 +04:00
|
|
|
nsresult rv =
|
|
|
|
nsGenericHTMLElement::BindToTree(aDocument, aParent, aBindingParent);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2015-06-04 01:25:57 +03:00
|
|
|
LOG(LogLevel::Debug, ("Track Element bound to tree."));
|
2018-04-15 13:29:46 +03:00
|
|
|
auto* parent = HTMLMediaElement::FromNodeOrNull(aParent);
|
|
|
|
if (!parent) {
|
2013-05-21 20:14:00 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Store our parent so we can look up its frame for display.
|
|
|
|
if (!mMediaParent) {
|
2018-04-15 13:29:46 +03:00
|
|
|
mMediaParent = parent;
|
2013-05-21 20:14:00 +04:00
|
|
|
|
|
|
|
// TODO: separate notification for 'alternate' tracks?
|
2016-06-02 10:37:14 +03:00
|
|
|
mMediaParent->NotifyAddedSource();
|
2015-06-04 01:25:57 +03:00
|
|
|
LOG(LogLevel::Debug, ("Track element sent notification to parent."));
|
2013-05-21 20:14:00 +04:00
|
|
|
|
2016-06-02 10:37:14 +03:00
|
|
|
// We may already have a TextTrack at this point if GetTrack() has already
|
|
|
|
// been called. This happens, for instance, if script tries to get the
|
|
|
|
// TextTrack before its mTrackElement has been bound to the DOM tree.
|
|
|
|
if (!mTrack) {
|
|
|
|
CreateTextTrack();
|
|
|
|
}
|
2016-07-21 11:49:24 +03:00
|
|
|
DispatchLoadResource();
|
2013-05-21 20:14:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void HTMLTrackElement::UnbindFromTree(bool aDeep, bool aNullParent) {
|
2016-04-26 11:38:24 +03:00
|
|
|
if (mMediaParent && aNullParent) {
|
2013-06-24 19:35:58 +04:00
|
|
|
// mTrack can be null if HTMLTrackElement::LoadResource has never been
|
|
|
|
// called.
|
|
|
|
if (mTrack) {
|
|
|
|
mMediaParent->RemoveTextTrack(mTrack);
|
2017-02-21 10:44:10 +03:00
|
|
|
mMediaParent->UpdateReadyState();
|
2013-06-24 19:35:58 +04:00
|
|
|
}
|
2016-04-26 11:38:24 +03:00
|
|
|
mMediaParent = nullptr;
|
2013-05-21 20:14:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsGenericHTMLElement::UnbindFromTree(aDeep, aNullParent);
|
|
|
|
}
|
|
|
|
|
2013-10-25 08:14:36 +04:00
|
|
|
uint16_t HTMLTrackElement::ReadyState() const {
|
|
|
|
if (!mTrack) {
|
2014-03-13 22:29:32 +04:00
|
|
|
return TextTrackReadyState::NotLoaded;
|
2013-10-25 08:14:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return mTrack->ReadyState();
|
|
|
|
}
|
|
|
|
|
2014-03-14 20:13:41 +04:00
|
|
|
void HTMLTrackElement::SetReadyState(uint16_t aReadyState) {
|
2016-08-18 14:10:31 +03:00
|
|
|
if (ReadyState() == aReadyState) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-03-14 20:13:41 +04:00
|
|
|
if (mTrack) {
|
|
|
|
switch (aReadyState) {
|
|
|
|
case TextTrackReadyState::Loaded:
|
2014-07-07 18:49:00 +04:00
|
|
|
DispatchTrackRunnable(NS_LITERAL_STRING("load"));
|
2014-03-14 20:13:41 +04:00
|
|
|
break;
|
|
|
|
case TextTrackReadyState::FailedToLoad:
|
|
|
|
DispatchTrackRunnable(NS_LITERAL_STRING("error"));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
mTrack->SetReadyState(aReadyState);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void HTMLTrackElement::DispatchTrackRunnable(const nsString& aEventName) {
|
2017-03-08 05:10:35 +03:00
|
|
|
nsIDocument* doc = OwnerDoc();
|
|
|
|
if (!doc) {
|
|
|
|
return;
|
|
|
|
}
|
2017-06-12 22:34:10 +03:00
|
|
|
nsCOMPtr<nsIRunnable> runnable = NewRunnableMethod<const nsString>(
|
|
|
|
"dom::HTMLTrackElement::DispatchTrustedEvent", this,
|
|
|
|
&HTMLTrackElement::DispatchTrustedEvent, aEventName);
|
2017-07-26 11:13:35 +03:00
|
|
|
doc->Dispatch(TaskCategory::Other, runnable.forget());
|
2014-03-14 20:13:41 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void HTMLTrackElement::DispatchTrustedEvent(const nsAString& aName) {
|
|
|
|
nsIDocument* doc = OwnerDoc();
|
|
|
|
if (!doc) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
nsContentUtils::DispatchTrustedEvent(doc, static_cast<nsIContent*>(this),
|
2018-06-25 19:23:50 +03:00
|
|
|
aName, CanBubble::eNo, Cancelable::eNo);
|
2014-03-14 20:13:41 +04:00
|
|
|
}
|
|
|
|
|
2014-06-19 00:10:24 +04:00
|
|
|
void HTMLTrackElement::DropChannel() { mChannel = nullptr; }
|
|
|
|
|
2016-08-05 10:13:36 +03:00
|
|
|
void HTMLTrackElement::NotifyShutdown() {
|
|
|
|
if (mChannel) {
|
|
|
|
mChannel->Cancel(NS_BINDING_ABORTED);
|
|
|
|
}
|
|
|
|
mChannel = nullptr;
|
|
|
|
mListener = nullptr;
|
|
|
|
}
|
|
|
|
|
2013-05-21 20:14:00 +04:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|