Bug 1337694 - Add language negotiation heuristics to LocaleService. draft
authorZibi Braniecki <gandalf@mozilla.com>
Mon, 13 Feb 2017 15:49:37 -0800
changeset 486830 3dd2473efa260b2efcf89c399e40910f0c9c0260
parent 483291 195049fabb7ac5709e5f75614ba630ba3d1b5a9b
child 486831 f2189a78081ad535efb59ba387ef424fe7b94d2d
push id46069
push userzbraniecki@mozilla.com
push dateMon, 20 Feb 2017 02:17:11 +0000
bugs1337694
milestone54.0a1
Bug 1337694 - Add language negotiation heuristics to LocaleService. MozReview-Commit-ID: Ka6ESWYqyTQ
intl/locale/LocaleService.cpp
intl/locale/LocaleService.h
intl/locale/tests/gtest/TestLocaleServiceNegotiate.cpp
intl/locale/tests/gtest/moz.build
--- a/intl/locale/LocaleService.cpp
+++ b/intl/locale/LocaleService.cpp
@@ -70,16 +70,21 @@ LocaleService::Refresh()
     mAppLocales = Move(newLocales);
     nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
     if (obs) {
       obs->NotifyObservers(nullptr, "intl:app-locales-changed", nullptr);
     }
   }
 }
 
+void LocaleService::Negotiate(nsTArray<nsCString>& requestedLocales,
+    nsTArray<nsCString>& availableLocales, nsACString& defaultLocale, nsTArray<nsCString>& aRetVal)
+{
+}
+
 /**
  * mozILocaleService methods
  */
 NS_IMETHODIMP
 LocaleService::GetAppLocales(JSContext* aCtx, JS::MutableHandleValue aRetVal)
 {
   if (mAppLocales.IsEmpty()) {
     ReadAppLocales(mAppLocales);
--- a/intl/locale/LocaleService.h
+++ b/intl/locale/LocaleService.h
@@ -67,16 +67,19 @@ public:
   /**
    * Triggers a refresh of the language negotiation process.
    *
    * If the result differs from the previous list, it will additionally
    * trigger a global event "intl:app-locales-changed".
    */
   void Refresh();
 
+  void Negotiate(nsTArray<nsCString>& requestedLocales,
+      nsTArray<nsCString>& availableLocales, nsACString& defaultLocale, nsTArray<nsCString>& aRetVal);
+
 protected:
   nsTArray<nsCString> mAppLocales;
 
 private:
   virtual ~LocaleService() {};
 
   static StaticRefPtr<LocaleService> sInstance;
 };
new file mode 100644
--- /dev/null
+++ b/intl/locale/tests/gtest/TestLocaleServiceNegotiate.cpp
@@ -0,0 +1,13 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "gtest/gtest.h"
+#include "LocaleService.h"
+#include "mozilla/Services.h"
+#include "nsIToolkitChromeRegistry.h"
+
+using namespace mozilla::intl;
+
+
--- a/intl/locale/tests/gtest/moz.build
+++ b/intl/locale/tests/gtest/moz.build
@@ -1,16 +1,17 @@
 # -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
 # vim: set filetype=python:
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 UNIFIED_SOURCES += [
     'TestLocaleService.cpp',
+    'TestLocaleServiceNegotiate.cpp',
 ]
 
 if CONFIG['ENABLE_INTL_API']:
     UNIFIED_SOURCES += [
         'TestDateTimeFormat.cpp',
         'TestOSPreferences.cpp',
     ]