From 0574a6b496f76a0de042fbaf9f0d81cb074a591d Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Tue, 25 Jul 2017 20:36:14 +1000 Subject: [PATCH] Bug 1384835 (part 2) - Remove the Preferences::Get*String() variants that return nsAdoptingString. r=froydnj. Because we want to remove nsAdoptingString. We have other variants that don't use nsAdoptingString, which can be used instead. There are three basic patterns. 1. The easiest case is when we don't check for success. > nsAdoptingString s = Preferences::GetString("foo"); > foo(s); becomes: > nsAutoString s; > Preferences::GetString("foo", s); > foo(s); 2. The next case is when we check if the result is empty. > nsAdoptingString s = Preferences::GetString("foo"); > if (s.IsEmpty()) { ... } becomes: > nsAutoString s; > Preferences::GetString("foo", s); > if (s.IsEmpty()) { ... } 3. The final case is when we null check the result. > nsAdoptingString s = Preferences::GetString("foo"); > if (s) { ... } becomes: > nsAutoString s; > nsresult rv = Preferences::GetString("foo", s); > if (NS_SUCCEEDED(rv)) { ... } The patch also avoids some UTF8/UTF16 conversions in a few places. --HG-- extra : rebase_source : f339b1a3dda4dc93979d38c30c001fbe77485b55 --- caps/nsScriptSecurityManager.cpp | 4 +- dom/audiochannel/AudioChannelService.cpp | 3 +- dom/base/Navigator.cpp | 49 ++++++++++++----------- dom/base/nsContentUtils.cpp | 3 +- dom/base/nsDocument.cpp | 5 ++- dom/base/nsGlobalWindow.cpp | 4 +- dom/html/HTMLInputElement.cpp | 2 +- dom/media/CubebUtils.cpp | 26 ++++++------ dom/media/DecoderDoctorDiagnostics.cpp | 4 +- dom/svg/SVGSwitchElement.cpp | 4 +- dom/svg/SVGTests.cpp | 8 +++- dom/workers/RuntimeService.cpp | 12 +++--- editor/composer/nsEditorSpellCheck.cpp | 2 +- gfx/src/DriverCrashGuard.cpp | 3 +- gfx/thebes/gfxFcPlatformFontList.cpp | 14 ++++--- gfx/thebes/gfxFontUtils.cpp | 5 ++- gfx/thebes/gfxPlatform.cpp | 6 +-- layout/base/StaticPresData.cpp | 5 ++- layout/base/nsPresContext.cpp | 24 +++++------ layout/xul/nsTextBoxFrame.cpp | 6 ++- modules/libpref/Preferences.cpp | 36 ----------------- modules/libpref/Preferences.h | 5 --- security/manager/ssl/nsNSSComponent.cpp | 15 +++---- toolkit/xre/nsXREDirProvider.cpp | 5 ++- widget/android/PrefsHelper.h | 25 +++++++----- widget/cocoa/nsDeviceContextSpecX.mm | 6 +-- widget/windows/IMMHandler.cpp | 16 +++++--- widget/windows/PDFiumEngineShim.cpp | 6 +-- widget/windows/nsDeviceContextSpecWin.cpp | 7 ++-- widget/windows/nsWindow.cpp | 4 +- 30 files changed, 148 insertions(+), 166 deletions(-) diff --git a/caps/nsScriptSecurityManager.cpp b/caps/nsScriptSecurityManager.cpp index 648960f438ff..01645c752d96 100644 --- a/caps/nsScriptSecurityManager.cpp +++ b/caps/nsScriptSecurityManager.cpp @@ -1655,7 +1655,9 @@ nsScriptSecurityManager::EnsureFileURIWhitelist() nsCString checkLoadURIPrefName = NS_LITERAL_CSTRING("capability.policy.") + policyName + NS_LITERAL_CSTRING(".checkloaduri.enabled"); - if (!Preferences::GetString(checkLoadURIPrefName.get()).LowerCaseEqualsLiteral("allaccess")) { + nsAutoString value; + nsresult rv = Preferences::GetString(checkLoadURIPrefName.get(), value); + if (NS_FAILED(rv) || !value.LowerCaseEqualsLiteral("allaccess")) { continue; } diff --git a/dom/audiochannel/AudioChannelService.cpp b/dom/audiochannel/AudioChannelService.cpp index 365d84bfe36f..56a67bb00956 100644 --- a/dom/audiochannel/AudioChannelService.cpp +++ b/dom/audiochannel/AudioChannelService.cpp @@ -563,7 +563,8 @@ AudioChannelService::GetAudioChannel(const nsAString& aChannel) /* static */ AudioChannel AudioChannelService::GetDefaultAudioChannel() { - nsAutoString audioChannel(Preferences::GetString("media.defaultAudioChannel")); + nsAutoString audioChannel; + Preferences::GetString("media.defaultAudioChannel", audioChannel); if (audioChannel.IsEmpty()) { return AudioChannel::Normal; } diff --git a/dom/base/Navigator.cpp b/dom/base/Navigator.cpp index ab24d4db0c5d..a9d7b77c7b7c 100644 --- a/dom/base/Navigator.cpp +++ b/dom/base/Navigator.cpp @@ -379,8 +379,8 @@ Navigator::GetAcceptLanguages(nsTArray& aLanguages) aLanguages.Clear(); // E.g. "de-de, en-us,en". - const nsAdoptingString& acceptLang = - Preferences::GetLocalizedString("intl.accept_languages"); + nsAutoString acceptLang; + Preferences::GetLocalizedString("intl.accept_languages", acceptLang); // Split values on commas. nsCharSeparatedTokenizer langTokenizer(acceptLang, ','); @@ -473,10 +473,9 @@ Navigator::GetOscpu(nsAString& aOSCPU, CallerType aCallerType, return; } - const nsAdoptingString& override = - Preferences::GetString("general.oscpu.override"); - - if (override) { + nsAutoString override; + nsresult rv = Preferences::GetString("general.oscpu.override", override); + if (NS_SUCCEEDED(rv)) { aOSCPU = override; return; } @@ -653,10 +652,9 @@ Navigator::GetBuildID(nsAString& aBuildID, CallerType aCallerType, aBuildID.AssignLiteral(LEGACY_BUILD_ID); return; } - const nsAdoptingString& override = - Preferences::GetString("general.buildID.override"); - - if (override) { + nsAutoString override; + nsresult rv = Preferences::GetString("general.buildID.override", override); + if (NS_SUCCEEDED(rv)) { aBuildID = override; return; } @@ -704,7 +702,8 @@ Navigator::JavaEnabled(CallerType aCallerType, ErrorResult& aRv) Telemetry::AutoTimer telemetryTimer; // Return true if we have a handler for the java mime - nsAdoptingString javaMIME = Preferences::GetString("plugin.java.mime"); + nsAutoString javaMIME; + Preferences::GetString("plugin.java.mime", javaMIME); NS_ENSURE_TRUE(!javaMIME.IsEmpty(), false); if (!mMimeTypes) { @@ -1783,10 +1782,11 @@ Navigator::GetPlatform(nsAString& aPlatform, bool aUsePrefOverriddenValue) aPlatform.AssignLiteral(SPOOFED_PLATFORM); return NS_OK; } - const nsAdoptingString& override = - mozilla::Preferences::GetString("general.platform.override"); + nsAutoString override; + nsresult rv = + mozilla::Preferences::GetString("general.platform.override", override); - if (override) { + if (NS_SUCCEEDED(rv)) { aPlatform = override; return NS_OK; } @@ -1834,10 +1834,11 @@ Navigator::GetAppVersion(nsAString& aAppVersion, bool aUsePrefOverriddenValue) aAppVersion.AssignLiteral(SPOOFED_APPVERSION); return NS_OK; } - const nsAdoptingString& override = - mozilla::Preferences::GetString("general.appversion.override"); + nsAutoString override; + nsresult rv = + mozilla::Preferences::GetString("general.appversion.override", override); - if (override) { + if (NS_SUCCEEDED(rv)) { aAppVersion = override; return NS_OK; } @@ -1878,10 +1879,11 @@ Navigator::AppName(nsAString& aAppName, bool aUsePrefOverriddenValue) return; } - const nsAdoptingString& override = - mozilla::Preferences::GetString("general.appname.override"); + nsAutoString override; + nsresult rv = + mozilla::Preferences::GetString("general.appname.override", override); - if (override) { + if (NS_SUCCEEDED(rv)) { aAppName = override; return; } @@ -1907,10 +1909,11 @@ Navigator::GetUserAgent(nsPIDOMWindowInner* aWindow, // when 'privacy.resistFingerprinting' is true. if (!aIsCallerChrome && !nsContentUtils::ShouldResistFingerprinting()) { - const nsAdoptingString& override = - mozilla::Preferences::GetString("general.useragent.override"); + nsAutoString override; + nsresult rv = + mozilla::Preferences::GetString("general.useragent.override", override); - if (override) { + if (NS_SUCCEEDED(rv)) { aUserAgent = override; return NS_OK; } diff --git a/dom/base/nsContentUtils.cpp b/dom/base/nsContentUtils.cpp index cf127d5985c7..f387db9a076c 100644 --- a/dom/base/nsContentUtils.cpp +++ b/dom/base/nsContentUtils.cpp @@ -5577,7 +5577,8 @@ nsContentUtils::GetLocalizedEllipsis() { static char16_t sBuf[4] = { 0, 0, 0, 0 }; if (!sBuf[0]) { - nsAdoptingString tmp = Preferences::GetLocalizedString("intl.ellipsis"); + nsAutoString tmp; + Preferences::GetLocalizedString("intl.ellipsis", tmp); uint32_t len = std::min(uint32_t(tmp.Length()), uint32_t(ArrayLength(sBuf) - 1)); CopyUnicodeTo(tmp, 0, sBuf, len); diff --git a/dom/base/nsDocument.cpp b/dom/base/nsDocument.cpp index 463a2f3a0c65..9c0b74fcf647 100644 --- a/dom/base/nsDocument.cpp +++ b/dom/base/nsDocument.cpp @@ -2764,8 +2764,9 @@ nsDocument::InitCSP(nsIChannel* aChannel) // Note that when the content signing becomes a standard, we might have // to restrict this enforcement to "remote content" only. if (applySignedContentCSP) { - nsAdoptingString signedContentCSP = - Preferences::GetString("security.signed_content.CSP.default"); + nsAutoString signedContentCSP; + Preferences::GetString("security.signed_content.CSP.default", + signedContentCSP); csp->AppendPolicy(signedContentCSP, false, false); } diff --git a/dom/base/nsGlobalWindow.cpp b/dom/base/nsGlobalWindow.cpp index a32f007de8b1..2a29ac50cb94 100644 --- a/dom/base/nsGlobalWindow.cpp +++ b/dom/base/nsGlobalWindow.cpp @@ -8046,8 +8046,8 @@ nsGlobalWindow::HomeOuter(nsIPrincipal& aSubjectPrincipal, ErrorResult& aError) return; } - nsAdoptingString homeURL = - Preferences::GetLocalizedString(PREF_BROWSER_STARTUP_HOMEPAGE); + nsAutoString homeURL; + Preferences::GetLocalizedString(PREF_BROWSER_STARTUP_HOMEPAGE, homeURL); if (homeURL.IsEmpty()) { // if all else fails, use this diff --git a/dom/html/HTMLInputElement.cpp b/dom/html/HTMLInputElement.cpp index 027909bd6046..dc3db039fe18 100644 --- a/dom/html/HTMLInputElement.cpp +++ b/dom/html/HTMLInputElement.cpp @@ -484,7 +484,7 @@ UploadLastDir::ContentPrefCallback::HandleCompletion(uint16_t aReason) nsAutoString prefStr; if (aReason == nsIContentPrefCallback2::COMPLETE_ERROR || !mResult) { - prefStr = Preferences::GetString("dom.input.fallbackUploadDir"); + Preferences::GetString("dom.input.fallbackUploadDir", prefStr); } if (prefStr.IsEmpty() && mResult) { diff --git a/dom/media/CubebUtils.cpp b/dom/media/CubebUtils.cpp index 192aef8c2a3f..8560db02bcc7 100644 --- a/dom/media/CubebUtils.cpp +++ b/dom/media/CubebUtils.cpp @@ -162,13 +162,13 @@ namespace CubebUtils { void PrefChanged(const char* aPref, void* aClosure) { if (strcmp(aPref, PREF_VOLUME_SCALE) == 0) { - nsAdoptingString value = Preferences::GetString(aPref); + nsAutoCString value; + Preferences::GetCString(aPref, value); StaticMutexAutoLock lock(sMutex); if (value.IsEmpty()) { sVolumeScale = 1.0; } else { - NS_ConvertUTF16toUTF8 utf8(value); - sVolumeScale = std::max(0, PR_strtod(utf8.get(), nullptr)); + sVolumeScale = std::max(0, PR_strtod(value.get(), nullptr)); } } else if (strcmp(aPref, PREF_CUBEB_LATENCY_PLAYBACK) == 0) { // Arbitrary default stream latency of 100ms. The higher this @@ -188,28 +188,28 @@ void PrefChanged(const char* aPref, void* aClosure) // experiment. sCubebMSGLatencyInFrames = std::min(std::max(value, 128), 1e6); } else if (strcmp(aPref, PREF_CUBEB_LOGGING_LEVEL) == 0) { - nsAdoptingString value = Preferences::GetString(aPref); - NS_ConvertUTF16toUTF8 utf8(value); + nsAutoCString value; + Preferences::GetCString(aPref, value); LogModule* cubebLog = LogModule::Get("cubeb"); - if (strcmp(utf8.get(), "verbose") == 0) { + if (value.EqualsLiteral("verbose")) { cubeb_set_log_callback(CUBEB_LOG_VERBOSE, CubebLogCallback); cubebLog->SetLevel(LogLevel::Verbose); - } else if (strcmp(utf8.get(), "normal") == 0) { + } else if (value.EqualsLiteral("normal")) { cubeb_set_log_callback(CUBEB_LOG_NORMAL, CubebLogCallback); cubebLog->SetLevel(LogLevel::Error); - } else if (utf8.IsEmpty()) { + } else if (value.IsEmpty()) { cubeb_set_log_callback(CUBEB_LOG_DISABLED, nullptr); cubebLog->SetLevel(LogLevel::Disabled); } } else if (strcmp(aPref, PREF_CUBEB_BACKEND) == 0) { - nsAdoptingString value = Preferences::GetString(aPref); + nsAutoCString value; + Preferences::GetCString(aPref, value); if (value.IsEmpty()) { sCubebBackendName = nullptr; } else { - NS_LossyConvertUTF16toASCII ascii(value); - sCubebBackendName = new char[ascii.Length() + 1]; - PodCopy(sCubebBackendName.get(), ascii.get(), ascii.Length()); - sCubebBackendName[ascii.Length()] = 0; + sCubebBackendName = new char[value.Length() + 1]; + PodCopy(sCubebBackendName.get(), value.get(), value.Length()); + sCubebBackendName[value.Length()] = 0; } } } diff --git a/dom/media/DecoderDoctorDiagnostics.cpp b/dom/media/DecoderDoctorDiagnostics.cpp index 27eeeca3ec60..587da2a572b7 100644 --- a/dom/media/DecoderDoctorDiagnostics.cpp +++ b/dom/media/DecoderDoctorDiagnostics.cpp @@ -628,8 +628,8 @@ DecoderDoctorDocumentWatcher::SynthesizeAnalysis() nsAutoCString formatsPref("media.decoder-doctor."); formatsPref += id->mReportStringId; formatsPref += ".formats"; - nsAdoptingString formatsWithIssues = - Preferences::GetString(formatsPref.Data()); + nsAutoString formatsWithIssues; + Preferences::GetString(formatsPref.Data(), formatsWithIssues); if (formatsWithIssues.IsEmpty()) { continue; } diff --git a/dom/svg/SVGSwitchElement.cpp b/dom/svg/SVGSwitchElement.cpp index a0358dc155bb..13f83c945e5a 100644 --- a/dom/svg/SVGSwitchElement.cpp +++ b/dom/svg/SVGSwitchElement.cpp @@ -127,8 +127,8 @@ SVGSwitchElement::IsAttributeMapped(const nsIAtom* name) const nsIContent * SVGSwitchElement::FindActiveChild() const { - const nsAdoptingString& acceptLangs = - Preferences::GetLocalizedString("intl.accept_languages"); + nsAutoString acceptLangs; + Preferences::GetLocalizedString("intl.accept_languages", acceptLangs); if (!acceptLangs.IsEmpty()) { int32_t bestLanguagePreferenceRank = -1; diff --git a/dom/svg/SVGTests.cpp b/dom/svg/SVGTests.cpp index c0883b510788..77898f104663 100644 --- a/dom/svg/SVGTests.cpp +++ b/dom/svg/SVGTests.cpp @@ -147,8 +147,12 @@ SVGTests::PassesConditionalProcessingTests(const nsString *aAcceptLangs) const } // Get our language preferences - const nsAutoString acceptLangs(aAcceptLangs ? *aAcceptLangs : - Preferences::GetLocalizedString("intl.accept_languages")); + nsAutoString acceptLangs; + if (aAcceptLangs) { + acceptLangs.Assign(*aAcceptLangs); + } else { + Preferences::GetLocalizedString("intl.accept_languages", acceptLangs); + } if (acceptLangs.IsEmpty()) { NS_WARNING("no default language specified for systemLanguage conditional test"); diff --git a/dom/workers/RuntimeService.cpp b/dom/workers/RuntimeService.cpp index 880eaf878ea5..e3a0515024ed 100644 --- a/dom/workers/RuntimeService.cpp +++ b/dom/workers/RuntimeService.cpp @@ -1323,8 +1323,8 @@ AppNameOverrideChanged(const char* /* aPrefName */, void* /* aClosure */) { AssertIsOnMainThread(); - const nsAdoptingString& override = - mozilla::Preferences::GetString("general.appname.override"); + nsAutoString override; + Preferences::GetString("general.appname.override", override); RuntimeService* runtime = RuntimeService::GetService(); if (runtime) { @@ -1337,8 +1337,8 @@ AppVersionOverrideChanged(const char* /* aPrefName */, void* /* aClosure */) { AssertIsOnMainThread(); - const nsAdoptingString& override = - mozilla::Preferences::GetString("general.appversion.override"); + nsAutoString override; + Preferences::GetString("general.appversion.override", override); RuntimeService* runtime = RuntimeService::GetService(); if (runtime) { @@ -1351,8 +1351,8 @@ PlatformOverrideChanged(const char* /* aPrefName */, void* /* aClosure */) { AssertIsOnMainThread(); - const nsAdoptingString& override = - mozilla::Preferences::GetString("general.platform.override"); + nsAutoString override; + Preferences::GetString("general.platform.override", override); RuntimeService* runtime = RuntimeService::GetService(); if (runtime) { diff --git a/editor/composer/nsEditorSpellCheck.cpp b/editor/composer/nsEditorSpellCheck.cpp index 972a3f8d78f2..30ee70722efe 100644 --- a/editor/composer/nsEditorSpellCheck.cpp +++ b/editor/composer/nsEditorSpellCheck.cpp @@ -904,7 +904,7 @@ nsEditorSpellCheck::SetFallbackDictionary(DictionaryFetcher* aFetcher) // Get the preference value. nsAutoString preferredDict; - preferredDict = Preferences::GetLocalizedString("spellchecker.dictionary"); + Preferences::GetLocalizedString("spellchecker.dictionary", preferredDict); if (!dictName.IsEmpty()) { // RFC 5646 explicitly states that matches should be case-insensitive. diff --git a/gfx/src/DriverCrashGuard.cpp b/gfx/src/DriverCrashGuard.cpp index 89fb4771835b..8ef45775af07 100644 --- a/gfx/src/DriverCrashGuard.cpp +++ b/gfx/src/DriverCrashGuard.cpp @@ -351,7 +351,8 @@ DriverCrashGuard::CheckAndUpdatePref(const char* aPrefName, const nsAString& aCu { std::string pref = GetFullPrefName(aPrefName); - nsAdoptingString oldValue = Preferences::GetString(pref.c_str()); + nsAutoString oldValue; + Preferences::GetString(pref.c_str(), oldValue); if (oldValue == aCurrentValue) { return false; } diff --git a/gfx/thebes/gfxFcPlatformFontList.cpp b/gfx/thebes/gfxFcPlatformFontList.cpp index 3c78356d9813..7ad2d38fd9c2 100644 --- a/gfx/thebes/gfxFcPlatformFontList.cpp +++ b/gfx/thebes/gfxFcPlatformFontList.cpp @@ -1698,17 +1698,21 @@ gfxFcPlatformFontList::AddGenericFonts(mozilla::FontFamilyType aGenericType, if ((!mAlwaysUseFontconfigGenerics && aLanguage) || aLanguage == nsGkAtoms::x_math) { nsIAtom* langGroup = GetLangGroup(aLanguage); - nsAdoptingString fontlistValue = - Preferences::GetString(NamePref(generic, langGroup).get()); + nsAutoString fontlistValue; + Preferences::GetString(NamePref(generic, langGroup).get(), + fontlistValue); + nsresult rv; if (fontlistValue.IsEmpty()) { // The font name list may have two or more family names as comma // separated list. In such case, not matching with generic font // name is fine because if the list prefers specific font, we // should try to use the pref with complicated path. - fontlistValue = - Preferences::GetString(NameListPref(generic, langGroup).get()); + rv = Preferences::GetString(NameListPref(generic, langGroup).get(), + fontlistValue); + } else { + rv = NS_OK; } - if (fontlistValue) { + if (NS_SUCCEEDED(rv)) { if (!fontlistValue.EqualsLiteral("serif") && !fontlistValue.EqualsLiteral("sans-serif") && !fontlistValue.EqualsLiteral("monospace")) { diff --git a/gfx/thebes/gfxFontUtils.cpp b/gfx/thebes/gfxFontUtils.cpp index d340c8434569..27682a77816a 100644 --- a/gfx/thebes/gfxFontUtils.cpp +++ b/gfx/thebes/gfxFontUtils.cpp @@ -860,8 +860,9 @@ void gfxFontUtils::AppendPrefsFontList(const char *aPrefName, nsTArray& aFontList) { // get the list of single-face font families - nsAdoptingString fontlistValue = Preferences::GetString(aPrefName); - if (!fontlistValue) { + nsAutoString fontlistValue; + nsresult rv = Preferences::GetString(aPrefName, fontlistValue); + if (NS_FAILED(rv)) { return; } diff --git a/gfx/thebes/gfxPlatform.cpp b/gfx/thebes/gfxPlatform.cpp index b7569deeaf89..8048928940d2 100644 --- a/gfx/thebes/gfxPlatform.cpp +++ b/gfx/thebes/gfxPlatform.cpp @@ -570,9 +570,9 @@ void RecordingPrefChanged(const char *aPrefName, void *aClosure) { if (Preferences::GetBool("gfx.2d.recording", false)) { nsAutoCString fileName; - nsAdoptingString prefFileName = Preferences::GetString("gfx.2d.recordingfile"); - - if (prefFileName) { + nsAutoString prefFileName; + nsresult rv = Preferences::GetString("gfx.2d.recordingfile", prefFileName); + if (NS_SUCCEEDED(rv)) { fileName.Append(NS_ConvertUTF16toUTF8(prefFileName)); } else { nsCOMPtr tmpFile; diff --git a/layout/base/StaticPresData.cpp b/layout/base/StaticPresData.cpp index d7929f7edb00..5f8eefe3dc32 100644 --- a/layout/base/StaticPresData.cpp +++ b/layout/base/StaticPresData.cpp @@ -163,7 +163,8 @@ LangGroupFontPrefs::Initialize(nsIAtom* aLangGroupAtom) // XXX "font.name.variable."? There is no such pref... MAKE_FONT_PREF_KEY(pref, "font.name.variable.", langGroup); - nsAdoptingString value = Preferences::GetString(pref.get()); + nsAutoString value; + Preferences::GetString(pref.get(), value); if (!value.IsEmpty()) { FontFamilyName defaultVariableName = FontFamilyName::Convert(value); FontFamilyType defaultType = defaultVariableName.mType; @@ -174,7 +175,7 @@ LangGroupFontPrefs::Initialize(nsIAtom* aLangGroupAtom) } else { MAKE_FONT_PREF_KEY(pref, "font.default.", langGroup); - value = Preferences::GetString(pref.get()); + Preferences::GetString(pref.get(), value); if (!value.IsEmpty()) { FontFamilyName defaultVariableName = FontFamilyName::Convert(value); FontFamilyType defaultType = defaultVariableName.mType; diff --git a/layout/base/nsPresContext.cpp b/layout/base/nsPresContext.cpp index c925ef7cff63..dade9f3b0a03 100644 --- a/layout/base/nsPresContext.cpp +++ b/layout/base/nsPresContext.cpp @@ -516,15 +516,13 @@ nsPresContext::GetDocumentColorPreferences() mBackgroundColor = LookAndFeel::GetColorUsingStandins( LookAndFeel::eColorID_window, NS_RGB(0xff, 0xff, 0xff)); } else if (usePrefColors) { - nsAdoptingString colorStr = - Preferences::GetString("browser.display.foreground_color"); - + nsAutoString colorStr; + Preferences::GetString("browser.display.foreground_color", colorStr); if (!colorStr.IsEmpty()) { mDefaultColor = MakeColorPref(colorStr); } - colorStr = Preferences::GetString("browser.display.background_color"); - + Preferences::GetString("browser.display.background_color", colorStr); if (!colorStr.IsEmpty()) { mBackgroundColor = MakeColorPref(colorStr); } @@ -583,20 +581,18 @@ nsPresContext::GetUserPreferences() mUnderlineLinks = Preferences::GetBool("browser.underline_anchors", mUnderlineLinks); - nsAdoptingString colorStr = Preferences::GetString("browser.anchor_color"); - + nsAutoString colorStr; + Preferences::GetString("browser.anchor_color", colorStr); if (!colorStr.IsEmpty()) { mLinkColor = MakeColorPref(colorStr); } - colorStr = Preferences::GetString("browser.active_color"); - + Preferences::GetString("browser.active_color", colorStr); if (!colorStr.IsEmpty()) { mActiveLinkColor = MakeColorPref(colorStr); } - colorStr = Preferences::GetString("browser.visited_color"); - + Preferences::GetString("browser.visited_color", colorStr); if (!colorStr.IsEmpty()) { mVisitedLinkColor = MakeColorPref(colorStr); } @@ -607,14 +603,12 @@ nsPresContext::GetUserPreferences() mFocusTextColor = mDefaultColor; mFocusBackgroundColor = mBackgroundColor; - colorStr = Preferences::GetString("browser.display.focus_text_color"); - + Preferences::GetString("browser.display.focus_text_color", colorStr); if (!colorStr.IsEmpty()) { mFocusTextColor = MakeColorPref(colorStr); } - colorStr = Preferences::GetString("browser.display.focus_background_color"); - + Preferences::GetString("browser.display.focus_background_color", colorStr); if (!colorStr.IsEmpty()) { mFocusBackgroundColor = MakeColorPref(colorStr); } diff --git a/layout/xul/nsTextBoxFrame.cpp b/layout/xul/nsTextBoxFrame.cpp index 78ed70a81443..9b05cc250b5c 100644 --- a/layout/xul/nsTextBoxFrame.cpp +++ b/layout/xul/nsTextBoxFrame.cpp @@ -146,7 +146,8 @@ nsTextBoxFrame::AlwaysAppendAccessKey() gAccessKeyPrefInitialized = true; const char* prefName = "intl.menuitems.alwaysappendaccesskeys"; - nsAdoptingString val = Preferences::GetLocalizedString(prefName); + nsAutoString val; + Preferences::GetLocalizedString(prefName, val); gAlwaysAppendAccessKey = val.EqualsLiteral("true"); } return gAlwaysAppendAccessKey; @@ -160,7 +161,8 @@ nsTextBoxFrame::InsertSeparatorBeforeAccessKey() gInsertSeparatorPrefInitialized = true; const char* prefName = "intl.menuitems.insertseparatorbeforeaccesskeys"; - nsAdoptingString val = Preferences::GetLocalizedString(prefName); + nsAutoString val; + Preferences::GetLocalizedString(prefName, val); gInsertSeparatorBeforeAccessKey = val.EqualsLiteral("true"); } return gInsertSeparatorBeforeAccessKey; diff --git a/modules/libpref/Preferences.cpp b/modules/libpref/Preferences.cpp index 0f27a1f52153..0f1a1b8e7f5f 100644 --- a/modules/libpref/Preferences.cpp +++ b/modules/libpref/Preferences.cpp @@ -1674,15 +1674,6 @@ Preferences::GetCString(const char* aPref) return result; } -// static -nsAdoptingString -Preferences::GetString(const char* aPref) -{ - nsAdoptingString result; - GetString(aPref, result); - return result; -} - // static nsresult Preferences::GetCString(const char* aPref, nsACString& aResult) @@ -1718,15 +1709,6 @@ Preferences::GetLocalizedCString(const char* aPref) return result; } -// static -nsAdoptingString -Preferences::GetLocalizedString(const char* aPref) -{ - nsAdoptingString result; - GetLocalizedString(aPref, result); - return result; -} - // static nsresult Preferences::GetLocalizedCString(const char* aPref, nsACString& aResult) @@ -2249,15 +2231,6 @@ Preferences::GetDefaultLocalizedString(const char* aPref, return rv; } -// static -nsAdoptingString -Preferences::GetDefaultString(const char* aPref) -{ - nsAdoptingString result; - GetDefaultString(aPref, result); - return result; -} - // static nsAdoptingCString Preferences::GetDefaultCString(const char* aPref) @@ -2267,15 +2240,6 @@ Preferences::GetDefaultCString(const char* aPref) return result; } -// static -nsAdoptingString -Preferences::GetDefaultLocalizedString(const char* aPref) -{ - nsAdoptingString result; - GetDefaultLocalizedString(aPref, result); - return result; -} - // static nsAdoptingCString Preferences::GetDefaultLocalizedCString(const char* aPref) diff --git a/modules/libpref/Preferences.h b/modules/libpref/Preferences.h index f5df028e9fc1..bb88c80ed79c 100644 --- a/modules/libpref/Preferences.h +++ b/modules/libpref/Preferences.h @@ -21,7 +21,6 @@ #include "mozilla/MemoryReporting.h" class nsIFile; -class nsAdoptingString; class nsAdoptingCString; #ifndef have_PrefChangedFunc_typedef @@ -170,9 +169,7 @@ public: * when you need to check whether it was failure or not. */ static nsAdoptingCString GetCString(const char* aPref); - static nsAdoptingString GetString(const char* aPref); static nsAdoptingCString GetLocalizedCString(const char* aPref); - static nsAdoptingString GetLocalizedString(const char* aPref); /** * Gets int, float, or bool type pref value with raw return value of @@ -387,9 +384,7 @@ public: * See the comment at definition at GetString() and GetCString() for more * details of the result. */ - static nsAdoptingString GetDefaultString(const char* aPref); static nsAdoptingCString GetDefaultCString(const char* aPref); - static nsAdoptingString GetDefaultLocalizedString(const char* aPref); static nsAdoptingCString GetDefaultLocalizedCString(const char* aPref); static nsresult GetDefaultCString(const char* aPref, nsACString& aResult); diff --git a/security/manager/ssl/nsNSSComponent.cpp b/security/manager/ssl/nsNSSComponent.cpp index 707de81a51fb..d53ef8fd73da 100644 --- a/security/manager/ssl/nsNSSComponent.cpp +++ b/security/manager/ssl/nsNSSComponent.cpp @@ -1950,11 +1950,11 @@ nsNSSComponent::InitializeNSS() // ensure we have initial values for various root hashes #ifdef DEBUG - mTestBuiltInRootHash = - Preferences::GetString("security.test.built_in_root_hash"); + Preferences::GetString("security.test.built_in_root_hash", + mTestBuiltInRootHash); #endif - mContentSigningRootHash = - Preferences::GetString("security.content.signature.root_hash"); + Preferences::GetString("security.content.signature.root_hash", + mContentSigningRootHash); mNSSInitialized = true; } @@ -2122,14 +2122,15 @@ nsNSSComponent::Observe(nsISupports* aSubject, const char* aTopic, #ifdef DEBUG } else if (prefName.EqualsLiteral("security.test.built_in_root_hash")) { MutexAutoLock lock(mMutex); - mTestBuiltInRootHash = Preferences::GetString("security.test.built_in_root_hash"); + Preferences::GetString("security.test.built_in_root_hash", + mTestBuiltInRootHash); #endif // DEBUG } else if (prefName.Equals(kFamilySafetyModePref)) { MaybeEnableFamilySafetyCompatibility(); } else if (prefName.EqualsLiteral("security.content.signature.root_hash")) { MutexAutoLock lock(mMutex); - mContentSigningRootHash = - Preferences::GetString("security.content.signature.root_hash"); + Preferences::GetString("security.content.signature.root_hash", + mContentSigningRootHash); } else if (prefName.Equals(kEnterpriseRootModePref)) { MaybeImportEnterpriseRoots(); } else { diff --git a/toolkit/xre/nsXREDirProvider.cpp b/toolkit/xre/nsXREDirProvider.cpp index e76e14eff612..54bbaca6a61f 100644 --- a/toolkit/xre/nsXREDirProvider.cpp +++ b/toolkit/xre/nsXREDirProvider.cpp @@ -779,8 +779,9 @@ CreateContentProcessSandboxTempDir() // Get (and create if blank) temp directory suffix pref. nsresult rv; - nsAdoptingString tempDirSuffix = - Preferences::GetString("security.sandbox.content.tempDirSuffix"); + nsAutoString tempDirSuffix; + Preferences::GetString("security.sandbox.content.tempDirSuffix", + tempDirSuffix); if (tempDirSuffix.IsEmpty()) { nsCOMPtr uuidgen = do_GetService("@mozilla.org/uuid-generator;1", &rv); diff --git a/widget/android/PrefsHelper.h b/widget/android/PrefsHelper.h index b053c979a468..6857e5cf933a 100644 --- a/widget/android/PrefsHelper.h +++ b/widget/android/PrefsHelper.h @@ -138,7 +138,7 @@ public: nsTArray nameRefArray(aPrefNames->GetElements()); nsCOMPtr obsServ; nsCOMPtr value; - nsAdoptingString strVal; + nsAutoString strVal; for (jni::Object::LocalRef& nameRef : nameRefArray) { jni::String::LocalRef nameStr(mozilla::Move(nameRef)); @@ -159,14 +159,15 @@ public: intVal = Preferences::GetInt(name.get()); break; - case nsIPrefBranch::PREF_STRING: + case nsIPrefBranch::PREF_STRING: { type = java::PrefsHelper::PREF_STRING; - strVal = Preferences::GetLocalizedString(name.get()); - if (!strVal) { - strVal = Preferences::GetString(name.get()); + nsresult rv = + Preferences::GetLocalizedString(name.get(), strVal); + if (NS_FAILED(rv)) { + Preferences::GetString(name.get(), strVal); } break; - + } default: // Pref not found; try to find it. if (!obsServ) { @@ -288,7 +289,7 @@ public: int32_t type = -1; bool boolVal = false; int32_t intVal = false; - nsAdoptingString strVal; + nsAutoString strVal; switch (Preferences::GetType(name.get())) { case nsIPrefBranch::PREF_BOOL: @@ -299,13 +300,15 @@ public: type = java::PrefsHelper::PREF_INT; intVal = Preferences::GetInt(name.get()); break; - case nsIPrefBranch::PREF_STRING: + case nsIPrefBranch::PREF_STRING: { type = java::PrefsHelper::PREF_STRING; - strVal = Preferences::GetLocalizedString(name.get()); - if (!strVal) { - strVal = Preferences::GetString(name.get()); + nsresult rv = + Preferences::GetLocalizedString(name.get(), strVal); + if (NS_FAILED(rv)) { + Preferences::GetString(name.get(), strVal); } break; + } default: NS_WARNING(nsPrintfCString("Invalid pref %s", name.get()).get()); diff --git a/widget/cocoa/nsDeviceContextSpecX.mm b/widget/cocoa/nsDeviceContextSpecX.mm index 5dcc7ec8f2bf..905fb50d1795 100644 --- a/widget/cocoa/nsDeviceContextSpecX.mm +++ b/widget/cocoa/nsDeviceContextSpecX.mm @@ -80,9 +80,9 @@ NS_IMETHODIMP nsDeviceContextSpecX::Init(nsIWidget *aWidget, mPrintSettings = settings->GetPMPrintSettings(); #ifdef MOZ_ENABLE_SKIA_PDF - const nsAdoptingString& printViaPdf = - mozilla::Preferences::GetString("print.print_via_pdf_encoder"); - if (printViaPdf == NS_LITERAL_STRING("skia-pdf")) { + nsAutoString printViaPdf; + mozilla::Preferences::GetString("print.print_via_pdf_encoder", printViaPdf); + if (printViaPdf.EqualsLiteral("skia-pdf")) { // Annoyingly, PMPrinterPrintWithFile does not pay attention to the // kPMDestination* value set in the PMPrintSession; it always sends the PDF // to the specified printer. This means that if we create the PDF using diff --git a/widget/windows/IMMHandler.cpp b/widget/windows/IMMHandler.cpp index 18ffb2d10232..166037aa834e 100644 --- a/widget/windows/IMMHandler.cpp +++ b/widget/windows/IMMHandler.cpp @@ -363,8 +363,8 @@ IMMHandler::InitKeyboardLayout(nsWindow* aWindow, // For hacking some bugs of some TIP, we should set an IME name from the // pref. if (sCodePage == 932 && sIMEName.IsEmpty()) { - sIMEName = - Preferences::GetString("intl.imm.japanese.assume_active_tip_name_as"); + Preferences::GetString("intl.imm.japanese.assume_active_tip_name_as", + sIMEName); } // Whether the IME supports vertical writing mode might be changed or @@ -2538,8 +2538,12 @@ IMMHandler::AdjustCompositionFont(nsWindow* aWindow, // Therefore, we need to store the information which are set to the IM // context to static variables since IM context is never recreated. static bool sCompositionFontsInitialized = false; - static nsString sCompositionFont = - Preferences::GetString("intl.imm.composition_font"); + static nsString sCompositionFont; + static bool sCompositionFontPrefDone = false; + if (!sCompositionFontPrefDone) { + sCompositionFontPrefDone = true; + Preferences::GetString("intl.imm.composition_font", sCompositionFont); + } // If composition font is customized by pref, we need to modify the // composition font of the IME context at first time even if the writing mode @@ -2588,8 +2592,8 @@ IMMHandler::AdjustCompositionFont(nsWindow* aWindow, if (IsJapanist2003Active() && sCompositionFontForJapanist2003.IsEmpty()) { const char* kCompositionFontForJapanist2003 = "intl.imm.composition_font.japanist_2003"; - sCompositionFontForJapanist2003 = - Preferences::GetString(kCompositionFontForJapanist2003); + Preferences::GetString(kCompositionFontForJapanist2003, + sCompositionFontForJapanist2003); // If the font name is not specified properly, let's use // "MS PGothic" instead. if (sCompositionFontForJapanist2003.IsEmpty() || diff --git a/widget/windows/PDFiumEngineShim.cpp b/widget/windows/PDFiumEngineShim.cpp index 3576dc8d0a38..3a23d07e368c 100644 --- a/widget/windows/PDFiumEngineShim.cpp +++ b/widget/windows/PDFiumEngineShim.cpp @@ -65,8 +65,8 @@ PDFiumEngineShim::Init() } #ifdef USE_EXTERNAL_PDFIUM - const nsAdoptingString& PDFiumPath = - mozilla::Preferences::GetString("print.load_external_pdfium"); + nsAutoString PDFiumPath; + mozilla::Preferences::GetString("print.load_external_pdfium", PDFiumPath); NS_ENSURE_FALSE(PDFiumPath.IsEmpty(), false); nsAutoCString filePath = NS_ConvertUTF16toUTF8(PDFiumPath); @@ -169,4 +169,4 @@ PDFiumEngineShim::RenderPage(HDC aDC, FPDF_PAGE aPage, } } // namespace widget -} // namespace mozilla \ No newline at end of file +} // namespace mozilla diff --git a/widget/windows/nsDeviceContextSpecWin.cpp b/widget/windows/nsDeviceContextSpecWin.cpp index 1c64a7b610f3..af54d228cf0e 100644 --- a/widget/windows/nsDeviceContextSpecWin.cpp +++ b/widget/windows/nsDeviceContextSpecWin.cpp @@ -153,10 +153,9 @@ NS_IMETHODIMP nsDeviceContextSpecWin::Init(nsIWidget* aWidget, nsresult rv = NS_ERROR_GFX_PRINTER_NO_PRINTER_AVAILABLE; if (aPrintSettings) { #ifdef MOZ_ENABLE_SKIA_PDF - const nsAdoptingString& printViaPdf = - mozilla::Preferences::GetString("print.print_via_pdf_encoder"); - - if (printViaPdf == NS_LITERAL_STRING("skia-pdf")) { + nsAutoString printViaPdf; + Preferences::GetString("print.print_via_pdf_encoder", printViaPdf); + if (printViaPdf.EqualsLiteral("skia-pdf")) { mPrintViaSkPDF = true; } #endif diff --git a/widget/windows/nsWindow.cpp b/widget/windows/nsWindow.cpp index e07d33e08ba9..460cb3d6faf7 100644 --- a/widget/windows/nsWindow.cpp +++ b/widget/windows/nsWindow.cpp @@ -8127,8 +8127,8 @@ nsWindow::GetMainWindowClass() { static const wchar_t* sMainWindowClass = nullptr; if (!sMainWindowClass) { - nsAdoptingString className = - Preferences::GetString("ui.window_class_override"); + nsAutoString className; + Preferences::GetString("ui.window_class_override", className); if (!className.IsEmpty()) { sMainWindowClass = wcsdup(className.get()); } else {