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


Commits:
334c638e by hackademix at 2024-04-16T17:24:54+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/334c638e5c21a40441674c8ffc1fadbbaff3e67d

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


_______________________________________________
tor-commits mailing list
tor-commits@lists.torproject.org
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits

Reply via email to