Bug 1546390 - Enable determining whether the current document should respect resist fingerprinting mode on the main thread in OffscreenCanvas.toBlob(); r=baku
authorEhsan Akhgari <ehsan@mozilla.com>
Thu, 25 Apr 2019 07:47:45 +0000
changeset 530127 904076df6327430699a83cfc75c2caca72dfa872
parent 530126 b9f3ca50c00e6226e0c4877ef9199c714f8a5a5b
child 530128 60c8ad955f976d5f88887fe71294f6185c02e9c5
push id11265
push userffxbld-merge
push dateMon, 13 May 2019 10:53:39 +0000
treeherdermozilla-beta@77e0fe8dbdd3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku
bugs1546390
milestone68.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 1546390 - Enable determining whether the current document should respect resist fingerprinting mode on the main thread in OffscreenCanvas.toBlob(); r=baku Differential Revision: https://phabricator.services.mozilla.com/D28593
dom/canvas/OffscreenCanvas.cpp
dom/canvas/crashtests/1546390.html
dom/canvas/crashtests/crashtests.list
--- a/dom/canvas/OffscreenCanvas.cpp
+++ b/dom/canvas/OffscreenCanvas.cpp
@@ -246,23 +246,27 @@ already_AddRefed<Promise> OffscreenCanva
     }
 
     nsCOMPtr<nsIGlobalObject> mGlobal;
     RefPtr<Promise> mPromise;
   };
 
   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.
-  dom::WorkerPrivate* workerPrivate = dom::GetCurrentThreadWorkerPrivate();
-  bool usePlaceholder =
-      nsContentUtils::ShouldResistFingerprinting(workerPrivate->GetPrincipal());
+  bool usePlaceholder;
+  if (NS_IsMainThread()) {
+    nsCOMPtr<nsPIDOMWindowInner> window = do_QueryInterface(GetGlobalObject());
+    Document* doc = window->GetExtantDoc();
+    usePlaceholder =
+        doc ? nsContentUtils::ShouldResistFingerprinting(doc) : false;
+  } else {
+    dom::WorkerPrivate* workerPrivate = dom::GetCurrentThreadWorkerPrivate();
+    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) {
new file mode 100644
--- /dev/null
+++ b/dom/canvas/crashtests/1546390.html
@@ -0,0 +1,11 @@
+<html>
+<head>
+    <script>
+      function start () {
+        new OffscreenCanvas(1, 127).toBlob()
+      }
+
+      window.addEventListener('load', start)
+    </script>
+</head>
+</html>
--- a/dom/canvas/crashtests/crashtests.list
+++ b/dom/canvas/crashtests/crashtests.list
@@ -47,8 +47,9 @@ load 1305312-1.html
 load 1305850.html
 load 1334366-1.html
 load 1334647-1.html
 load 1349067.html
 pref(gfx.offscreencanvas.enabled,true) load 1348976-1.html
 load 1357092.html
 load 1441613.html
 pref(gfx.offscreencanvas.enabled,true) load 1443671.html
+pref(gfx.offscreencanvas.enabled,true) load 1546390.html