mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-10 03:45:46 +00:00
Bug 364991 - Stop loading CFLocale functions dynamically. r=josh, sr=pink.
This commit is contained in:
parent
baf80aeeb7
commit
0b04b8f43d
@ -53,8 +53,9 @@
|
||||
#elif defined(XP_OS2)
|
||||
# include "unidef.h"
|
||||
# include "nsIOS2Locale.h"
|
||||
#elif defined(XP_MAC) || defined(XP_MACOSX)
|
||||
#elif defined(XP_MACOSX)
|
||||
# include <Script.h>
|
||||
# include <Carbon/Carbon.h>
|
||||
# include "nsIMacLocale.h"
|
||||
#elif defined(XP_UNIX) || defined(XP_BEOS)
|
||||
# include <locale.h>
|
||||
@ -94,14 +95,6 @@ static int posix_locale_category[LocaleListLength] =
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifdef XP_MACOSX
|
||||
#if !defined(__COREFOUNDATION_CFLOCALE__)
|
||||
typedef void* CFLocaleRef;
|
||||
#endif
|
||||
typedef CFLocaleRef (*fpCFLocaleCopyCurrent_type) (void);
|
||||
typedef CFStringRef (*fpCFLocaleGetIdentifier_type) (CFLocaleRef);
|
||||
#endif
|
||||
|
||||
//
|
||||
// nsILocaleService implementation
|
||||
//
|
||||
@ -168,7 +161,7 @@ protected:
|
||||
nsLocaleService::nsLocaleService(void)
|
||||
: mSystemLocale(0), mApplicationLocale(0)
|
||||
{
|
||||
#if defined(XP_WIN)
|
||||
#ifdef XP_WIN
|
||||
nsCOMPtr<nsIWin32Locale> win32Converter = do_GetService(NS_WIN32LOCALE_CONTRACTID);
|
||||
|
||||
NS_ASSERTION(win32Converter, "nsLocaleService: can't get win32 converter\n");
|
||||
@ -242,7 +235,7 @@ nsLocaleService::nsLocaleService(void)
|
||||
} // if ( NS_SUCCEEDED )...
|
||||
|
||||
#endif // XP_UNIX || XP_BEOS
|
||||
#if defined(XP_OS2)
|
||||
#ifdef XP_OS2
|
||||
nsCOMPtr<nsIOS2Locale> os2Converter = do_GetService(NS_OS2LOCALE_CONTRACTID);
|
||||
nsAutoString xpLocale;
|
||||
if (os2Converter) {
|
||||
@ -293,86 +286,37 @@ nsLocaleService::nsLocaleService(void)
|
||||
mSystemLocale = do_QueryInterface(resultLocale);
|
||||
mApplicationLocale = do_QueryInterface(resultLocale);
|
||||
} // if ( NS_SUCCEEDED )...
|
||||
#endif // XP_OS2
|
||||
|
||||
#endif
|
||||
#ifdef XP_MACOSX
|
||||
// Get string representation of user's current locale
|
||||
CFLocaleRef userLocaleRef = ::CFLocaleCopyCurrent();
|
||||
CFStringRef userLocaleStr = ::CFLocaleGetIdentifier(userLocaleRef);
|
||||
::CFRetain(userLocaleStr);
|
||||
|
||||
#if defined(XP_MAC) || defined(XP_MACOSX)
|
||||
// On MacOSX, the recommended way to get the user's current locale is to use
|
||||
// the CFLocale APIs. However, these are only available on 10.3 and later.
|
||||
// So for the older systems, we have to keep using the Script Manager APIs.
|
||||
|
||||
static PRBool checked = PR_FALSE;
|
||||
static fpCFLocaleCopyCurrent_type fpCFLocaleCopyCurrent = NULL;
|
||||
static fpCFLocaleGetIdentifier_type fpCFLocaleGetIdentifier = NULL;
|
||||
|
||||
if (!checked)
|
||||
nsAutoBuffer<UniChar, 32> buffer;
|
||||
int size = ::CFStringGetLength(userLocaleStr);
|
||||
if (buffer.EnsureElemCapacity(size))
|
||||
{
|
||||
CFBundleRef bundle =
|
||||
::CFBundleGetBundleWithIdentifier(CFSTR("com.apple.Carbon"));
|
||||
if (bundle)
|
||||
{
|
||||
// We dynamically load these two functions and only use them if
|
||||
// they are available (OS 10.3+).
|
||||
fpCFLocaleCopyCurrent = (fpCFLocaleCopyCurrent_type)
|
||||
::CFBundleGetFunctionPointerForName(bundle,
|
||||
CFSTR("CFLocaleCopyCurrent"));
|
||||
fpCFLocaleGetIdentifier = (fpCFLocaleGetIdentifier_type)
|
||||
::CFBundleGetFunctionPointerForName(bundle,
|
||||
CFSTR("CFLocaleGetIdentifier"));
|
||||
}
|
||||
checked = PR_TRUE;
|
||||
}
|
||||
CFRange range = ::CFRangeMake(0, size);
|
||||
::CFStringGetCharacters(userLocaleStr, range, buffer.get());
|
||||
buffer.get()[size] = 0;
|
||||
|
||||
if (fpCFLocaleCopyCurrent)
|
||||
{
|
||||
// Get string representation of user's current locale
|
||||
CFLocaleRef userLocaleRef = fpCFLocaleCopyCurrent();
|
||||
CFStringRef userLocaleStr = fpCFLocaleGetIdentifier(userLocaleRef);
|
||||
::CFRetain(userLocaleStr);
|
||||
// Convert the locale string to the format that Mozilla expects
|
||||
nsAutoString xpLocale(buffer.get());
|
||||
xpLocale.ReplaceChar('_', '-');
|
||||
|
||||
nsAutoBuffer<UniChar, 32> buffer;
|
||||
int size = ::CFStringGetLength(userLocaleStr);
|
||||
if (buffer.EnsureElemCapacity(size))
|
||||
{
|
||||
CFRange range = ::CFRangeMake(0, size);
|
||||
::CFStringGetCharacters(userLocaleStr, range, buffer.get());
|
||||
buffer.get()[size] = 0;
|
||||
|
||||
// Convert the locale string to the format that Mozilla expects
|
||||
nsAutoString xpLocale(buffer.get());
|
||||
xpLocale.ReplaceChar('_', '-');
|
||||
|
||||
nsresult rv = NewLocale(xpLocale, getter_AddRefs(mSystemLocale));
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
mApplicationLocale = mSystemLocale;
|
||||
}
|
||||
}
|
||||
|
||||
::CFRelease(userLocaleStr);
|
||||
::CFRelease(userLocaleRef);
|
||||
|
||||
NS_ASSERTION(mApplicationLocale, "Failed to create locale objects");
|
||||
}
|
||||
else
|
||||
{
|
||||
// Legacy MacOSX locale code
|
||||
long script = GetScriptManagerVariable(smSysScript);
|
||||
long lang = GetScriptVariable(smSystemScript,smScriptLang);
|
||||
long region = GetScriptManagerVariable(smRegionCode);
|
||||
nsCOMPtr<nsIMacLocale> macConverter = do_GetService(NS_MACLOCALE_CONTRACTID);
|
||||
if (macConverter) {
|
||||
nsresult result;
|
||||
nsAutoString xpLocale;
|
||||
result = macConverter->GetXPLocale((short)script,(short)lang,(short)region, xpLocale);
|
||||
if (NS_SUCCEEDED(result)) {
|
||||
result = NewLocale(xpLocale, getter_AddRefs(mSystemLocale));
|
||||
if (NS_SUCCEEDED(result)) {
|
||||
mApplicationLocale = mSystemLocale;
|
||||
}
|
||||
}
|
||||
nsresult rv = NewLocale(xpLocale, getter_AddRefs(mSystemLocale));
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
mApplicationLocale = mSystemLocale;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
::CFRelease(userLocaleStr);
|
||||
::CFRelease(userLocaleRef);
|
||||
|
||||
NS_ASSERTION(mApplicationLocale, "Failed to create locale objects");
|
||||
#endif // XP_MACOSX
|
||||
}
|
||||
|
||||
nsLocaleService::~nsLocaleService(void)
|
||||
|
Loading…
Reference in New Issue
Block a user