Bug 1369309 - Part 1: Spoofing media statistics to 0 when 'privacy.resistFingerprinting' is true. r?jwwang,arthuredelstein draft
authorTim Huang <tihuang@mozilla.com>
Mon, 19 Jun 2017 14:43:26 +0800
changeset 643928 76f9147efbdc66051857b7609317a6a154c09525
parent 643612 a4a448ba7f187069fce916ee234a06cbb0d06f80
child 643929 ecbdb23c65eb1f18df3177b944964cda9af77a4f
push id73260
push userbmo:tihuang@mozilla.com
push dateThu, 10 Aug 2017 08:38:35 +0000
reviewersjwwang, arthuredelstein
bugs1369309
milestone57.0a1
Bug 1369309 - Part 1: Spoofing media statistics to 0 when 'privacy.resistFingerprinting' is true. r?jwwang,arthuredelstein MozReview-Commit-ID: FNALpUGFDTQ
dom/html/HTMLVideoElement.cpp
dom/html/HTMLVideoElement.h
--- a/dom/html/HTMLVideoElement.cpp
+++ b/dom/html/HTMLVideoElement.cpp
@@ -146,53 +146,57 @@ HTMLVideoElement::IsInteractiveHTMLConte
 {
   return HasAttr(kNameSpaceID_None, nsGkAtoms::controls) ||
          HTMLMediaElement::IsInteractiveHTMLContent(aIgnoreTabindex);
 }
 
 uint32_t HTMLVideoElement::MozParsedFrames() const
 {
   MOZ_ASSERT(NS_IsMainThread(), "Should be on main thread.");
-  if (!sVideoStatsEnabled) {
+  if (!IsVideoStatsEnabled()) {
     return 0;
   }
   return mDecoder ? mDecoder->GetFrameStatistics().GetParsedFrames() : 0;
 }
 
 uint32_t HTMLVideoElement::MozDecodedFrames() const
 {
   MOZ_ASSERT(NS_IsMainThread(), "Should be on main thread.");
-  if (!sVideoStatsEnabled) {
+  if (!IsVideoStatsEnabled()) {
     return 0;
   }
   return mDecoder ? mDecoder->GetFrameStatistics().GetDecodedFrames() : 0;
 }
 
 uint32_t HTMLVideoElement::MozPresentedFrames() const
 {
   MOZ_ASSERT(NS_IsMainThread(), "Should be on main thread.");
-  if (!sVideoStatsEnabled) {
+  if (!IsVideoStatsEnabled()) {
     return 0;
   }
   return mDecoder ? mDecoder->GetFrameStatistics().GetPresentedFrames() : 0;
 }
 
 uint32_t HTMLVideoElement::MozPaintedFrames()
 {
   MOZ_ASSERT(NS_IsMainThread(), "Should be on main thread.");
-  if (!sVideoStatsEnabled) {
+  if (!IsVideoStatsEnabled()) {
     return 0;
   }
   layers::ImageContainer* container = GetImageContainer();
   return container ? container->GetPaintCount() : 0;
 }
 
 double HTMLVideoElement::MozFrameDelay()
 {
   MOZ_ASSERT(NS_IsMainThread(), "Should be on main thread.");
+  if (!IsVideoStatsEnabled()) {
+    return 0.0;
+  }
+
   VideoFrameContainer* container = GetVideoFrameContainer();
   // Hide negative delays. Frame timing tweaks in the compositor (e.g.
   // adding a bias value to prevent multiple dropped/duped frames when
   // frame times are aligned with composition times) may produce apparent
   // negative delay, but we shouldn't report that.
   return container ? std::max(0.0, container->GetFrameDelay()) : 0.0;
 }
 
@@ -237,17 +241,17 @@ HTMLVideoElement::GetFrameStatistics()
 already_AddRefed<VideoPlaybackQuality>
 HTMLVideoElement::GetVideoPlaybackQuality()
 {
   DOMHighResTimeStamp creationTime = 0;
   uint32_t totalFrames = 0;
   uint32_t droppedFrames = 0;
   uint32_t corruptedFrames = 0;
 
-  if (sVideoStatsEnabled) {
+  if (IsVideoStatsEnabled()) {
     if (nsPIDOMWindowInner* window = OwnerDoc()->GetInnerWindow()) {
       Performance* perf = window->GetPerformance();
       if (perf) {
         creationTime = perf->Now();
       }
     }
 
     if (mDecoder) {
@@ -320,10 +324,16 @@ HTMLVideoElement::UpdateScreenWakeLock()
 }
 
 void
 HTMLVideoElement::Init()
 {
   Preferences::AddBoolVarCache(&sVideoStatsEnabled, "media.video_stats.enabled");
 }
 
+/* static */
+bool
+HTMLVideoElement::IsVideoStatsEnabled() {
+  return sVideoStatsEnabled && !nsContentUtils::ShouldResistFingerprinting();
+}
+
 } // namespace dom
 } // namespace mozilla
--- a/dom/html/HTMLVideoElement.h
+++ b/dom/html/HTMLVideoElement.h
@@ -146,14 +146,16 @@ protected:
   void UpdateScreenWakeLock();
 
   bool mUseScreenWakeLock;
   RefPtr<WakeLock> mScreenWakeLock;
 
 private:
   static void MapAttributesIntoRule(const nsMappedAttributes* aAttributes,
                                     GenericSpecifiedValues* aGenericData);
+
+  static bool IsVideoStatsEnabled();
 };
 
 } // namespace dom
 } // namespace mozilla
 
 #endif // mozilla_dom_HTMLVideoElement_h