Bug 1532414 - Pass a document/principal pointer to nsContentUtils::ShouldResistFingerprinting() callers in the canvas API; r=baku
☠☠ backed out by e39ea97ade1e ☠ ☠
authorEhsan Akhgari <ehsan@mozilla.com>
Tue, 05 Mar 2019 12:42:51 +0000
changeset 520324 ff14d3c64e53dad7b4720c983b8f19bb494ed28a
parent 520323 14b6b6f8a599748d3a7d8435f57c37e696a97df7
child 520325 b6e605718832c9bec3bb18933f3da8a286843efa
push id10862
push userffxbld-merge
push dateMon, 11 Mar 2019 13:01:11 +0000
treeherdermozilla-beta@a2e7f5c935da [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku
bugs1532414
milestone67.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 1532414 - Pass a document/principal pointer to nsContentUtils::ShouldResistFingerprinting() callers in the canvas API; r=baku Differential Revision: https://phabricator.services.mozilla.com/D22002
dom/canvas/CanvasUtils.cpp
dom/canvas/OffscreenCanvas.cpp
dom/canvas/WebGLContextExtensions.cpp
dom/canvas/WebGLContextValidate.cpp
--- a/dom/canvas/CanvasUtils.cpp
+++ b/dom/canvas/CanvasUtils.cpp
@@ -44,17 +44,17 @@
 using namespace mozilla::gfx;
 
 namespace mozilla {
 namespace CanvasUtils {
 
 bool IsImageExtractionAllowed(Document* aDocument, JSContext* aCx,
                               nsIPrincipal& aPrincipal) {
   // Do the rest of the checks only if privacy.resistFingerprinting is on.
-  if (!nsContentUtils::ShouldResistFingerprinting()) {
+  if (!nsContentUtils::ShouldResistFingerprinting(aDocument)) {
     return true;
   }
 
   // Don't proceed if we don't have a document or JavaScript context.
   if (!aDocument || !aCx) {
     return false;
   }
 
--- a/dom/canvas/OffscreenCanvas.cpp
+++ b/dom/canvas/OffscreenCanvas.cpp
@@ -250,17 +250,19 @@ already_AddRefed<Promise> OffscreenCanva
   };
 
   RefPtr<EncodeCompleteCallback> callback = new EncodeCallback(global, promise);
 
   // TODO: Can we obtain the context and document here somehow
   // so that we can decide when usePlaceholder should be true/false?
   // See https://trac.torproject.org/18599
   // For now, we always return a placeholder if fingerprinting resistance is on.
-  bool usePlaceholder = nsContentUtils::ShouldResistFingerprinting();
+  dom::WorkerPrivate* workerPrivate = dom::GetCurrentThreadWorkerPrivate();
+  bool usePlaceholder =
+      nsContentUtils::ShouldResistFingerprinting(workerPrivate->GetPrincipal());
   CanvasRenderingContextHelper::ToBlob(aCx, global, callback, aType, aParams,
                                        usePlaceholder, aRv);
 
   return promise.forget();
 }
 
 already_AddRefed<gfx::SourceSurface> OffscreenCanvas::GetSurfaceSnapshot(
     gfxAlphaType* const aOutAlphaType) {
--- a/dom/canvas/WebGLContextExtensions.cpp
+++ b/dom/canvas/WebGLContextExtensions.cpp
@@ -102,16 +102,25 @@ bool WebGLContext::IsExtensionSupported(
   }
 
   return IsExtensionSupported(ext);
 }
 
 bool WebGLContext::IsExtensionSupported(WebGLExtensionID ext) const {
   if (mDisableExtensions) return false;
 
+  bool shouldResistFingerprinting =
+      mCanvasElement ?
+                     // If we're constructed from a canvas element
+          nsContentUtils::ShouldResistFingerprinting(GetOwnerDoc())
+                     :
+                     // If we're constructed from an offscreen canvas
+          nsContentUtils::ShouldResistFingerprinting(
+              mOffscreenCanvas->GetOwnerGlobal()->PrincipalOrNull());
+
   switch (ext) {
     // In alphabetical order
     // ANGLE_
     case WebGLExtensionID::ANGLE_instanced_arrays:
       return WebGLExtensionInstancedArrays::IsSupported(this);
 
     // EXT_
     case WebGLExtensionID::EXT_blend_minmax:
@@ -196,20 +205,20 @@ bool WebGLContext::IsExtensionSupported(
     case WebGLExtensionID::WEBGL_compressed_texture_s3tc:
       return WebGLExtensionCompressedTextureS3TC::IsSupported(this);
 
     case WebGLExtensionID::WEBGL_compressed_texture_s3tc_srgb:
       return WebGLExtensionCompressedTextureS3TC_SRGB::IsSupported(this);
 
     case WebGLExtensionID::WEBGL_debug_renderer_info:
       return Preferences::GetBool("webgl.enable-debug-renderer-info", false) &&
-             !nsContentUtils::ShouldResistFingerprinting();
+             !shouldResistFingerprinting;
 
     case WebGLExtensionID::WEBGL_debug_shaders:
-      return !nsContentUtils::ShouldResistFingerprinting();
+      return !shouldResistFingerprinting;
 
     case WebGLExtensionID::WEBGL_depth_texture:
       return WebGLExtensionDepthTexture::IsSupported(this);
 
     case WebGLExtensionID::WEBGL_draw_buffers:
       return WebGLExtensionDrawBuffers::IsSupported(this);
 
     case WebGLExtensionID::WEBGL_lose_context:
--- a/dom/canvas/WebGLContextValidate.cpp
+++ b/dom/canvas/WebGLContextValidate.cpp
@@ -466,16 +466,24 @@ bool WebGLContext::InitAndValidateGL(Fai
   gl->fGetFloatv(LOCAL_GL_ALIASED_LINE_WIDTH_RANGE, mGLAliasedLineWidthRange);
 
   const GLenum driverPName = gl->IsCoreProfile()
                                  ? LOCAL_GL_POINT_SIZE_RANGE
                                  : LOCAL_GL_ALIASED_POINT_SIZE_RANGE;
   gl->fGetFloatv(driverPName, mGLAliasedPointSizeRange);
 
   ////////////////
+  bool shouldResistFingerprinting =
+      mCanvasElement ?
+                     // If we're constructed from a canvas element
+          nsContentUtils::ShouldResistFingerprinting(GetOwnerDoc())
+                     :
+                     // If we're constructed from an offscreen canvas
+          nsContentUtils::ShouldResistFingerprinting(
+              mOffscreenCanvas->GetOwnerGlobal()->PrincipalOrNull());
 
   if (gfxPrefs::WebGLMinCapabilityMode()) {
     bool ok = true;
 
     ok &= RestrictCap(&mGLMaxVertexTextureImageUnits,
                       kMinMaxVertexTextureImageUnits);
     ok &= RestrictCap(&mGLMaxFragmentTextureImageUnits,
                       kMinMaxFragmentTextureImageUnits);
@@ -500,17 +508,17 @@ bool WebGLContext::InitAndValidateGL(Fai
     ok &= RestrictCap(&mGLMaxRenderbufferSize, kMinMaxRenderbufferSize);
 
     if (!ok) {
       GenerateWarning("Unable to restrict WebGL limits to minimums.");
       return false;
     }
 
     mDisableFragHighP = true;
-  } else if (nsContentUtils::ShouldResistFingerprinting()) {
+  } else if (shouldResistFingerprinting) {
     bool ok = true;
 
     ok &= RestrictCap(&mGLMaxTextureSize, kCommonMaxTextureSize);
     ok &= RestrictCap(&mGLMaxCubeMapTextureSize, kCommonMaxCubeMapTextureSize);
     ok &= RestrictCap(&mGLMaxRenderbufferSize, kCommonMaxRenderbufferSize);
 
     ok &= RestrictCap(&mGLMaxVertexTextureImageUnits,
                       kCommonMaxVertexTextureImageUnits);