Bug 1570212 - Make security.turn_off_all_security... a non-VarCache pref. r=mccr8

This could be made into a static pref, but then it would be always defined and
thus visible in about:config, which seems undesirable for such a senstive pre.
So this patch uses a callback that makes it work just like the existing
VarCache, i.e. it's not defined by default, in which case it defaults to false.

Differential Revision: https://phabricator.services.mozilla.com/D40343

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Nicholas Nethercote 2019-08-09 00:58:55 +00:00
parent f6e8f9fa92
commit 9bc90adc09
2 changed files with 22 additions and 6 deletions

View File

@ -1210,3 +1210,21 @@ void xpc::YieldCooperativeContext() {
void xpc::ResumeCooperativeContext() {
JS_ResumeCooperativeContext(XPCJSContext::Get()->Context());
}
void xpc::CacheAutomationPref(bool* aMirror) {
// The obvious thing is to make this pref a static pref. But then it would
// always be defined and always show up in about:config, and users could flip
// it, which we don't want. Instead we roll our own callback so that if the
// pref is undefined (the normal case) then sAutomationPrefIsSet is false and
// nothing shows up in about:config.
nsresult rv = mozilla::Preferences::RegisterCallbackAndCall(
[](const char* aPrefName, void* aData) {
auto aMirror = static_cast<bool*>(aData);
*aMirror =
mozilla::Preferences::GetBool(aPrefName, /* aFallback */ false);
},
"security."
"turn_off_all_security_so_that_viruses_can_take_over_this_computer",
static_cast<void*>(aMirror));
MOZ_RELEASE_ASSERT(NS_SUCCEEDED(rv));
}

View File

@ -679,15 +679,13 @@ inline bool AreNonLocalConnectionsDisabled() {
return disabledForTest;
}
void CacheAutomationPref(bool* aPref);
inline bool IsInAutomation() {
static bool sAutomationPrefIsSet;
static bool sAutomationPrefIsSet = false;
static bool sPrefCacheAdded = false;
if (!sPrefCacheAdded) {
mozilla::Preferences::AddBoolVarCache(
&sAutomationPrefIsSet,
"security.turn_off_all_security_so_that_viruses_can_take_over_this_"
"computer",
false);
CacheAutomationPref(&sAutomationPrefIsSet);
sPrefCacheAdded = true;
}
return sAutomationPrefIsSet && AreNonLocalConnectionsDisabled();