summaryrefslogtreecommitdiffstats
path: root/modules/libpref/nsPrefBranch.cpp
diff options
context:
space:
mode:
authorFlorian Quèze <florian@queze.net>2019-03-23 10:02:03 -0400
committerAscrod <32915892+Ascrod@users.noreply.github.com>2019-03-23 19:35:32 -0400
commitcac3f9678de46298a93537e8913912bba28d89f7 (patch)
treef6cd6725c44d0ad3cd550a73cbbff969bb058eb9 /modules/libpref/nsPrefBranch.cpp
parent9fc25801fdae8a88e2baa68bb500b24e53d9d8bf (diff)
downloadUXP-cac3f9678de46298a93537e8913912bba28d89f7.tar
UXP-cac3f9678de46298a93537e8913912bba28d89f7.tar.gz
UXP-cac3f9678de46298a93537e8913912bba28d89f7.tar.lz
UXP-cac3f9678de46298a93537e8913912bba28d89f7.tar.xz
UXP-cac3f9678de46298a93537e8913912bba28d89f7.zip
Bug 1338306 - nsIPrefBranch.get*Pref should support providing a default value, r=bsmedberg.
Diffstat (limited to 'modules/libpref/nsPrefBranch.cpp')
-rw-r--r--modules/libpref/nsPrefBranch.cpp57
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);