Bug 1410794 - Change some |string| occurrences in nsIPrefBranch.idl to |ACString|. r=erahm.

This makes the code nicer. In particular, it removes many getter_Copies()
calls. The patch also converts a lot of nsCStrings to nsAutoCString, which will
avoid heap allocation in the common case.

The patch also renames PREF_CopyCharPref() as PREF_GetCStringPref(), because
it's actually getting a string, not a char, and that matches the existing
GetCString() and GetDefaultCString() methods. Correspondingly, it also renames
PREF_SetCharPref() as PREF_SetCStringPref().

The |aPrefName| arguments in nsIPrefBranch.idl remain as |string| because they
almost always involve passing in C string literals, and passing "foo" is much
nicer than passing NS_LITERAL_CSTRING("foo").

It's worth noting that early versions of this patch used |AUTF8String| instead
of |ACString|. But it turns out that libpref stores prefs internally as Latin1.
And |ACString| is compatible with Latin1 but |AUTF8String| isn't, because
non-ASCII Latin1 strings are not valid UTF-8!

--HG--
extra : rebase_source : 725ccf57943283a60ef8c9d654afe4515b4089f8
This commit is contained in:
Nicholas Nethercote 2017-10-25 10:22:38 +11:00
parent 294c5fd86d
commit a861772b10
20 changed files with 131 additions and 169 deletions

View File

