Bug 635170 - DeCOM nsIWin32Locale. r=smontagu
authorBrandon Bohrer <bjb322@drexel.edu>
Mon, 02 May 2011 17:49:11 +0900
changeset 68834 a45b194f7d11f3d88de99090d440cdd9be22cdb1
parent 68833 3a3209e98dea99e404bf263f253d526c1d0d1dcc
child 68835 d761dc1a15f592c57ce1003ec689f419041b322e
push idunknown
push userunknown
push dateunknown
reviewerssmontagu
bugs635170
milestone6.0a1
Bug 635170 - DeCOM nsIWin32Locale. r=smontagu
intl/build/nsI18nModule.cpp
intl/locale/public/Makefile.in
intl/locale/public/nsIWin32Locale.h
intl/locale/public/nsWin32Locale.h
intl/locale/src/nsLocaleConstructors.h
intl/locale/src/nsLocaleService.cpp
intl/locale/src/windows/Makefile.in
intl/locale/src/windows/nsCollationWin.cpp
intl/locale/src/windows/nsDateTimeFormatWin.cpp
intl/locale/src/windows/nsIWin32LocaleImpl.cpp
intl/locale/src/windows/nsIwin32LocaleImpl.h
intl/locale/src/windows/nsWin32Locale.cpp
intl/locale/src/windows/nsWinCharset.cpp
--- a/intl/build/nsI18nModule.cpp
+++ b/intl/build/nsI18nModule.cpp
@@ -87,17 +87,16 @@ NS_DEFINE_NAMED_CID(NS_STRINGBUNDLESERVI
 NS_DEFINE_NAMED_CID(NS_STRINGBUNDLETEXTOVERRIDE_CID);
 NS_DEFINE_NAMED_CID(NS_LOCALESERVICE_CID);
 NS_DEFINE_NAMED_CID(NS_COLLATIONFACTORY_CID);
 NS_DEFINE_NAMED_CID(NS_SCRIPTABLEDATEFORMAT_CID);
 NS_DEFINE_NAMED_CID(NS_LANGUAGEATOMSERVICE_CID);
 NS_DEFINE_NAMED_CID(NS_CHARSETALIAS_CID);
 NS_DEFINE_NAMED_CID(NS_PLATFORMCHARSET_CID);
 #ifdef XP_WIN
-NS_DEFINE_NAMED_CID(NS_WIN32LOCALE_CID);
 NS_DEFINE_NAMED_CID(NS_COLLATION_CID);
 NS_DEFINE_NAMED_CID(NS_DATETIMEFORMAT_CID);
 #endif
 #ifdef USE_UNIX_LOCALE
 NS_DEFINE_NAMED_CID(NS_POSIXLOCALE_CID);
 NS_DEFINE_NAMED_CID(NS_COLLATION_CID);
 NS_DEFINE_NAMED_CID(NS_DATETIMEFORMAT_CID);
 #endif
@@ -125,17 +124,16 @@ static const mozilla::Module::CIDEntry k
     { &kNS_STRINGBUNDLETEXTOVERRIDE_CID, false, NULL, nsStringBundleTextOverrideConstructor },
     { &kNS_LOCALESERVICE_CID, false, NULL, CreateLocaleService },
     { &kNS_COLLATIONFACTORY_CID, false, NULL, nsCollationFactoryConstructor },
     { &kNS_SCRIPTABLEDATEFORMAT_CID, false, NULL, NS_NewScriptableDateFormat },
     { &kNS_LANGUAGEATOMSERVICE_CID, false, NULL, nsLanguageAtomServiceConstructor },
     { &kNS_CHARSETALIAS_CID, false, NULL, nsCharsetAlias2Constructor },
     { &kNS_PLATFORMCHARSET_CID, false, NULL, nsPlatformCharsetConstructor },
 #ifdef XP_WIN
-    { &kNS_WIN32LOCALE_CID, false, NULL, nsIWin32LocaleImplConstructor },
     { &kNS_COLLATION_CID, false, NULL, nsCollationWinConstructor },
     { &kNS_DATETIMEFORMAT_CID, false, NULL, nsDateTimeFormatWinConstructor },
 #endif
 #ifdef USE_UNIX_LOCALE
     { &kNS_POSIXLOCALE_CID, false, NULL, nsPosixLocaleConstructor },
     { &kNS_COLLATION_CID, false, NULL, nsCollationUnixConstructor },
     { &kNS_DATETIMEFORMAT_CID, false, NULL, nsDateTimeFormatUnixConstructor },
 #endif
@@ -165,17 +163,16 @@ static const mozilla::Module::ContractID
     { NS_STRINGBUNDLETEXTOVERRIDE_CONTRACTID, &kNS_STRINGBUNDLETEXTOVERRIDE_CID },
     { NS_LOCALESERVICE_CONTRACTID, &kNS_LOCALESERVICE_CID },
     { NS_COLLATIONFACTORY_CONTRACTID, &kNS_COLLATIONFACTORY_CID },
     { NS_SCRIPTABLEDATEFORMAT_CONTRACTID, &kNS_SCRIPTABLEDATEFORMAT_CID },
     { NS_LANGUAGEATOMSERVICE_CONTRACTID, &kNS_LANGUAGEATOMSERVICE_CID },
     { NS_CHARSETALIAS_CONTRACTID, &kNS_CHARSETALIAS_CID },
     { NS_PLATFORMCHARSET_CONTRACTID, &kNS_PLATFORMCHARSET_CID },
 #ifdef XP_WIN
-    { NS_WIN32LOCALE_CONTRACTID, &kNS_WIN32LOCALE_CID },
     { NS_COLLATION_CONTRACTID, &kNS_COLLATION_CID },
     { NS_DATETIMEFORMAT_CONTRACTID, &kNS_DATETIMEFORMAT_CID },
 #endif
 #ifdef USE_UNIX_LOCALE
     { NS_POSIXLOCALE_CONTRACTID, &kNS_POSIXLOCALE_CID },
     { NS_COLLATION_CONTRACTID, &kNS_COLLATION_CID },
     { NS_DATETIMEFORMAT_CONTRACTID, &kNS_DATETIMEFORMAT_CID },
 #endif
--- a/intl/locale/public/Makefile.in
+++ b/intl/locale/public/Makefile.in
@@ -47,16 +47,16 @@ MODULE		= locale
 EXPORTS		= \
 		nsCollationCID.h \
 		nsDateTimeFormatCID.h \
 		nsIDateTimeFormat.h \
 		nsILanguageAtomService.h \
 		nsIMacLocale.h \
 		nsIPosixLocale.h \
 		nsIOS2Locale.h \
-		nsIWin32Locale.h \
+		nsWin32Locale.h \
 		nsICharsetAlias.h \
 		nsIPlatformCharset.h \
 		nsLocaleCID.h \
 		$(NULL)
 
 include $(topsrcdir)/config/rules.mk
 
rename from intl/locale/public/nsIWin32Locale.h
rename to intl/locale/public/nsWin32Locale.h
--- a/intl/locale/public/nsIWin32Locale.h
+++ b/intl/locale/public/nsWin32Locale.h
@@ -29,34 +29,36 @@
  * under the terms of either the GPL or the LGPL, and not to allow others to
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
-#ifndef nsIWin32Locale_h__
-#define nsIWin32Locale_h__
+#ifndef nsWin32Locale_h__
+#define nsWin32Locale_h__
 
-
-#include "nsISupports.h"
 #include "nscore.h"
 #include "nsString.h"
 #include <windows.h>
 
-// {D92D57C2-BA1D-11d2-AF0C-0060089FE59B}
-#define  NS_IWIN32LOCALE_IID              \
-{  0xd92d57c2, 0xba1d, 0x11d2,            \
-{  0xaf, 0xc, 0x0, 0x60, 0x8, 0x9f, 0xe5, 0x9b }}
 
+class nsWin32Locale {
+public: 
+  static nsresult    GetPlatformLocale(const nsAString& locale, LCID* winLCID); 
+  static void        GetXPLocale(LCID winLCID, nsAString& locale);
 
-class nsIWin32Locale : public nsISupports {
-public:
-  NS_DECLARE_STATIC_IID_ACCESSOR(NS_IWIN32LOCALE_IID)
+private:
+  // Static class - Don't allow instantiation.
+  nsWin32Locale(void) {}
 
-  NS_IMETHOD GetPlatformLocale(const nsAString& locale, LCID* winLCID) = 0;
-  NS_IMETHOD GetXPLocale(LCID winLCID, nsAString& locale) = 0;
+  typedef LCID (WINAPI*LocaleNameToLCIDPtr)(LPCWSTR lpName, DWORD dwFlags);
+  typedef int (WINAPI*LCIDToLocaleNamePtr)(LCID Locale, LPWSTR lpName,
+                                           int cchName, DWORD dwFlags);
+
+  static LocaleNameToLCIDPtr localeNameToLCID;
+  static LCIDToLocaleNamePtr lcidToLocaleName;
+
+  static void initFunctionPointers ();
 };
 
-NS_DEFINE_STATIC_IID_ACCESSOR(nsIWin32Locale, NS_IWIN32LOCALE_IID)
-
 #endif
--- a/intl/locale/src/nsLocaleConstructors.h
+++ b/intl/locale/src/nsLocaleConstructors.h
@@ -54,17 +54,16 @@
 #define USE_MAC_LOCALE
 #endif
 
 #if defined(XP_UNIX) && !defined(XP_MACOSX)
 #define USE_UNIX_LOCALE
 #endif
 
 #ifdef XP_WIN
-#include "nsIwin32LocaleImpl.h"
 #include "nsCollationWin.h"
 #include "nsDateTimeFormatWin.h"
 #endif
 
 #ifdef XP_OS2
 #include "nsOS2Locale.h"
 #include "nsCollationOS2.h"
 #include "nsDateTimeFormatOS2.h"
@@ -102,17 +101,16 @@ ctor_(nsISupports* aOuter, REFNSIID aIID
 NSLOCALE_MAKE_CTOR(CreateLocaleService, nsILocaleService, NS_NewLocaleService)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsCollationFactory)
 //NS_GENERIC_FACTORY_CONSTRUCTOR(nsScriptableDateTimeFormat)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsLanguageAtomService)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsCharsetAlias2)
 NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsPlatformCharset, Init)
 
 #ifdef XP_WIN
-NS_GENERIC_FACTORY_CONSTRUCTOR(nsIWin32LocaleImpl)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsCollationWin)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsDateTimeFormatWin)
 #endif
 
 #ifdef USE_UNIX_LOCALE
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsPosixLocale)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsCollationUnix)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsDateTimeFormatUnix)
--- a/intl/locale/src/nsLocaleService.cpp
+++ b/intl/locale/src/nsLocaleService.cpp
@@ -50,17 +50,17 @@
 #include "nsReadableUtils.h"
 #include "nsCRT.h"
 #include "prprf.h"
 #include "nsTArray.h"
 
 #include <ctype.h>
 
 #if defined(XP_WIN)
