diff options
author | Moonchild <mcwerewolf@wolfbeast.com> | 2019-03-24 11:54:50 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-03-24 11:54:50 +0100 |
commit | 834ea744c2bf56d951c0134f6043f692b28c36ef (patch) | |
tree | f6cd6725c44d0ad3cd550a73cbbff969bb058eb9 /modules/libpref/nsPrefBranch.cpp | |
parent | 9fc25801fdae8a88e2baa68bb500b24e53d9d8bf (diff) | |
parent | cac3f9678de46298a93537e8913912bba28d89f7 (diff) | |
download | UXP-834ea744c2bf56d951c0134f6043f692b28c36ef.tar UXP-834ea744c2bf56d951c0134f6043f692b28c36ef.tar.gz UXP-834ea744c2bf56d951c0134f6043f692b28c36ef.tar.lz UXP-834ea744c2bf56d951c0134f6043f692b28c36ef.tar.xz UXP-834ea744c2bf56d951c0134f6043f692b28c36ef.zip |
Merge pull request #1021 from Ascrod/default-pref
Bug 1338306 - nsIPrefBranch.get*Pref should support providing a default value
Diffstat (limited to 'modules/libpref/nsPrefBranch.cpp')
-rw-r--r-- | modules/libpref/nsPrefBranch.cpp | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/modules/libpref/nsPrefBranch.cpp b/modules/libpref/nsPrefBranch.cpp index 98e06aaa4..5173db06e 100644 --- a/modules/libpref/nsPrefBranch.cpp +++ b/modules/libpref/nsPrefBranch.cpp @@ -141,6 +141,20 @@ NS_IMETHODIMP nsPrefBranch::GetPrefType(const char *aPrefName, int32_t *_retval) return NS_OK; } +NS_IMETHODIMP nsPrefBranch::GetBoolPrefWithDefault(const char *aPrefName, + bool aDefaultValue, + uint8_t _argc, bool *_retval) +{ + nsresult rv = GetBoolPref(aPrefName, _retval); + + if (NS_FAILED(rv) && _argc == 1) { + *_retval = aDefaultValue; + return NS_OK; + } + + return rv; +} + NS_IMETHODIMP nsPrefBranch::GetBoolPref(const char *aPrefName, bool *_retval) { NS_ENSURE_ARG(aPrefName); @@ -156,6 +170,20 @@ NS_IMETHODIMP nsPrefBranch::SetBoolPref(const char *aPrefName, bool aValue) return PREF_SetBoolPref(pref, aValue, mIsDefault); } +NS_IMETHODIMP nsPrefBranch::GetFloatPrefWithDefault(const char *aPrefName, + float aDefaultValue, + uint8_t _argc, float *_retval) +{ + nsresult rv = GetFloatPref(aPrefName, _retval); + + if (NS_FAILED(rv) && _argc == 1) { + *_retval = aDefaultValue; + return NS_OK; + } + + return rv; +} + NS_IMETHODIMP nsPrefBranch::GetFloatPref(const char *aPrefName, float *_retval) { NS_ENSURE_ARG(aPrefName); @@ -169,6 +197,21 @@ NS_IMETHODIMP nsPrefBranch::GetFloatPref(const char *aPrefName, float *_retval) return rv; } +NS_IMETHODIMP nsPrefBranch::GetCharPrefWithDefault(const char *aPrefName, + const char *aDefaultValue, + uint8_t _argc, char **_retval) +{ + nsresult rv = GetCharPref(aPrefName, _retval); + + if (NS_FAILED(rv) && _argc == 1) { + NS_ENSURE_ARG(aDefaultValue); + *_retval = NS_strdup(aDefaultValue); + return NS_OK; + } + + return rv; +} + NS_IMETHODIMP nsPrefBranch::GetCharPref(const char *aPrefName, char **_retval) { NS_ENSURE_ARG(aPrefName); @@ -195,6 +238,20 @@ nsresult nsPrefBranch::SetCharPrefInternal(const char *aPrefName, const char *aV return PREF_SetCharPref(pref, aValue, mIsDefault); } +NS_IMETHODIMP nsPrefBranch::GetIntPrefWithDefault(const char *aPrefName, + int32_t aDefaultValue, + uint8_t _argc, int32_t *_retval) +{ + nsresult rv = GetIntPref(aPrefName, _retval); + + if (NS_FAILED(rv) && _argc == 1) { + *_retval = aDefaultValue; + return NS_OK; + } + + return rv; +} + NS_IMETHODIMP nsPrefBranch::GetIntPref(const char *aPrefName, int32_t *_retval) { NS_ENSURE_ARG(aPrefName); |