Bug 1548634 - Update the default letterboxing behavior to use stepped ranges r=johannh
authorTom Ritter <tom@mozilla.com>
Tue, 07 May 2019 16:06:43 +0000
changeset 534835 6d2d7856e468e04234f4efad320fa26d222a2eb9
parent 534834 a66cab570864911c2607359e76d510a43fbbeb4f
child 534836 17b693747dbd8b6020787a0111ed4883b517acff
push id2082
push userffxbld-merge
push dateMon, 01 Jul 2019 08:34:18 +0000
treeherdermozilla-release@2fb19d0466d2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjohannh
bugs1548634
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 1548634 - Update the default letterboxing behavior to use stepped ranges r=johannh Differential Revision: https://phabricator.services.mozilla.com/D29759
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
@@ -6,19 +6,17 @@
  *   rounded if the window is resized when letterboxing is enabled.
  *
  * 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;
+const { RFPHelper } = ChromeUtils.import("resource://gre/modules/RFPHelper.jsm");
 
 // 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},
@@ -45,20 +43,19 @@ function handleOSFuzziness(aContent, aTa
   if (getPlatform() == "win") {
     return Math.abs(aContent - aTarget) <= 1;
   }
   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);
+  // We can get the rounded size by subtracting twice the margin.
+  let targetWidth = aRealWidth - (2 * RFPHelper.steppedRange(aRealWidth));
+  let targetHeight = aRealHeight - (2 * RFPHelper.steppedRange(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",
     });
   }
@@ -333,16 +330,34 @@ class _RFPHelper {
     if (tab.isEmpty || aBrowser.contentPrincipal.isSystemPrincipal) {
       this._clearContentViewMargin(aBrowser);
     } else {
       this._roundContentView(aBrowser);
     }
   }
 
   /**
+   * Given a width or height, returns the appropriate margin to apply.
+   */
+  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;
+  }
+
+  /**
    * The function will round the given browser by adding margins around the
    * content viewport.
    */
   async _roundContentView(aBrowser) {
     let logId = Math.random();
     log("_roundContentView[" + logId + "]");
     let win = aBrowser.ownerGlobal;
     let browserContainer = aBrowser.getTabBrowser()
@@ -368,18 +383,18 @@ class _RFPHelper {
 
     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) {
         result = {
-          width: (aWidth % kDefaultWidthStepping) / 2,
-          height: (aHeight % kDefaultHeightStepping) / 2,
+          width: this.steppedRange(aWidth),
+          height: this.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;