--- a/modules/libpref/Preferences.cpp
+++ b/modules/libpref/Preferences.cpp
@@ -4612,76 +4612,92 @@ Preferences::GetLocalizedString(const ch
/* static */ nsresult
Preferences::GetComplex(const char* aPref, const nsIID& aType, void** aResult)
{
NS_ENSURE_TRUE(InitStaticMembers(), NS_ERROR_NOT_AVAILABLE);
return sPreferences->mRootBranch->GetComplexValue(aPref, aType, aResult);
}
/* static */ nsresult
-Preferences::SetCString(const char* aPref, const char* aValue)
+Preferences::SetCString(const char* aPrefName,
+ const char* aValue,
+ PrefValueKind aKind)
{
- ENSURE_MAIN_PROCESS("SetCString", aPref);
+ ENSURE_MAIN_PROCESS("SetCString", aPrefName);
NS_ENSURE_TRUE(InitStaticMembers(), NS_ERROR_NOT_AVAILABLE);
- return PREF_SetCStringPref(aPref, nsDependentCString(aValue), false);
+ return PREF_SetCStringPref(
+ aPrefName, nsDependentCString(aValue), aKind == PrefValueKind::Default);
}
/* static */ nsresult
-Preferences::SetCString(const char* aPref, const nsACString& aValue)
+Preferences::SetCString(const char* aPrefName,
+ const nsACString& aValue,
+ PrefValueKind aKind)
{
- ENSURE_MAIN_PROCESS("SetCString", aPref);
+ ENSURE_MAIN_PROCESS("SetCString", aPrefName);
NS_ENSURE_TRUE(InitStaticMembers(), NS_ERROR_NOT_AVAILABLE);
- return PREF_SetCStringPref(aPref, aValue, false);
+ return PREF_SetCStringPref(
+ aPrefName, aValue, aKind == PrefValueKind::Default);
}
/* static */ nsresult
-Preferences::SetString(const char* aPref, const char16ptr_t aValue)
+Preferences::SetString(const char* aPrefName,
+ const char16ptr_t aValue,
+ PrefValueKind aKind)
{
- ENSURE_MAIN_PROCESS("SetString", aPref);
+ ENSURE_MAIN_PROCESS("SetString", aPrefName);
NS_ENSURE_TRUE(InitStaticMembers(), NS_ERROR_NOT_AVAILABLE);
- return PREF_SetCStringPref(aPref, NS_ConvertUTF16toUTF8(aValue), false);
+ return PREF_SetCStringPref(
+ aPrefName, NS_ConvertUTF16toUTF8(aValue), aKind == PrefValueKind::Default);
}
/* static */ nsresult
-Preferences::SetString(const char* aPref, const nsAString& aValue)
+Preferences::SetString(const char* aPrefName,
+ const nsAString& aValue,
+ PrefValueKind aKind)
{
- ENSURE_MAIN_PROCESS("SetString", aPref);
+ ENSURE_MAIN_PROCESS("SetString", aPrefName);
NS_ENSURE_TRUE(InitStaticMembers(), NS_ERROR_NOT_AVAILABLE);
- return PREF_SetCStringPref(aPref, NS_ConvertUTF16toUTF8(aValue), false);
+ return PREF_SetCStringPref(
+ aPrefName, NS_ConvertUTF16toUTF8(aValue), aKind == PrefValueKind::Default);
}
/* static */ nsresult
-Preferences::SetBool(const char* aPref, bool aValue)
+Preferences::SetBool(const char* aPrefName, bool aValue, PrefValueKind aKind)
{
- ENSURE_MAIN_PROCESS("SetBool", aPref);
+ ENSURE_MAIN_PROCESS("SetBool", aPrefName);
NS_ENSURE_TRUE(InitStaticMembers(), NS_ERROR_NOT_AVAILABLE);
- return PREF_SetBoolPref(aPref, aValue, false);
+ return PREF_SetBoolPref(aPrefName, aValue, aKind == PrefValueKind::Default);
}
/* static */ nsresult
-Preferences::SetInt(const char* aPref, int32_t aValue)
+Preferences::SetInt(const char* aPrefName, int32_t aValue, PrefValueKind aKind)
{
- ENSURE_MAIN_PROCESS("SetInt", aPref);
+ ENSURE_MAIN_PROCESS("SetInt", aPrefName);
NS_ENSURE_TRUE(InitStaticMembers(), NS_ERROR_NOT_AVAILABLE);
- return PREF_SetIntPref(aPref, aValue, false);
+ return PREF_SetIntPref(aPrefName, aValue, aKind == PrefValueKind::Default);
}
/* static */ nsresult
-Preferences::SetFloat(const char* aPref, float aValue)
+Preferences::SetFloat(const char* aPrefName, float aValue, PrefValueKind aKind)
{
- return SetCString(aPref, nsPrintfCString("%f", aValue).get());
+ return SetCString(aPrefName, nsPrintfCString("%f", aValue).get(), aKind);
}
/* static */ nsresult
-Preferences::SetComplex(const char* aPref,
+Preferences::SetComplex(const char* aPrefName,
const nsIID& aType,
- nsISupports* aValue)
+ nsISupports* aValue,
+ PrefValueKind aKind)
{
NS_ENSURE_TRUE(InitStaticMembers(), NS_ERROR_NOT_AVAILABLE);
- return sPreferences->mRootBranch->SetComplexValue(aPref, aType, aValue);
+ nsCOMPtr<nsIPrefBranch> branch = (aKind == PrefValueKind::Default)
+ ? sPreferences->mDefaultRootBranch
+ : sPreferences->mRootBranch;
+ return branch->SetComplexValue(aPrefName, aType, aValue);
}
/* static */ nsresult
Preferences::ClearUser(const char* aPref)
{
ENSURE_MAIN_PROCESS("ClearUser", aPref);
NS_ENSURE_TRUE(InitStaticMembers(), NS_ERROR_NOT_AVAILABLE);
return PREF_ClearUserPref(aPref);
--- a/modules/libpref/Preferences.h
+++ b/modules/libpref/Preferences.h
@@ -183,31 +183,48 @@ public:
}
static float GetFloat(const char* aPref, float aDefault = 0)
{
float result = aDefault;
GetFloat(aPref, &result);
return result;
}
- // Setters of user values.
- static nsresult SetBool(const char* aPref, bool aValue);
- static nsresult SetInt(const char* aPref, int32_t aValue);
- static nsresult SetUint(const char* aPref, uint32_t aValue)
+ // Value setters.
+ static nsresult SetBool(const char* aPrefName,
+ bool aValue,
+ PrefValueKind aKind = PrefValueKind::User);
+ static nsresult SetInt(const char* aPrefName,
+ int32_t aValue,
+ PrefValueKind aKind = PrefValueKind::User);
+ static nsresult SetUint(const char* aPrefName,
+ uint32_t aValue,
+ PrefValueKind aKind = PrefValueKind::User)
{
- return SetInt(aPref, static_cast<int32_t>(aValue));
+ return SetInt(aPrefName, static_cast<int32_t>(aValue), aKind);
}
- static nsresult SetFloat(const char* aPref, float aValue);
- static nsresult SetCString(const char* aPref, const char* aValue);
- static nsresult SetCString(const char* aPref, const nsACString& aValue);
- static nsresult SetString(const char* aPref, const char16ptr_t aValue);
- static nsresult SetString(const char* aPref, const nsAString& aValue);
- static nsresult SetComplex(const char* aPref,
+ static nsresult SetFloat(const char* aPrefName,
+ float aValue,
+ PrefValueKind aKind = PrefValueKind::User);
+ static nsresult SetCString(const char* aPrefName,
+ const char* aValue,
+ PrefValueKind aKind = PrefValueKind::User);
+ static nsresult SetCString(const char* aPrefName,
+ const nsACString& aValue,
+ PrefValueKind aKind = PrefValueKind::User);
+ static nsresult SetString(const char* aPrefName,
+ const char16ptr_t aValue,
+ PrefValueKind aKind = PrefValueKind::User);
+ static nsresult SetString(const char* aPrefName,
+ const nsAString& aValue,
+ PrefValueKind aKind = PrefValueKind::User);
+ static nsresult SetComplex(const char* aPrefName,
const nsIID& aType,
- nsISupports* aValue);
+ nsISupports* aValue,
+ PrefValueKind aKind = PrefValueKind::User);
// Clears user set pref.
static nsresult ClearUser(const char* aPref);
// Whether the pref has a user value or not.
static bool HasUserValue(const char* aPref);
// Adds/Removes the observer for the root pref branch. See nsIPrefBranch.idl