-#  include "nsIWin32Locale.h"
+#  include "nsWin32Locale.h"
 #elif defined(XP_OS2)
 #  include "unidef.h"
 #  include "nsIOS2Locale.h"
 #elif defined(XP_MACOSX)
 #  include <Carbon/Carbon.h>
 #  include "nsIMacLocale.h"
 #elif defined(XP_UNIX)
 #  include <locale.h>
@@ -133,44 +133,34 @@ protected:
 
 //
 // nsLocaleService methods
 //
 nsLocaleService::nsLocaleService(void) 
     : mSystemLocale(0), mApplicationLocale(0)
 {
 #ifdef XP_WIN
-    nsCOMPtr<nsIWin32Locale> win32Converter = do_GetService(NS_WIN32LOCALE_CONTRACTID);
-
-    NS_ASSERTION(win32Converter, "nsLocaleService: can't get win32 converter\n");
+    nsAutoString        xpLocale;
+    //
+    // get the system LCID
+    //
+    LCID win_lcid = GetSystemDefaultLCID();
+    NS_ENSURE_TRUE(win_lcid, );
+    nsWin32Locale::GetXPLocale(win_lcid, xpLocale);
+    nsresult rv = NewLocale(xpLocale, getter_AddRefs(mSystemLocale));
+    NS_ENSURE_SUCCESS(rv, );
 
-    nsAutoString        xpLocale;
-    if (win32Converter) {
-        
-        nsresult result;
-        //
-        // get the system LCID
-        //
-        LCID win_lcid = GetSystemDefaultLCID();
-        if (win_lcid==0) { return;}
-            result = win32Converter->GetXPLocale(win_lcid, xpLocale);
-        if (NS_FAILED(result)) { return;}
-            result = NewLocale(xpLocale, getter_AddRefs(mSystemLocale));
-        if (NS_FAILED(result)) { return;}
-
-        //
-        // get the application LCID
-        //
-        win_lcid = GetUserDefaultLCID();
-        if (win_lcid==0) { return;}
-            result = win32Converter->GetXPLocale(win_lcid, xpLocale);
-        if (NS_FAILED(result)) { return;}
-            result = NewLocale(xpLocale, getter_AddRefs(mApplicationLocale));
-        if (NS_FAILED(result)) { return;}
-    }
+    //
+    // get the application LCID
+    //
+    win_lcid = GetUserDefaultLCID();
+    NS_ENSURE_TRUE(win_lcid, );
+    nsWin32Locale::GetXPLocale(win_lcid, xpLocale);
+    rv = NewLocale(xpLocale, getter_AddRefs(mApplicationLocale));
+    NS_ENSURE_SUCCESS(rv, );
 #endif
 #if defined(XP_UNIX) && !defined(XP_MACOSX)
     nsCOMPtr<nsIPosixLocale> posixConverter = do_GetService(NS_POSIXLOCALE_CONTRACTID);
 
     nsAutoString xpLocale, platformLocale;
     if (posixConverter) {
         nsAutoString category, category_platform;
         int i;
--- a/intl/locale/src/windows/Makefile.in
+++ b/intl/locale/src/windows/Makefile.in
@@ -46,17 +46,17 @@ MODULE		= locale
 LIBRARY_NAME	= platlocale_s
 FORCE_STATIC_LIB	= 1
 LIBXUL_LIBRARY  = 1
 
 
 CPPSRCS		= \
 		nsCollationWin.cpp \
 		nsDateTimeFormatWin.cpp \
-		nsIWin32LocaleImpl.cpp \
+		nsWin32Locale.cpp \
 		nsWinCharset.cpp \
 		$(NULL)
 
 include $(topsrcdir)/config/rules.mk
 
 INCLUDES	+= -I$(srcdir)/..
 
 nsWinCharset.$(OBJ_SUFFIX): wincharset.properties.h
--- a/intl/locale/src/windows/nsCollationWin.cpp
+++ b/intl/locale/src/windows/nsCollationWin.cpp
@@ -38,17 +38,17 @@
 
 
 #include "nsCollationWin.h"
 #include "nsIServiceManager.h"
 #include "nsIComponentManager.h"
 #include "nsLocaleCID.h"
 #include "nsILocaleService.h"
 #include "nsIPlatformCharset.h"
-#include "nsIWin32Locale.h"
+#include "nsWin32Locale.h"
 #include "nsCOMPtr.h"
 #include "prmem.h"
 #include "plstr.h"
 #include <windows.h>
 
 #undef CompareString
 
 NS_IMPL_ISUPPORTS1(nsCollationWin, nsICollation)
@@ -95,24 +95,20 @@ nsresult nsCollationWin::Initialize(nsIL
     }
   }
   else {
     res = locale->GetCategory(NS_LITERAL_STRING("NSILOCALE_COLLATE"), 
                               localeStr);
   }
 
   // Get LCID and charset name from locale, if available
-  nsCOMPtr <nsIWin32Locale> win32Locale = 
-      do_GetService(NS_WIN32LOCALE_CONTRACTID);
-  if (win32Locale) {
-    LCID lcid;
-    res = win32Locale->GetPlatformLocale(localeStr, &lcid);
-    if (NS_SUCCEEDED(res)) {
-      mLCID = lcid;
-    }
+  LCID lcid;
+  res = nsWin32Locale::GetPlatformLocale(localeStr, &lcid);
+  if (NS_SUCCEEDED(res)) {
+    mLCID = lcid;
   }
 
   nsCOMPtr <nsIPlatformCharset> platformCharset = 
       do_GetService(NS_PLATFORMCHARSET_CONTRACTID);
   if (platformCharset) {
     nsCAutoString mappedCharset;
     res = platformCharset->GetDefaultCharsetForLocale(localeStr, mappedCharset);
     if (NS_SUCCEEDED(res)) {
--- a/intl/locale/src/windows/nsDateTimeFormatWin.cpp
+++ b/intl/locale/src/windows/nsDateTimeFormatWin.cpp
@@ -36,17 +36,17 @@
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include "nsDateTimeFormatWin.h"
 #include "nsIServiceManager.h"
 #include "nsIComponentManager.h"
 #include "nsLocaleCID.h"
 #include "nsILocaleService.h"
-#include "nsIWin32Locale.h"
+#include "nsWin32Locale.h"
 #include "nsUnicharUtils.h"
 #include "nsCRT.h"
 #include "nsCOMPtr.h"
 #include "prmem.h"
 
 
 #define NSDATETIMEFORMAT_BUFFER_LEN  80
 
@@ -97,21 +97,17 @@ nsresult nsDateTimeFormatWin::Initialize
   }
   else {
     res = locale->GetCategory(NS_LITERAL_STRING("NSILOCALE_TIME"), localeStr);
   }
 
   // Get LCID and charset name from locale, if available
   if (NS_SUCCEEDED(res) && !localeStr.IsEmpty()) {
     mLocale.Assign(localeStr); // cache locale name
-
-    nsCOMPtr <nsIWin32Locale> win32Locale = do_GetService(NS_WIN32LOCALE_CONTRACTID);
-    if (win32Locale) {
-      res = win32Locale->GetPlatformLocale(mLocale, (LCID *) &mLCID);
-    }
+    res = nsWin32Locale::GetPlatformLocale(mLocale, (LCID *) &mLCID);
   }
 
   return res;
 }
 
 // performs a locale sensitive date formatting operation on the time_t parameter
 nsresult nsDateTimeFormatWin::FormatTime(nsILocale* locale, 
                                          const nsDateFormatSelector  dateFormatSelector, 
deleted file mode 100644
--- a/intl/locale/src/windows/nsIwin32LocaleImpl.h
+++ /dev/null
@@ -1,72 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is mozilla.org code.
- *
- * The Initial Developer of the Original Code is
- * Netscape Communications Corporation.
- * Portions created by the Initial Developer are Copyright (C) 1998
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either of the GNU General Public License Version 2 or later (the "GPL"),
- * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-
-#ifndef nsIWin32LocaleImpl_h__
-#define nsIWin32LocaleImpl_h__
-
-
-#include "nsISupports.h"
-#include "nscore.h"
-#include "nsString.h"
-#include "nsIWin32Locale.h"
-#include <windows.h>
-
-class nsIWin32LocaleImpl: public nsIWin32Locale
-{
-
-	NS_DECL_ISUPPORTS
-
-public:
-
-	nsIWin32LocaleImpl(void);
-	~nsIWin32LocaleImpl(void);
-
-	NS_IMETHOD GetPlatformLocale(const nsAString& locale, LCID* winLCID);
-	NS_IMETHOD GetXPLocale(LCID winLCID, nsAString& locale);
-
-	typedef LCID (WINAPI*LocaleNameToLCIDPtr)(LPCWSTR lpName, DWORD dwFlags);
-	typedef int (WINAPI*LCIDToLocaleNamePtr)(LCID Locale, LPWSTR lpName,
-	                                         int cchName, DWORD dwFlags);
-
-	static LocaleNameToLCIDPtr localeNameToLCID;
-	static LCIDToLocaleNamePtr lcidToLocaleName;
-
-private:
-	static HMODULE sKernelDLL;
-};
-
-#endif
rename from intl/locale/src/windows/nsIWin32LocaleImpl.cpp
rename to intl/locale/src/windows/nsWin32Locale.cpp
--- a/intl/locale/src/windows/nsIWin32LocaleImpl.cpp
+++ b/intl/locale/src/windows/nsWin32Locale.cpp
@@ -30,44 +30,41 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
-#include "nsISupports.h"
 #include "nscore.h"
 #include "nsString.h"
+#include "nsXPCOMStrings.h"
 #include "nsReadableUtils.h"
-#include "nsIwin32LocaleImpl.h"
+#include "nsWin32Locale.h"
 #include "nsLocaleCID.h"
 #include "prprf.h"
 #include <windows.h>
 #include "nsCRT.h"
- #include "nsReadableUtils.h"
-#include "nsXPCOMStrings.h"
 
 struct iso_pair 
 {
 	const char*	iso_code;
 	DWORD       win_code;
 };
 
 struct iso_map
 {
 	const char* iso_code;
 	DWORD       win_code;
 	iso_pair    sublang_list[20];
 };
 
-HMODULE nsIWin32LocaleImpl::sKernelDLL = NULL;
-nsIWin32LocaleImpl::LocaleNameToLCIDPtr nsIWin32LocaleImpl::localeNameToLCID = NULL;
-nsIWin32LocaleImpl::LCIDToLocaleNamePtr nsIWin32LocaleImpl::lcidToLocaleName = NULL;
+nsWin32Locale::LocaleNameToLCIDPtr nsWin32Locale::localeNameToLCID = NULL;
+nsWin32Locale::LCIDToLocaleNamePtr nsWin32Locale::lcidToLocaleName = NULL;
 
 // Older versions of VC++ and Win32 SDK  and mingw don't have 
 // macros for languages and sublanguages recently added to Win32. 
 // see http://www.tug.org/ftp/tex/texinfo/intl/localename.c
 
 #ifndef LANG_URDU
 #define LANG_URDU                           0x20
 #endif
@@ -601,44 +598,41 @@ iso_pair dbg_list[] =
 	{"zh",	LANG_CHINESE},
 	{"",0}
 };
 #endif
 
 #define CROATIAN_ISO_CODE "hr"
 #define SERBIAN_ISO_CODE "sr"
 
-/* nsIWin32LocaleImpl */
-NS_IMPL_ISUPPORTS1(nsIWin32LocaleImpl,nsIWin32Locale)
-
-nsIWin32LocaleImpl::nsIWin32LocaleImpl(void)
+void
+nsWin32Locale::initFunctionPointers(void)
 {
+  static PRBool sInitialized = PR_FALSE;
   // We use the Vista and above functions if we have them
-  sKernelDLL = LoadLibraryW(L"kernel32.dll");
-  if (sKernelDLL) {
-    localeNameToLCID = (LocaleNameToLCIDPtr) GetProcAddress(sKernelDLL, "LocaleNameToLCID");
-    lcidToLocaleName = (LCIDToLocaleNamePtr) GetProcAddress(sKernelDLL, "LCIDToLocaleName");
+  if (!sInitialized) {
+    HMODULE kernelDLL = GetModuleHandleW(L"kernel32.dll");
+    if (kernelDLL) {
+      localeNameToLCID = (LocaleNameToLCIDPtr) GetProcAddress(kernelDLL, "LocaleNameToLCID");
+      lcidToLocaleName = (LCIDToLocaleNamePtr) GetProcAddress(kernelDLL, "LCIDToLocaleName");
+    }
+    sInitialized = PR_TRUE;
   }
 }
 
-nsIWin32LocaleImpl::~nsIWin32LocaleImpl(void)
-{
-  if (sKernelDLL)
-    FreeLibrary(sKernelDLL);
-}
-
 //
 // the mapping routines are a first approximation to get us going on
 // the tier-1 languages.  we are making an assumption that we can map
 // language and country codes separately on Windows, which isn't true
 //
+nsresult
+nsWin32Locale::GetPlatformLocale(const nsAString& locale, LCID* winLCID)
+{
+  initFunctionPointers ();
 
-NS_IMETHODIMP
-nsIWin32LocaleImpl::GetPlatformLocale(const nsAString& locale,LCID* winLCID)
-{
   if (localeNameToLCID) {
     nsAutoString locale_autostr(locale);
     LCID lcid = localeNameToLCID(locale_autostr.get(), 0);
     // The function returning 0 means that the locale name couldn't be matched,
     // so we fallback to the old function
     if (lcid != 0)
     {
       *winLCID = lcid;
@@ -678,51 +672,51 @@ nsIWin32LocaleImpl::GetPlatformLocale(co
     
   return NS_ERROR_FAILURE;
 }
 
 #ifndef LOCALE_NAME_MAX_LENGTH
 #define LOCALE_NAME_MAX_LENGTH 85
 #endif
 
-NS_IMETHODIMP
-nsIWin32LocaleImpl::GetXPLocale(LCID winLCID, nsAString& locale)
+void
+nsWin32Locale::GetXPLocale(LCID winLCID, nsAString& locale)
 {
+  initFunctionPointers ();
+
   if (lcidToLocaleName)
   {
     WCHAR ret_locale[LOCALE_NAME_MAX_LENGTH];
     int rv = lcidToLocaleName(winLCID, ret_locale, LOCALE_NAME_MAX_LENGTH, 0);
     // rv 0 means that the function failed to match up the LCID, so we fallback
     // to the old function
     if (rv != 0)
     {
       locale.Assign(ret_locale);
-      return NS_OK;
+      return;
     }
   }
 
   DWORD    lang_id, sublang_id;
   int      i,j;
 
   lang_id = PRIMARYLANGID(LANGIDFROMLCID(winLCID));
   sublang_id = SUBLANGID(LANGIDFROMLCID(winLCID));
 
   /* Special-case Norwegian Bokmal and Norwegian Nynorsk, which have the same
      LANG_ID on Windows, but have separate ISO-639-2 codes */
   if (lang_id == LANG_NORWEGIAN) {
     if (sublang_id == SUBLANG_NORWEGIAN_BOKMAL) {
       locale.AssignASCII("nb-NO");
-      return NS_OK;
-    }
-    if (sublang_id == SUBLANG_NORWEGIAN_NYNORSK) {
+    } else if (sublang_id == SUBLANG_NORWEGIAN_NYNORSK) {
       locale.AssignASCII("nn-NO");
-      return NS_OK;
+    } else {
+      locale.AssignASCII("no-NO");
     }
-    locale.AssignASCII("no-NO");
-    return NS_OK;
+    return;
   }
 
   for(i=0;i<LENGTH_MAPPING_LIST;i++) {
     if (lang_id==iso_list[i].win_code) {
       /* Special-case Croatian and Serbian, which have the same LANG_ID on
          Windows, but have been split into separate ISO-639-2 codes */
       if (lang_id == LANG_CROATIAN) {
         if (sublang_id == SUBLANG_DEFAULT) {
@@ -735,27 +729,26 @@ nsIWin32LocaleImpl::GetXPLocale(LCID win
       }
       for(j=0;iso_list[i].sublang_list[j].win_code;j++) {
         if (sublang_id == iso_list[i].sublang_list[j].win_code) {
           locale.Append(PRUnichar('-'));
           locale.AppendASCII(iso_list[i].sublang_list[j].iso_code);
           break;
         }
       }
-      return NS_OK;
+      return;
     }
   }
 
   //
   // didn't find any match. fall back to en-US, which is better 
   // than unusable buttons without 'OK', 'Cancel', etc (bug 224546)       
   //
   locale.AssignLiteral("en-US"); 
-  return NS_OK;
-
+  return;
 }
 
 #ifdef DEBUG
 void
 test_internal_tables(void)
 {
 	int	i;
 
--- a/intl/locale/src/windows/nsWinCharset.cpp
+++ b/intl/locale/src/windows/nsWinCharset.cpp
@@ -34,17 +34,17 @@
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include "nsIPlatformCharset.h"
 #include "nsUConvPropertySearch.h"
 #include "pratom.h"
 #include <windows.h>
-#include "nsIWin32Locale.h"
+#include "nsWin32Locale.h"
 #include "nsCOMPtr.h"
 #include "nsReadableUtils.h"
 #include "nsLocaleCID.h"
 #include "nsServiceManagerUtils.h"
 #include "nsITimelineService.h"
 #include "nsPlatformCharset.h"
 
 static const char* kWinCharsets[][3] = {
@@ -89,29 +89,25 @@ nsPlatformCharset::GetCharset(nsPlatform
 {
   oResult = mCharset;
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsPlatformCharset::GetDefaultCharsetForLocale(const nsAString& localeName, nsACString& oResult)
 {
-  nsCOMPtr<nsIWin32Locale>  winLocale;
   LCID                      localeAsLCID;
 
   //
   // convert locale name to a code page (through the LCID)
   //
   nsresult rv;
   oResult.Truncate();
 
-  winLocale = do_GetService(NS_WIN32LOCALE_CONTRACTID, &rv);
-  if (NS_FAILED(rv)) { return rv; }
-
-  rv = winLocale->GetPlatformLocale(localeName, &localeAsLCID);
+  rv = nsWin32Locale::GetPlatformLocale(localeName, &localeAsLCID);
   if (NS_FAILED(rv)) { return rv; }
 
   PRUnichar acp_name[6];
   if (GetLocaleInfoW(localeAsLCID, LOCALE_IDEFAULTANSICODEPAGE, acp_name,
                      NS_ARRAY_LENGTH(acp_name))==0) {
     return NS_ERROR_FAILURE; 
   }
   nsAutoString acp_key(NS_LITERAL_STRING("acp."));