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

File 0001-bug-23104-Add-a-default-line-height-compensation.5.patch, 5.5 KB (added by igt0, 18 months ago)

version 5 - Make sure the content is not inside the chrome

  • layout/generic/ReflowInput.cpp

    From 9af140187e36cd9af9450717e658b4dfed8f5334 Mon Sep 17 00:00:00 2001
    From: Igor Oliveira <igor.oliveira@posteo.net>
    Date: Sun, 10 Dec 2017 18:16:59 -0200
    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 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(-)
     create mode 100644 tbb-tests/test_tor_bug23104.html
    
    diff --git a/layout/generic/ReflowInput.cpp b/layout/generic/ReflowInput.cpp
    index 42f4a24b5314..cda602c50431 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
    ReflowInput::CalculateBlockSideMargins(nsIAtom* aFrameType) 
    27592760// For risk management, we use preference to control the behavior, and
    27602761// eNoExternalLeading is the old behavior.
    27612762static nscoord
    2762 GetNormalLineHeight(nsFontMetrics* aFontMetrics)
     2763GetNormalLineHeight(nsIContent* aContent, nsFontMetrics* aFontMetrics)
    27632764{
    27642765  NS_PRECONDITION(nullptr != aFontMetrics, "no font metrics");
    27652766
    GetNormalLineHeight(nsFontMetrics* aFontMetrics) 
    27682769  nscoord externalLeading = aFontMetrics->ExternalLeading();
    27692770  nscoord internalLeading = aFontMetrics->InternalLeading();
    27702771  nscoord emHeight = aFontMetrics->EmHeight();
     2772
     2773  if (nsContentUtils::ShouldResistFingerprinting() &&
     2774      !aContent->IsInChromeDocument()) {
     2775    return NSToCoordRound(emHeight * NORMAL_LINE_HEIGHT_FACTOR);
     2776  }
     2777
    27712778  switch (GetNormalLineHeightCalcControl()) {
    27722779  case eIncludeExternalLeading:
    27732780    normalLineHeight = emHeight+ internalLeading + externalLeading;
    GetNormalLineHeight(nsFontMetrics* aFontMetrics) 
    27862793}
    27872794
    27882795static inline nscoord
    2789 ComputeLineHeight(nsStyleContext* aStyleContext,
     2796ComputeLineHeight(nsIContent* aContent,
     2797                  nsStyleContext* aStyleContext,
    27902798                  nscoord aBlockBSize,
    27912799                  float aFontSizeInflation)
    27922800{
    ComputeLineHeight(nsStyleContext* aStyleContext, 
    28212829
    28222830  RefPtr<nsFontMetrics> fm = nsLayoutUtils::
    28232831    GetFontMetricsForStyleContext(aStyleContext, aFontSizeInflation);
    2824   return GetNormalLineHeight(fm);
     2832  return GetNormalLineHeight(aContent, fm);
    28252833}
    28262834
    28272835nscoord
    ReflowInput::CalcLineHeight(nsIContent* aContent, 
    28442852  NS_PRECONDITION(aStyleContext, "Must have a style context");
    28452853
    28462854  nscoord lineHeight =
    2847     ComputeLineHeight(aStyleContext, aBlockBSize, aFontSizeInflation);
     2855    ComputeLineHeight(aContent, aStyleContext, aBlockBSize, aFontSizeInflation);
    28482856
    28492857  NS_ASSERTION(lineHeight >= 0, "ComputeLineHeight screwed up");
    28502858
  • tbb-tests/mochitest.ini

    diff --git a/tbb-tests/mochitest.ini b/tbb-tests/mochitest.ini
    index 3d2e7c9db803..fca972a51211 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 000000000000..ae73a3446037
    - +  
     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), 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>