Bug 1382545 - Part 1: Rounding the time of Animation API to 100ms when 'privacy.resistFingerprinting'is true. r?birtles,arthuredelstein draft
authorTim Huang <tihuang@mozilla.com>
Thu, 17 Aug 2017 22:37:29 +0800
changeset 651979 48fe009701b6a7c63c952817f54f406bad452c2f
parent 651826 d1c70c20e7b52f7295411343e4dc5db8ee7c92b9
child 651980 05c7a5338c6654127c7f5592faafa9ad5e108cf5
child 652205 ba579aed70953c08f3f5c71d0984ad48e2067a50
push id75910
push userbmo:tihuang@mozilla.com
push dateThu, 24 Aug 2017 09:54:16 +0000
reviewersbirtles, arthuredelstein
bugs1382545, 16337
milestone57.0a1
Bug 1382545 - Part 1: Rounding the time of Animation API to 100ms when 'privacy.resistFingerprinting'is true. r?birtles,arthuredelstein Adopt from Tor #16337. This patch makes Animation API to report a rounded time when 'privacy.resistFingerprinting' is true. The Animation API uses AnimationUtils::TimeDurationToDouble() to convert its time duration into a double value and reports it when someone tries to query time through Animation API. So, we use nsRFPService::ReduceTimePrecisionAsMSecs() inside this method to round the time in the scope of the millisecond. MozReview-Commit-ID: 8o01G6AlAu9
dom/animation/AnimationUtils.h
--- a/dom/animation/AnimationUtils.h
+++ b/dom/animation/AnimationUtils.h
@@ -5,16 +5,17 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef mozilla_dom_AnimationUtils_h
 #define mozilla_dom_AnimationUtils_h
 
 #include "mozilla/TimeStamp.h"
 #include "mozilla/dom/BindingDeclarations.h"
 #include "mozilla/dom/Nullable.h"
+#include "nsRFPService.h"
 #include "nsStringFwd.h"
 
 class nsIContent;
 class nsIDocument;
 class nsIFrame;
 struct JSContext;
 
 namespace mozilla {
@@ -26,17 +27,19 @@ class AnimationUtils
 {
 public:
   static dom::Nullable<double>
   TimeDurationToDouble(const dom::Nullable<TimeDuration>& aTime)
   {
     dom::Nullable<double> result;
 
     if (!aTime.IsNull()) {
-      result.SetValue(aTime.Value().ToMilliseconds());
+      result.SetValue(
+        nsRFPService::ReduceTimePrecisionAsMSecs(aTime.Value().ToMilliseconds())
+      );
     }
 
     return result;
   }
 
   static dom::Nullable<TimeDuration>
   DoubleToTimeDuration(const dom::Nullable<double>& aTime)
   {