mirror of
https://github.com/roytam1/palemoon27.git
synced 2026-05-26 14:18:48 +00:00
fdb63ff9b9
- Bug 1163201 - Part 1: Remove instances of #ifdef PR_LOGGING in dom/. r=froydnj (9979c0e74) - Bug 1183972 - No sync-dispatch of new GMPParent - r=cpearce (93339b530) - Bug 1142935 - reset transports with NuwaAddConstructor(). r=tlee (277406812) - Bug 1121676 - Use a lock to protect the list of top-level actors (r=bent) (3d0be2f87) - Bug 1121676 - Use static mutex to protect top-level protocols (r=bent) (4491dd318) - Bug 1163201 - Part 2: Wrap expensive calls in PR_LOG_TEST. r=froydnj (7de4b9a97) - Bug 1163201 - Part 3: Remove mSamples in |MediaEngineWebRTCAudioSource|. r=cpeterson (452442773) - Bug 1163201 - Part 4: Fix b2g build. r=bustage (a824ea36d) - Bug 1165518 - Part 1: Add Logging.h. r=froydnj (09d68aaa6) - Bug 1162850 - Don't stop looking for style sheet load finishes after the FontFaceSet gets a DOMContentLoaded. r=jdaggett (c29fbffa0) - Bug 1056479 p0 - rename ambiguous GetFontList method in Android fontlist. r=m_kato (76239d7a0) - Bug 1056479 p1 - add language to FindFamily parameters. r=jfkthame (2271bd7d0) - Bug 1056479 p1a - use lang as part of pref font fallback. r=karlt (5f5fd66c5) - cleanup GetTableFromFontData() to match gecko code again (78076fc26) - Bug 1056479 p2 - implement platform fontlist based on fontconfig. r=karlt (6a7631e44) - Bug 1056479 p3 - fixup various reftests for Linux. r=jfkthame (b25360708) - Bug 1056479 p4 - fix accessibility api for font-weight. r=jfkthame (efa8f5080) - Bug 1056479 p5 - fixup printpreview test. r=jfkthame (3fe2ddc0b) - Bug 1056479 p6 - handle font updates. r=jfkthame (eb78b2c54) - Bug 1056479 p7 - fixup assertion for non-italic fallback. r=m_kato (f5e9f539e) - Bug 1056479 p8 - switch gfxFontConfig to gfxFontconfig. r=karlt (4da146b50) - Bug 1056479 p9 - fix build bustage. r=birtles (28f246c2b) - Bug 1056479 p10 - activate bundled fonts. r=m_kato (d7627c3fa) - Bug 1056479 p10 - activate bundled fonts. r=m_kato (251c02315) - Bug 1056479 followup: Annotate gfxPlatformGtk::CreatePlatformFontList() as 'override'. rs=ehsan (993e65d6e)
365 lines
11 KiB
C++
365 lines
11 KiB
C++
/* -*- 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/Element.h"
|
|
#include "mozilla/dom/HTMLMediaElement.h"
|
|
#include "mozilla/dom/HTMLTrackElement.h"
|
|
#include "mozilla/dom/HTMLTrackElementBinding.h"
|
|
#include "mozilla/dom/HTMLUnknownElement.h"
|
|
#include "nsIContentPolicy.h"
|
|
#include "mozilla/LoadInfo.h"
|
|
#include "WebVTTListener.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 "nsIDOMEventTarget.h"
|
|
#include "nsIDOMHTMLMediaElement.h"
|
|
#include "nsIHttpChannel.h"
|
|
#include "nsIInterfaceRequestor.h"
|
|
#include "nsILoadGroup.h"
|
|
#include "nsIObserver.h"
|
|
#include "nsIStreamListener.h"
|
|
#include "nsISupportsImpl.h"
|
|
#include "nsMappedAttributes.h"
|
|
#include "nsNetUtil.h"
|
|
#include "nsRuleData.h"
|
|
#include "nsStyleConsts.h"
|
|
#include "nsThreadUtils.h"
|
|
#include "nsVideoFrame.h"
|
|
|
|
static PRLogModuleInfo* gTrackElementLog;
|
|
#define LOG(type, msg) PR_LOG(gTrackElementLog, type, msg)
|
|
|
|
// Replace the usual NS_IMPL_NS_NEW_HTML_ELEMENT(Track) so
|
|
// we can return an UnknownElement instead when pref'd off.
|
|
nsGenericHTMLElement*
|
|
NS_NewHTMLTrackElement(already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo,
|
|
mozilla::dom::FromParser aFromParser)
|
|
{
|
|
if (!mozilla::dom::HTMLTrackElement::IsWebVTTEnabled()) {
|
|
return new mozilla::dom::HTMLUnknownElement(aNodeInfo);
|
|
}
|
|
|
|
return new mozilla::dom::HTMLTrackElement(aNodeInfo);
|
|
}
|
|
|
|
namespace mozilla {
|
|
namespace dom {
|
|
|
|
// Map html attribute string values to TextTrackKind enums.
|
|
static MOZ_CONSTEXPR nsAttrValue::EnumTable kKindTable[] = {
|
|
{ "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) },
|
|
{ 0 }
|
|
};
|
|
|
|
// The default value for kKindTable is "subtitles"
|
|
static MOZ_CONSTEXPR const char* kKindTableDefaultString = kKindTable->tag;
|
|
|
|
/** HTMLTrackElement */
|
|
HTMLTrackElement::HTMLTrackElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo)
|
|
: nsGenericHTMLElement(aNodeInfo)
|
|
{
|
|
if (!gTrackElementLog) {
|
|
gTrackElementLog = PR_NewLogModule("nsTrackElement");
|
|
}
|
|
}
|
|
|
|
HTMLTrackElement::~HTMLTrackElement()
|
|
{
|
|
}
|
|
|
|
NS_IMPL_ELEMENT_CLONE(HTMLTrackElement)
|
|
|
|
NS_IMPL_ADDREF_INHERITED(HTMLTrackElement, Element)
|
|
NS_IMPL_RELEASE_INHERITED(HTMLTrackElement, Element)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_INHERITED(HTMLTrackElement, nsGenericHTMLElement,
|
|
mTrack, mMediaParent, mListener)
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(HTMLTrackElement)
|
|
NS_INTERFACE_MAP_END_INHERITING(nsGenericHTMLElement)
|
|
|
|
void
|
|
HTMLTrackElement::GetKind(DOMString& aKind) const
|
|
{
|
|
GetEnumAttr(nsGkAtoms::kind, kKindTableDefaultString, aKind);
|
|
}
|
|
|
|
void
|
|
HTMLTrackElement::OnChannelRedirect(nsIChannel* aChannel,
|
|
nsIChannel* aNewChannel,
|
|
uint32_t aFlags)
|
|
{
|
|
NS_ASSERTION(aChannel == mChannel, "Channels should match!");
|
|
mChannel = aNewChannel;
|
|
}
|
|
|
|
JSObject*
|
|
HTMLTrackElement::WrapNode(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
|
{
|
|
return HTMLTrackElementBinding::Wrap(aCx, this, aGivenProto);
|
|
}
|
|
|
|
bool
|
|
HTMLTrackElement::IsWebVTTEnabled()
|
|
{
|
|
// Our callee does not use its arguments.
|
|
return HTMLTrackElementBinding::ConstructorEnabled(nullptr, JS::NullPtr());
|
|
}
|
|
|
|
TextTrack*
|
|
HTMLTrackElement::GetTrack()
|
|
{
|
|
if (!mTrack) {
|
|
CreateTextTrack();
|
|
}
|
|
|
|
return mTrack;
|
|
}
|
|
|
|
void
|
|
HTMLTrackElement::CreateTextTrack()
|
|
{
|
|
nsString label, srcLang;
|
|
GetSrclang(srcLang);
|
|
GetLabel(label);
|
|
|
|
TextTrackKind kind;
|
|
if (const nsAttrValue* value = GetParsedAttr(nsGkAtoms::kind)) {
|
|
kind = static_cast<TextTrackKind>(value->GetEnumValue());
|
|
} else {
|
|
kind = TextTrackKind::Subtitles;
|
|
}
|
|
|
|
nsISupports* parentObject =
|
|
OwnerDoc()->GetParentObject();
|
|
|
|
NS_ENSURE_TRUE_VOID(parentObject);
|
|
|
|
nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(parentObject);
|
|
mTrack = new TextTrack(window, kind, label, srcLang,
|
|
TextTrackMode::Disabled,
|
|
TextTrackReadyState::NotLoaded,
|
|
TextTrackSource::Track);
|
|
mTrack->SetTrackElement(this);
|
|
|
|
if (mMediaParent) {
|
|
mMediaParent->AddTextTrack(mTrack);
|
|
}
|
|
}
|
|
|
|
bool
|
|
HTMLTrackElement::ParseAttribute(int32_t aNamespaceID,
|
|
nsIAtom* aAttribute,
|
|
const nsAString& aValue,
|
|
nsAttrValue& aResult)
|
|
{
|
|
if (aNamespaceID == kNameSpaceID_None && aAttribute == nsGkAtoms::kind) {
|
|
// Case-insensitive lookup, with the first element as the default.
|
|
return aResult.ParseEnumValue(aValue, kKindTable, false, kKindTable);
|
|
}
|
|
|
|
// Otherwise call the generic implementation.
|
|
return nsGenericHTMLElement::ParseAttribute(aNamespaceID,
|
|
aAttribute,
|
|
aValue,
|
|
aResult);
|
|
}
|
|
|
|
void
|
|
HTMLTrackElement::LoadResource()
|
|
{
|
|
// 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));
|
|
LOG(PR_LOG_ALWAYS, ("%p Trying to load from src=%s", this,
|
|
NS_ConvertUTF16toUTF8(src).get()));
|
|
|
|
if (mChannel) {
|
|
mChannel->Cancel(NS_BINDING_ABORTED);
|
|
mChannel = nullptr;
|
|
}
|
|
|
|
rv = nsContentUtils::GetSecurityManager()->
|
|
CheckLoadURIWithPrincipal(NodePrincipal(), uri,
|
|
nsIScriptSecurityManager::STANDARD);
|
|
NS_ENSURE_TRUE_VOID(NS_SUCCEEDED(rv));
|
|
|
|
int16_t shouldLoad = nsIContentPolicy::ACCEPT;
|
|
rv = NS_CheckContentLoadPolicy(nsIContentPolicy::TYPE_MEDIA,
|
|
uri,
|
|
NodePrincipal(),
|
|
static_cast<Element*>(this),
|
|
NS_LITERAL_CSTRING("text/vtt"), // mime type
|
|
nullptr, // extra
|
|
&shouldLoad,
|
|
nsContentUtils::GetContentPolicy(),
|
|
nsContentUtils::GetSecurityManager());
|
|
NS_ENSURE_TRUE_VOID(NS_SUCCEEDED(rv));
|
|
if (NS_CP_REJECTED(shouldLoad)) {
|
|
return;
|
|
}
|
|
|
|
// 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();
|
|
}
|
|
|
|
nsCOMPtr<nsIChannel> channel;
|
|
nsCOMPtr<nsILoadGroup> loadGroup = OwnerDoc()->GetDocumentLoadGroup();
|
|
rv = NS_NewChannel(getter_AddRefs(channel),
|
|
uri,
|
|
static_cast<Element*>(this),
|
|
nsILoadInfo::SEC_NORMAL,
|
|
nsIContentPolicy::TYPE_MEDIA,
|
|
loadGroup);
|
|
|
|
NS_ENSURE_TRUE_VOID(NS_SUCCEEDED(rv));
|
|
|
|
mListener = new WebVTTListener(this);
|
|
rv = mListener->LoadResource();
|
|
NS_ENSURE_TRUE_VOID(NS_SUCCEEDED(rv));
|
|
channel->SetNotificationCallbacks(mListener);
|
|
|
|
LOG(PR_LOG_DEBUG, ("opening webvtt channel"));
|
|
rv = channel->AsyncOpen(mListener, nullptr);
|
|
NS_ENSURE_TRUE_VOID(NS_SUCCEEDED(rv));
|
|
|
|
mChannel = channel;
|
|
}
|
|
|
|
nsresult
|
|
HTMLTrackElement::BindToTree(nsIDocument* aDocument,
|
|
nsIContent* aParent,
|
|
nsIContent* aBindingParent,
|
|
bool aCompileEventHandlers)
|
|
{
|
|
nsresult rv = nsGenericHTMLElement::BindToTree(aDocument,
|
|
aParent,
|
|
aBindingParent,
|
|
aCompileEventHandlers);
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
if (!aDocument) {
|
|
return NS_OK;
|
|
}
|
|
|
|
LOG(PR_LOG_DEBUG, ("Track Element bound to tree."));
|
|
if (!aParent || !aParent->IsNodeOfType(nsINode::eMEDIA)) {
|
|
return NS_OK;
|
|
}
|
|
|
|
// Store our parent so we can look up its frame for display.
|
|
if (!mMediaParent) {
|
|
mMediaParent = static_cast<HTMLMediaElement*>(aParent);
|
|
|
|
HTMLMediaElement* media = static_cast<HTMLMediaElement*>(aParent);
|
|
// TODO: separate notification for 'alternate' tracks?
|
|
media->NotifyAddedSource();
|
|
LOG(PR_LOG_DEBUG, ("Track element sent notification to parent."));
|
|
|
|
mMediaParent->RunInStableState(
|
|
NS_NewRunnableMethod(this, &HTMLTrackElement::LoadResource));
|
|
}
|
|
|
|
return NS_OK;
|
|
}
|
|
|
|
void
|
|
HTMLTrackElement::UnbindFromTree(bool aDeep, bool aNullParent)
|
|
{
|
|
if (mMediaParent) {
|
|
// mTrack can be null if HTMLTrackElement::LoadResource has never been
|
|
// called.
|
|
if (mTrack) {
|
|
mMediaParent->RemoveTextTrack(mTrack);
|
|
}
|
|
if (aNullParent) {
|
|
mMediaParent = nullptr;
|
|
}
|
|
}
|
|
|
|
nsGenericHTMLElement::UnbindFromTree(aDeep, aNullParent);
|
|
}
|
|
|
|
uint16_t
|
|
HTMLTrackElement::ReadyState() const
|
|
{
|
|
if (!mTrack) {
|
|
return TextTrackReadyState::NotLoaded;
|
|
}
|
|
|
|
return mTrack->ReadyState();
|
|
}
|
|
|
|
void
|
|
HTMLTrackElement::SetReadyState(uint16_t aReadyState)
|
|
{
|
|
if (mTrack) {
|
|
switch (aReadyState) {
|
|
case TextTrackReadyState::Loaded:
|
|
DispatchTrackRunnable(NS_LITERAL_STRING("load"));
|
|
break;
|
|
case TextTrackReadyState::FailedToLoad:
|
|
DispatchTrackRunnable(NS_LITERAL_STRING("error"));
|
|
break;
|
|
}
|
|
mTrack->SetReadyState(aReadyState);
|
|
}
|
|
}
|
|
|
|
void
|
|
HTMLTrackElement::DispatchTrackRunnable(const nsString& aEventName)
|
|
{
|
|
nsCOMPtr<nsIRunnable> runnable =
|
|
NS_NewRunnableMethodWithArg
|
|
<const nsString>(this,
|
|
&HTMLTrackElement::DispatchTrustedEvent,
|
|
aEventName);
|
|
NS_DispatchToMainThread(runnable);
|
|
}
|
|
|
|
void
|
|
HTMLTrackElement::DispatchTrustedEvent(const nsAString& aName)
|
|
{
|
|
nsIDocument* doc = OwnerDoc();
|
|
if (!doc) {
|
|
return;
|
|
}
|
|
nsContentUtils::DispatchTrustedEvent(doc, static_cast<nsIContent*>(this),
|
|
aName, false, false);
|
|
}
|
|
|
|
void
|
|
HTMLTrackElement::DropChannel()
|
|
{
|
|
mChannel = nullptr;
|
|
}
|
|
|
|
} // namespace dom
|
|
} // namespace mozilla
|