[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [tor-browser/tor-browser-52.5.2esr-7.5-2] Bug 23104: Add a default line height compensation



commit 89d8bc54cfe6a4cd999ab1f16f434c4fb809b643
Author: Igor Oliveira <igor.oliveira@xxxxxxxxxx>
Date:   Sun Dec 10 18:16:59 2017 -0200

    Bug 23104: Add a default line height compensation
    
    Many fonts have issues with their vertical metrics. they
    are used to influence the height of ascenders and depth
    of descenders. Gecko uses it to calculate the line height
    (font height + ascender + descender), however because of
    that idiosyncratic behavior across multiple operating
    systems, it can be used to identify the user's OS.
    
    The solution proposed in the patch uses a default factor
    to be multiplied with the font size, simulating the concept
    of ascender and descender. This way all operating
    systems will have the same line height only and only if the
    frame is outside the chrome.
---
 layout/generic/ReflowInput.cpp   | 16 +++++++++----
 tbb-tests/mochitest.ini          |  1 +
 tbb-tests/test_tor_bug23104.html | 51 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 64 insertions(+), 4 deletions(-)

diff --git a/layout/generic/ReflowInput.cpp b/layout/generic/ReflowInput.cpp
index 42f4a24b5314..cda602c50431 100644
--- a/layout/generic/ReflowInput.cpp
+++ b/layout/generic/ReflowInput.cpp
@@ -30,6 +30,7 @@
 #include "CounterStyleManager.h"
 #include <algorithm>
 #include "mozilla/dom/HTMLInputElement.h"
+#include "nsContentUtils.h"
 
 #ifdef DEBUG
 #undef NOISY_VERTICAL_ALIGN
@@ -2759,7 +2760,7 @@ ReflowInput::CalculateBlockSideMargins(nsIAtom* aFrameType)
 // For risk management, we use preference to control the behavior, and 
 // eNoExternalLeading is the old behavior.
 static nscoord
-GetNormalLineHeight(nsFontMetrics* aFontMetrics)
+GetNormalLineHeight(nsIContent* aContent, nsFontMetrics* aFontMetrics)
 {
   NS_PRECONDITION(nullptr != aFontMetrics, "no font metrics");
 
@@ -2768,6 +2769,12 @@ GetNormalLineHeight(nsFontMetrics* aFontMetrics)
   nscoord externalLeading = aFontMetrics->ExternalLeading();
   nscoord internalLeading = aFontMetrics->InternalLeading();
   nscoord emHeight = aFontMetrics->EmHeight();
+
+  if (nsContentUtils::ShouldResistFingerprinting() &&
+      !aContent->IsInChromeDocument()) {
+    return NSToCoordRound(emHeight * NORMAL_LINE_HEIGHT_FACTOR);
+  }
+
   switch (GetNormalLineHeightCalcControl()) {
   case eIncludeExternalLeading:
     normalLineHeight = emHeight+ internalLeading + externalLeading;
@@ -2786,7 +2793,8 @@ GetNormalLineHeight(nsFontMetrics* aFontMetrics)
 }
 
 static inline nscoord
-ComputeLineHeight(nsStyleContext* aStyleContext,
+ComputeLineHeight(nsIContent* aContent,
+                  nsStyleContext* aStyleContext,
                   nscoord aBlockBSize,
                   float aFontSizeInflation)
 {
@@ -2821,7 +2829,7 @@ ComputeLineHeight(nsStyleContext* aStyleContext,
 
   RefPtr<nsFontMetrics> fm = nsLayoutUtils::
     GetFontMetricsForStyleContext(aStyleContext, aFontSizeInflation);
-  return GetNormalLineHeight(fm);
+  return GetNormalLineHeight(aContent, fm);
 }
 
 nscoord
@@ -2844,7 +2852,7 @@ ReflowInput::CalcLineHeight(nsIContent* aContent,
   NS_PRECONDITION(aStyleContext, "Must have a style context");
 
   nscoord lineHeight =
-    ComputeLineHeight(aStyleContext, aBlockBSize, aFontSizeInflation);
+    ComputeLineHeight(aContent, aStyleContext, aBlockBSize, aFontSizeInflation);
 
   NS_ASSERTION(lineHeight >= 0, "ComputeLineHeight screwed up");
 
diff --git a/tbb-tests/mochitest.ini b/tbb-tests/mochitest.ini
index 3d2e7c9db803..fca972a51211 100644
--- a/tbb-tests/mochitest.ini
+++ b/tbb-tests/mochitest.ini
@@ -10,3 +10,4 @@ support-files =
 [test_tor_bug2875.html]
 [test_tor_bug4755.html]
 [test_tor_bug5856.html]
+[test_tor_bug23104.html]
diff --git a/tbb-tests/test_tor_bug23104.html b/tbb-tests/test_tor_bug23104.html
new file mode 100644
index 000000000000..ae73a3446037
--- /dev/null
+++ b/tbb-tests/test_tor_bug23104.html
@@ -0,0 +1,51 @@
+<!DOCTYPE HTML>
+<meta charset="UTF-8">
+<html>
+<head>
+  <title>Test for Tor Bug #23104: CSS line-height reveals the platform Tor browser is running</title>
+  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <script type="application/javascript" src="/tests/SimpleTest/SpawnTask.js"></script>
+  <style type="text/css">
+    span {
+      background-color: #000;
+      color: #fff;
+      font-size: 16.5px;
+    }
+  </style>
+</head>
+<body>
+<span id="test1">Test1</span>
+<span id="test2">Ù?Ù?Ù?Ø©</span>
+<span id="test3">ação</span>
+<script type="application/javascript;version=1.7">
+
+let setPref = function* (key, value) {
+  return new Promise(function(resolve, reject) {
+    SpecialPowers.pushPrefEnv({"set": [[key, value]]}, resolve);
+  });
+}
+
+function getStyle(el, styleprop) {
+  el = document.getElementById(el);
+  return document.defaultView.getComputedStyle(el, null).getPropertyValue(styleprop);
+}
+
+function validateElement(elementName, isFingerprintResistent) {
+  var fontSize = getStyle(elementName, 'font-size');
+  var lineHeight = getStyle(elementName, 'line-height');
+  var validationCb = isFingerprintResistent ? is : isnot;
+  validationCb(parseFloat(lineHeight), parseFloat(fontSize) * 1.2, 'Line Height validation');
+}
+
+add_task(function* () {
+  for (let resistFingerprintingValue of [true, false]) {
+  yield setPref("privacy.resistFingerprinting", resistFingerprintingValue);
+    for (let elementId of ['test1', 'test2', 'test3']) {
+      validateElement(elementId, resistFingerprintingValue);
+    }
+  }
+});
+
+</script>
+</body>
+</html>

_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits