diff --git a/dom/base/ChromeUtils.cpp b/dom/base/ChromeUtils.cpp index 52f0af76ec..2a7a9ae4fc 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 "ThirdPartyUtil.h" @@ -2414,6 +2416,24 @@ 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 */ @@ -2440,6 +2440,65 @@ 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::CamouGetBool(GlobalObject& aGlobal, const nsAString& aVarName, + bool aDefaultValue) { + NS_ConvertUTF16toUTF8 utf8VarName(aVarName); + if (auto value = MaskConfig::GetBool(utf8VarName.get())) { + return value.value(); + } + return aDefaultValue; +} + +/* static */ +void ChromeUtils::CamouGetString(GlobalObject& aGlobal, + const nsAString& aVarName, + nsAString& aRetVal) { + NS_ConvertUTF16toUTF8 utf8VarName(aVarName); + if (auto value = MaskConfig::GetString(utf8VarName.get())) { + aRetVal.Assign(NS_ConvertUTF8toUTF16(value.value())); + } else { + aRetVal.Truncate(); + } +} + +/* static */ +void ChromeUtils::CamouGetStringList(GlobalObject& aGlobal, + const nsAString& aVarName, + nsTArray& aRetVal) { + NS_ConvertUTF16toUTF8 utf8VarName(aVarName); + if (auto values = MaskConfig::GetStringList(utf8VarName.get()); + !values.empty()) { + aRetVal.Clear(); + for (const auto& str : values) { + aRetVal.AppendElement(NS_ConvertUTF8toUTF16(str)); + } + return; + } + aRetVal.Clear(); +} + /* static */ bool ChromeUtils::ShouldResistFingerprinting( GlobalObject& aGlobal, JSRFPTarget aTarget, diff --git a/dom/base/ChromeUtils.h b/dom/base/ChromeUtils.h index 138b9c3f80..c7c7ce74bf 100644 --- a/dom/base/ChromeUtils.h +++ b/dom/base/ChromeUtils.h @@ -305,6 +305,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&); @@ -314,6 +314,20 @@ class ChromeUtils { static void GetAllPossibleUtilityActorNames(GlobalObject& aGlobal, nsTArray& aNames); + static int32_t CamouGetInt(GlobalObject& aGlobal, const nsAString& aVarName); + + static double CamouGetDouble(GlobalObject& aGlobal, const nsAString& aVarName, + double aDefaultValue); + + static bool CamouGetBool(GlobalObject& aGlobal, const nsAString& aVarName, + bool aDefaultValue); + + static void CamouGetString(GlobalObject& aGlobal, const nsAString& aVarName, + nsAString& aRetVal); + + static void CamouGetStringList(GlobalObject& aGlobal, const nsAString& aVarName, + nsTArray& aRetVal); + static bool ShouldResistFingerprinting( GlobalObject& aGlobal, JSRFPTarget aTarget, const Nullable& aOverriddenFingerprintingSettings); diff --git a/dom/chrome-webidl/ChromeUtils.webidl b/dom/chrome-webidl/ChromeUtils.webidl index 6a99703db1..82415eba19 100644 --- a/dom/chrome-webidl/ChromeUtils.webidl +++ b/dom/chrome-webidl/ChromeUtils.webidl @@ -750,6 +750,13 @@ partial namespace ChromeUtils { */ boolean isDarkBackground(Element element); + /** + * Omegafox debug commands + */ + undefined camouDebug(DOMString varName); + + boolean isCamouDebug(); + /** * Starts the JSOracle process for ORB JavaScript validation, if it hasn't started already. */ @@ -761,6 +768,31 @@ partial namespace ChromeUtils { [ChromeOnly] readonly attribute unsigned long aliveUtilityProcesses; + /** + * Get an int value from Omegafox MaskConfig. + */ + long camouGetInt(DOMString varName); + + /** + * Get a double value from Omegafox MaskConfig. + */ + double camouGetDouble(DOMString varName, double defaultValue); + + /** + * Get a bool value from Omegafox MaskConfig. + */ + boolean camouGetBool(DOMString varName, boolean defaultValue); + + /** + * Get a string value from Omegafox MaskConfig. + */ + DOMString camouGetString(DOMString varName); + + /** + * Get a list of strings from Omegafox MaskConfig. + */ + sequence camouGetStringList(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