[tbb-commits] [Git][tpo/applications/tor-browser][base-browser-115.10.0esr-13.5-1] fixup! Bug 41631: Prevent weird initial window dimensions caused by subpixel computations

ma1 (@ma1) git at gitlab.torproject.org
Tue Apr 16 20:18:02 UTC 2024



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


Commits:
97575530 by hackademix at 2024-04-16T22:17:42+02:00
fixup! Bug 41631: Prevent weird initial window dimensions caused by subpixel computations

Bug 42520: Correctly record new initial window size after auto-shrinking

- - - - -


1 changed file:

- toolkit/components/resistfingerprinting/RFPHelper.sys.mjs


Changes:

=====================================
toolkit/components/resistfingerprinting/RFPHelper.sys.mjs
=====================================
@@ -633,9 +633,16 @@ class _RFPHelper {
               lazy.logConsole.error(e);
             }
           }
-          if (needToShrink) {
-            win.shrinkToLetterbox();
-            this._recordWindowSize(win);
+          if (needToShrink && win.shrinkToLetterbox()) {
+            win.addEventListener(
+              "resize",
+              () => {
+                // We need to record the "new" initial size in this listener
+                // because resized dimensions are not immediately available.
+                RFPHelper._recordWindowSize(win);
+              },
+              { once: true }
+            );
           }
         });
       },
@@ -741,23 +748,30 @@ class _RFPHelper {
   }
 
   _recordWindowSize(aWindow) {
-    aWindow._rfpOriginalSize = {
-      width: aWindow.outerWidth,
-      height: aWindow.outerHeight,
-      containerHeight: aWindow.gBrowser.getBrowserContainer()?.clientHeight,
-    };
-    log("Recording original window size", aWindow._rfpOriginalSize);
+    aWindow.promiseDocumentFlushed(() => {
+      aWindow._rfpOriginalSize = {
+        width: aWindow.outerWidth,
+        height: aWindow.outerHeight,
+        containerHeight: aWindow.gBrowser.getBrowserContainer()?.clientHeight,
+      };
+      log("Recording original window size", aWindow._rfpOriginalSize);
+    });
   }
 
   // We will attach this method to each browser window. When called
   // it will instantly resize the window to exactly fit the selected
   // (possibly letterboxed) browser.
+  // Returns true if a window resize will occur, false otherwise.
   shrinkToLetterbox() {
     let { selectedBrowser } = this.gBrowser;
     let stack = selectedBrowser.closest(".browserStack");
     const outer = stack.getBoundingClientRect();
     const inner = selectedBrowser.getBoundingClientRect();
-    this.resizeBy(inner.width - outer.width, inner.height - outer.height);
+    if (inner.width !== outer.witdh || inner.height !== outer.height) {
+      this.resizeBy(inner.width - outer.width, inner.height - outer.height);
+      return true;
+    }
+    return false;
   }
 
   _onWindowDoubleClick(e) {



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

-- 
View it on GitLab: https://gitlab.torproject.org/tpo/applications/tor-browser/-/commit/9757553093631c9142890b0b35f7b4927d70999b
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/20240416/b2151e01/attachment-0001.htm>


More information about the tbb-commits mailing list