[tbb-commits] [Git][tpo/applications/tor-browser][base-browser-115.8.0esr-13.5-1] Bug 41918: Option to reuse last window size when letterboxing is enabled.

ma1 (@ma1) git at gitlab.torproject.org
Wed Mar 6 17:19:53 UTC 2024



ma1 pushed to branch base-browser-115.8.0esr-13.5-1 at The Tor Project / Applications / Tor Browser


Commits:
f3ff4275 by hackademix at 2024-03-06T18:18:16+01:00
Bug 41918: Option to reuse last window size when letterboxing is enabled.

- - - - -


6 changed files:

- browser/app/profile/001-base-profile.js
- dom/base/nsContentUtils.cpp
- dom/base/nsContentUtils.h
- toolkit/components/resistfingerprinting/RFPHelper.sys.mjs
- toolkit/components/windowwatcher/nsWindowWatcher.cpp
- xpfe/appshell/AppWindow.cpp


Changes:

=====================================
browser/app/profile/001-base-profile.js
=====================================
@@ -380,6 +380,8 @@ pref("privacy.resistFingerprinting.letterboxing", true);
 pref("privacy.resistFingerprinting.letterboxing.vcenter", true);
 // tor-browser#41917 letterboxing gradient background
 pref("privacy.resistFingerprinting.letterboxing.gradient", true);
+// tor-browser#41918: should we reuse last window sizes if letterboxing is enabled
+pref("privacy.resistFingerprinting.letterboxing.rememberSize", false);
 // tor-browser#41695: how many warnings we show if user closes them without restoring the window size
 pref("privacy.resistFingerprinting.resizeWarnings", 3);
 // tor-browser#33282: new windows start at 1400x900 when there's enough screen space, otherwise down by 200x100 blocks


=====================================
dom/base/nsContentUtils.cpp
=====================================
@@ -2663,6 +2663,18 @@ void nsContentUtils::CalcRoundedWindowSizeForResistingFingerprinting(
   *aOutputHeight = resultHeight;
 }
 
