Bug 1633212 - Update nsSuiteDirectoryProvider for changes to locale retrieval. r=frg
authorIan Neal <iann_cvs@blueyonder.co.uk>
Sat, 25 Apr 2020 17:52:05 +0100
changeset 39210 b8c06eb419142c4deea5775cd522c863518a81df
parent 39209 44171a2e26b1e23c73022a2754d8b4808291e66c
child 39211 1f1af3f6677b3bf539cc86f1e42546ecdfe85aa1
push id402
push userclokep@gmail.com
push dateMon, 29 Jun 2020 20:48:04 +0000
reviewersfrg
bugs1633212, 1252627, 1299234, 1346616
Bug 1633212 - Update nsSuiteDirectoryProvider for changes to locale retrieval. r=frg Port the relevant parts of the following bugs to SeaMonkey: * Bug 1252627 - distribution defaultLocale should take precedence over user agent locale * Bug 1299234 - Fix incorrect if statement block in AppendDistroSearchDirs() * Bug 1346616 - Migrate callsites that are retrieving requested locale from pref, to use LocaleService::GetRequestedLocales
suite/components/profile/nsSuiteDirectoryProvider.cpp
--- a/suite/components/profile/nsSuiteDirectoryProvider.cpp
+++ b/suite/components/profile/nsSuiteDirectoryProvider.cpp
@@ -4,21 +4,23 @@
 
 #include "nsSuiteDirectoryProvider.h"
 #include "nsAppDirectoryServiceDefs.h"
 #include "nsCategoryManagerUtils.h"
 #include "nsXULAppAPI.h"
 #include "nsDirectoryServiceUtils.h"
 #include "nsIPrefBranch.h"
 #include "nsDirectoryServiceDefs.h"
-#include "nsIPrefLocalizedString.h"
+#include "mozilla/intl/LocaleService.h"
 #include "nsIPrefService.h"
 #include "nsArrayEnumerator.h"
 #include "nsEnumeratorUtils.h"
 
+using mozilla::intl::LocaleService;
+
 NS_IMPL_ISUPPORTS(nsSuiteDirectoryProvider,
                    nsIDirectoryServiceProvider,
                    nsIDirectoryServiceProvider2)
 
 NS_IMETHODIMP
 nsSuiteDirectoryProvider::GetFile(const char *aKey,
                                   bool *aPersist,
                                   nsIFile* *aResult)
@@ -206,52 +208,41 @@ nsSuiteDirectoryProvider::AppendDistroSe
   if (prefs) {
     nsCOMPtr<nsIFile> localePlugins;
     rv = searchPlugins->Clone(getter_AddRefs(localePlugins));
     if (NS_FAILED(rv))
       return;
 
     localePlugins->AppendNative(NS_LITERAL_CSTRING("locale"));
 
-    nsCString locale;
-    nsCOMPtr<nsIPrefLocalizedString> prefString;
-    rv = prefs->GetComplexValue("general.useragent.locale",
-                                NS_GET_IID(nsIPrefLocalizedString),
-                                getter_AddRefs(prefString));
-    if (NS_SUCCEEDED(rv)) {
-      nsAutoString wLocale;
-      prefString->GetData(wLocale);
-      CopyUTF16toUTF8(wLocale, locale);
-    } else {
-      rv = prefs->GetCharPref("general.useragent.locale", locale);
-    }
-
-    if (NS_SUCCEEDED(rv)) {
-      nsCOMPtr<nsIFile> curLocalePlugins;
-      rv = localePlugins->Clone(getter_AddRefs(curLocalePlugins));
-      if (NS_SUCCEEDED(rv)) {
-
-        curLocalePlugins->AppendNative(locale);
-        rv = curLocalePlugins->Exists(&exists);
-        if (NS_SUCCEEDED(rv) && exists) {
-          array.AppendObject(curLocalePlugins);
-          return; // all done
-        }
-      }
-    }
-
     // we didn't append the locale dir - try the default one
     nsCString defLocale;
     rv = prefs->GetCharPref("distribution.searchplugins.defaultLocale",
                             defLocale);
     if (NS_SUCCEEDED(rv)) {
       nsCOMPtr<nsIFile> defLocalePlugins;
       rv = localePlugins->Clone(getter_AddRefs(defLocalePlugins));
       if (NS_SUCCEEDED(rv)) {
-
         defLocalePlugins->AppendNative(defLocale);
         rv = defLocalePlugins->Exists(&exists);
-        if (NS_SUCCEEDED(rv) && exists)
+        if (NS_SUCCEEDED(rv) && exists) {
           array.AppendObject(defLocalePlugins);
+          return; // all done
+        }
+      }
+    }
+
+    // we didn't have a defaultLocale, use the user agent locale
+    nsAutoCString locale;
+    LocaleService::GetInstance()->GetAppLocaleAsLangTag(locale);
+
+    nsCOMPtr<nsIFile> curLocalePlugins;
+    rv = localePlugins->Clone(getter_AddRefs(curLocalePlugins));
+    if (NS_SUCCEEDED(rv)) {
+      curLocalePlugins->AppendNative(locale);
+      rv = curLocalePlugins->Exists(&exists);
+      if (NS_SUCCEEDED(rv) && exists) {
+        array.AppendObject(curLocalePlugins);
+        return; // all done
       }
     }
   }
 }