brizental pushed to branch tor-browser-153.4.0esr-16.0-1 at The Tor Project / Applications / Tor Browser

Commits:

1 changed file:

Changes:

  • toolkit/components/resistfingerprinting/RFPHelper.sys.mjs
    ... ... @@ -10,6 +10,9 @@ const kPrefResistFingerprinting = "privacy.resistFingerprinting";
    10 10
     const kPrefSpoofEnglish = "privacy.spoof_english";
    
    11 11
     const kTopicHttpOnModifyRequest = "http-on-modify-request";
    
    12 12
     
    
    13
    +// The original (rounded) size of each window, recorded when it was ready.
    
    14
    +const originalWindowSizes = new WeakMap();
    
    15
    +
    
    13 16
     const kPrefLetterboxing = "privacy.resistFingerprinting.letterboxing";
    
    14 17
     const kPrefLetterboxingDimensions =
    
    15 18
       "privacy.resistFingerprinting.letterboxing.dimensions";
    
    ... ... @@ -29,6 +32,9 @@ const kPrefVerticalTabs = "sidebar.verticalTabs";
    29 32
     
    
    30 33
     const kPrefResizeWarnings = "privacy.resistFingerprinting.resizeWarnings";
    
    31 34
     
    
    35
    +// Timeouts that hide the letterboxing size status, keyed by window.
    
    36
    +const letterboxingStatusTimeouts = new WeakMap();
    
    37
    +
    
    32 38
     const lazy = {};
    
    33 39
     
    
    34 40
     ChromeUtils.defineESModuleGetters(lazy, {
    
    ... ... @@ -113,9 +119,9 @@ async function windowResizeHandler(aEvent) {
    113 119
             // reset notification timer to work-around resize race conditions
    
    114 120
             windowResizeHandler.timestamp = Date.now();
    
    115 121
             // restore the original (rounded) size we had stored on window startup
    
    116
    -        let { _rfpOriginalSize } = window;
    
    122
    +        let originalSize = originalWindowSizes.get(window);
    
    117 123
             window.setTimeout(() => {
    
    118
    -          window.resizeTo(_rfpOriginalSize.width, _rfpOriginalSize.height);
    
    124
    +          window.resizeTo(originalSize.width, originalSize.height);
    
    119 125
             }, 0);
    
    120 126
           },
    
    121 127
         },
    
    ... ... @@ -567,16 +573,17 @@ class _RFPHelper {
    567 573
           ])
    
    568 574
         );
    
    569 575
     
    
    576
    +    const originalSize = originalWindowSizes.get(win);
    
    570 577
         const isInitialSize =
    
    571
    -      win._rfpOriginalSize &&
    
    572
    -      win.outerWidth === win._rfpOriginalSize.width &&
    
    573
    -      win.outerHeight === win._rfpOriginalSize.height;
    
    578
    +      originalSize &&
    
    579
    +      win.outerWidth === originalSize.width &&
    
    580
    +      win.outerHeight === originalSize.height;
    
    574 581
     
    
    575 582
         // We may need to shrink this window to rounded size if the browser container
    
    576 583
         // area is taller than the original, meaning extra chrome (like the optional
    
    577 584
         // "Only Show on New Tab" bookmarks toobar) was present and now gone.
    
    578 585
         const needToShrink =
    
    579
    -      isInitialSize && containerHeight > win._rfpOriginalSize.containerHeight;
    
    586
    +      isInitialSize && containerHeight > originalSize.containerHeight;
    
    580 587
     
    
    581 588
         log(
    
    582 589
           `${logPrefix} contentWidth=${contentWidth} contentHeight=${contentHeight} parentWidth=${parentWidth} parentHeight=${parentHeight} containerWidth=${containerWidth} containerHeight=${containerHeight}${
    
    ... ... @@ -664,7 +671,7 @@ class _RFPHelper {
    664 671
                   lazy.logConsole.error(e);
    
    665 672
                 }
    
    666 673
               }
    
    667
    -          if (needToShrink && win.shrinkToLetterbox()) {
    
    674
    +          if (needToShrink && RFPHelper.shrinkToLetterbox(win)) {
    
    668 675
                 win.addEventListener(
    
    669 676
                   "resize",
    
    670 677
                   () => {
    
    ... ... @@ -739,8 +746,11 @@ class _RFPHelper {
    739 746
                 browserParent.classList.add(clazz);
    
    740 747
               }
    
    741 748
               updateStatus(lastRoundedSize);
    
    742
    -          win.clearTimeout(win._letterboxingStatusTimeout);
    
    743
    -          win._letterboxingStatusTimeout = win.setTimeout(updateStatus, 1000);
    
    749
    +          win.clearTimeout(letterboxingStatusTimeouts.get(win));
    
    750
    +          letterboxingStatusTimeouts.set(
    
    751
    +            win,
    
    752
    +            win.setTimeout(updateStatus, 1000)
    
    753
    +          );
    
    744 754
             } else {
    
    745 755
               updateStatus("");
    
    746 756
             }
    
    ... ... @@ -808,7 +818,7 @@ class _RFPHelper {
    808 818
         // maximized.
    
    809 819
         aWindow.setTimeout(() => {
    
    810 820
           tabBrowser.tabbox.classList.add("letterboxing-ready");
    
    811
    -      if (!aWindow._rfpOriginalSize) {
    
    821
    +      if (!originalWindowSizes.has(aWindow)) {
    
    812 822
             this._recordWindowSize(aWindow);
    
    813 823
           }
    
    814 824
         });
    
    ... ... @@ -816,26 +826,26 @@ class _RFPHelper {
    816 826
     
    
    817 827
       _recordWindowSize(aWindow) {
    
    818 828
         aWindow.promiseDocumentFlushed(() => {
    
    819
    -      aWindow._rfpOriginalSize = {
    
    829
    +      const size = {
    
    820 830
             width: aWindow.outerWidth,
    
    821 831
             height: aWindow.outerHeight,
    
    822 832
             containerHeight: aWindow.gBrowser.getBrowserContainer()?.clientHeight,
    
    823 833
           };
    
    824
    -      log("Recording original window size", aWindow._rfpOriginalSize);
    
    834
    +      originalWindowSizes.set(aWindow, size);
    
    835
    +      log("Recording original window size", size);
    
    825 836
         });
    
    826 837
       }
    
    827 838
     
    
    828
    -  // We will attach this method to each browser window. When called
    
    829
    -  // it will instantly resize the window to exactly fit the selected
    
    830
    -  // (possibly letterboxed) browser.
    
    839
    +  // Instantly resize the window to exactly fit the selected (possibly
    
    840
    +  // letterboxed) browser.
    
    831 841
       // Returns true if a window resize will occur, false otherwise.
    
    832
    -  shrinkToLetterbox() {
    
    833
    -    let { selectedBrowser } = this.gBrowser;
    
    842
    +  shrinkToLetterbox(aWindow) {
    
    843
    +    let { selectedBrowser } = aWindow.gBrowser;
    
    834 844
         let stack = selectedBrowser.closest(".browserStack");
    
    835 845
         const outer = stack.getBoundingClientRect();
    
    836 846
         const inner = selectedBrowser.getBoundingClientRect();
    
    837 847
         if (inner.width !== outer.witdh || inner.height !== outer.height) {
    
    838
    -      this.resizeBy(inner.width - outer.width, inner.height - outer.height);
    
    848
    +      aWindow.resizeBy(inner.width - outer.width, inner.height - outer.height);
    
    839 849
           return true;
    
    840 850
         }
    
    841 851
         return false;
    
    ... ... @@ -843,14 +853,13 @@ class _RFPHelper {
    843 853
     
    
    844 854
       _onWindowDoubleClick(e) {
    
    845 855
         if (e.target.classList.contains("browserStack")) {
    
    846
    -      e.currentTarget.shrinkToLetterbox();
    
    856
    +      RFPHelper.shrinkToLetterbox(e.currentTarget);
    
    847 857
         }
    
    848 858
       }
    
    849 859
     
    
    850 860
       _attachWindow(aWindow) {
    
    851 861
         this._fixRounding(aWindow);
    
    852 862
         aWindow.addEventListener("sizemodechange", windowResizeHandler);
    
    853
    -    aWindow.shrinkToLetterbox = this.shrinkToLetterbox;
    
    854 863
         aWindow.addEventListener("dblclick", this._onWindowDoubleClick);
    
    855 864
         aWindow.gBrowser.addTabsProgressListener(this);
    
    856 865
         aWindow.addEventListener("TabOpen", this);
    
    ... ... @@ -1203,7 +1212,6 @@ class _RFPHelper {
    1203 1212
           this._resetContentSize(browser);
    
    1204 1213
         }
    
    1205 1214
         aWindow.removeEventListener("dblclick", this._onWindowDoubleClick);
    
    1206
    -    delete aWindow.shrinkToLetterbox;
    
    1207 1215
         aWindow.removeEventListener("sizemodechange", windowResizeHandler);
    
    1208 1216
     
    
    1209 1217
         aWindow.removeEventListener("nativethemechange", this);