Bug 364991 - Stop loading CFLocale functions dynamically. r=josh, sr=pink.

This commit is contained in:
mozilla.mano%sent.com 2006-12-26 20:18:15 +00:00
parent baf80aeeb7
commit 0b04b8f43d

View File

@ -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,41 +286,12 @@ nsLocaleService::nsLocaleService(void)
mSystemLocale = do_QueryInterface(resultLocale);
mApplicationLocale = do_QueryInterface(resultLocale);
} // if ( NS_SUCCEEDED )...
#endif // XP_OS2
#endif
#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)
{
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;
}
if (fpCFLocaleCopyCurrent)
{
#ifdef XP_MACOSX
// Get string representation of user's current locale
CFLocaleRef userLocaleRef = fpCFLocaleCopyCurrent();
CFStringRef userLocaleStr = fpCFLocaleGetIdentifier(userLocaleRef);
CFLocaleRef userLocaleRef = ::CFLocaleCopyCurrent();
CFStringRef userLocaleStr = ::CFLocaleGetIdentifier(userLocaleRef);
::CFRetain(userLocaleStr);
nsAutoBuffer<UniChar, 32> buffer;
@ -352,27 +316,7 @@ nsLocaleService::nsLocaleService(void)
::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;
}
}
}
}
#endif
#endif // XP_MACOSX
}
nsLocaleService::~nsLocaleService(void)