From 6dcc6a8a610135d3b630411217b785fcd9a84ef7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9onard=20Beck?= Date: Tue, 11 Jun 2013 17:23:13 +0200 Subject: [PATCH] Bug 654550 - Add a preference to disable media statistics. r = padenot,jaws --- .../html/content/public/HTMLVideoElement.h | 3 + content/html/content/src/HTMLVideoElement.cpp | 20 ++++++ content/media/test/Makefile.in | 1 + content/media/test/manifest.js | 7 ++ content/media/test/test_bug654550.html | 70 +++++++++++++++++++ layout/build/nsLayoutStatics.cpp | 3 + modules/libpref/src/init/all.js | 3 + 7 files changed, 107 insertions(+) create mode 100644 content/media/test/test_bug654550.html diff --git a/content/html/content/public/HTMLVideoElement.h b/content/html/content/public/HTMLVideoElement.h index 62a60c64b05d..944ee7a23f8f 100644 --- a/content/html/content/public/HTMLVideoElement.h +++ b/content/html/content/public/HTMLVideoElement.h @@ -47,6 +47,9 @@ public: const nsAString& aValue, nsAttrValue& aResult); NS_IMETHOD_(bool) IsAttributeMapped(const nsIAtom* aAttribute) const MOZ_OVERRIDE; + + static void Init(); + virtual nsMapRuleToAttributesFunc GetAttributeMappingFunction() const MOZ_OVERRIDE; virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const MOZ_OVERRIDE; diff --git a/content/html/content/src/HTMLVideoElement.cpp b/content/html/content/src/HTMLVideoElement.cpp index d80bfa351346..840dbd78d61b 100644 --- a/content/html/content/src/HTMLVideoElement.cpp +++ b/content/html/content/src/HTMLVideoElement.cpp @@ -33,12 +33,15 @@ #include "nsIPowerManagerService.h" #include "MediaError.h" #include "MediaDecoder.h" +#include "mozilla/Preferences.h" NS_IMPL_NS_NEW_HTML_ELEMENT(Video) namespace mozilla { namespace dom { +static bool sVideoStatsEnabled; + NS_IMPL_ADDREF_INHERITED(HTMLVideoElement, HTMLMediaElement) NS_IMPL_RELEASE_INHERITED(HTMLVideoElement, HTMLMediaElement) @@ -160,6 +163,9 @@ NS_IMPL_URI_ATTR(HTMLVideoElement, Poster, poster) uint32_t HTMLVideoElement::MozParsedFrames() const { MOZ_ASSERT(NS_IsMainThread(), "Should be on main thread."); + if (!sVideoStatsEnabled) { + return 0; + } return mDecoder ? mDecoder->GetFrameStatistics().GetParsedFrames() : 0; } @@ -172,6 +178,9 @@ NS_IMETHODIMP HTMLVideoElement::GetMozParsedFrames(uint32_t *aMozParsedFrames) uint32_t HTMLVideoElement::MozDecodedFrames() const { MOZ_ASSERT(NS_IsMainThread(), "Should be on main thread."); + if (!sVideoStatsEnabled) { + return 0; + } return mDecoder ? mDecoder->GetFrameStatistics().GetDecodedFrames() : 0; } @@ -184,6 +193,9 @@ NS_IMETHODIMP HTMLVideoElement::GetMozDecodedFrames(uint32_t *aMozDecodedFrames) uint32_t HTMLVideoElement::MozPresentedFrames() const { MOZ_ASSERT(NS_IsMainThread(), "Should be on main thread."); + if (!sVideoStatsEnabled) { + return 0; + } return mDecoder ? mDecoder->GetFrameStatistics().GetPresentedFrames() : 0; } @@ -196,6 +208,9 @@ NS_IMETHODIMP HTMLVideoElement::GetMozPresentedFrames(uint32_t *aMozPresentedFra uint32_t HTMLVideoElement::MozPaintedFrames() { MOZ_ASSERT(NS_IsMainThread(), "Should be on main thread."); + if (!sVideoStatsEnabled) { + return 0; + } layers::ImageContainer* container = GetImageContainer(); return container ? container->GetPaintCount() : 0; } @@ -282,5 +297,10 @@ HTMLVideoElement::WakeLockUpdate() } } +void +HTMLVideoElement::Init() +{ + Preferences::AddBoolVarCache(&sVideoStatsEnabled, "media.video_stats.enabled"); +} } // namespace dom } // namespace mozilla diff --git a/content/media/test/Makefile.in b/content/media/test/Makefile.in index 20da0b8b494f..eac71827c09a 100644 --- a/content/media/test/Makefile.in +++ b/content/media/test/Makefile.in @@ -72,6 +72,7 @@ MOCHITEST_FILES = \ test_bug493187.html \ test_bug495145.html \ test_bug495300.html \ + test_bug654550.html \ test_bug686942.html \ test_can_play_type.html \ test_can_play_type_mpeg.html \ diff --git a/content/media/test/manifest.js b/content/media/test/manifest.js index 28d5f9255c48..8b143e5e40d4 100644 --- a/content/media/test/manifest.js +++ b/content/media/test/manifest.js @@ -16,6 +16,13 @@ var gSmallTests = [ { name:"bogus.duh", type:"bogus/duh" } ]; +// Used by test_bug654550.html, for videoStats preference +var gVideoTests = [ + { name:"320x240.ogv", type:"video/ogg", width:320, height:240, duration:0.266 }, + { name:"seek.webm", type:"video/webm", width:320, height:240, duration:3.966 }, + { name:"bogus.duh", type:"bogus/duh" } +]; + // Used by test_progress to ensure we get the correct progress information // during resource download. var gProgressTests = [ diff --git a/content/media/test/test_bug654550.html b/content/media/test/test_bug654550.html new file mode 100644 index 000000000000..341ad3051b36 --- /dev/null +++ b/content/media/test/test_bug654550.html @@ -0,0 +1,70 @@ + + + + + + Test for Bug 654550 + + + + + +Mozilla Bug 654550 +
+
+
+ + diff --git a/layout/build/nsLayoutStatics.cpp b/layout/build/nsLayoutStatics.cpp index 5764e5be1384..c5ad9c6e876f 100644 --- a/layout/build/nsLayoutStatics.cpp +++ b/layout/build/nsLayoutStatics.cpp @@ -116,6 +116,7 @@ using namespace mozilla::system; #include "mozilla/dom/time/DateCacheCleaner.h" #include "nsIMEStateManager.h" #include "nsDocument.h" +#include "mozilla/dom/HTMLVideoElement.h" extern void NS_ShutdownEventTargetChainItemRecyclePool(); @@ -272,6 +273,8 @@ nsLayoutStatics::Initialize() InitializeDateCacheCleaner(); + HTMLVideoElement::Init(); + return NS_OK; } diff --git a/modules/libpref/src/init/all.js b/modules/libpref/src/init/all.js index 947e3a79f7b3..079882928a4d 100644 --- a/modules/libpref/src/init/all.js +++ b/modules/libpref/src/init/all.js @@ -232,6 +232,9 @@ pref("media.autoplay.enabled", true); // MediaDecoderReader's mVideoQueue. pref("media.video-queue.default-size", 10); +// Whether to disable the video stats to prevent fingerprinting +pref("media.video_stats.enabled", true); + // Whether to enable the audio writing APIs on the audio element pref("media.audio_data.enabled", true);