2008-07-09 08:22:20 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
2012-05-21 11:12:37 +00: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/. */
|
2011-10-11 05:50:08 +00:00
|
|
|
|
2008-07-09 08:22:20 +00:00
|
|
|
#include "nsIDOMHTMLSourceElement.h"
|
2013-03-19 12:27:35 +00:00
|
|
|
#include "mozilla/dom/HTMLVideoElement.h"
|
2013-03-19 12:28:34 +00:00
|
|
|
#include "mozilla/dom/HTMLVideoElementBinding.h"
|
2008-07-09 08:22:20 +00:00
|
|
|
#include "nsGenericHTMLElement.h"
|
|
|
|
#include "nsGkAtoms.h"
|
|
|
|
#include "nsSize.h"
|
2012-07-27 14:03:27 +00:00
|
|
|
#include "nsError.h"
|
2008-07-09 08:22:20 +00:00
|
|
|
#include "nsNodeInfoManager.h"
|
|
|
|
#include "plbase64.h"
|
|
|
|
#include "nsNetUtil.h"
|
|
|
|
#include "nsXPCOMStrings.h"
|
|
|
|
#include "prlock.h"
|
|
|
|
#include "nsThreadUtils.h"
|
2012-08-21 04:06:46 +00:00
|
|
|
#include "ImageContainer.h"
|
2008-07-09 08:22:20 +00:00
|
|
|
|
|
|
|
#include "nsIScriptSecurityManager.h"
|
|
|
|
#include "nsIXPConnect.h"
|
|
|
|
|
|
|
|
#include "nsITimer.h"
|
|
|
|
|
2013-02-14 15:59:21 +00:00
|
|
|
#include "MediaError.h"
|
2012-11-14 19:46:40 +00:00
|
|
|
#include "MediaDecoder.h"
|
2013-06-11 15:23:13 +00:00
|
|
|
#include "mozilla/Preferences.h"
|
2014-01-07 12:16:07 +00:00
|
|
|
#include "mozilla/dom/WakeLock.h"
|
|
|
|
#include "mozilla/dom/power/PowerManagerService.h"
|
2013-10-21 21:23:33 +00:00
|
|
|
#include "nsPerformance.h"
|
|
|
|
#include "mozilla/dom/VideoPlaybackQuality.h"
|
2008-07-09 08:22:20 +00:00
|
|
|
|
2011-09-18 09:22:18 +00:00
|
|
|
NS_IMPL_NS_NEW_HTML_ELEMENT(Video)
|
2008-07-09 08:22:20 +00:00
|
|
|
|
2013-03-19 12:27:35 +00:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
2008-07-09 08:22:20 +00:00
|
|
|
|
2013-06-11 15:23:13 +00:00
|
|
|
static bool sVideoStatsEnabled;
|
|
|
|
|
2013-03-19 12:27:35 +00:00
|
|
|
NS_IMPL_ELEMENT_CLONE(HTMLVideoElement)
|
2008-07-09 08:22:20 +00:00
|
|
|
|
2014-07-13 02:20:42 +00:00
|
|
|
HTMLVideoElement::HTMLVideoElement(already_AddRefed<NodeInfo>& aNodeInfo)
|
2013-03-19 12:23:54 +00:00
|
|
|
: HTMLMediaElement(aNodeInfo)
|
2008-07-09 08:22:20 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-03-19 12:27:35 +00:00
|
|
|
HTMLVideoElement::~HTMLVideoElement()
|
2008-07-09 08:22:20 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-03-19 12:27:35 +00:00
|
|
|
nsresult HTMLVideoElement::GetVideoSize(nsIntSize* size)
|
2008-07-09 08:22:20 +00:00
|
|
|
{
|
2012-05-11 08:32:15 +00:00
|
|
|
if (mMediaSize.width == -1 && mMediaSize.height == -1) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2014-05-23 09:34:14 +00:00
|
|
|
if (mDisableVideo) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2012-05-11 08:32:15 +00:00
|
|
|
size->height = mMediaSize.height;
|
|
|
|
size->width = mMediaSize.width;
|
|
|
|
return NS_OK;
|
2008-07-09 08:22:20 +00:00
|
|
|
}
|
2009-02-26 07:04:42 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2013-03-19 12:27:35 +00:00
|
|
|
HTMLVideoElement::ParseAttribute(int32_t aNamespaceID,
|
|
|
|
nsIAtom* aAttribute,
|
|
|
|
const nsAString& aValue,
|
|
|
|
nsAttrValue& aResult)
|
2009-02-26 07:04:42 +00:00
|
|
|
{
|
|
|
|
if (aAttribute == nsGkAtoms::width || aAttribute == nsGkAtoms::height) {
|
2011-02-04 19:46:16 +00:00
|
|
|
return aResult.ParseSpecialIntValue(aValue);
|
2009-02-26 07:04:42 +00:00
|
|
|
}
|
|
|
|
|
2013-03-19 12:23:54 +00:00
|
|
|
return HTMLMediaElement::ParseAttribute(aNamespaceID, aAttribute, aValue,
|
|
|
|
aResult);
|
2009-02-26 07:04:42 +00:00
|
|
|
}
|
|
|
|
|
2013-11-19 19:21:29 +00:00
|
|
|
void
|
|
|
|
HTMLVideoElement::MapAttributesIntoRule(const nsMappedAttributes* aAttributes,
|
|
|
|
nsRuleData* aData)
|
2009-02-26 07:04:42 +00:00
|
|
|
{
|
|
|
|
nsGenericHTMLElement::MapImageSizeAttributesInto(aAttributes, aData);
|
|
|
|
nsGenericHTMLElement::MapCommonAttributesInto(aAttributes, aData);
|
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
NS_IMETHODIMP_(bool)
|
2013-03-19 12:27:35 +00:00
|
|
|
HTMLVideoElement::IsAttributeMapped(const nsIAtom* aAttribute) const
|
2009-02-26 07:04:42 +00:00
|
|
|
{
|
|
|
|
static const MappedAttributeEntry attributes[] = {
|
|
|
|
{ &nsGkAtoms::width },
|
|
|
|
{ &nsGkAtoms::height },
|
2012-07-30 14:20:58 +00:00
|
|
|
{ nullptr }
|
2009-02-26 07:04:42 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const MappedAttributeEntry* const map[] = {
|
|
|
|
attributes,
|
|
|
|
sCommonAttributeMap
|
|
|
|
};
|
|
|
|
|
2011-12-18 10:09:27 +00:00
|
|
|
return FindAttributeDependence(aAttribute, map);
|
2009-02-26 07:04:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsMapRuleToAttributesFunc
|
2013-03-19 12:27:35 +00:00
|
|
|
HTMLVideoElement::GetAttributeMappingFunction() const
|
2009-02-26 07:04:42 +00:00
|
|
|
{
|
|
|
|
return &MapAttributesIntoRule;
|
|
|
|
}
|
2009-06-26 07:25:17 +00:00
|
|
|
|
2013-03-19 12:27:35 +00:00
|
|
|
nsresult HTMLVideoElement::SetAcceptHeader(nsIHttpChannel* aChannel)
|
2010-07-29 04:58:07 +00:00
|
|
|
{
|
2012-09-02 02:35:17 +00:00
|
|
|
nsAutoCString value(
|
2010-07-29 04:58:07 +00:00
|
|
|
#ifdef MOZ_WEBM
|
2011-11-16 07:50:19 +00:00
|
|
|
"video/webm,"
|
2010-07-29 04:58:07 +00:00
|
|
|
#endif
|
2011-11-16 07:50:19 +00:00
|
|
|
"video/ogg,"
|
|
|
|
"video/*;q=0.9,"
|
|
|
|
"application/ogg;q=0.7,"
|
|
|
|
"audio/*;q=0.6,*/*;q=0.5");
|
2010-07-29 04:58:07 +00:00
|
|
|
|
2011-11-16 07:50:19 +00:00
|
|
|
return aChannel->SetRequestHeader(NS_LITERAL_CSTRING("Accept"),
|
|
|
|
value,
|
|
|
|
false);
|
2010-07-29 04:58:07 +00:00
|
|
|
}
|
|
|
|
|
2015-01-20 20:39:28 +00:00
|
|
|
bool
|
|
|
|
HTMLVideoElement::IsInteractiveHTMLContent() const
|
|
|
|
{
|
|
|
|
return HasAttr(kNameSpaceID_None, nsGkAtoms::controls);
|
|
|
|
}
|
|
|
|
|
2013-03-19 12:28:34 +00:00
|
|
|
uint32_t HTMLVideoElement::MozParsedFrames() const
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread(), "Should be on main thread.");
|
2013-06-11 15:23:13 +00:00
|
|
|
if (!sVideoStatsEnabled) {
|
|
|
|
return 0;
|
|
|
|
}
|
2013-03-19 12:28:34 +00:00
|
|
|
return mDecoder ? mDecoder->GetFrameStatistics().GetParsedFrames() : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t HTMLVideoElement::MozDecodedFrames() const
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread(), "Should be on main thread.");
|
2013-06-11 15:23:13 +00:00
|
|
|
if (!sVideoStatsEnabled) {
|
|
|
|
return 0;
|
|
|
|
}
|
2013-03-19 12:28:34 +00:00
|
|
|
return mDecoder ? mDecoder->GetFrameStatistics().GetDecodedFrames() : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t HTMLVideoElement::MozPresentedFrames() const
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread(), "Should be on main thread.");
|
2013-06-11 15:23:13 +00:00
|
|
|
if (!sVideoStatsEnabled) {
|
|
|
|
return 0;
|
|
|
|
}
|
2013-03-19 12:28:34 +00:00
|
|
|
return mDecoder ? mDecoder->GetFrameStatistics().GetPresentedFrames() : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t HTMLVideoElement::MozPaintedFrames()
|
2011-03-23 22:28:57 +00:00
|
|
|
{
|
2013-03-19 12:28:34 +00:00
|
|
|
MOZ_ASSERT(NS_IsMainThread(), "Should be on main thread.");
|
2013-06-11 15:23:13 +00:00
|
|
|
if (!sVideoStatsEnabled) {
|
|
|
|
return 0;
|
|
|
|
}
|
2013-03-19 12:23:54 +00:00
|
|
|
layers::ImageContainer* container = GetImageContainer();
|
2013-03-19 12:28:34 +00:00
|
|
|
return container ? container->GetPaintCount() : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
double HTMLVideoElement::MozFrameDelay()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread(), "Should be on main thread.");
|
2012-02-15 04:35:01 +00:00
|
|
|
VideoFrameContainer* container = GetVideoFrameContainer();
|
2013-03-19 12:28:34 +00:00
|
|
|
return container ? container->GetFrameDelay() : 0;
|
2011-03-23 22:28:57 +00:00
|
|
|
}
|
2012-04-28 15:01:10 +00:00
|
|
|
|
2013-03-19 12:28:34 +00:00
|
|
|
bool HTMLVideoElement::MozHasAudio() const
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread(), "Should be on main thread.");
|
|
|
|
return mHasAudio;
|
|
|
|
}
|
|
|
|
|
|
|
|
JSObject*
|
2014-04-08 22:27:17 +00:00
|
|
|
HTMLVideoElement::WrapNode(JSContext* aCx)
|
2013-03-19 12:28:34 +00:00
|
|
|
{
|
Bug 991742 part 6. Remove the "aScope" argument of binding Wrap() methods. r=bholley
This patch was mostly generated with this command:
find . -name "*.h" -o -name "*.cpp" | xargs sed -e 's/Binding::Wrap(aCx, aScope, this/Binding::Wrap(aCx, this/' -e 's/Binding_workers::Wrap(aCx, aScope, this/Binding_workers::Wrap(aCx, this/' -e 's/Binding::Wrap(cx, scope, this/Binding::Wrap(cx, this/' -i ""
plus a few manual fixes to dom/bindings/Codegen.py, js/xpconnect/src/event_impl_gen.py, and a few C++ files that were not caught in the search-and-replace above.
2014-04-08 22:27:17 +00:00
|
|
|
return HTMLVideoElementBinding::Wrap(aCx, this);
|
2013-03-19 12:28:34 +00:00
|
|
|
}
|
|
|
|
|
2013-05-10 12:42:39 +00:00
|
|
|
void
|
|
|
|
HTMLVideoElement::NotifyOwnerDocumentActivityChanged()
|
|
|
|
{
|
|
|
|
HTMLMediaElement::NotifyOwnerDocumentActivityChanged();
|
2014-03-18 08:44:41 +00:00
|
|
|
UpdateScreenWakeLock();
|
2013-05-10 12:42:39 +00:00
|
|
|
}
|
|
|
|
|
2013-07-05 00:24:35 +00:00
|
|
|
already_AddRefed<VideoPlaybackQuality>
|
|
|
|
HTMLVideoElement::GetVideoPlaybackQuality()
|
2013-06-21 03:14:18 +00:00
|
|
|
{
|
2013-07-05 00:24:35 +00:00
|
|
|
DOMHighResTimeStamp creationTime = 0;
|
2013-06-21 03:14:18 +00:00
|
|
|
uint64_t totalFrames = 0;
|
|
|
|
uint64_t droppedFrames = 0;
|
|
|
|
uint64_t corruptedFrames = 0;
|
2013-07-11 03:52:22 +00:00
|
|
|
|
|
|
|
if (sVideoStatsEnabled) {
|
|
|
|
nsPIDOMWindow* window = OwnerDoc()->GetInnerWindow();
|
|
|
|
if (window) {
|
|
|
|
nsPerformance* perf = window->GetPerformance();
|
|
|
|
if (perf) {
|
|
|
|
creationTime = perf->GetDOMTiming()->TimeStampToDOMHighRes(TimeStamp::Now());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mDecoder) {
|
|
|
|
MediaDecoder::FrameStatistics& stats = mDecoder->GetFrameStatistics();
|
|
|
|
totalFrames = stats.GetParsedFrames();
|
|
|
|
droppedFrames = totalFrames - stats.GetPresentedFrames();
|
|
|
|
corruptedFrames = totalFrames - stats.GetDecodedFrames();
|
|
|
|
}
|
2013-06-21 03:14:18 +00:00
|
|
|
}
|
|
|
|
|
2013-07-05 00:24:35 +00:00
|
|
|
nsRefPtr<VideoPlaybackQuality> playbackQuality =
|
|
|
|
new VideoPlaybackQuality(this, creationTime, totalFrames, droppedFrames,
|
2014-03-04 02:31:57 +00:00
|
|
|
corruptedFrames);
|
2013-06-21 03:14:18 +00:00
|
|
|
return playbackQuality.forget();
|
|
|
|
}
|
|
|
|
|
2013-05-10 12:42:39 +00:00
|
|
|
void
|
|
|
|
HTMLVideoElement::WakeLockCreate()
|
|
|
|
{
|
2014-03-18 08:44:41 +00:00
|
|
|
HTMLMediaElement::WakeLockCreate();
|
|
|
|
UpdateScreenWakeLock();
|
2013-05-10 12:42:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
HTMLVideoElement::WakeLockRelease()
|
|
|
|
{
|
2014-03-18 08:44:41 +00:00
|
|
|
UpdateScreenWakeLock();
|
|
|
|
HTMLMediaElement::WakeLockRelease();
|
2013-05-10 12:42:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-03-18 08:44:41 +00:00
|
|
|
HTMLVideoElement::UpdateScreenWakeLock()
|
2013-05-10 12:42:39 +00:00
|
|
|
{
|
2013-07-01 07:02:28 +00:00
|
|
|
bool hidden = OwnerDoc()->Hidden();
|
2013-05-10 12:42:39 +00:00
|
|
|
|
|
|
|
if (mScreenWakeLock && (mPaused || hidden)) {
|
2014-01-07 12:16:07 +00:00
|
|
|
ErrorResult rv;
|
|
|
|
mScreenWakeLock->Unlock(rv);
|
|
|
|
NS_WARN_IF_FALSE(!rv.Failed(), "Failed to unlock the wakelock.");
|
2013-05-10 12:42:39 +00:00
|
|
|
mScreenWakeLock = nullptr;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-10-01 15:39:10 +00:00
|
|
|
if (!mScreenWakeLock && !mPaused && !hidden && mHasVideo) {
|
2014-01-07 12:16:07 +00:00
|
|
|
nsRefPtr<power::PowerManagerService> pmService =
|
|
|
|
power::PowerManagerService::GetInstance();
|
2013-05-10 12:42:39 +00:00
|
|
|
NS_ENSURE_TRUE_VOID(pmService);
|
|
|
|
|
2014-01-07 12:16:07 +00:00
|
|
|
ErrorResult rv;
|
|
|
|
mScreenWakeLock = pmService->NewWakeLock(NS_LITERAL_STRING("screen"),
|
|
|
|
OwnerDoc()->GetInnerWindow(),
|
|
|
|
rv);
|
2013-05-10 12:42:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-11 15:23:13 +00:00
|
|
|
void
|
|
|
|
HTMLVideoElement::Init()
|
|
|
|
{
|
|
|
|
Preferences::AddBoolVarCache(&sVideoStatsEnabled, "media.video_stats.enabled");
|
|
|
|
}
|
2014-07-13 02:20:42 +00:00
|
|
|
|
2013-03-19 12:27:35 +00:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|