Bug 1434215: Simplify some ResistFingerprinting callers in nsMediaFeatures. r=xidorn
authorEmilio Cobos Álvarez <emilio@crisal.io>
Thu, 18 Jan 2018 15:41:37 +0100
changeset 401475 4fb5f2af57595b102dcc98f235658ac5b3bd7fa6
parent 401474 bd3079e9390c1f1a5020286dfa5e7a88cb97a54f
child 401476 a680bba448c42b4b63f344b0f1f6671f3ab483e7
push id33345
push userncsoregi@mozilla.com
push dateTue, 30 Jan 2018 16:18:22 +0000
treeherdermozilla-central@fd995039d897 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersxidorn
bugs1434215
milestone60.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1434215: Simplify some ResistFingerprinting callers in nsMediaFeatures. r=xidorn The docshell version just redirects to the document one, so no need to ping-pong. MozReview-Commit-ID: AggEoLubCIF
layout/style/nsMediaFeatures.cpp
--- a/layout/style/nsMediaFeatures.cpp
+++ b/layout/style/nsMediaFeatures.cpp
@@ -133,36 +133,31 @@ static void
 GetHeight(nsIDocument* aDocument, const nsMediaFeature*,
           nsCSSValue& aResult)
 {
   nsSize size = GetSize(aDocument);
   aResult.SetFloatValue(CSSPixel::FromAppUnits(size.height), eCSSUnit_Pixel);
 }
 
 static bool
-ShouldResistFingerprinting(nsIDocument* aDocument)
-{
-  return nsContentUtils::ShouldResistFingerprinting(aDocument->GetDocShell());
-}
-
-static bool
 IsDeviceSizePageSize(nsIDocument* aDocument)
 {
   nsIDocShell* docShell = aDocument->GetDocShell();
   if (!docShell) {
     return false;
   }
   return docShell->GetDeviceSizeIsPageSize();
 }
 
 // A helper for three features below.
 static nsSize
 GetDeviceSize(nsIDocument* aDocument)
 {
-  if (ShouldResistFingerprinting(aDocument) || IsDeviceSizePageSize(aDocument)) {
+  if (nsContentUtils::ShouldResistFingerprinting(aDocument) ||
+      IsDeviceSizePageSize(aDocument)) {
     return GetSize(aDocument);
   }
 
   nsPresContext* pc = GetPresContext(aDocument);
   // NOTE(emilio): We should probably figure out how to return an appropriate
   // device size here, though in a multi-screen world that makes no sense
   // really.
   if (!pc) {
@@ -269,17 +264,17 @@ GetDeviceContextFor(nsIDocument* aDocume
 static void
 GetColor(nsIDocument* aDocument, const nsMediaFeature*,
          nsCSSValue& aResult)
 {
   // Use depth of 24 when resisting fingerprinting, or when we're not being
   // rendered.
   uint32_t depth = 24;
 
-  if (!ShouldResistFingerprinting(aDocument)) {
+  if (!nsContentUtils::ShouldResistFingerprinting(aDocument)) {
     if (nsDeviceContext* dx = GetDeviceContextFor(aDocument)) {
       // FIXME: On a monochrome device, return 0!
       dx->GetDepth(depth);
     }
   }
 
   // The spec says to use bits *per color component*, so divide by 3,
   // and round down, since the spec says to use the smallest when the
@@ -318,17 +313,17 @@ GetResolution(nsIDocument* aDocument, co
   // We're returning resolution in terms of device pixels per css pixel, since
   // that is the preferred unit for media queries of resolution. This avoids
   // introducing precision error from conversion to and from less-used
   // physical units like inches.
 
   float dppx = 1.;
 
   if (nsDeviceContext* dx = GetDeviceContextFor(aDocument)) {
-    if (ShouldResistFingerprinting(aDocument)) {
+    if (nsContentUtils::ShouldResistFingerprinting(aDocument)) {
       dppx = dx->GetFullZoom();
     } else {
       // Get the actual device pixel ratio, which also takes zoom into account.
       dppx =
         float(nsPresContext::AppUnitsPerCSSPixel()) / dx->AppUnitsPerDevPixel();
     }
   }
 
@@ -392,17 +387,17 @@ GetGrid(nsIDocument* aDocument, const ns
   // feature is always 0.
   aResult.SetIntValue(0, eCSSUnit_Integer);
 }
 
 static void
 GetDevicePixelRatio(nsIDocument* aDocument, const nsMediaFeature*,
                     nsCSSValue& aResult)
 {
-  if (ShouldResistFingerprinting(aDocument)) {
+  if (nsContentUtils::ShouldResistFingerprinting(aDocument)) {
     aResult.SetFloatValue(1.0, eCSSUnit_Number);
     return;
   }
 
   nsIPresShell* presShell = aDocument->GetShell();
   if (!presShell) {
     aResult.SetFloatValue(1.0, eCSSUnit_Number);
     return;
@@ -449,17 +444,18 @@ GetSystemMetric(nsIDocument* aDocument, 
   aResult.Reset();
 
   const bool isAccessibleFromContentPages =
     !(aFeature->mReqFlags & nsMediaFeature::eUserAgentAndChromeOnly);
 
   MOZ_ASSERT(!isAccessibleFromContentPages ||
              *aFeature->mName == nsGkAtoms::_moz_touch_enabled);
 
-  if (isAccessibleFromContentPages && ShouldResistFingerprinting(aDocument)) {
+  if (isAccessibleFromContentPages &&
+      nsContentUtils::ShouldResistFingerprinting(aDocument)) {
     // If "privacy.resistFingerprinting" is enabled, then we simply don't
     // return any system-backed media feature values. (No spoofed values
     // returned.)
     return;
   }
 
   MOZ_ASSERT(aFeature->mValueType == nsMediaFeature::eBoolInteger,
              "unexpected type");
@@ -471,17 +467,17 @@ GetSystemMetric(nsIDocument* aDocument, 
 
 static void
 GetWindowsTheme(nsIDocument* aDocument, const nsMediaFeature* aFeature,
                 nsCSSValue& aResult)
 {
   aResult.Reset();
 
   MOZ_ASSERT(aFeature->mReqFlags & nsMediaFeature::eUserAgentAndChromeOnly);
-  if (ShouldResistFingerprinting(aDocument)) {
+  if (nsContentUtils::ShouldResistFingerprinting(aDocument)) {
     return;
   }
 
 #ifdef XP_WIN
   uint8_t windowsThemeId = GetWindowsThemeIdentifier();
 
   // Classic mode should fail to match.
   if (windowsThemeId == LookAndFeel::eWindowsTheme_Classic)
@@ -500,17 +496,17 @@ GetWindowsTheme(nsIDocument* aDocument, 
 
 static void
 GetOperatingSystemVersion(nsIDocument* aDocument, const nsMediaFeature* aFeature,
                          nsCSSValue& aResult)
 {
   aResult.Reset();
 
   MOZ_ASSERT(aFeature->mReqFlags & nsMediaFeature::eUserAgentAndChromeOnly);
-  if (ShouldResistFingerprinting(aDocument)) {
+  if (nsContentUtils::ShouldResistFingerprinting(aDocument)) {
     return;
   }
 
 #ifdef XP_WIN
   int32_t metricResult;
   if (NS_SUCCEEDED(
         LookAndFeel::GetInt(LookAndFeel::eIntID_OperatingSystemVersionIdentifier,
                             &metricResult))) {