Make common ChromeUtils patch

This commit is contained in:
daijro 2024-09-22 08:26:38 -05:00
parent a0e7baf1aa
commit d0ea1a297b
3 changed files with 135 additions and 127 deletions

129
patches/chromeutil.patch Normal file
View file

@ -0,0 +1,129 @@
diff --git a/dom/base/ChromeUtils.cpp b/dom/base/ChromeUtils.cpp
index 6833d2227f..d3d2ef088d 100644
--- a/dom/base/ChromeUtils.cpp
+++ b/dom/base/ChromeUtils.cpp
@@ -5,6 +5,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "ChromeUtils.h"
+#include "MaskConfig.hpp"
#include "JSOracleParent.h"
#include "js/CallAndConstruct.h" // JS::Call
@@ -2068,6 +2069,25 @@ bool ChromeUtils::IsDarkBackground(GlobalObject&, Element& aElement) {
return nsNativeTheme::IsDarkBackground(f);
}
+/* static */
+void ChromeUtils::CamouDebug(GlobalObject& aGlobal,
+ const nsAString& aVarName) {
+ if (auto value = MaskConfig::GetBool("debug");
+ value.has_value() && !value.value()) {
+ return;
+ }
+ NS_ConvertUTF16toUTF8 utf8VarName(aVarName);
+ printf_stderr("DEBUG: %s\n", utf8VarName.get());
+}
+
+bool ChromeUtils::IsCamouDebug(GlobalObject& aGlobal) {
+ if (auto value = MaskConfig::GetBool("debug");
+ value.has_value() && value.value()) {
+ return true;
+ }
+ return false;
+}
+
double ChromeUtils::DateNow(GlobalObject&) { return JS_Now() / 1000.0; }
/* static */
@@ -2094,6 +2114,28 @@ void ChromeUtils::GetAllPossibleUtilityActorNames(GlobalObject& aGlobal,
}
}
+/* static */
+int32_t ChromeUtils::CamouGetInt(GlobalObject& aGlobal,
+ const nsAString& aVarName) {
+ NS_ConvertUTF16toUTF8 utf8VarName(aVarName);
+ if (auto value = MaskConfig::GetInt32(utf8VarName.get())) {
+ return value.value();
+ }
+ return 0;
+}
+
+/* static */
+double ChromeUtils::CamouGetDouble(GlobalObject& aGlobal,
+ const nsAString& aVarName,
+ double aDefaultValue) {
+ NS_ConvertUTF16toUTF8 utf8VarName(aVarName);
+ if (auto value = MaskConfig::GetDouble(utf8VarName.get())) {
+ return value.value();
+ }
+ return aDefaultValue;
+}
+
+
/* static */
bool ChromeUtils::ShouldResistFingerprinting(
GlobalObject& aGlobal, JSRFPTarget aTarget,
diff --git a/dom/base/ChromeUtils.h b/dom/base/ChromeUtils.h
index 0150c59670..d297ab5788 100644
--- a/dom/base/ChromeUtils.h
+++ b/dom/base/ChromeUtils.h
@@ -301,6 +301,10 @@ class ChromeUtils {
static bool IsDarkBackground(GlobalObject&, Element&);
+ static void CamouDebug(GlobalObject& aGlobal, const nsAString& aVarName);
+
+ static bool IsCamouDebug(GlobalObject& aGlobal);
+
static double DateNow(GlobalObject&);
static void EnsureJSOracleStarted(GlobalObject&);
@@ -310,6 +314,11 @@ class ChromeUtils {
static void GetAllPossibleUtilityActorNames(GlobalObject& aGlobal,
nsTArray<nsCString>& aNames);
+ static int32_t CamouGetInt(GlobalObject& aGlobal, const nsAString& aVarName);
+
+ static double CamouGetDouble(GlobalObject& aGlobal, const nsAString& aVarName,
+ double aDefaultValue);
+
static bool ShouldResistFingerprinting(
GlobalObject& aGlobal, JSRFPTarget aTarget,
const Nullable<uint64_t>& aOverriddenFingerprintingSettings);
diff --git a/dom/chrome-webidl/ChromeUtils.webidl b/dom/chrome-webidl/ChromeUtils.webidl
index bf196f039d..994b5803df 100644
--- a/dom/chrome-webidl/ChromeUtils.webidl
+++ b/dom/chrome-webidl/ChromeUtils.webidl
@@ -746,6 +746,13 @@ partial namespace ChromeUtils {
*/
boolean isDarkBackground(Element element);
+ /**
+ * Camoufox debug commands
+ */
+ undefined camouDebug(DOMString varName);
+
+ boolean isCamouDebug();
+
/**
* Starts the JSOracle process for ORB JavaScript validation, if it hasn't started already.
*/
@@ -757,6 +764,16 @@ partial namespace ChromeUtils {
[ChromeOnly]
readonly attribute unsigned long aliveUtilityProcesses;
+ /**
+ * Get an int value from Camoufox MaskConfig.
+ */
+ long camouGetInt(DOMString varName);
+
+ /**
+ * Get a double value from Camoufox MaskConfig.
+ */
+ double camouGetDouble(DOMString varName, double defaultValue);
+
/**
* Get a list of all possible Utility process Actor Names ; mostly useful to
* perform testing and ensure about:processes display is sound and misses no

View file

@ -1,63 +0,0 @@
diff --git a/dom/base/ChromeUtils.cpp b/dom/base/ChromeUtils.cpp
index 71d897a0d0..2234834f3e 100644
--- a/dom/base/ChromeUtils.cpp
+++ b/dom/base/ChromeUtils.cpp
@@ -2069,6 +2069,25 @@ bool ChromeUtils::IsDarkBackground(GlobalObject&, Element& aElement) {
return nsNativeTheme::IsDarkBackground(f);
}
+/* static */
+void ChromeUtils::CamouDebug(GlobalObject& aGlobal,
+ const nsAString& aVarName) {
+ if (auto value = MaskConfig::GetBool("debug");
+ value.has_value() && !value.value()) {
+ return;
+ }
+ NS_ConvertUTF16toUTF8 utf8VarName(aVarName);
+ printf_stderr("DEBUG: %s\n", utf8VarName.get());
+}
+
+bool ChromeUtils::IsCamouDebug(GlobalObject& aGlobal) {
+ if (auto value = MaskConfig::GetBool("debug");
+ value.has_value() && value.value()) {
+ return true;
+ }
+ return false;
+}
+
double ChromeUtils::DateNow(GlobalObject&) { return JS_Now() / 1000.0; }
/* static */
diff --git a/dom/base/ChromeUtils.h b/dom/base/ChromeUtils.h
index 42b74131d6..9f151ca2e7 100644
--- a/dom/base/ChromeUtils.h
+++ b/dom/base/ChromeUtils.h
@@ -301,6 +301,10 @@ class ChromeUtils {
static bool IsDarkBackground(GlobalObject&, Element&);
+ static void CamouDebug(GlobalObject& aGlobal, const nsAString& aVarName);
+
+ static bool IsCamouDebug(GlobalObject& aGlobal);
+
static double DateNow(GlobalObject&);
static void EnsureJSOracleStarted(GlobalObject&);
diff --git a/dom/chrome-webidl/ChromeUtils.webidl b/dom/chrome-webidl/ChromeUtils.webidl
index f761be86a4..c6409bd56e 100644
--- a/dom/chrome-webidl/ChromeUtils.webidl
+++ b/dom/chrome-webidl/ChromeUtils.webidl
@@ -746,6 +746,13 @@ partial namespace ChromeUtils {
*/
boolean isDarkBackground(Element element);
+ /**
+ * Camoufox debug commands
+ */
+ undefined camouDebug(DOMString varName);
+
+ boolean isCamouDebug();
+
/**
* Starts the JSOracle process for ORB JavaScript validation, if it hasn't started already.
*/

View file

@ -1,5 +1,5 @@
diff --git a/browser/base/content/browser-init.js b/browser/base/content/browser-init.js
index f8d49ac2a3..0bf5981a2e 100644
index bee5309c04..d7fa2af364 100644
--- a/browser/base/content/browser-init.js
+++ b/browser/base/content/browser-init.js
@@ -72,7 +72,7 @@ var gBrowserInit = {
@ -11,7 +11,7 @@ index f8d49ac2a3..0bf5981a2e 100644
// When the fingerprinting resistance is enabled, making sure that we don't
// have a maximum window to interfere with generating rounded window dimensions.
document.documentElement.setAttribute("sizemode", "normal");
@@ -300,6 +300,48 @@ var gBrowserInit = {
@@ -302,6 +302,48 @@ var gBrowserInit = {
)?.removeAttribute("key");
}
@ -20,12 +20,12 @@ index f8d49ac2a3..0bf5981a2e 100644
+
+ // Hijack the outer window size
+ let outerWidth, outerHeight;
+ if ((outerWidth = ChromeUtils.camouGetConfig("window.outerWidth"))) {
+ if ((outerWidth = ChromeUtils.camouGetInt("window.outerWidth"))) {
+ document.documentElement.style.setProperty('width', outerWidth + 'px');
+ browser.style.setProperty('width', outerWidth + 'px');
+ window.resizeTo(outerWidth, window.outerHeight);
+ }
+ if ((outerHeight = ChromeUtils.camouGetConfig("window.outerHeight"))) {
+ if ((outerHeight = ChromeUtils.camouGetInt("window.outerHeight"))) {
+ document.documentElement.style.setProperty('height', outerHeight + 'px');
+ browser.style.setProperty('height', outerHeight + 'px');
+ window.resizeTo(window.outerWidth, outerHeight);
@ -33,8 +33,8 @@ index f8d49ac2a3..0bf5981a2e 100644
+ browser.style.setProperty('box-sizing', 'content-box');
+
+ // Hijack the inner window size
+ let innerWidth = ChromeUtils.camouGetConfig("window.innerWidth") || ChromeUtils.camouGetConfig("document.body.clientWidth");
+ let innerHeight = ChromeUtils.camouGetConfig("window.innerHeight") || ChromeUtils.camouGetConfig("document.body.clientHeight");
+ let innerWidth = ChromeUtils.camouGetInt("window.innerWidth") || ChromeUtils.camouGetInt("document.body.clientWidth");
+ let innerHeight = ChromeUtils.camouGetInt("window.innerHeight") || ChromeUtils.camouGetInt("document.body.clientHeight");
+
+ if (innerWidth || innerHeight) {
+ let win_inner_style = document.createElement('style');
@ -60,61 +60,3 @@ index f8d49ac2a3..0bf5981a2e 100644
this._loadHandled = true;
},
diff --git a/dom/base/ChromeUtils.cpp b/dom/base/ChromeUtils.cpp
index d412679e64..3802d9c481 100644
--- a/dom/base/ChromeUtils.cpp
+++ b/dom/base/ChromeUtils.cpp
@@ -5,6 +5,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "ChromeUtils.h"
+#include "MaskConfig.hpp"
#include "JSOracleParent.h"
#include "js/CallAndConstruct.h" // JS::Call
@@ -2077,6 +2078,16 @@ void ChromeUtils::GetAllPossibleUtilityActorNames(GlobalObject& aGlobal,
}
}
+/* static */
+int32_t ChromeUtils::CamouGetConfig(GlobalObject& aGlobal,
+ const nsAString& aVarName) {
+ NS_ConvertUTF16toUTF8 utf8VarName(aVarName);
+ if (auto value = MaskConfig::GetInt32(utf8VarName.get())) {
+ return value.value();
+ }
+ return 0;
+}
+
/* static */
bool ChromeUtils::ShouldResistFingerprinting(
GlobalObject& aGlobal, JSRFPTarget aTarget,
diff --git a/dom/base/ChromeUtils.h b/dom/base/ChromeUtils.h
index 707a04b1d3..3335f153b5 100644
--- a/dom/base/ChromeUtils.h
+++ b/dom/base/ChromeUtils.h
@@ -302,6 +302,8 @@ class ChromeUtils {
static void GetAllPossibleUtilityActorNames(GlobalObject& aGlobal,
nsTArray<nsCString>& aNames);
+ static int32_t CamouGetConfig(GlobalObject& aGlobal, const nsAString& aVarName);
+
static bool ShouldResistFingerprinting(
GlobalObject& aGlobal, JSRFPTarget aTarget,
const Nullable<uint64_t>& aOverriddenFingerprintingSettings);
diff --git a/dom/chrome-webidl/ChromeUtils.webidl b/dom/chrome-webidl/ChromeUtils.webidl
index c0a4d900d4..d23e8adaf7 100644
--- a/dom/chrome-webidl/ChromeUtils.webidl
+++ b/dom/chrome-webidl/ChromeUtils.webidl
@@ -741,6 +741,11 @@ partial namespace ChromeUtils {
[ChromeOnly]
readonly attribute unsigned long aliveUtilityProcesses;
+ /**
+ * Get the value from Camoufox MaskConfig.
+ */
+ long camouGetConfig(DOMString varName);
+
/**
* Get a list of all possible Utility process Actor Names ; mostly useful to
* perform testing and ensure about:processes display is sound and misses no