Bug 1369309 - Part 1: Spoofing media statistics to 0 when 'privacy.resistFingerprinting' is true. r?jwwang,arthuredelstein
MozReview-Commit-ID: FNALpUGFDTQ
--- 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