Ticket #23104: 0001-bug-23104-Add-a-default-line-height-compensation.4.patch

File 0001-bug-23104-Add-a-default-line-height-compensation.4.patch, 4.0 KB (added by igt0, 22 months ago)

Revision 4

  • layout/generic/ReflowInput.cpp

    From 2948b9bff4c12f4ba59ada8fcbae2c21958d576c Mon Sep 17 00:00:00 2001
    From: igt0 <igt0-tor@gmail.com>
    Date: Sat, 16 Sep 2017 16:50:17 -0300
    Subject: [PATCH] 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.
    ---
     layout/generic/ReflowInput.cpp   |  6 +++++
     tbb-tests/mochitest.ini          |  1 +
     tbb-tests/test_tor_bug23104.html | 52 ++++++++++++++++++++++++++++++++++++++++
     3 files changed, 59 insertions(+)
     create mode 100644 tbb-tests/test_tor_bug23104.html
    
    diff --git a/layout/generic/ReflowInput.cpp b/layout/generic/ReflowInput.cpp
    index 42f4a24..e219ae0 100644
    a b  
    3030#include "CounterStyleManager.h"
    3131#include <algorithm>
    3232#include "mozilla/dom/HTMLInputElement.h"
     33#include "nsContentUtils.h"
    3334
    3435#ifdef DEBUG
    3536#undef NOISY_VERTICAL_ALIGN
    GetNormalLineHeight(nsFontMetrics* aFontMetrics) 
    27682769  nscoord externalLeading = aFontMetrics->ExternalLeading();
    27692770  nscoord internalLeading = aFontMetrics->InternalLeading();
    27702771  nscoord emHeight = aFontMetrics->EmHeight();
     2772
     2773  if (nsContentUtils::ShouldResistFingerprinting()) {
     2774    return NSToCoordRound(emHeight * NORMAL_LINE_HEIGHT_FACTOR);
     2775  }
     2776
    27712777  switch (GetNormalLineHeightCalcControl()) {
    27722778  case eIncludeExternalLeading:
    27732779    normalLineHeight = emHeight+ internalLeading + externalLeading;
  • tbb-tests/mochitest.ini

    diff --git a/tbb-tests/mochitest.ini b/tbb-tests/mochitest.ini
    index 3d2e7c9..fca972a 100644
    a b support-files = 
    1010[test_tor_bug2875.html]
    1111[test_tor_bug4755.html]
    1212[test_tor_bug5856.html]
     13[test_tor_bug23104.html]
  • new file tbb-tests/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 0000000..c2e4a51
    - +  
     1<!DOCTYPE HTML>
     2<meta charset="UTF-8">
     3<html>
     4<head>
     5  <title>Test for Tor Bug #23104: CSS line-height reveals the platform Tor browser is running</title>
     6  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
     7  <script type="application/javascript" src="/tests/SimpleTest/SpawnTask.js"></script>
     8  <style type="text/css">
     9    span {
     10      background-color: #000;
     11      color: #fff;
     12      font-size: 16.5px;
     13    }
     14  </style>
     15</head>
     16<body>
     17<span id="test1">Test1</span>
     18<span id="test2">كلمة</span>
     19<span id="test3">ação</span>
     20<script type="application/javascript;version=1.7">
     21
     22let setPref = function* (key, value) {
     23  return new Promise(function(resolve, reject) {
     24    SpecialPowers.pushPrefEnv({"set": [[key, value]]}, resolve);
     25  });
     26}
     27
     28function getStyle(el, styleprop) {
     29  el = document.getElementById(el);
     30  return document.defaultView.getComputedStyle(el, null).getPropertyValue(styleprop);
     31}
     32
     33function validateElement(elementName, isFingerprintResistent) {
     34  var fontSize = getStyle(elementName, 'font-size');
     35  var lineHeight = getStyle(elementName, 'line-height');
     36  var validationCb = isFingerprintResistent ? is : isnot;
     37  validationCb(parseFloat(lineHeight), Math.ceil(parseFloat(fontSize)) * 1.2, 'Line Height validation');
     38}
     39
     40add_task(function* () {
     41  for (let resistFingerprintingValue of [true, false]) {
     42  yield setPref("privacy.resistFingerprinting", resistFingerprintingValue);
     43    for (let elementId of ['test1', 'test2', 'test3']) {
     44      validateElement(elementId, resistFingerprintingValue);
     45    }
     46  }
     47});
     48
     49</script>
     50</body>
     51</html>
     52