Bug 1384835 (part 2, attempt 2) - Remove the Preferences::Get*String() variants that return nsAdoptingString. r=froydnj.
authorNicholas Nethercote <nnethercote@mozilla.com>
Mon, 31 Jul 2017 14:23:50 +1000
changeset 371921 f2356ef5b902b23d5e8c5ff6a53df46b3489c637
parent 371920 c23ec9e1395c8c02b458d99349795031c680374a
child 371922 2b347fb55a9965acec727f6e40671ba859636603
push id93173
push usernnethercote@mozilla.com
push dateMon, 31 Jul 2017 08:02:19 +0000
treeherdermozilla-inbound@2b347fb55a99 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1384835
milestone56.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1384835 (part 2, attempt 2) - Remove the Preferences::Get*String() variants that return nsAdoptingString. r=froydnj.
caps/nsScriptSecurityManager.cpp
dom/audiochannel/AudioChannelService.cpp
dom/base/Navigator.cpp
dom/base/nsContentUtils.cpp
dom/base/nsDocument.cpp
dom/base/nsGlobalWindow.cpp
dom/html/HTMLInputElement.cpp
dom/media/CubebUtils.cpp
dom/media/DecoderDoctorDiagnostics.cpp
dom/svg/SVGSwitchElement.cpp
dom/svg/SVGTests.cpp
dom/workers/RuntimeService.cpp
editor/composer/nsEditorSpellCheck.cpp
gfx/src/DriverCrashGuard.cpp
gfx/thebes/gfxFcPlatformFontList.cpp
gfx/thebes/gfxFontUtils.cpp
gfx/thebes/gfxPlatform.cpp
layout/base/StaticPresData.cpp
layout/base/nsPresContext.cpp
layout/xul/nsTextBoxFrame.cpp
modules/libpref/Preferences.cpp
modules/libpref/Preferences.h
security/manager/ssl/nsNSSComponent.cpp
toolkit/xre/nsXREDirProvider.cpp
widget/android/PrefsHelper.h
widget/cocoa/nsDeviceContextSpecX.mm
widget/windows/IMMHandler.cpp
widget/windows/PDFiumEngineShim.cpp
widget/windows/nsDeviceContextSpecWin.cpp
widget/windows/nsWindow.cpp
--- a/caps/nsScriptSecurityManager.cpp
+++ b/caps/nsScriptSecurityManager.cpp
@@ -1650,17 +1650,19 @@ nsScriptSecurityManager::EnsureFileURIWh
         // Grab the current policy name.
         bound = SkipUntil<IsWhitespaceOrComma>(policies, base);
         auto policyName = Substring(policies, base, bound - base);
 
         // Figure out if this policy allows loading file:// URIs. If not, we can skip it.
         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;
         }
 
         // Grab the list of domains associated with this policy.
         nsCString domainPrefName = NS_LITERAL_CSTRING("capability.policy.") +
                                    policyName +
                                    NS_LITERAL_CSTRING(".sites");
         auto siteList = Preferences::GetCString(domainPrefName.get());
