From 9bc90adc09727c65efeb2b4c547542bf9576744e Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Fri, 9 Aug 2019 00:58:55 +0000 Subject: [PATCH] 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 --- js/xpconnect/src/nsXPConnect.cpp | 18 ++++++++++++++++++ js/xpconnect/src/xpcpublic.h | 10 ++++------ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/js/xpconnect/src/nsXPConnect.cpp b/js/xpconnect/src/nsXPConnect.cpp index 794d2066a171..2eec7e719432 100644 --- a/js/xpconnect/src/nsXPConnect.cpp +++ b/js/xpconnect/src/nsXPConnect.cpp @@ -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(aData); + *aMirror = + mozilla::Preferences::GetBool(aPrefName, /* aFallback */ false); + }, + "security." + "turn_off_all_security_so_that_viruses_can_take_over_this_computer", + static_cast(aMirror)); + MOZ_RELEASE_ASSERT(NS_SUCCEEDED(rv)); +} diff --git a/js/xpconnect/src/xpcpublic.h b/js/xpconnect/src/xpcpublic.h index 4d3532f9b033..69632a7460e2 100644 --- a/js/xpconnect/src/xpcpublic.h +++ b/js/xpconnect/src/xpcpublic.h @@ -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();