commit 2e90d2ad087712c8798f9824311c9be8e74d23c7
parent b80e26a6f9420ab9c430915cd576c030c1259b81
Author: hackademix <giorgio@maone.net>
Date: Wed, 6 Mar 2024 14:15:53 +0100
BB 41918: Option to reuse last window size when letterboxing is enabled.
Diffstat:
7 files changed, 45 insertions(+), 5 deletions(-)
diff --git a/browser/app/profile/001-base-profile.js b/browser/app/profile/001-base-profile.js
@@ -482,6 +482,8 @@ pref("privacy.resistFingerprinting.randomDataOnCanvasExtract", true, locked);
pref("privacy.resistFingerprinting", true);
pref("privacy.resistFingerprinting.exemptedDomains", "");
#endif
+// tor-browser#43904: Enable this so we skip the blank window if user is resisting fingerprinting.
+pref("privacy.resistFingerprinting.skipEarlyBlankFirstPaint", true);
// tor-browser#18603: failIfMajorPerformanceCaveat is an optional attribute that
// can be used when creating a WebGL context if the browser detects that the
// performance would be low. That could be used to fingerpting users with a not
@@ -525,6 +527,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#43402: Avoid a resize from the skeleton to the newwin size.
// Should be fixed in ESR-140 with Bug 1448423.
pref("browser.startup.blankWindow", false);
diff --git a/dom/base/nsContentUtils.cpp b/dom/base/nsContentUtils.cpp
@@ -3030,6 +3030,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();
diff --git a/dom/base/nsContentUtils.h b/dom/base/nsContentUtils.h
@@ -422,6 +422,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
diff --git a/toolkit/components/resistfingerprinting/RFPHelper.sys.mjs b/toolkit/components/resistfingerprinting/RFPHelper.sys.mjs
@@ -18,6 +18,10 @@ const kPrefLetterboxingTesting =
"privacy.resistFingerprinting.letterboxing.testing";
const kPrefLetterboxingVcenter =
"privacy.resistFingerprinting.letterboxing.vcenter";
+const kPrefLetterboxingDidForceSize =
+ "privacy.resistFingerprinting.letterboxing.didForceSize";
+const kPrefLetterboxingRememberSize =
+ "privacy.resistFingerprinting.letterboxing.rememberSize";
const kTopicDOMWindowOpened = "domwindowopened";
const kTopicDOMWindowClosed = "domwindowclosed";
@@ -178,6 +182,7 @@ class _RFPHelper {
_handlePrefChanged(data) {
switch (data) {
case kPrefResistFingerprinting:
+ Services.prefs.clearUserPref(kPrefLetterboxingDidForceSize);
this._handleResistFingerprintingChanged();
break;
case kPrefSpoofEnglish:
@@ -185,6 +190,8 @@ class _RFPHelper {
this._handleSpoofEnglishChanged();
break;
case kPrefLetterboxing:
+ Services.prefs.clearUserPref(kPrefLetterboxingDidForceSize);
+ // fall-through
case kPrefLetterboxingVcenter:
this._handleLetterboxingPrefChanged();
break;
@@ -1114,7 +1121,10 @@ class _RFPHelper {
}
_fixRounding(aWindow) {
- if (!this.rfpEnabled) {
+ if (
+ !this.rfpEnabled ||
+ Services.prefs.getBoolPref(kPrefLetterboxingRememberSize, false)
+ ) {
return;
}
diff --git a/toolkit/components/windowwatcher/nsWindowWatcher.cpp b/toolkit/components/windowwatcher/nsWindowWatcher.cpp
@@ -2422,7 +2422,8 @@ static void SizeOpenedWindow(nsIDocShellTreeOwner* aTreeOwner,
"complicated, and this is a conservative behavior to avoid "
"exempting something that shouldn't be. It also presents a "
"uniform behavior for something that's very browser-related.",
- RFPTarget::RoundWindowSize)) {
+ RFPTarget::RoundWindowSize) &&
+ nsContentUtils::ShouldRoundWindowSizeForResistingFingerprinting()) {
/* Unlike position, force size out-of-bounds check only if
size actually was specified. Otherwise, intrinsically sized
windows are broken. */
diff --git a/toolkit/xre/nsAppRunner.cpp b/toolkit/xre/nsAppRunner.cpp
@@ -291,6 +291,7 @@ static const char kPrefThemeId[] = "extensions.activeThemeID";
static const char kPrefBrowserStartupBlankWindow[] =
"browser.startup.blankWindow";
static const char kPrefPreXulSkeletonUI[] = "browser.startup.preXulSkeletonUI";
+static const char kPrefResistFingerprinting[] = "privacy.resistFingerprinting";
#endif // defined(XP_WIN)
#if defined(MOZ_WIDGET_GTK)
@@ -2313,6 +2314,7 @@ static void ReflectSkeletonUIPrefToRegistry(const char* aPref, void* aData) {
!mProfileSvc->HasShowProfileSelector() &&
Preferences::GetBool(kPrefPreXulSkeletonUI, false) &&
Preferences::GetBool(kPrefBrowserStartupBlankWindow, false) &&
+ !Preferences::GetBool(kPrefResistFingerprinting, false) &&
LookAndFeel::DrawInTitlebar();
if (shouldBeEnabled && Preferences::HasUserValue(kPrefThemeId)) {
nsCString themeId;
diff --git a/xpfe/appshell/AppWindow.cpp b/xpfe/appshell/AppWindow.cpp
@@ -1039,8 +1039,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;
@@ -1080,6 +1081,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;
}
@@ -2488,7 +2494,8 @@ void AppWindow::SizeShell() {
"if RFP is enabled we want to round the dimensions of the new"
"new pop up window regardless of their origin",
RFPTarget::RoundWindowSize) &&
- windowType.EqualsLiteral("navigator:browser")) {
+ windowType.EqualsLiteral("navigator:browser") &&
+ nsContentUtils::ShouldRoundWindowSizeForResistingFingerprinting()) {
// Once we've got primary content, force dimensions.
if (mPrimaryContentShell || mPrimaryBrowserParent) {
ForceRoundedDimensions();