--- a/dom/audiochannel/AudioChannelService.cpp
+++ b/dom/audiochannel/AudioChannelService.cpp
@@ -558,17 +558,18 @@ AudioChannelService::GetAudioChannel(con
   }
 
   return AudioChannel::Normal;
 }
 
 /* static */ AudioChannel
 AudioChannelService::GetDefaultAudioChannel()
 {
-  nsAutoString audioChannel(Preferences::GetString("media.defaultAudioChannel"));
+  nsAutoString audioChannel;
+  Preferences::GetString("media.defaultAudioChannel", audioChannel);
   if (audioChannel.IsEmpty()) {
     return AudioChannel::Normal;
   }
 
   for (uint32_t i = 0; kMozAudioChannelAttributeTable[i].tag; ++i) {
     if (audioChannel.EqualsASCII(kMozAudioChannelAttributeTable[i].tag)) {
       return static_cast<AudioChannel>(kMozAudioChannelAttributeTable[i].value);
     }
--- a/dom/base/Navigator.cpp
+++ b/dom/base/Navigator.cpp
@@ -374,18 +374,18 @@ Navigator::GetAppName(nsAString& aAppNam
 /* static */ void
 Navigator::GetAcceptLanguages(nsTArray<nsString>& aLanguages)
 {
   MOZ_ASSERT(NS_IsMainThread());
 
   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, ',');
   while (langTokenizer.hasMoreTokens()) {
     nsDependentSubstring lang = langTokenizer.nextToken();
 
     // Replace "_" with "-" to avoid POSIX/Windows "en_US" notation.
     // NOTE: we should probably rely on the pref being set correctly.
@@ -468,20 +468,19 @@ Navigator::GetOscpu(nsAString& aOSCPU, C
   if (aCallerType != CallerType::System) {
     // If fingerprinting resistance is on, we will spoof this value. See nsRFPService.h
     // for details about spoofed values.
     if (nsContentUtils::ShouldResistFingerprinting()) {
       aOSCPU.AssignLiteral(SPOOFED_OSCPU);
       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;
     }
   }
 
   nsresult rv;
   nsCOMPtr<nsIHttpProtocolHandler>
     service(do_GetService(NS_NETWORK_PROTOCOL_CONTRACTID_PREFIX "http", &rv));
@@ -648,20 +647,19 @@ Navigator::GetBuildID(nsAString& aBuildI
 {
   if (aCallerType != CallerType::System) {
     // If fingerprinting resistance is on, we will spoof this value. See nsRFPService.h
     // for details about spoofed values.
     if (nsContentUtils::ShouldResistFingerprinting()) {
       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;
     }
   }
 
   nsCOMPtr<nsIXULAppInfo> appInfo =
     do_GetService("@mozilla.org/xre/app-info;1");
   if (!appInfo) {
@@ -699,17 +697,18 @@ Navigator::GetDoNotTrack(nsAString &aRes
 }
 
 bool
 Navigator::JavaEnabled(CallerType aCallerType, ErrorResult& aRv)
 {
   Telemetry::AutoTimer<Telemetry::CHECK_JAVA_ENABLED> 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) {
     if (!mWindow) {
       aRv.Throw(NS_ERROR_UNEXPECTED);
       return false;
     }
     mMimeTypes = new nsMimeTypeArray(mWindow);
@@ -1778,20 +1777,21 @@ Navigator::GetPlatform(nsAString& aPlatf
 
   if (aUsePrefOverriddenValue) {
     // If fingerprinting resistance is on, we will spoof this value. See nsRFPService.h
     // for details about spoofed values.
     if (nsContentUtils::ShouldResistFingerprinting()) {
       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;
     }
   }
 
   nsresult rv;
 
   nsCOMPtr<nsIHttpProtocolHandler>
@@ -1829,20 +1829,21 @@ Navigator::GetAppVersion(nsAString& aApp
 
   if (aUsePrefOverriddenValue) {
     // If fingerprinting resistance is on, we will spoof this value. See nsRFPService.h
     // for details about spoofed values.
     if (nsContentUtils::ShouldResistFingerprinting()) {
       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;
     }
   }
 
   nsresult rv;
 
   nsCOMPtr<nsIHttpProtocolHandler>
@@ -1873,20 +1874,21 @@ Navigator::AppName(nsAString& aAppName, 
   if (aUsePrefOverriddenValue) {
     // If fingerprinting resistance is on, we will spoof this value. See nsRFPService.h
     // for details about spoofed values.
     if (nsContentUtils::ShouldResistFingerprinting()) {
       aAppName.AssignLiteral(SPOOFED_APPNAME);
       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;
     }
   }
 
   aAppName.AssignLiteral("Netscape");
 }
 
@@ -1902,20 +1904,21 @@ Navigator::GetUserAgent(nsPIDOMWindowInn
                         nsAString& aUserAgent)
 {
   MOZ_ASSERT(NS_IsMainThread());
 
   // We will skip the override and pass to httpHandler to get spoofed userAgent
   // 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;
     }
   }
 
   nsresult rv;
   nsCOMPtr<nsIHttpProtocolHandler>
     service(do_GetService(NS_NETWORK_PROTOCOL_CONTRACTID_PREFIX "http", &rv));
--- a/dom/base/nsContentUtils.cpp
+++ b/dom/base/nsContentUtils.cpp
@@ -5572,17 +5572,18 @@ nsContentUtils::GetTopLevelWidget(nsIWid
 }
 
 /* static */
 const nsDependentString
 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);
     if (!sBuf[0])
       sBuf[0] = char16_t(0x2026);
   }
   return nsDependentString(sBuf);
 }
--- a/dom/base/nsDocument.cpp
+++ b/dom/base/nsDocument.cpp
@@ -2759,18 +2759,19 @@ nsDocument::InitCSP(nsIChannel* aChannel
       csp->AppendPolicy(addonCSP, false, false);
     }
   }
 
   // ----- if the doc is a signed content, apply the default CSP.
   // 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);
   }
 
   // ----- if there's a full-strength CSP header, apply it.
   if (!cspHeaderValue.IsEmpty()) {
     rv = CSP_AppendCSPFromHeader(csp, cspHeaderValue, false);
     NS_ENSURE_SUCCESS(rv, rv);
   }
--- a/dom/base/nsGlobalWindow.cpp
+++ b/dom/base/nsGlobalWindow.cpp
@@ -8041,18 +8041,18 @@ void
 nsGlobalWindow::HomeOuter(nsIPrincipal& aSubjectPrincipal, ErrorResult& aError)
 {
   MOZ_RELEASE_ASSERT(IsOuterWindow());
 
   if (!mDocShell) {
     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
 #ifdef DEBUG_seth
     printf("all else failed.  using %s as the home page\n", DEFAULT_HOME_PAGE);
 #endif
     CopyASCIItoUTF16(DEFAULT_HOME_PAGE, homeURL);
   }
--- a/dom/html/HTMLInputElement.cpp
+++ b/dom/html/HTMLInputElement.cpp
@@ -479,17 +479,17 @@ NS_IMPL_ISUPPORTS(UploadLastDir::Content
 
 NS_IMETHODIMP
 UploadLastDir::ContentPrefCallback::HandleCompletion(uint16_t aReason)
 {
   nsCOMPtr<nsIFile> localFile;
   nsAutoString prefStr;
 
   if (aReason == nsIContentPrefCallback2::COMPLETE_ERROR || !mResult) {
-    prefStr = Preferences::GetString("dom.input.fallbackUploadDir");
+    Preferences::GetString("dom.input.fallbackUploadDir", prefStr);
   }
 
   if (prefStr.IsEmpty() && mResult) {
     nsCOMPtr<nsIVariant> pref;
     mResult->GetValue(getter_AddRefs(pref));
     pref->GetAsAString(prefStr);
   }
 
--- a/dom/media/CubebUtils.cpp
+++ b/dom/media/CubebUtils.cpp
@@ -157,23 +157,23 @@ static const uint32_t CUBEB_NORMAL_LATEN
 // Consevative default that can work on all platforms.
 static const uint32_t CUBEB_NORMAL_LATENCY_FRAMES = 1024;
 
 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<double>(0, PR_strtod(utf8.get(), nullptr));
+      sVolumeScale = std::max<double>(0, PR_strtod(value.get(), nullptr));
     }
   } else if (strcmp(aPref, PREF_CUBEB_LATENCY_PLAYBACK) == 0) {
     // Arbitrary default stream latency of 100ms.  The higher this
     // value, the longer stream volume changes will take to become
     // audible.
     sCubebPlaybackLatencyPrefSet = Preferences::HasUserValue(aPref);
     uint32_t value = Preferences::GetUint(aPref, CUBEB_NORMAL_LATENCY_MS);
     StaticMutexAutoLock lock(sMutex);
@@ -183,38 +183,38 @@ void PrefChanged(const char* aPref, void
     uint32_t value = Preferences::GetUint(aPref, CUBEB_NORMAL_LATENCY_FRAMES);
     StaticMutexAutoLock lock(sMutex);
     // 128 is the block size for the Web Audio API, which limits how low the
     // latency can be here.
     // We don't want to limit the upper limit too much, so that people can
     // experiment.
     sCubebMSGLatencyInFrames = std::min<uint32_t>(std::max<uint32_t>(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;
     }
   }
 }
 
 bool GetFirstStream()
 {
   static bool sFirstStream = true;
 
--- a/dom/media/DecoderDoctorDiagnostics.cpp
+++ b/dom/media/DecoderDoctorDiagnostics.cpp
@@ -623,18 +623,18 @@ DecoderDoctorDocumentWatcher::Synthesize
       { &supportedKeySystems, &playableFormats };
     // For each type of notification, retrieve the pref that contains formats/
     // key systems with issues.
     for (const NotificationAndReportStringId* id :
            sAllNotificationsAndReportStringIds) {
       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;
       }
       // See if that list of formats-with-issues contains any formats that are
       // now playable/supported.
       bool solved = false;
       for (const nsAString* workingFormats : workingFormatsArray) {
         for (const auto& workingFormat : MakeStringListRange(*workingFormats)) {
--- a/dom/svg/SVGSwitchElement.cpp
+++ b/dom/svg/SVGSwitchElement.cpp
@@ -122,18 +122,18 @@ SVGSwitchElement::IsAttributeMapped(cons
 }
 
 //----------------------------------------------------------------------
 // Implementation Helpers:
 
 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;
     nsIContent *bestChild = nullptr;
     nsIContent *defaultChild = nullptr;
     for (nsIContent* child = nsINode::GetFirstChild();
          child;
          child = child->GetNextSibling()) {
--- a/dom/svg/SVGTests.cpp
+++ b/dom/svg/SVGTests.cpp
@@ -142,18 +142,22 @@ SVGTests::PassesConditionalProcessingTes
   // prefix of one of the languages given in the value of this parameter such
   // that the first tag character following the prefix is "-".
   if (mStringListAttributes[LANGUAGE].IsExplicitlySet()) {
     if (mStringListAttributes[LANGUAGE].IsEmpty()) {
       return false;
     }
 
     // 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");
       return false;
     }
 
     const nsDefaultStringComparator defaultComparator;
 
--- a/dom/workers/RuntimeService.cpp
+++ b/dom/workers/RuntimeService.cpp
@@ -1319,46 +1319,46 @@ PrefLanguagesChanged(const char* /* aPre
   }
 }
 
 void
 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) {
     runtime->UpdateAppNameOverridePreference(override);
   }
 }
 
 void
 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) {
     runtime->UpdateAppVersionOverridePreference(override);
   }
 }
 
 void
 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) {
     runtime->UpdatePlatformOverridePreference(override);
   }
 }
 
 class BackgroundChildCallback final
--- a/editor/composer/nsEditorSpellCheck.cpp
+++ b/editor/composer/nsEditorSpellCheck.cpp
@@ -899,17 +899,17 @@ nsEditorSpellCheck::SetFallbackDictionar
   nsAutoString dictName(mPreferredLang);
 #ifdef DEBUG_DICT
   printf("***** Assigned from element/doc |%s|\n",
          NS_ConvertUTF16toUTF8(dictName).get());
 #endif
 
   // 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.
     BuildDictionaryList(dictName, dictList, DICT_COMPARE_CASE_INSENSITIVE,
                         tryDictList);
 
 #ifdef DEBUG_DICT
     printf("***** Trying from element/doc |%s| \n",
--- a/gfx/src/DriverCrashGuard.cpp
+++ b/gfx/src/DriverCrashGuard.cpp
@@ -346,17 +346,18 @@ DriverCrashGuard::CheckAndUpdateBoolPref
   return true;
 }
 
 bool
 DriverCrashGuard::CheckAndUpdatePref(const char* aPrefName, const nsAString& aCurrentValue)
 {
   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;
   }
   Preferences::SetString(pref.c_str(), aCurrentValue);
   return true;
 }
 
 std::string
--- a/gfx/thebes/gfxFcPlatformFontList.cpp
+++ b/gfx/thebes/gfxFcPlatformFontList.cpp
@@ -1693,27 +1693,31 @@ gfxFcPlatformFontList::AddGenericFonts(m
 
     // By default, most font prefs on Linux map to "use fontconfig"
     // keywords. So only need to explicitly lookup font pref if
     // non-default settings exist
     NS_ConvertASCIItoUTF16 genericToLookup(generic);
     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")) {
                 usePrefFontList = true;
             } else {
                 // serif, sans-serif or monospace was specified
                 genericToLookup.Assign(fontlistValue);
             }
--- a/gfx/thebes/gfxFontUtils.cpp
+++ b/gfx/thebes/gfxFontUtils.cpp
@@ -855,18 +855,19 @@ void gfxFontUtils::ParseFontList(const n
         ++p;
     }
 }
 
 void gfxFontUtils::AppendPrefsFontList(const char *aPrefName,
                                        nsTArray<nsString>& 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;
     }
 
     ParseFontList(fontlistValue, aFontList);
 }
 
 void gfxFontUtils::GetPrefsFontList(const char *aPrefName,
                                     nsTArray<nsString>& aFontList)
--- a/gfx/thebes/gfxPlatform.cpp
+++ b/gfx/thebes/gfxPlatform.cpp
@@ -565,19 +565,19 @@ gfxPlatform::InitChild(const ContentDevi
   Init();
   gContentDeviceInitData = nullptr;
 }
 
 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<nsIFile> tmpFile;
       if (NS_FAILED(NS_GetSpecialDirectory(NS_OS_TEMP_DIR, getter_AddRefs(tmpFile)))) {
         return;
       }
       fileName.AppendPrintf("moz2drec_%i_%i.aer", XRE_GetProcessType(), getpid());
 
--- a/layout/base/StaticPresData.cpp
+++ b/layout/base/StaticPresData.cpp
@@ -158,28 +158,29 @@ LangGroupFontPrefs::Initialize(nsIAtom* 
     nsFont* font = fontTypes[eType];
 
     // set the default variable font (the other fonts are seen as 'generic' fonts
     // in GFX and will be queried there when hunting for alternative fonts)
     if (eType == eDefaultFont_Variable) {
       // 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;
         NS_ASSERTION(defaultType == eFamily_serif ||
                      defaultType == eFamily_sans_serif,
                      "default type must be serif or sans-serif");
         mDefaultVariableFont.fontlist = FontFamilyList(defaultType);
       }
       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;
           NS_ASSERTION(defaultType == eFamily_serif ||
                        defaultType == eFamily_sans_serif,
                        "default type must be serif or sans-serif");
           mDefaultVariableFont.fontlist = FontFamilyList(defaultType);
         }
--- a/layout/base/nsPresContext.cpp
+++ b/layout/base/nsPresContext.cpp
@@ -511,25 +511,24 @@ nsPresContext::GetDocumentColorPreferenc
   if (sUseStandinsForNativeColors) {
     // Once the preference "ui.use_standins_for_native_colors" is enabled,
     // use fixed color values instead of prefered colors and system colors.
     mDefaultColor = LookAndFeel::GetColorUsingStandins(
         LookAndFeel::eColorID_windowtext, NS_RGB(0x00, 0x00, 0x00));
     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");
-
+    colorStr.Truncate();
+    Preferences::GetString("browser.display.background_color", colorStr);
     if (!colorStr.IsEmpty()) {
       mBackgroundColor = MakeColorPref(colorStr);
     }
   }
   else {
     mDefaultColor =
       LookAndFeel::GetColor(LookAndFeel::eColorID_WindowForeground,
                             NS_RGB(0x00, 0x00, 0x00));
@@ -578,48 +577,48 @@ nsPresContext::GetUserPreferences()
   mSendAfterPaintToContent =
     Preferences::GetBool("dom.send_after_paint_to_content",
                          mSendAfterPaintToContent);
 
   // * link colors
   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");
-
+  colorStr.Truncate();
+  Preferences::GetString("browser.active_color", colorStr);
   if (!colorStr.IsEmpty()) {
     mActiveLinkColor = MakeColorPref(colorStr);
   }
 
-  colorStr = Preferences::GetString("browser.visited_color");
-
+  colorStr.Truncate();
+  Preferences::GetString("browser.visited_color", colorStr);
   if (!colorStr.IsEmpty()) {
     mVisitedLinkColor = MakeColorPref(colorStr);
   }
 
   mUseFocusColors =
     Preferences::GetBool("browser.display.use_focus_colors", mUseFocusColors);
 
   mFocusTextColor = mDefaultColor;
   mFocusBackgroundColor = mBackgroundColor;
 
-  colorStr = Preferences::GetString("browser.display.focus_text_color");
-
+  colorStr.Truncate();
+  Preferences::GetString("browser.display.focus_text_color", colorStr);
   if (!colorStr.IsEmpty()) {
     mFocusTextColor = MakeColorPref(colorStr);
   }
 
-  colorStr = Preferences::GetString("browser.display.focus_background_color");
-
+  colorStr.Truncate();
+  Preferences::GetString("browser.display.focus_background_color", colorStr);
   if (!colorStr.IsEmpty()) {
     mFocusBackgroundColor = MakeColorPref(colorStr);
   }
 
   mFocusRingWidth =
     Preferences::GetInt("browser.display.focus_ring_width", mFocusRingWidth);
 
   mFocusRingOnAnything =
--- a/layout/xul/nsTextBoxFrame.cpp
+++ b/layout/xul/nsTextBoxFrame.cpp
@@ -141,31 +141,33 @@ nsTextBoxFrame::DestroyFrom(nsIFrame* aD
 bool
 nsTextBoxFrame::AlwaysAppendAccessKey()
 {
   if (!gAccessKeyPrefInitialized)
   {
     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;
 }
 
 bool
 nsTextBoxFrame::InsertSeparatorBeforeAccessKey()
 {
   if (!gInsertSeparatorPrefInitialized)
   {
     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;
 }
 
 class nsAsyncAccesskeyUpdate final : public nsIReflowCallback
 {
 public:
--- a/modules/libpref/Preferences.cpp
+++ b/modules/libpref/Preferences.cpp
@@ -1670,25 +1670,16 @@ nsAdoptingCString
 Preferences::GetCString(const char* aPref)
 {
   nsAdoptingCString result;
   PREF_CopyCharPref(aPref, getter_Copies(result), false);
   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)
 {
   NS_ENSURE_TRUE(InitStaticMembers(), NS_ERROR_NOT_AVAILABLE);
   nsAutoCString result;
   nsresult rv = PREF_CopyCharPref(aPref, getter_Copies(result), false);
   if (NS_SUCCEEDED(rv)) {
     aResult = result;
@@ -1714,25 +1705,16 @@ nsAdoptingCString
 Preferences::GetLocalizedCString(const char* aPref)
 {
   nsAdoptingCString result;
   GetLocalizedCString(aPref, result);
   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)
 {
   nsAutoString result;
   nsresult rv = GetLocalizedString(aPref, result);
   if (NS_SUCCEEDED(rv)) {
     CopyUTF16toUTF8(result, aResult);
   }
@@ -2245,43 +2227,25 @@ Preferences::GetDefaultLocalizedString(c
   if (NS_SUCCEEDED(rv)) {
     NS_ASSERTION(prefLocalString, "Succeeded but the result is NULL");
     prefLocalString->GetData(getter_Copies(aResult));
   }
   return rv;
 }
 
 // static
-nsAdoptingString
-Preferences::GetDefaultString(const char* aPref)
-{
-  nsAdoptingString result;
-  GetDefaultString(aPref, result);
-  return result;
-}
-
-// static
 nsAdoptingCString
 Preferences::GetDefaultCString(const char* aPref)
 {
   nsAdoptingCString result;
   PREF_CopyCharPref(aPref, getter_Copies(result), true);
   return result;
 }
 
 // static
-nsAdoptingString
-Preferences::GetDefaultLocalizedString(const char* aPref)
-{
-  nsAdoptingString result;
-  GetDefaultLocalizedString(aPref, result);
-  return result;
-}
-
-// static
 nsAdoptingCString
 Preferences::GetDefaultLocalizedCString(const char* aPref)
 {
   nsAdoptingCString result;
   GetDefaultLocalizedCString(aPref, result);
   return result;
 }
 
--- a/modules/libpref/Preferences.h
+++ b/modules/libpref/Preferences.h
@@ -16,17 +16,16 @@
 #include "nsIObserver.h"
 #include "nsCOMPtr.h"
 #include "nsTArray.h"
 #include "nsWeakReference.h"
 #include "mozilla/Atomics.h"
 #include "mozilla/MemoryReporting.h"
 
 class nsIFile;
-class nsAdoptingString;
 class nsAdoptingCString;
 
 #ifndef have_PrefChangedFunc_typedef
 typedef void (*PrefChangedFunc)(const char *, void *);
 #define have_PrefChangedFunc_typedef
 #endif
 
 #ifdef DEBUG
@@ -165,19 +164,17 @@ public:
    * if (!value.get()) {
    *   // the condition is always FALSE!!
    * }
    *
    * The value.get() doesn't return nullptr. You must use nsAdoptingString
    * 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
    * nsIPrefBranch.
    *
    * @param aPref       A pref name.
    * @param aResult     Must not be nullptr.  The value is never modified
    *                    when these methods fail.
@@ -382,19 +379,17 @@ public:
   /**
    * Gets the default value of the char type pref.
    * If the get() of the result returned nullptr, that meant the value didn't
    * have default value.
    *
    * 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);
   static nsresult GetDefaultString(const char* aPref, nsAString& aResult);
   static nsresult GetDefaultLocalizedCString(const char* aPref,
                                              nsACString& aResult);
   static nsresult GetDefaultLocalizedString(const char* aPref,
                                             nsAString& aResult);
--- a/security/manager/ssl/nsNSSComponent.cpp
+++ b/security/manager/ssl/nsNSSComponent.cpp
@@ -1945,21 +1945,23 @@ nsNSSComponent::InitializeNSS()
 
   MOZ_LOG(gPIPNSSLog, LogLevel::Debug, ("NSS Initialization done\n"));
 
   {
     MutexAutoLock lock(mMutex);
 
     // ensure we have initial values for various root hashes
 #ifdef DEBUG
-    mTestBuiltInRootHash =
-      Preferences::GetString("security.test.built_in_root_hash");
+    mTestBuiltInRootHash.Truncate();
+    Preferences::GetString("security.test.built_in_root_hash",
+                           mTestBuiltInRootHash);
 #endif
-    mContentSigningRootHash =
-      Preferences::GetString("security.content.signature.root_hash");
+    mContentSigningRootHash.Truncate();
+    Preferences::GetString("security.content.signature.root_hash",
+                           mContentSigningRootHash);
 
     mNSSInitialized = true;
   }
 
   return NS_OK;
 }
 
 void
@@ -2117,24 +2119,27 @@ nsNSSComponent::Observe(nsISupports* aSu
                prefName.EqualsLiteral("security.pki.name_matching_mode") ||
                prefName.EqualsLiteral("security.pki.netscape_step_up_policy") ||
                prefName.EqualsLiteral("security.OCSP.timeoutMilliseconds.soft") ||
                prefName.EqualsLiteral("security.OCSP.timeoutMilliseconds.hard")) {
       setValidationOptions(false);
 #ifdef DEBUG
     } else if (prefName.EqualsLiteral("security.test.built_in_root_hash")) {
       MutexAutoLock lock(mMutex);
-      mTestBuiltInRootHash = Preferences::GetString("security.test.built_in_root_hash");
+      mTestBuiltInRootHash.Truncate();
+      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");
+      mContentSigningRootHash.Truncate();
+      Preferences::GetString("security.content.signature.root_hash",
+                             mContentSigningRootHash);
     } else if (prefName.Equals(kEnterpriseRootModePref)) {
       MaybeImportEnterpriseRoots();
     } else {
       clearSessionCache = false;
     }
     if (clearSessionCache)
       SSL_ClearSessionCache();
   }
--- a/toolkit/xre/nsXREDirProvider.cpp
+++ b/toolkit/xre/nsXREDirProvider.cpp
@@ -774,18 +774,19 @@ static already_AddRefed<nsIFile>
 CreateContentProcessSandboxTempDir()
 {
   if (IsContentSandboxDisabled()) {
     return nullptr;
   }
 
   // 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<nsIUUIDGenerator> uuidgen =
       do_GetService("@mozilla.org/uuid-generator;1", &rv);
     if (NS_WARN_IF(NS_FAILED(rv))) {
       return nullptr;
     }
 
     nsID uuid;
--- a/widget/android/PrefsHelper.h
+++ b/widget/android/PrefsHelper.h
@@ -133,45 +133,47 @@ class PrefsHelper
 public:
     static void GetPrefs(const jni::Class::LocalRef& aCls,
                          jni::ObjectArray::Param aPrefNames,
                          jni::Object::Param aPrefHandler)
     {
         nsTArray<jni::Object::LocalRef> nameRefArray(aPrefNames->GetElements());
         nsCOMPtr<nsIObserverService> obsServ;
         nsCOMPtr<nsIWritableVariant> value;
-        nsAdoptingString strVal;
+        nsAutoString strVal;
 
         for (jni::Object::LocalRef& nameRef : nameRefArray) {
             jni::String::LocalRef nameStr(mozilla::Move(nameRef));
             const nsCString& name = nameStr->ToCString();
 
             int32_t type = java::PrefsHelper::PREF_INVALID;
             bool boolVal = false;
             int32_t intVal = 0;
+            strVal.Truncate();
 
             switch (Preferences::GetType(name.get())) {
                 case nsIPrefBranch::PREF_BOOL:
                     type = java::PrefsHelper::PREF_BOOL;
                     boolVal = Preferences::GetBool(name.get());
                     break;
 
                 case nsIPrefBranch::PREF_INT:
                     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:
                     // Pref not found; try to find it.
                     if (!obsServ) {
                         obsServ = services::GetObserverService();
                         if (!obsServ) {
                             continue;
                         }
                     }
@@ -283,34 +285,36 @@ public:
 
     static void OnPrefChange(const char16_t* aData)
     {
         const nsCString& name = NS_LossyConvertUTF16toASCII(aData);
 
         int32_t type = -1;
         bool boolVal = false;
         int32_t intVal = false;
-        nsAdoptingString strVal;
+        nsAutoString strVal;
 
         switch (Preferences::GetType(name.get())) {
             case nsIPrefBranch::PREF_BOOL:
                 type = java::PrefsHelper::PREF_BOOL;
                 boolVal = Preferences::GetBool(name.get());
                 break;
             case nsIPrefBranch::PREF_INT:
                 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());
                 return;
         }
 
         java::PrefsHelper::OnPrefChange(
                 name, type, boolVal, intVal,
--- a/widget/cocoa/nsDeviceContextSpecX.mm
+++ b/widget/cocoa/nsDeviceContextSpecX.mm
@@ -75,19 +75,19 @@ NS_IMETHODIMP nsDeviceContextSpecX::Init
   }
 
   mPrintSession = settings->GetPMPrintSession();
   ::PMRetain(mPrintSession);
   mPageFormat = settings->GetPMPageFormat();
   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
     // SkPDF then we need to manually handle user actions like "Open PDF in
     // Preview" and "Save as PDF...".
     // TODO: Currently we do not support using SkPDF for kPMDestinationFax or
     // kPMDestinationProcessPDF ("Add PDF to iBooks, etc.), and we only support
     // it for kPMDestinationFile if the destination file is a PDF.
--- a/widget/windows/IMMHandler.cpp
+++ b/widget/windows/IMMHandler.cpp
@@ -358,18 +358,18 @@ IMMHandler::InitKeyboardLayout(nsWindow*
                    (PWSTR)&sCodePage, sizeof(sCodePage) / sizeof(WCHAR));
   sIMEProperty = ::ImmGetProperty(aKeyboardLayout, IGP_PROPERTY);
   sIMEUIProperty = ::ImmGetProperty(aKeyboardLayout, IGP_UI);
 
   // If active IME is a TIP of TSF, we cannot retrieve the name with IMM32 API.
   // 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
   // some IMEs may need specific font for their UI.  Therefore, we should
   // update composition font forcibly here.
   if (aWindow) {
     MaybeAdjustCompositionFont(aWindow, sWritingModeOfCompositionFont, true);
   }
@@ -2533,18 +2533,22 @@ IMMHandler::AdjustCompositionFont(nsWind
                                   const IMEContext& aContext,
                                   const WritingMode& aWritingMode,
                                   bool aForceUpdate)
 {
   // An instance of IMMHandler is destroyed when active IME is changed.
   // 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
   // is horizontal.
   bool setCompositionFontForcibly = aForceUpdate ||
     (!sCompositionFontsInitialized && !sCompositionFont.IsEmpty());
 
   static WritingMode sCurrentWritingMode;
@@ -2583,18 +2587,18 @@ IMMHandler::AdjustCompositionFont(nsWind
       ("AdjustCompositionFont, sCompositionFont=\"%s\" is initialized",
        NS_ConvertUTF16toUTF8(sCompositionFont).get()));
   }
 
   static nsString sCompositionFontForJapanist2003;
   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() ||
         sCompositionFontForJapanist2003.Length() > LF_FACESIZE - 2 ||
         sCompositionFontForJapanist2003[0] == '@') {
       sCompositionFontForJapanist2003.AssignLiteral("MS PGothic");
     }
   }
--- a/widget/windows/PDFiumEngineShim.cpp
+++ b/widget/windows/PDFiumEngineShim.cpp
@@ -60,18 +60,18 @@ PDFiumEngineShim::~PDFiumEngineShim()
 bool
 PDFiumEngineShim::Init()
 {
   if (mInitialized) {
     return true;
   }
 
 #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);
   mPRLibrary = PR_LoadLibrary(filePath.get());
   NS_ENSURE_TRUE(mPRLibrary, false);
 
   mFPDF_InitLibrary = (FPDF_InitLibrary_Pfn)PR_FindFunctionSymbol(
     mPRLibrary, "FPDF_InitLibrary");
@@ -164,9 +164,9 @@ PDFiumEngineShim::RenderPage(HDC aDC, FP
                              int aRotate, int aFlags)
 {
   MOZ_ASSERT(mInitialized);
   mFPDF_RenderPage(aDC, aPage, aStartX, aStartY,
                    aSizeX, aSizeY, aRotate, aFlags);
 }
 
 } // namespace widget
-} // namespace mozilla
\ No newline at end of file
+} // namespace mozilla
--- a/widget/windows/nsDeviceContextSpecWin.cpp
+++ b/widget/windows/nsDeviceContextSpecWin.cpp
@@ -148,20 +148,19 @@ NS_IMETHODIMP nsDeviceContextSpecWin::In
                                            nsIPrintSettings* aPrintSettings,
                                            bool aIsPrintPreview)
 {
   mPrintSettings = aPrintSettings;
 
   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
 
     // If we're in the child and printing via the parent or we're printing to
     // PDF we only need information from the print settings.
     mPrintSettings->GetOutputFormat(&mOutputFormat);
     if ((XRE_IsContentProcess() &&
--- a/widget/windows/nsWindow.cpp
+++ b/widget/windows/nsWindow.cpp
@@ -8127,18 +8127,18 @@ bool nsWindow::CanTakeFocus()
   return false;
 }
 
 /* static */ const wchar_t*
 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 {
       sMainWindowClass = kClassNameGeneral;
     }
   }
   return sMainWindowClass;
 }