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
This commit is contained in:
Makoto Kato 2017-03-06 11:03:46 +09:00
Родитель 53638cee1c
Коммит 989d78dec8
5 изменённых файлов: 38 добавлений и 6 удалений

Просмотреть файл

@ -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
}
/**

Просмотреть файл

@ -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"

Просмотреть файл

@ -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 += [

Просмотреть файл

@ -24,3 +24,4 @@ skip-if = toolkit == "android" # bug 1309447
[test_localeService.js]
[test_osPreferences.js]
skip-if = toolkit == "android" # bug 1344596

Просмотреть файл

@ -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<nsCString>& aLocaleList)
{
#ifdef ENABLE_INTL_API
MOZ_ASSERT(aLocaleList.IsEmpty());
nsAutoCString defaultLang(uloc_getDefault());
@ -20,6 +22,15 @@ OSPreferences::ReadSystemLocales(nsTArray<nsCString>& 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