Bug 1548634 - Update the default letterboxing behavior to use stepped ranges r?johannh draft
authorTom Ritter <tom@mozilla.com>
Thu, 02 May 2019 13:16:05 -0500
changeset 1978910 0b1eef9eeb06668fc06b3b4d877daaf957c3c1da
parent 1978909 1b23145ed904be055bf0efe1000e03ec50c02cb3
child 1978911 61badb0a4eee2a0c7764b63d3e4efefd164989cf
push id356063
push usertritter@mozilla.com
push dateThu, 02 May 2019 21:31:49 +0000
treeherdertry@61badb0a4eee [default view] [failures only]
reviewersjohannh
bugs1548634
milestone60.6.2
Bug 1548634 - Update the default letterboxing behavior to use stepped ranges r?johannh
browser/components/resistfingerprinting/test/browser/browser_dynamical_window_rounding.js
toolkit/components/resistfingerprinting/RFPHelper.jsm
--- a/browser/components/resistfingerprinting/test/browser/browser_dynamical_window_rounding.js
+++ b/browser/components/resistfingerprinting/test/browser/browser_dynamical_window_rounding.js
@@ -7,18 +7,30 @@
  *
  * A helpful note: if this test starts randomly failing; it may be because the
  * zoom level was not reset by an earlier-run test. See Bug 1407366 for an
  * example.
  */
 
 const TEST_PATH = "http://example.net/browser/browser/components/resistfingerprinting/test/browser/";
 
-const DEFAULT_ROUNDED_WIDTH_STEP  = 200;
-const DEFAULT_ROUNDED_HEIGHT_STEP = 100;
+function defaultRounding(aDimension) {
+    var stepping;
+    if (aDimension <= 50) {
+	return aDimension;
+    } else if (aDimension <= 500) {
+	stepping = 50;
+    } else if (aDimension <= 1600) {
+	stepping = 100;
+    } else {
+	stepping = 200;
+    }
+
+    return (aDimension % stepping);
+}
 
 // A set of test cases which defines the width and the height of the outer window.
 const TEST_CASES = [
   {width: 1250, height: 1000},
   {width: 1500, height: 1050},
   {width: 1120, height: 760},
   {width: 800,  height: 600},
   {width: 640,  height: 400},
@@ -47,18 +59,18 @@ function handleOSFuzziness(aContent, aTa
   }
   return aContent == aTarget;
 }
 
 function checkForDefaultSetting(
   aContentWidth, aContentHeight, aRealWidth, aRealHeight) {
   // The default behavior for rounding is to round window with 200x100 stepping.
   // So, we can get the rounded size by subtracting the remainder.
-  let targetWidth = aRealWidth - (aRealWidth % DEFAULT_ROUNDED_WIDTH_STEP);
-  let targetHeight = aRealHeight - (aRealHeight % DEFAULT_ROUNDED_HEIGHT_STEP);
+    let targetWidth = aRealWidth - defaultRounding(aRealWidth);
+    let targetHeight = aRealHeight - defaultRounding(aRealHeight);
 
   // This platform-specific code is explained in the large comment below.
   if (getPlatform() != "linux") {
     ok(handleOSFuzziness(aContentWidth, targetWidth),
       `Default Dimensions: The content window width is correctly rounded into. ${aRealWidth}px -> ${aContentWidth}px should equal ${targetWidth}px`);
 
     ok(handleOSFuzziness(aContentHeight, targetHeight),
       `Default Dimensions: The content window height is correctly rounded into. ${aRealHeight}px -> ${aContentHeight}px should equal ${targetHeight}px`);
--- a/toolkit/components/resistfingerprinting/RFPHelper.jsm
+++ b/toolkit/components/resistfingerprinting/RFPHelper.jsm
@@ -16,19 +16,16 @@ const kTopicHttpOnModifyRequest = "http-
 const kPrefLetterboxing = "privacy.resistFingerprinting.letterboxing";
 const kPrefLetterboxingDimensions =
   "privacy.resistFingerprinting.letterboxing.dimensions";
 const kPrefLetterboxingTesting =
   "privacy.resistFingerprinting.letterboxing.testing";
 const kTopicDOMWindowOpened = "domwindowopened";
 const kEventLetterboxingSizeUpdate = "Letterboxing:ContentSizeUpdated";
 
-const kDefaultWidthStepping = 200;
-const kDefaultHeightStepping = 100;
-
 var logConsole;
 function log(msg) {
   if (!logConsole) {
     logConsole = console.createInstance({
       prefix: "RFPHelper.jsm",
       maxLogLevelPref: "privacy.resistFingerprinting.jsmloglevel",
     });
   }
@@ -367,19 +364,33 @@ class _RFPHelper {
       " containerWidth=" + containerWidth + " containerHeight=" + containerHeight + " ");
 
     let calcMargins = (aWidth, aHeight) => {
       let result;
       log("_roundContentView[" + logId + "] calcMargins(" + aWidth + ", " + aHeight + ")");
       // If the set is empty, we will round the content with the default
       // stepping size.
       if (!this._letterboxingDimensions.length) {
+        let steppedRange = (aDimension) => {
+          let stepping;
+          if (aDimension <= 50) {
+            return 0;
+          } else if (aDimension <= 500) {
+            stepping = 50;
+          } else if (aDimension <= 1600) {
+            stepping = 100;
+          } else {
+            stepping = 200;
+          }
+
+          return (aDimension % stepping) / 2;
+        };
         result = {
-          width: (aWidth % kDefaultWidthStepping) / 2,
-          height: (aHeight % kDefaultHeightStepping) / 2,
+          width: steppedRange(aWidth),
+          height: steppedRange(aHeight),
         };
         log("_roundContentView[" + logId + "] calcMargins(" + aWidth + ", " + aHeight + ") = " + result.width + " x " + result.height);
         return result;
       }
 
       let matchingArea = aWidth * aHeight;
       let minWaste = Number.MAX_SAFE_INTEGER;
       let targetDimensions = undefined;