From 989d78dec84d99b74d63129e036c6eeec598c1fa Mon Sep 17 00:00:00 2001 From: Makoto Kato Date: Mon, 6 Mar 2017 11:03:46 +0900 Subject: [PATCH] Bug 1344596 - Allow OSPreferences API without ENABLE_INTL_API. r=gandalf Since we have to keep --with-intl-api=no setting, we allow OSPrefrences API wiout ENABLE_INTL_API. MozReview-Commit-ID: 8sQHW6iq9Ss --HG-- extra : rebase_source : 94e2efbeeb70f3edc519ffc9bfeaf7416ea1dc0e --- intl/locale/OSPreferences.cpp | 22 ++++++++++++++++++++++ intl/locale/OSPreferences.h | 2 ++ intl/locale/moz.build | 8 ++------ intl/locale/tests/unit/xpcshell.ini | 1 + intl/locale/unix/OSPreferences_unix.cpp | 11 +++++++++++ 5 files changed, 38 insertions(+), 6 deletions(-) diff --git a/intl/locale/OSPreferences.cpp b/intl/locale/OSPreferences.cpp index 73b4d9c946a1..615d058a4df8 100644 --- a/intl/locale/OSPreferences.cpp +++ b/intl/locale/OSPreferences.cpp @@ -14,8 +14,10 @@ #include "mozilla/ClearOnShutdown.h" #include "mozilla/Services.h" #include "nsIObserverService.h" +#ifdef ENABLE_INTL_API #include "unicode/udat.h" #include "unicode/udatpg.h" +#endif using namespace mozilla::intl; @@ -71,6 +73,7 @@ OSPreferences::Refresh() bool OSPreferences::CanonicalizeLanguageTag(nsCString& aLoc) { +#ifdef ENABLE_INTL_API char langTag[512]; UErrorCode status = U_ZERO_ERROR; @@ -84,6 +87,9 @@ OSPreferences::CanonicalizeLanguageTag(nsCString& aLoc) aLoc.Assign(langTag, langTagLen); return true; +#else + return false; +#endif } /** @@ -95,6 +101,7 @@ OSPreferences::GetDateTimePatternForStyle(DateTimeFormatStyle aDateStyle, const nsACString& aLocale, nsAString& aRetVal) { +#ifdef ENABLE_INTL_API UDateFormatStyle timeStyle = UDAT_NONE; UDateFormatStyle dateStyle = UDAT_NONE; @@ -158,6 +165,9 @@ OSPreferences::GetDateTimePatternForStyle(DateTimeFormatStyle aDateStyle, } aRetVal.Assign((const char16_t*)pattern, patsize); return true; +#else + return false; +#endif } @@ -175,6 +185,7 @@ OSPreferences::GetDateTimeSkeletonForStyle(DateTimeFormatStyle aDateStyle, const nsACString& aLocale, nsAString& aRetVal) { +#ifdef ENABLE_INTL_API nsAutoString pattern; if (!GetDateTimePatternForStyle(aDateStyle, aTimeStyle, aLocale, pattern)) { return false; @@ -194,6 +205,9 @@ OSPreferences::GetDateTimeSkeletonForStyle(DateTimeFormatStyle aDateStyle, aRetVal.Assign((const char16_t*)skeleton, skelsize); return true; +#else + return false; +#endif } /** @@ -210,6 +224,7 @@ OSPreferences::GetPatternForSkeleton(const nsAString& aSkeleton, const nsACString& aLocale, nsAString& aRetVal) { +#ifdef ENABLE_INTL_API UErrorCode status = U_ZERO_ERROR; UDateTimePatternGenerator* pg = udatpg_open(PromiseFlatCString(aLocale).get(), &status); if (U_FAILURE(status)) { @@ -230,6 +245,9 @@ OSPreferences::GetPatternForSkeleton(const nsAString& aSkeleton, udatpg_close(pg); return U_SUCCESS(status); +#else + return false; +#endif } /** @@ -245,6 +263,7 @@ bool OSPreferences::GetDateTimeConnectorPattern(const nsACString& aLocale, nsAString& aRetVal) { +#ifdef ENABLE_INTL_API UErrorCode status = U_ZERO_ERROR; UDateTimePatternGenerator* pg = udatpg_open(PromiseFlatCString(aLocale).get(), &status); if (U_FAILURE(status)) { @@ -257,6 +276,9 @@ OSPreferences::GetDateTimeConnectorPattern(const nsACString& aLocale, aRetVal.Assign((char16_t*)value, resultSize); return true; +#else + return false; +#endif } /** diff --git a/intl/locale/OSPreferences.h b/intl/locale/OSPreferences.h index 62ec3d70c1f1..d9fc97d9076a 100644 --- a/intl/locale/OSPreferences.h +++ b/intl/locale/OSPreferences.h @@ -9,7 +9,9 @@ #include "mozilla/StaticPtr.h" #include "nsString.h" #include "nsTArray.h" +#ifdef ENABLE_INTL_API #include "unicode/uloc.h" +#endif #include "mozIOSPreferences.h" diff --git a/intl/locale/moz.build b/intl/locale/moz.build index bedb87d007a9..1f79fd12dd6c 100644 --- a/intl/locale/moz.build +++ b/intl/locale/moz.build @@ -6,12 +6,6 @@ XPCSHELL_TESTS_MANIFESTS += ['tests/unit/xpcshell.ini'] -if CONFIG['ENABLE_INTL_API']: - SOURCES += ['OSPreferences.cpp'] - EXPORTS.mozilla.intl += [ - 'OSPreferences.h', - ] - toolkit = CONFIG['MOZ_WIDGET_TOOLKIT'] if toolkit == 'windows': @@ -47,6 +41,7 @@ EXPORTS += [ EXPORTS.mozilla.intl += [ 'LocaleService.h', + 'OSPreferences.h', ] UNIFIED_SOURCES += [ @@ -58,6 +53,7 @@ UNIFIED_SOURCES += [ 'nsLocaleService.cpp', 'nsScriptableDateFormat.cpp', 'nsUConvPropertySearch.cpp', + 'OSPreferences.cpp', ] EXTRA_JS_MODULES += [ diff --git a/intl/locale/tests/unit/xpcshell.ini b/intl/locale/tests/unit/xpcshell.ini index 1b76eadb2cf7..c7e1049ae695 100644 --- a/intl/locale/tests/unit/xpcshell.ini +++ b/intl/locale/tests/unit/xpcshell.ini @@ -24,3 +24,4 @@ skip-if = toolkit == "android" # bug 1309447 [test_localeService.js] [test_osPreferences.js] +skip-if = toolkit == "android" # bug 1344596 diff --git a/intl/locale/unix/OSPreferences_unix.cpp b/intl/locale/unix/OSPreferences_unix.cpp index ca96f2135eb9..d2408f167452 100644 --- a/intl/locale/unix/OSPreferences_unix.cpp +++ b/intl/locale/unix/OSPreferences_unix.cpp @@ -4,6 +4,7 @@ * 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 "nsPosixLocale.h" #include "OSPreferences.h" using namespace mozilla::intl; @@ -11,6 +12,7 @@ using namespace mozilla::intl; bool OSPreferences::ReadSystemLocales(nsTArray& aLocaleList) { +#ifdef ENABLE_INTL_API MOZ_ASSERT(aLocaleList.IsEmpty()); nsAutoCString defaultLang(uloc_getDefault()); @@ -20,6 +22,15 @@ OSPreferences::ReadSystemLocales(nsTArray& aLocaleList) return true; } return false; +#else + nsAutoString locale; + nsPosixLocale::GetXPLocale(getenv("LANG"), locale); + if (locale.IsEmpty()) { + locale.AssignLiteral("en-US"); + } + aLocaleList.AppendElement(NS_LossyConvertUTF16toASCII(locale)); + return true; +#endif } bool