mirror of
https://github.com/roytam1/palemoon27.git
synced 2026-05-26 14:30:27 +00:00
3dbfc972a4
- Bug 586587 - support kHTMLMime in the Windows clipboard as CF_HTML. r=jimm (6af5a0d7fa) - Bug 1159604: Use a fallible allocation in nsClipboard::GetGlobalData. r=bbondy (c9645301a4) - Bug 1048624 - Cleanup and refactor the media crashtest manifests and re-enable some disabled tests that now pass. (d712e08056) - crashtest for bug 1020370 r=padenot (c0900de1df) - crashtest for bug 1206362 r=padenot (07ace6a42f) - Bug 1207546 - Integrate WebRTC with audio channels, r=roc (0ecafba529) - Bug 1219478: Replace PRLogModuleInfo usage with LazyLogModule in dom folders except media.r=amerchesini (2e67bd7308) - Bug 1198422 - CSP: Allow nonce to load if default-src is not specified in second policy (r=dveditz) (8a8bca1eb3) - Bug 1192433: Return an empty list rather than throwing an error when attempting to read a directory in an app: URL (fixes M1 bustage). r=trivial (9898282868) - Bug 1187152 (part 1) - Replace nsBaseHashtable::Enumerate() calls in modules/ with iterators. r=mwu. (85cea6dce7) - Bug 1187152 (part 2) - Replace nsBaseHashtable::Enumerate() calls in modules/ with iterators. r=froydnj. (e909442934) - Bug 1187152 (part 3) - Replace nsBaseHashtable::Enumerate() calls in modules/ with iterators. r=froydnj. (48c78d75e6) - mixed stuff (870e9f52b4) - Bug 1196301 - Prefer install.rdf over manifest.json. r=Mossop (defecac1a4) - Bug 1212059: Don't require shipped system add-ons to be signed, always require updated system add-ons to be signed. r=rhelmer (836aee8d83) - Bug 1209341 - allow loading unsigned restartless add-ons at runtime. r=mossop (82dd2824a2) - Bug 1164006: Reduce recursion from calls to AddonManager.getAddonsByIDs. r=paolo (226ccd91c0) - Bug 1226386: Remove most of the preprocessing from the add-ons manager. r=gps (b39b27c4dc) - kill MOZ_PHOENIX_EXTENSIONS (4d11abcfe8) - Bug 1195060 - In the Add-ons manager, make Ctrl+f focus the search box again instead of invoking the findbar first. r=mossop (d4460d9b78) - Bug 1224961: Remove non-standard JS features from WebExtension code (dfd6a202c0) - Bug 1213975 - fix WebExtension tabs.onUpdated cleanup on context close. r=billm (6d3e731718) - Bug 1213975 - add WebExtension tabs.onUpdated test case. r=billm (683f95f161) - Bug 1205221 - Fix chrome.tabs.onUpdate event doesn't be fired correctly when tab's attribute is changed. r=billm (9c1c83f7f3) - Bug 1215893: [webext] Check capturing event listeners for the correct target. r=billm (1736ed865e) - Bug 1200674 - Allow flexible icon sizes in ExtensionUtils. r=dtownsend (a9480952a3) - bit of 1148996 (af605cf222) - Bug 1164178 - Use an empty value by default for lightweightThemes.selectedThemeID;r=dao (1b44150400) - Bug 608972 - Make sure there is a theme author before using it. r=Mossop (651c4ee60b) - Bug 1190966: Ensure that the signature verification scan disables existing add-ons if the pref has been flipped in the meantime. r=rhelmer (f81c5680c4) - Bug 1220911: Remove most of the special casing around experiments. r=rhelmer (c3e5b498bb) - Bug 1226386: Remove createWrapper function and replace with a memoized property. r=rhelmer (abe251be9f) - Bug 1193973: System add-ons that shipped with the app should be loaded in safe mode. r=rhelmer (5e481459de) - revert some force-pending (c559e0a25f)
343 lines
9.7 KiB
C++
343 lines
9.7 KiB
C++
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
/* 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 mozilla::LazyLogModule gTrackElementLog("nsTrackElement");
|
|
#define LOG(type, msg) MOZ_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)
|
|
{
|
|
}
|
|
|
|
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, 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(LogLevel::Info, ("%p Trying to load from src=%s", this,
|
|
NS_ConvertUTF16toUTF8(src).get()));
|
|
|
|
if (mChannel) {
|
|
mChannel->Cancel(NS_BINDING_ABORTED);
|
|
mChannel = nullptr;
|
|
}
|
|
|
|
// 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_ALLOW_CROSS_ORIGIN_DATA_INHERITS,
|
|
nsIContentPolicy::TYPE_INTERNAL_TRACK,
|
|
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(LogLevel::Debug, ("opening webvtt channel"));
|
|
rv = channel->AsyncOpen2(mListener);
|
|
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(LogLevel::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(LogLevel::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
|