Pier Angelo Vendrame pushed to branch base-browser-128.7.0esr-14.5-1 at The Tor Project / Applications / Tor Browser
Commits: c7cc05f5 by Pier Angelo Vendrame at 2025-02-27T10:35:32+01:00 fixup! BB 32308: Use direct browser sizing for letterboxing.
When the dimension is less than 50px, we need to return dimension itself, rather than a 0px margin.
- - - - - 7a9352a7 by Pier Angelo Vendrame at 2025-02-27T10:35:35+01:00 fixup! BB 41631: Prevent weird initial window dimensions caused by subpixel computations
BB 43205: Fix newwin rounding.
RFP might produce bad rounding because of platform-specific bugs. Solving them might involve a refactor that is out of our capacity, therefore we add a JS patch to fix wrong sizes.
- - - - - c2980c01 by Pier Angelo Vendrame at 2025-02-27T10:35:35+01:00 fixup! BB 41918: Option to reuse last window size when letterboxing is enabled.
BB 43205: Fix newwin rounding.
Do not fix sizes when remember last size is enabled.
- - - - -
1 changed file:
- toolkit/components/resistfingerprinting/RFPHelper.sys.mjs
Changes:
===================================== toolkit/components/resistfingerprinting/RFPHelper.sys.mjs ===================================== @@ -4,6 +4,7 @@ * You can obtain one at https://mozilla.org/MPL/2.0/. */
import { XPCOMUtils } from "resource://gre/modules/XPCOMUtils.sys.mjs"; +import { AppConstants } from "resource://gre/modules/AppConstants.sys.mjs"; import * as constants from "resource://gre/modules/RFPTargetConstants.sys.mjs";
const kPrefResistFingerprinting = "privacy.resistFingerprinting"; @@ -21,6 +22,8 @@ const kPrefLetterboxingGradient = "privacy.resistFingerprinting.letterboxing.gradient"; const kPrefLetterboxingDidForceSize = "privacy.resistFingerprinting.letterboxing.didForceSize"; +const kPrefLetterboxingRememberSize = + "privacy.resistFingerprinting.letterboxing.rememberSize";
const kTopicDOMWindowOpened = "domwindowopened";
@@ -519,22 +522,23 @@ class _RFPHelper { } }
+ stepping(aDimension, aIsWidth) { + if (aDimension <= 500) { + return 50; + } else if (aDimension <= 1600) { + return aIsWidth ? 200 : 100; + } + return 200; + } + /** * Given a width or height, rounds it with the proper stepping. */ steppedSize(aDimension, aIsWidth = false) { - let stepping; if (aDimension <= 50) { - return 0; - } else if (aDimension <= 500) { - stepping = 50; - } else if (aDimension <= 1600) { - stepping = aIsWidth ? 200 : 100; - } else { - stepping = 200; + return aDimension; } - - return aDimension - (aDimension % stepping); + return aDimension - (aDimension % this.stepping(aDimension, aIsWidth)); }
/** @@ -806,6 +810,7 @@ class _RFPHelper { }
_attachWindow(aWindow) { + this._fixRounding(aWindow); aWindow.addEventListener("sizemodechange", windowResizeHandler); aWindow.shrinkToLetterbox = this.shrinkToLetterbox; aWindow.addEventListener("dblclick", this._onWindowDoubleClick); @@ -865,6 +870,52 @@ class _RFPHelper { ); }
+ _fixRounding(aWindow) { + if ( + !this.rfpEnabled || + Services.prefs.getBoolPref(kPrefLetterboxingRememberSize, false) + ) { + return; + } + + // tor-browser#43205: in case of subpixels, new windows might have a wrong + // size because of platform-specific bugs (e.g., Bug 1947439 on Windows). + const contentContainer = aWindow.document.getElementById("browser"); + const rect = contentContainer.getBoundingClientRect(); + const steppingWidth = this.stepping(rect.width, true); + const steppingHeight = this.stepping(rect.height, false); + const deltaWidth = + rect.width - steppingWidth * Math.round(rect.width / steppingWidth); + const deltaHeight = + rect.height - steppingHeight * Math.round(rect.height / steppingHeight); + + // It seems that under X11, a window cannot have all the possible (integer) + // sizes (see the videos on tor-browser#43205 and Bug 1947439)... + // We observed this behavior with 1.25 scaling, but we could not find + // where it happens exactly, so this code might be wrong. + // On the same system, this problem does not happen with Wayland. + if (AppConstants.platform === "linux") { + let targetWidth = aWindow.outerWidth - deltaWidth; + let targetHeight = aWindow.outerHeight - deltaHeight; + const x11Size = s => + Math.floor( + // This first rounding is done by Gecko, rather than X11. + Math.round(s * aWindow.devicePixelRatio) / aWindow.devicePixelRatio + ); + const x11Width = x11Size(targetWidth); + const x11Height = x11Size(targetHeight); + if (x11Width < targetWidth) { + targetWidth = x11Width + 2; + } + if (x11Height < targetHeight) { + targetHeight = x11Height + 2; + } + aWindow.resizeTo(targetWidth, targetHeight); + } else { + aWindow.resizeBy(deltaWidth, deltaHeight); + } + } + getTargets() { return constants.Targets; }
View it on GitLab: https://gitlab.torproject.org/tpo/applications/tor-browser/-/compare/20e649a...
tbb-commits@lists.torproject.org