@ -109,9 +109,9 @@ AppendDistroSearchDirs(nsIProperties* aDirSvc, nsCOMArray<nsIFile> &array)
localePlugins->AppendNative(NS_LITERAL_CSTRING("locale"));
nsCString defLocale;
nsAutoCString defLocale;
rv = prefs->GetCharPref("distribution.searchplugins.defaultLocale",
getter_Copies(defLocale));
defLocale);
if (NS_SUCCEEDED(rv)) {
nsCOMPtr<nsIFile> defLocalePlugins;

View File

@ -128,8 +128,8 @@ nsChromeRegistryChrome::Init()
if (!prefs) {
NS_WARNING("Could not get pref service!");
} else {
nsCString provider;
rv = prefs->GetCharPref(SELECTED_SKIN_PREF, getter_Copies(provider));
nsAutoCString provider;
rv = prefs->GetCharPref(SELECTED_SKIN_PREF, provider);
if (NS_SUCCEEDED(rv))
mSelectedSkin = provider;
@ -275,8 +275,8 @@ nsChromeRegistryChrome::Observe(nsISupports *aSubject, const char *aTopic,
NS_ConvertUTF16toUTF8 pref(someData);
if (pref.EqualsLiteral(SELECTED_SKIN_PREF)) {
nsCString provider;
rv = prefs->GetCharPref(pref.get(), getter_Copies(provider));
nsAutoCString provider;
rv = prefs->GetCharPref(pref.get(), provider);
if (NS_FAILED(rv)) {
NS_ERROR("Couldn't get new skin pref!");
return rv;

View File

@ -102,10 +102,10 @@ static PRFuncPtr KLCacheHasValidTicketsPtr;
static nsresult
gssInit()
{
nsCString libPath;
nsAutoCString libPath;
nsCOMPtr<nsIPrefBranch> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
if (prefs) {
prefs->GetCharPref(kNegotiateAuthGssLib, getter_Copies(libPath));
prefs->GetCharPref(kNegotiateAuthGssLib, libPath);
prefs->GetBoolPref(kNegotiateAuthNativeImp, &gssNativeImp);
}

View File

@ -458,7 +458,7 @@ nsresult nsAutoConfig::getEmailAddr(nsACString & emailAddr)
{
nsresult rv;
nsCString prefValue;
nsAutoCString prefValue;
/* Getting an email address through set of three preferences:
First getting a default account with
@ -468,12 +468,12 @@ nsresult nsAutoConfig::getEmailAddr(nsACString & emailAddr)
*/
rv = mPrefBranch->GetCharPref("mail.accountmanager.defaultaccount",
getter_Copies(prefValue));
prefValue);
if (NS_SUCCEEDED(rv) && !prefValue.IsEmpty()) {
emailAddr = NS_LITERAL_CSTRING("mail.account.") +
prefValue + NS_LITERAL_CSTRING(".identities");
rv = mPrefBranch->GetCharPref(PromiseFlatCString(emailAddr).get(),
getter_Copies(prefValue));
prefValue);
if (NS_FAILED(rv) || prefValue.IsEmpty())
return PromptForEMailAddress(emailAddr);
int32_t commandIndex = prefValue.FindChar(',');
@ -482,15 +482,14 @@ nsresult nsAutoConfig::getEmailAddr(nsACString & emailAddr)
emailAddr = NS_LITERAL_CSTRING("mail.identity.") +
prefValue + NS_LITERAL_CSTRING(".useremail");
rv = mPrefBranch->GetCharPref(PromiseFlatCString(emailAddr).get(),
getter_Copies(prefValue));
prefValue);
if (NS_FAILED(rv) || prefValue.IsEmpty())
return PromptForEMailAddress(emailAddr);
emailAddr = prefValue;
}
else {
// look for 4.x pref in case we just migrated.
rv = mPrefBranch->GetCharPref("mail.identity.useremail",
getter_Copies(prefValue));
rv = mPrefBranch->GetCharPref("mail.identity.useremail", prefValue);
if (NS_SUCCEEDED(rv) && !prefValue.IsEmpty())
emailAddr = prefValue;
else

View File

@ -115,8 +115,8 @@ NS_IMETHODIMP nsReadConfig::Observe(nsISupports *aSubject, const char *aTopic, c
nsresult nsReadConfig::readConfigFile()
{
nsresult rv = NS_OK;
nsCString lockFileName;
nsCString lockVendor;
nsAutoCString lockFileName;
nsAutoCString lockVendor;
uint32_t fileNameLen = 0;
nsCOMPtr<nsIPrefBranch> defaultPrefBranch;
@ -133,7 +133,7 @@ nsresult nsReadConfig::readConfigFile()
// running mozilla or netscp6)
rv = defaultPrefBranch->GetCharPref("general.config.filename",
getter_Copies(lockFileName));
lockFileName);
MOZ_LOG(MCD, LogLevel::Debug, ("general.config.filename = %s\n", lockFileName.get()));
@ -179,16 +179,14 @@ nsresult nsReadConfig::readConfigFile()
return rv;
}
rv = prefBranch->GetCharPref("general.config.filename",
getter_Copies(lockFileName));
rv = prefBranch->GetCharPref("general.config.filename", lockFileName);
if (NS_FAILED(rv))
// There is NO REASON we should ever get here. This is POST reading
// of the config file.
return NS_ERROR_FAILURE;
rv = prefBranch->GetCharPref("general.config.vendor",
getter_Copies(lockVendor));
rv = prefBranch->GetCharPref("general.config.vendor", lockVendor);
// If vendor is not nullptr, do this check
if (NS_SUCCEEDED(rv)) {
@ -203,9 +201,8 @@ nsresult nsReadConfig::readConfigFile()
}
// get the value of the autoconfig url
nsCString urlName;
rv = prefBranch->GetCharPref("autoadmin.global_config_url",
getter_Copies(urlName));
nsAutoCString urlName;
rv = prefBranch->GetCharPref("autoadmin.global_config_url", urlName);
if (NS_SUCCEEDED(rv) && !urlName.IsEmpty()) {
// Instantiating nsAutoConfig object if the pref is present

View File

@ -314,8 +314,8 @@ mozHunspell::LoadDictionaryList(bool aNotifyChildProcesses)
// check preferences first
nsCOMPtr<nsIPrefBranch> prefs(do_GetService(NS_PREFSERVICE_CONTRACTID));
if (prefs) {
nsCString extDictPath;
rv = prefs->GetCharPref("spellchecker.dictionary_path", getter_Copies(extDictPath));
nsAutoCString extDictPath;
rv = prefs->GetCharPref("spellchecker.dictionary_path", extDictPath);
if (NS_SUCCEEDED(rv)) {
// set the spellchecker.dictionary_path
rv = NS_NewNativeLocalFile(extDictPath, true, getter_AddRefs(dictDir));

View File

@ -457,7 +457,7 @@ NrIceCtx::InitializeGlobals(bool allow_loopback,
&ice_tcp_listen_backlog);
branch->GetCharPref(
"media.peerconnection.ice.force_interface",
getter_Copies(force_net_interface));
force_net_interface);
}
}
@ -633,8 +633,8 @@ NrIceCtx::Initialize(const std::string& ufrag,
}
}
nsCString mapping_type;
nsCString filtering_type;
nsAutoCString mapping_type;
nsAutoCString filtering_type;
bool block_udp = false;
bool block_tcp = false;
@ -648,10 +648,10 @@ NrIceCtx::Initialize(const std::string& ufrag,
if (NS_SUCCEEDED(rv)) {
rv = pref_branch->GetCharPref(
"media.peerconnection.nat_simulator.mapping_type",
getter_Copies(mapping_type));
mapping_type);
rv = pref_branch->GetCharPref(
"media.peerconnection.nat_simulator.filtering_type",
getter_Copies(filtering_type));
filtering_type);
rv = pref_branch->GetBoolPref(
"media.peerconnection.nat_simulator.block_udp",
&block_udp);

View File

@ -485,20 +485,25 @@ StrEscape(const char* aOriginal, nsCString& aResult)
// Each set returns PREF_VALUECHANGED if the user value changed (triggering a
// callback), or PREF_NOERROR if the value was unchanged.
static nsresult
PREF_SetCharPref(const char* aPrefName, const char* aValue, bool aSetDefault)
PREF_SetCStringPref(const char* aPrefName,
const nsACString& aValue,
bool aSetDefault)
{
if (strlen(aValue) > MAX_PREF_LENGTH) {
if (aValue.Length() > MAX_PREF_LENGTH) {
return NS_ERROR_ILLEGAL_VALUE;
}
// It's ok to stash a pointer to the temporary PromiseFlatCString's chars in
// pref because pref_HashPref() duplicates those chars.
PrefValue pref;
pref.mStringVal = const_cast<char*>(aValue);
const nsCString& flat = PromiseFlatCString(aValue);
pref.mStringVal = const_cast<char*>(flat.get());
return pref_HashPref(
aPrefName, pref, PrefType::String, aSetDefault ? kPrefSetDefault : 0);
}
// Like PREF_SetCharPref(), but for integers.
// Like PREF_SetCStringPref(), but for integers.
static nsresult
PREF_SetIntPref(const char* aPrefName, int32_t aValue, bool aSetDefault)
{
@ -509,7 +514,7 @@ PREF_SetIntPref(const char* aPrefName, int32_t aValue, bool aSetDefault)
aPrefName, pref, PrefType::Int, aSetDefault ? kPrefSetDefault : 0);
}
// Like PREF_SetCharPref(), but for booleans.
// Like PREF_SetCStringPref(), but for booleans.
static nsresult
PREF_SetBoolPref(const char* aPrefName, bool aValue, bool aSetDefault)
{
@ -535,8 +540,7 @@ SetPrefValue(const char* aPrefName,
switch (aValue.type()) {
case dom::PrefValue::TnsCString:
return PREF_SetCharPref(
aPrefName, aValue.get_nsCString().get(), setDefault);
return PREF_SetCStringPref(aPrefName, aValue.get_nsCString(), setDefault);
case dom::PrefValue::Tint32_t:
return PREF_SetIntPref(aPrefName, aValue.get_int32_t(), setDefault);
@ -718,9 +722,10 @@ PREF_HasUserPref(const char* aPrefName)
return pref && pref->mPrefFlags.HasUserValue();
}
// This function allocates memory and the caller is responsible for freeing it.
static nsresult
PREF_CopyCharPref(const char* aPrefName, char** aValueOut, bool aGetDefault)
PREF_GetCStringPref(const char* aPrefName,
nsACString& aValueOut,
bool aGetDefault)
{
if (!gHashTable) {
return NS_ERROR_NOT_INITIALIZED;
@ -739,7 +744,7 @@ PREF_CopyCharPref(const char* aPrefName, char** aValueOut, bool aGetDefault)
}
if (stringVal) {
*aValueOut = moz_xstrdup(stringVal);
aValueOut = stringVal;
rv = NS_OK;
}
}
@ -2233,14 +2238,13 @@ protected:
nsAString& aReturn);
// As SetCharPref, but without any check on the length of |aValue|.
nsresult SetCharPrefInternal(const char* aPrefName, const char* aValue);
nsresult SetCharPrefInternal(const char* aPrefName, const nsACString& aValue);
// Reject strings that are more than 1Mb, warn if strings are more than 16kb.
nsresult CheckSanityOfStringLength(const char* aPrefName,
const nsAString& aValue);
nsresult CheckSanityOfStringLength(const char* aPrefName,
const nsACString& aValue);
nsresult CheckSanityOfStringLength(const char* aPrefName, const char* aValue);
nsresult CheckSanityOfStringLength(const char* aPrefName,
const uint32_t aLength);
@ -2333,11 +2337,9 @@ NS_INTERFACE_MAP_BEGIN(nsPrefBranch)
NS_INTERFACE_MAP_END
NS_IMETHODIMP
nsPrefBranch::GetRoot(char** aRoot)
nsPrefBranch::GetRoot(nsACString& aRoot)
{
NS_ENSURE_ARG_POINTER(aRoot);
*aRoot = ToNewCString(mPrefRoot);
aRoot = mPrefRoot;
return NS_OK;
}
@ -2423,7 +2425,7 @@ nsPrefBranch::GetFloatPref(const char* aPrefName, float* aRetVal)
NS_ENSURE_ARG(aPrefName);
nsAutoCString stringVal;
nsresult rv = GetCharPref(aPrefName, getter_Copies(stringVal));
nsresult rv = GetCharPref(aPrefName, stringVal);
if (NS_SUCCEEDED(rv)) {
*aRetVal = stringVal.ToFloat(&rv);
}
@ -2433,15 +2435,14 @@ nsPrefBranch::GetFloatPref(const char* aPrefName, float* aRetVal)
NS_IMETHODIMP
nsPrefBranch::GetCharPrefWithDefault(const char* aPrefName,
const char* aDefaultValue,
const nsACString& aDefaultValue,
uint8_t aArgc,
char** aRetVal)
nsACString& aRetVal)
{
nsresult rv = GetCharPref(aPrefName, aRetVal);
if (NS_FAILED(rv) && aArgc == 1) {
NS_ENSURE_ARG(aDefaultValue);
*aRetVal = moz_xstrdup(aDefaultValue);
aRetVal = aDefaultValue;
return NS_OK;
}
@ -2449,15 +2450,15 @@ nsPrefBranch::GetCharPrefWithDefault(const char* aPrefName,
}
NS_IMETHODIMP
nsPrefBranch::GetCharPref(const char* aPrefName, char** aRetVal)
nsPrefBranch::GetCharPref(const char* aPrefName, nsACString& aRetVal)
{
NS_ENSURE_ARG(aPrefName);
const PrefName& pref = GetPrefName(aPrefName);
return PREF_CopyCharPref(pref.get(), aRetVal, mIsDefault);
return PREF_GetCStringPref(pref.get(), aRetVal, mIsDefault);
}
NS_IMETHODIMP
nsPrefBranch::SetCharPref(const char* aPrefName, const char* aValue)
nsPrefBranch::SetCharPref(const char* aPrefName, const nsACString& aValue)
{
nsresult rv = CheckSanityOfStringLength(aPrefName, aValue);
if (NS_FAILED(rv)) {
@ -2467,15 +2468,14 @@ nsPrefBranch::SetCharPref(const char* aPrefName, const char* aValue)
}
nsresult
nsPrefBranch::SetCharPrefInternal(const char* aPrefName, const char* aValue)
nsPrefBranch::SetCharPrefInternal(const char* aPrefName,
const nsACString& aValue)
{
ENSURE_MAIN_PROCESS("SetCharPref", aPrefName);
NS_ENSURE_ARG(aPrefName);
NS_ENSURE_ARG(aValue);
const PrefName& pref = GetPrefName(aPrefName);
return PREF_SetCharPref(pref.get(), aValue, mIsDefault);
return PREF_SetCStringPref(pref.get(), aValue, mIsDefault);
}
NS_IMETHODIMP
@ -2485,7 +2485,7 @@ nsPrefBranch::GetStringPref(const char* aPrefName,
nsACString& aRetVal)
{
nsCString utf8String;
nsresult rv = GetCharPref(aPrefName, getter_Copies(utf8String));
nsresult rv = GetCharPref(aPrefName, utf8String);
if (NS_SUCCEEDED(rv)) {
aRetVal = utf8String;
return rv;
@ -2507,7 +2507,7 @@ nsPrefBranch::SetStringPref(const char* aPrefName, const nsACString& aValue)
return rv;
}
return SetCharPrefInternal(aPrefName, PromiseFlatCString(aValue).get());
return SetCharPrefInternal(aPrefName, aValue);
}
NS_IMETHODIMP
@ -2551,7 +2551,7 @@ nsPrefBranch::GetComplexValue(const char* aPrefName,
NS_ENSURE_ARG(aPrefName);
nsresult rv;
nsCString utf8String;
nsAutoCString utf8String;
// we have to do this one first because it's different than all the rest
if (aType.Equals(NS_GET_IID(nsIPrefLocalizedString))) {
@ -2582,7 +2582,7 @@ nsPrefBranch::GetComplexValue(const char* aPrefName,
theString->SetData(utf16String);
}
} else {
rv = GetCharPref(aPrefName, getter_Copies(utf8String));
rv = GetCharPref(aPrefName, utf8String);
if (NS_SUCCEEDED(rv)) {
theString->SetData(NS_ConvertUTF8toUTF16(utf8String));
}
@ -2596,7 +2596,7 @@ nsPrefBranch::GetComplexValue(const char* aPrefName,
}
// if we can't get the pref, there's no point in being here
rv = GetCharPref(aPrefName, getter_Copies(utf8String));
rv = GetCharPref(aPrefName, utf8String);
if (NS_FAILED(rv)) {
return rv;
}
@ -2706,16 +2706,6 @@ nsPrefBranch::GetComplexValue(const char* aPrefName,
return NS_NOINTERFACE;
}
nsresult
nsPrefBranch::CheckSanityOfStringLength(const char* aPrefName,
const char* aValue)
{
if (!aValue) {
return NS_OK;
}
return CheckSanityOfStringLength(aPrefName, strlen(aValue));
}
nsresult
nsPrefBranch::CheckSanityOfStringLength(const char* aPrefName,
const nsAString& aValue)
@ -2796,7 +2786,7 @@ nsPrefBranch::SetComplexValue(const char* aPrefName,
nsAutoCString descriptorString;
rv = file->GetPersistentDescriptor(descriptorString);
if (NS_SUCCEEDED(rv)) {
rv = SetCharPrefInternal(aPrefName, descriptorString.get());
rv = SetCharPrefInternal(aPrefName, descriptorString);
}
return rv;
}
@ -2840,7 +2830,7 @@ nsPrefBranch::SetComplexValue(const char* aPrefName,
descriptorString.Append(relativeToKey);
descriptorString.Append(']');
descriptorString.Append(relDescriptor);
return SetCharPrefInternal(aPrefName, descriptorString.get());
return SetCharPrefInternal(aPrefName, descriptorString);
}
if (aType.Equals(NS_GET_IID(nsISupportsString)) ||
@ -2857,8 +2847,7 @@ nsPrefBranch::SetComplexValue(const char* aPrefName,
if (NS_FAILED(rv)) {
return rv;
}
rv = SetCharPrefInternal(aPrefName,
NS_ConvertUTF16toUTF8(wideString).get());
rv = SetCharPrefInternal(aPrefName, NS_ConvertUTF16toUTF8(wideString));
}
}
return rv;
@ -3149,9 +3138,8 @@ nsPrefBranch::GetDefaultFromPropertiesFile(const char* aPrefName,
{
// The default value contains a URL to a .properties file.
nsCString propertyFileURL;
nsresult rv =
PREF_CopyCharPref(aPrefName, getter_Copies(propertyFileURL), true);
nsAutoCString propertyFileURL;
nsresult rv = PREF_GetCStringPref(aPrefName, propertyFileURL, true);
if (NS_FAILED(rv)) {
return rv;
}
@ -3978,7 +3966,7 @@ Preferences::Init()
return Ok();
}
nsCString lockFileName;
nsAutoCString lockFileName;
// The following is a small hack which will allow us to only load the library
// which supports the netscape.cfg file if the preference is defined. We
@ -3986,8 +3974,8 @@ Preferences::Init()
// all-ns.js (netscape 6), and if it exists we startup the pref config
// category which will do the rest.
nsresult rv = PREF_CopyCharPref(
"general.config.filename", getter_Copies(lockFileName), false);
nsresult rv =
PREF_GetCStringPref("general.config.filename", lockFileName, false);
if (NS_SUCCEEDED(rv)) {
NS_CreateServicesFromCategory(
"pref-config-startup",
@ -4914,7 +4902,7 @@ Preferences::GetFloat(const char* aPref, float* aResult)
NS_PRECONDITION(aResult, "aResult must not be NULL");
NS_ENSURE_TRUE(InitStaticMembers(), NS_ERROR_NOT_AVAILABLE);
nsAutoCString result;
nsresult rv = PREF_CopyCharPref(aPref, getter_Copies(result), false);
nsresult rv = PREF_GetCStringPref(aPref, result, false);
if (NS_SUCCEEDED(rv)) {
*aResult = result.ToFloat(&rv);
}
@ -4925,12 +4913,7 @@ Preferences::GetFloat(const char* aPref, float* aResult)
Preferences::GetCString(const char* aPref, nsACString& aResult)
{
NS_ENSURE_TRUE(InitStaticMembers(), NS_ERROR_NOT_AVAILABLE);
char* result;
nsresult rv = PREF_CopyCharPref(aPref, &result, false);
if (NS_SUCCEEDED(rv)) {
aResult.Adopt(result);
}
return rv;
return PREF_GetCStringPref(aPref, aResult, false);
}
/* static */ nsresult
@ -4938,7 +4921,7 @@ Preferences::GetString(const char* aPref, nsAString& aResult)
{
NS_ENSURE_TRUE(InitStaticMembers(), NS_ERROR_NOT_AVAILABLE);
nsAutoCString result;
nsresult rv = PREF_CopyCharPref(aPref, getter_Copies(result), false);
nsresult rv = PREF_GetCStringPref(aPref, result, false);
if (NS_SUCCEEDED(rv)) {
CopyUTF8toUTF16(result, aResult);
}
@ -4982,7 +4965,7 @@ Preferences::SetCString(const char* aPref, const char* aValue)
{
ENSURE_MAIN_PROCESS_WITH_WARNING("SetCString", aPref);
NS_ENSURE_TRUE(InitStaticMembers(), NS_ERROR_NOT_AVAILABLE);
return PREF_SetCharPref(aPref, aValue, false);
return PREF_SetCStringPref(aPref, nsDependentCString(aValue), false);
}
/* static */ nsresult
@ -4990,7 +4973,7 @@ Preferences::SetCString(const char* aPref, const nsACString& aValue)
{
ENSURE_MAIN_PROCESS_WITH_WARNING("SetCString", aPref);
NS_ENSURE_TRUE(InitStaticMembers(), NS_ERROR_NOT_AVAILABLE);
return PREF_SetCharPref(aPref, PromiseFlatCString(aValue).get(), false);
return PREF_SetCStringPref(aPref, aValue, false);
}
/* static */ nsresult
@ -4998,7 +4981,7 @@ Preferences::SetString(const char* aPref, const char16ptr_t aValue)
{
ENSURE_MAIN_PROCESS_WITH_WARNING("SetString", aPref);
NS_ENSURE_TRUE(InitStaticMembers(), NS_ERROR_NOT_AVAILABLE);
return PREF_SetCharPref(aPref, NS_ConvertUTF16toUTF8(aValue).get(), false);
return PREF_SetCStringPref(aPref, NS_ConvertUTF16toUTF8(aValue), false);
}
/* static */ nsresult
@ -5006,7 +4989,7 @@ Preferences::SetString(const char* aPref, const nsAString& aValue)
{
ENSURE_MAIN_PROCESS_WITH_WARNING("SetString", aPref);
NS_ENSURE_TRUE(InitStaticMembers(), NS_ERROR_NOT_AVAILABLE);
return PREF_SetCharPref(aPref, NS_ConvertUTF16toUTF8(aValue).get(), false);
return PREF_SetCStringPref(aPref, NS_ConvertUTF16toUTF8(aValue), false);
}
/* static */ nsresult
@ -5405,12 +5388,7 @@ Preferences::GetDefaultInt(const char* aPref, int32_t* aResult)
Preferences::GetDefaultCString(const char* aPref, nsACString& aResult)
{
NS_ENSURE_TRUE(InitStaticMembers(), NS_ERROR_NOT_AVAILABLE);
char* result;
nsresult rv = PREF_CopyCharPref(aPref, &result, true);
if (NS_SUCCEEDED(rv)) {
aResult.Adopt(result);
}
return rv;
return PREF_GetCStringPref(aPref, aResult, true);
}
/* static */ nsresult
@ -5418,7 +5396,7 @@ Preferences::GetDefaultString(const char* aPref, nsAString& aResult)
{
NS_ENSURE_TRUE(InitStaticMembers(), NS_ERROR_NOT_AVAILABLE);
nsAutoCString result;
nsresult rv = PREF_CopyCharPref(aPref, getter_Copies(result), true);
nsresult rv = PREF_GetCStringPref(aPref, result, true);
if (NS_SUCCEEDED(rv)) {
CopyUTF8toUTF16(result, aResult);
}

View File

@ -41,7 +41,7 @@ interface nsIPrefBranch : nsISupports
* Called to get the root on which this branch is based, such as
* "browser.startup."
*/
readonly attribute string root;
readonly attribute ACString root;
/**
* Called to determine the type of a specific preference.
@ -104,14 +104,15 @@ interface nsIPrefBranch : nsISupports
* @param aPrefName The string preference to retrieve.
* @param aDefaultValue The string to return if the preference is not set.
*
* @return string The value of the requested string preference.
* @return ACString The value of the requested string preference.
*
* @see setCharPref
*/
[optional_argc,binaryname(GetCharPrefWithDefault)]
string getCharPref(in string aPrefName, [optional] in string aDefaultValue);
ACString getCharPref(in string aPrefName,
[optional] in ACString aDefaultValue);
[noscript,binaryname(GetCharPref)]
string getCharPrefXPCOM(in string aPrefName);
ACString getCharPrefXPCOM(in string aPrefName);
/**
* Called to set the state of an individual ascii string preference.
@ -124,7 +125,7 @@ interface nsIPrefBranch : nsISupports
*
* @see getCharPref
*/
void setCharPref(in string aPrefName, in string aValue);
void setCharPref(in string aPrefName, in ACString aValue);
/**
* Called to get the state of an individual unicode string preference.
@ -132,7 +133,7 @@ interface nsIPrefBranch : nsISupports
* @param aPrefName The string preference to retrieve.
* @param aDefaultValue The string to return if the preference is not set.
*
* @return string The value of the requested string preference.
* @return ACString The value of the requested string preference.
*
* @see setStringPref
*/

View File

@ -1364,10 +1364,10 @@ nsIOService::PrefsChanged(nsIPrefBranch *prefs, const char *pref)
void
nsIOService::ParsePortList(nsIPrefBranch *prefBranch, const char *pref, bool remove)
{
nsCString portList;
nsAutoCString portList;
// Get a pref string and chop it up into a list of ports.
prefBranch->GetCharPref(pref, getter_Copies(portList));
prefBranch->GetCharPref(pref, portList);
if (!portList.IsVoid()) {
nsTArray<nsCString> portListArray;
ParseString(portList, ',', portListArray);

View File

@ -427,8 +427,8 @@ proxy_GetStringPref(nsIPrefBranch *aPrefBranch,
const char *aPref,
nsCString &aResult)
{
nsCString temp;
nsresult rv = aPrefBranch->GetCharPref(aPref, getter_Copies(temp));
nsAutoCString temp;
nsresult rv = aPrefBranch->GetCharPref(aPref, temp);
if (NS_FAILED(rv))
aResult.Truncate();
else {
@ -560,9 +560,8 @@ nsProtocolProxyService::ReloadNetworkPAC()
}
if (type == PROXYCONFIG_PAC) {
nsCString pacSpec;
prefs->GetCharPref(PROXY_PREF("autoconfig_url"),
getter_Copies(pacSpec));
nsAutoCString pacSpec;
prefs->GetCharPref(PROXY_PREF("autoconfig_url"), pacSpec);
if (!pacSpec.IsEmpty()) {
nsCOMPtr<nsIURI> pacURI;
rv = NS_NewURI(getter_AddRefs(pacURI), pacSpec);
@ -692,7 +691,7 @@ nsProtocolProxyService::PrefsChanged(nsIPrefBranch *prefBranch,
{
nsresult rv = NS_OK;
bool reloadPAC = false;
nsCString tempString;
nsAutoCString tempString;
if (!pref || !strcmp(pref, PROXY_PREF("type"))) {
int32_t type = -1;
@ -776,8 +775,7 @@ nsProtocolProxyService::PrefsChanged(nsIPrefBranch *prefBranch,
mFailedProxyTimeout);
if (!pref || !strcmp(pref, PROXY_PREF("no_proxies_on"))) {
rv = prefBranch->GetCharPref(PROXY_PREF("no_proxies_on"),
getter_Copies(tempString));
rv = prefBranch->GetCharPref(PROXY_PREF("no_proxies_on"), tempString);
if (NS_SUCCEEDED(rv))
LoadHostFilters(tempString);
}
@ -798,8 +796,7 @@ nsProtocolProxyService::PrefsChanged(nsIPrefBranch *prefBranch,
if (reloadPAC) {
tempString.Truncate();
if (mProxyConfig == PROXYCONFIG_PAC) {
prefBranch->GetCharPref(PROXY_PREF("autoconfig_url"),
getter_Copies(tempString));
prefBranch->GetCharPref(PROXY_PREF("autoconfig_url"), tempString);
if (mPACMan && !mPACMan->IsPACURI(tempString)) {
LOG(("PAC Thread URI Changed - Reset Pac Thread"));
ResetPACThread();
@ -1246,9 +1243,9 @@ nsProtocolProxyService::ReloadPAC()
if (NS_FAILED(rv))
return NS_OK;
nsCString pacSpec;
nsAutoCString pacSpec;
if (type == PROXYCONFIG_PAC)
prefs->GetCharPref(PROXY_PREF("autoconfig_url"), getter_Copies(pacSpec));
prefs->GetCharPref(PROXY_PREF("autoconfig_url"), pacSpec);
else if (type == PROXYCONFIG_WPAD)
pacSpec.AssignLiteral(WPAD_URL);
else if (type == PROXYCONFIG_SYSTEM) {

View File

@ -547,9 +547,9 @@ nsDNSService::Init()
int proxyType = nsIProtocolProxyService::PROXYCONFIG_DIRECT;
bool notifyResolution = false;
nsCString ipv4OnlyDomains;
nsCString localDomains;
nsCString forceResolve;
nsAutoCString ipv4OnlyDomains;
nsAutoCString localDomains;
nsAutoCString forceResolve;
// read prefs
nsCOMPtr<nsIPrefBranch> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
@ -564,9 +564,9 @@ nsDNSService::Init()
// ASSUMPTION: pref branch does not modify out params on failure
prefs->GetBoolPref(kPrefDisableIPv6, &disableIPv6);
prefs->GetCharPref(kPrefIPv4OnlyDomains, getter_Copies(ipv4OnlyDomains));
prefs->GetCharPref(kPrefDnsLocalDomains, getter_Copies(localDomains));
prefs->GetCharPref(kPrefDnsForceResolve, getter_Copies(forceResolve));
prefs->GetCharPref(kPrefIPv4OnlyDomains, ipv4OnlyDomains);
prefs->GetCharPref(kPrefDnsLocalDomains, localDomains);
prefs->GetCharPref(kPrefDnsForceResolve, forceResolve);
prefs->GetBoolPref(kPrefDnsOfflineLocalhost, &offlineLocalhost);
prefs->GetBoolPref(kPrefDisablePrefetch, &disablePrefetch);
prefs->GetBoolPref(kPrefBlockDotOnion, &blockDotOnion);

View File

@ -123,9 +123,9 @@ void nsIDNService::prefsChanged(nsIPrefBranch *prefBranch, const char16_t *pref)
mIDNUseWhitelist = val;
}
if (!pref || NS_LITERAL_STRING(NS_NET_PREF_IDNRESTRICTION).Equals(pref)) {
nsCString profile;
nsAutoCString profile;
if (NS_FAILED(prefBranch->GetCharPref(NS_NET_PREF_IDNRESTRICTION,
getter_Copies(profile)))) {
profile))) {
profile.Truncate();
}
if (profile.EqualsLiteral("moderate")) {

View File

@ -785,7 +785,7 @@ nsFtpState::S_pass() {
// XXX Is UTF-8 the best choice?
AppendUTF16toUTF8(mPassword, passwordStr);
} else {
nsCString anonPassword;
nsAutoCString anonPassword;
bool useRealEmail = false;
nsCOMPtr<nsIPrefBranch> prefs =
do_GetService(NS_PREFSERVICE_CONTRACTID);
@ -793,7 +793,7 @@ nsFtpState::S_pass() {
rv = prefs->GetBoolPref("advanced.mailftp", &useRealEmail);
if (NS_SUCCEEDED(rv) && useRealEmail) {
prefs->GetCharPref("network.ftp.anonymous_password",
getter_Copies(anonPassword));
anonPassword);
}
}
if (!anonPassword.IsEmpty()) {

View File

@ -924,7 +924,7 @@ nsGIOProtocolHandler::InitSupportedProtocolsPref(nsIPrefBranch *prefs)
// irrelevant to process by browser. By default accept only smb and sftp
// protocols so far.
nsresult rv = prefs->GetCharPref(MOZ_GIO_SUPPORTED_PROTOCOLS,
getter_Copies(mSupportedProtocols));
mSupportedProtocols);
if (NS_SUCCEEDED(rv)) {
mSupportedProtocols.StripWhitespace();
ToLowerCase(mSupportedProtocols);

View File

@ -137,15 +137,11 @@ URIMatchesPrefPattern(nsIURI *uri, const char *pref)
return false;
}
char *hostList;
if (NS_FAILED(prefs->GetCharPref(pref, &hostList)) || !hostList) {
nsAutoCString hostList;
if (NS_FAILED(prefs->GetCharPref(pref, hostList)) || hostList.IsEmpty()) {
return false;
}
struct FreePolicy { void operator()(void* p) { free(p); } };
mozilla::UniquePtr<char[], FreePolicy> hostListScope;
hostListScope.reset(hostList);
// pseudo-BNF
// ----------
//

View File

@ -1165,8 +1165,7 @@ nsHttpHandler::PrefsChanged(nsIPrefBranch *prefs, const char *pref)
// general.useragent.override
if (PREF_CHANGED(UA_PREF("override"))) {
prefs->GetCharPref(UA_PREF("override"),
getter_Copies(mUserAgentOverride));
prefs->GetCharPref(UA_PREF("override"), mUserAgentOverride);
mUserAgentIsDirty = true;
}
@ -1343,8 +1342,8 @@ nsHttpHandler::PrefsChanged(nsIPrefBranch *prefs, const char *pref)
}
if (PREF_CHANGED(HTTP_PREF("version"))) {
nsCString httpVersion;
prefs->GetCharPref(HTTP_PREF("version"), getter_Copies(httpVersion));
nsAutoCString httpVersion;
prefs->GetCharPref(HTTP_PREF("version"), httpVersion);
if (!httpVersion.IsVoid()) {
if (httpVersion.EqualsLiteral("1.1"))
mHttpVersion = NS_HTTP_VERSION_1_1;
@ -1356,8 +1355,8 @@ nsHttpHandler::PrefsChanged(nsIPrefBranch *prefs, const char *pref)
}
if (PREF_CHANGED(HTTP_PREF("proxy.version"))) {
nsCString httpVersion;
prefs->GetCharPref(HTTP_PREF("proxy.version"), getter_Copies(httpVersion));
nsAutoCString httpVersion;
prefs->GetCharPref(HTTP_PREF("proxy.version"), httpVersion);
if (!httpVersion.IsVoid()) {
if (httpVersion.EqualsLiteral("1.1"))
mProxyHttpVersion = NS_HTTP_VERSION_1_1;
@ -1374,9 +1373,8 @@ nsHttpHandler::PrefsChanged(nsIPrefBranch *prefs, const char *pref)
}
if (PREF_CHANGED(HTTP_PREF("accept.default"))) {
nsCString accept;
rv = prefs->GetCharPref(HTTP_PREF("accept.default"),
getter_Copies(accept));
nsAutoCString accept;
rv = prefs->GetCharPref(HTTP_PREF("accept.default"), accept);
if (NS_SUCCEEDED(rv)) {
rv = SetAccept(accept.get());
MOZ_ASSERT(NS_SUCCEEDED(rv));
@ -1384,9 +1382,8 @@ nsHttpHandler::PrefsChanged(nsIPrefBranch *prefs, const char *pref)
}
if (PREF_CHANGED(HTTP_PREF("accept-encoding"))) {
nsCString acceptEncodings;
rv = prefs->GetCharPref(HTTP_PREF("accept-encoding"),
getter_Copies(acceptEncodings));
nsAutoCString acceptEncodings;
rv = prefs->GetCharPref(HTTP_PREF("accept-encoding"), acceptEncodings);
if (NS_SUCCEEDED(rv)) {
rv = SetAcceptEncodings(acceptEncodings.get(), false);
MOZ_ASSERT(NS_SUCCEEDED(rv));
@ -1394,9 +1391,9 @@ nsHttpHandler::PrefsChanged(nsIPrefBranch *prefs, const char *pref)
}
if (PREF_CHANGED(HTTP_PREF("accept-encoding.secure"))) {
nsCString acceptEncodings;
nsAutoCString acceptEncodings;
rv = prefs->GetCharPref(HTTP_PREF("accept-encoding.secure"),
getter_Copies(acceptEncodings));
acceptEncodings);
if (NS_SUCCEEDED(rv)) {
rv = SetAcceptEncodings(acceptEncodings.get(), true);
MOZ_ASSERT(NS_SUCCEEDED(rv));
@ -1404,9 +1401,8 @@ nsHttpHandler::PrefsChanged(nsIPrefBranch *prefs, const char *pref)
}
if (PREF_CHANGED(HTTP_PREF("default-socket-type"))) {
nsCString sval;
rv = prefs->GetCharPref(HTTP_PREF("default-socket-type"),
getter_Copies(sval));
nsAutoCString sval;
rv = prefs->GetCharPref(HTTP_PREF("default-socket-type"), sval);
if (NS_SUCCEEDED(rv)) {
if (sval.IsEmpty())
mDefaultSocketType.SetIsVoid(true);

View File

@ -149,9 +149,9 @@ nsTypeAheadFind::PrefsReset()
bool isSoundEnabled = true;
prefBranch->GetBoolPref("accessibility.typeaheadfind.enablesound",
&isSoundEnabled);
nsCString soundStr;
nsAutoCString soundStr;
if (isSoundEnabled)
prefBranch->GetCharPref("accessibility.typeaheadfind.soundURL", getter_Copies(soundStr));
prefBranch->GetCharPref("accessibility.typeaheadfind.soundURL", soundStr);
mNotFoundSoundURL = soundStr;

View File

@ -136,9 +136,8 @@ CreateClientInfo()
nsCOMPtr<nsIPrefBranch> prefBranch =
do_GetService(NS_PREFSERVICE_CONTRACTID);
nsCString clientId;
nsresult rv = prefBranch->GetCharPref("browser.safebrowsing.id",
getter_Copies(clientId));
nsAutoCString clientId;
nsresult rv = prefBranch->GetCharPref("browser.safebrowsing.id", clientId);
if (NS_FAILED(rv)) {
clientId = "Firefox"; // Use "Firefox" as fallback.
@ -344,8 +343,8 @@ nsUrlClassifierUtils::GetProtocolVersion(const nsACString& aProvider,
if (prefBranch) {
nsPrintfCString prefName("browser.safebrowsing.provider.%s.pver",
nsCString(aProvider).get());
nsCString version;
nsresult rv = prefBranch->GetCharPref(prefName.get(), getter_Copies(version));
nsAutoCString version;
nsresult rv = prefBranch->GetCharPref(prefName.get(), version);
aVersion = NS_SUCCEEDED(rv) ? version.get() : DEFAULT_PROTOCOL_VERSION;
} else {
@ -836,9 +835,8 @@ nsUrlClassifierUtils::ReadProvidersFromPrefs(ProviderDictType& aDict)
nsCString provider(entry->GetKey());
nsPrintfCString owninListsPref("%s.lists", provider.get());
nsCString owningLists;
nsresult rv = prefBranch->GetCharPref(owninListsPref.get(),
getter_Copies(owningLists));
nsAutoCString owningLists;
nsresult rv = prefBranch->GetCharPref(owninListsPref.get(), owningLists);
if (NS_FAILED(rv)) {
continue;
}

View File

@ -4359,8 +4359,8 @@ XREMain::XRE_mainRun()
rv = prefs->GetDefaultBranch(nullptr, getter_AddRefs(defaultPrefBranch));
if (NS_SUCCEEDED(rv)) {
nsCString sval;
rv = defaultPrefBranch->GetCharPref("app.update.channel", getter_Copies(sval));
nsAutoCString sval;
rv = defaultPrefBranch->GetCharPref("app.update.channel", sval);
if (NS_SUCCEEDED(rv)) {
CrashReporter::AnnotateCrashReport(NS_LITERAL_CSTRING("ReleaseChannel"),
sval);