+bool nsContentUtils::ShouldRoundWindowSizeForResistingFingerprinting() {
+  return !(
+      Preferences::GetBool("privacy.resistFingerprinting.letterboxing",
+                           false) &&
+      // We want to round window size at least once in the browser's life time:
+      // AppWindow::ForceRoundedDimensions() will set this preference to true.
+      Preferences::GetBool(
+          "privacy.resistFingerprinting.letterboxing.didForceSize", false) &&
+      Preferences::GetBool(
+          "privacy.resistFingerprinting.letterboxing.rememberSize", false));
+}
+
 bool nsContentUtils::ThreadsafeIsCallerChrome() {
   return NS_IsMainThread() ? IsCallerChrome()
                            : IsCurrentThreadRunningChromeWorker();


=====================================
dom/base/nsContentUtils.h
=====================================
@@ -406,6 +406,10 @@ class nsContentUtils {
       bool aSetOuterWidth, bool aSetOuterHeight, int32_t* aOutputWidth,
       int32_t* aOutputHeight);
 
+  // Tell if we actually want to round size of new windows for RFP,
+  // depending on letterboxing status and user's preference.
+  static bool ShouldRoundWindowSizeForResistingFingerprinting();
+
   /**
    * Returns the parent node of aChild crossing document boundaries, but skips
    * any cross-process parent frames and continues with the nearest in-process


=====================================
toolkit/components/resistfingerprinting/RFPHelper.sys.mjs
=====================================
@@ -18,6 +18,8 @@ const kPrefLetterboxingVcenter =
   "privacy.resistFingerprinting.letterboxing.vcenter";
 const kPrefLetterboxingGradient =
   "privacy.resistFingerprinting.letterboxing.gradient";
+const  kPrefLetterboxingDidForceSize =
+  "privacy.resistFingerprinting.letterboxing.didForceSize";
 
 const kTopicDOMWindowOpened = "domwindowopened";
 
@@ -221,6 +223,7 @@ class _RFPHelper {
   _handlePrefChanged(data) {
     switch (data) {
       case kPrefResistFingerprinting:
+        Service.prefs.clearUserPref(kPrefLetterboxingDidForceSize);
         this._handleResistFingerprintingChanged();
         break;
       case kPrefSpoofEnglish:
@@ -228,6 +231,7 @@ class _RFPHelper {
         this._handleSpoofEnglishChanged();
         break;
       case kPrefLetterboxing:
+        Service.prefs.clearUserPref(kPrefLetterboxingDidForceSize);
       case kPrefLetterboxingVcenter:
       case kPrefLetterboxingGradient:
         this._handleLetterboxingPrefChanged();


=====================================
toolkit/components/windowwatcher/nsWindowWatcher.cpp
=====================================
@@ -2333,7 +2333,9 @@ static void SizeOpenedWindow(nsIDocShellTreeOwner* aTreeOwner,
           screenDesktopRect.Size() / screenCssToDesktopScale;
 
       if (aSizeSpec.SizeSpecified()) {
-        if (!nsContentUtils::ShouldResistFingerprinting()) {
+        if (!(nsContentUtils::ShouldResistFingerprinting() &&
+              nsContentUtils::
+                  ShouldRoundWindowSizeForResistingFingerprinting())) {
           /* Unlike position, force size out-of-bounds check only if
              size actually was specified. Otherwise, intrinsically sized
              windows are broken. */


=====================================
xpfe/appshell/AppWindow.cpp
=====================================
@@ -1123,8 +1123,9 @@ NS_IMETHODIMP AppWindow::GetAvailScreenSize(int32_t* aAvailWidth,
   return NS_OK;
 }
 
-// Rounds window size to 1000x1000, or, if there isn't enough available
-// screen space, to a multiple of 200x100.
+// Rounds window size to privacy.window.maxInnerWidth x
+// privacy.window.maxInnerWidth, or, if there isn't enough available screen
+// space, to a multiple of 200x100.
 NS_IMETHODIMP AppWindow::ForceRoundedDimensions() {
   if (mIsHiddenWindow) {
     return NS_OK;
@@ -1164,6 +1165,11 @@ NS_IMETHODIMP AppWindow::ForceRoundedDimensions() {
 
   SetPrimaryContentSize(targetSizeDev.width, targetSizeDev.height);
 
+  // Ensure we force initial rounded size at least once, as checked by
+  // nsContentUtils::ShouldRoundWindowSizeForResistingFingerprinting().
+  Preferences::SetBool("privacy.resistFingerprinting.letterboxing.didForceSize",
+                       true);
+
   return NS_OK;
 }
 
@@ -2703,7 +2709,8 @@ void AppWindow::SizeShell() {
   if (nsContentUtils::ShouldResistFingerprinting(
           "if RFP is enabled we want to round the dimensions of the new"
           "new pop up window regardless of their origin") &&
-      windowType.EqualsLiteral("navigator:browser")) {
+      windowType.EqualsLiteral("navigator:browser") &&
+      nsContentUtils::ShouldRoundWindowSizeForResistingFingerprinting()) {
     // Once we've got primary content, force dimensions.
     if (mPrimaryContentShell || mPrimaryBrowserParent) {
       ForceRoundedDimensions();



View it on GitLab: https://gitlab.torproject.org/tpo/applications/tor-browser/-/commit/f3ff4275741c8dad01032cae7633399d9807d5fa

-- 
View it on GitLab: https://gitlab.torproject.org/tpo/applications/tor-browser/-/commit/f3ff4275741c8dad01032cae7633399d9807d5fa
You're receiving this email because of your account on gitlab.torproject.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.torproject.org/pipermail/tbb-commits/attachments/20240306/1a5d374e/attachment-0001.htm>


More information about the tbb-commits mailing list