2001-09-20 00:02:59 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
1999-09-28 19:03:20 +00:00
|
|
|
*
|
2001-09-20 00:02:59 +00:00
|
|
|
* The contents of this file are subject to the Netscape Public
|
1999-11-06 03:43:54 +00:00
|
|
|
* License Version 1.1 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
2001-09-20 00:02:59 +00:00
|
|
|
* the License at http://www.mozilla.org/NPL/
|
1999-09-28 19:03:20 +00:00
|
|
|
*
|
1999-11-06 03:43:54 +00:00
|
|
|
* 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.
|
1999-09-28 19:03:20 +00:00
|
|
|
*
|
|
|
|
* The Original Code is Mozilla Communicator client code.
|
|
|
|
*
|
2001-09-20 00:02:59 +00:00
|
|
|
* The Initial Developer of the Original Code is Netscape Communications
|
|
|
|
* Corporation. Portions created by Netscape are
|
1999-11-06 03:43:54 +00:00
|
|
|
* Copyright (C) 1998 Netscape Communications Corporation. All
|
|
|
|
* Rights Reserved.
|
|
|
|
*
|
2001-09-20 00:02:59 +00:00
|
|
|
* Contributor(s):
|
2000-02-02 22:24:56 +00:00
|
|
|
* Pierre Phaneuf <pp@ludusdesign.com>
|
2001-09-20 00:02:59 +00:00
|
|
|
*/
|
1999-09-28 19:03:20 +00:00
|
|
|
#include "nsCOMPtr.h"
|
2001-02-07 01:21:55 +00:00
|
|
|
#include "nsIRegistry.h"
|
1999-09-28 19:03:20 +00:00
|
|
|
#include "nsIModule.h"
|
|
|
|
#include "nsIGenericFactory.h"
|
|
|
|
#include "nsIComponentManager.h"
|
|
|
|
#include "nsICharsetConverterManager.h"
|
|
|
|
#include "nsIUnicodeDecodeHelper.h"
|
|
|
|
#include "nsIUnicodeEncodeHelper.h"
|
|
|
|
#include "nsIPlatformCharset.h"
|
|
|
|
#include "nsICharsetAlias.h"
|
|
|
|
#include "nsITextToSubURI.h"
|
|
|
|
#include "nsIServiceManager.h"
|
|
|
|
#include "nsCharsetMenu.h"
|
|
|
|
#include "rdf.h"
|
|
|
|
#include "nsUConvDll.h"
|
2000-01-24 21:28:28 +00:00
|
|
|
#include "nsFileSpec.h"
|
|
|
|
#include "nsIFile.h"
|
2001-08-01 22:36:54 +00:00
|
|
|
#include "nsIScriptableUConv.h"
|
2001-02-07 01:21:55 +00:00
|
|
|
|
|
|
|
#include "nsUCvMinSupport.h"
|
|
|
|
#include "nsISO88591ToUnicode.h"
|
|
|
|
#include "nsCP1252ToUnicode.h"
|
|
|
|
#include "nsMacRomanToUnicode.h"
|
|
|
|
#include "nsUTF8ToUnicode.h"
|
|
|
|
#include "nsUnicodeToISO88591.h"
|
|
|
|
#include "nsUnicodeToCP1252.h"
|
|
|
|
#include "nsUnicodeToMacRoman.h"
|
|
|
|
#include "nsUnicodeToUTF8.h"
|
2001-08-01 22:36:54 +00:00
|
|
|
#include "nsScriptableUConv.h"
|
2001-02-07 01:21:55 +00:00
|
|
|
|
1999-09-28 19:03:20 +00:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Global functions and data [declaration]
|
|
|
|
|
2001-08-07 02:55:54 +00:00
|
|
|
/**
|
|
|
|
* Extra information about charset converters that is stored in the
|
|
|
|
* component registry.
|
|
|
|
*/
|
|
|
|
struct ConverterInfo {
|
|
|
|
nsCID mCID;
|
|
|
|
const char* mSource;
|
|
|
|
const char* mDestination;
|
1999-09-28 19:03:20 +00:00
|
|
|
};
|
|
|
|
|
2001-08-07 02:55:54 +00:00
|
|
|
static ConverterInfo gConverterInfo[] = {
|
|
|
|
{ NS_ISO88591TOUNICODE_CID, "ISO-8859-1", "Unicode" },
|
|
|
|
{ NS_CP1252TOUNICODE_CID, "windows-1252", "Unicode" },
|
|
|
|
{ NS_MACROMANTOUNICODE_CID, "x-mac-roman", "Unicode" },
|
|
|
|
{ NS_UTF8TOUNICODE_CID, "UTF-8", "Unicode" },
|
|
|
|
{ NS_UNICODETOISO88591_CID, "Unicode", "ISO-8859-1" },
|
|
|
|
{ NS_UNICODETOCP1252_CID, "Unicode", "windows-1252" },
|
|
|
|
{ NS_UNICODETOMACROMAN_CID, "Unicode", "x-mac-roman" },
|
|
|
|
{ NS_UNICODETOUTF8_CID, "Unicode", "UTF-8" },
|
2001-03-12 20:43:02 +00:00
|
|
|
};
|
|
|
|
|
2001-08-07 02:55:54 +00:00
|
|
|
#define NUM_CONVERTERS (sizeof(gConverterInfo) / sizeof(gConverterInfo[0]))
|
2001-03-12 20:43:02 +00:00
|
|
|
|
2001-08-07 02:55:54 +00:00
|
|
|
/**
|
|
|
|
* Register the to/from information about a converter.
|
|
|
|
*/
|
|
|
|
static NS_IMETHODIMP
|
|
|
|
RegisterConverter(nsIComponentManager* aCompMgr,
|
|
|
|
nsIFile* aPath,
|
|
|
|
const char *aLocation,
|
|
|
|
const char *aType,
|
|
|
|
const nsModuleComponentInfo* aInfo)
|
1999-09-28 19:03:20 +00:00
|
|
|
{
|
2001-08-07 02:55:54 +00:00
|
|
|
nsresult rv;
|
1999-09-28 19:03:20 +00:00
|
|
|
|
2001-08-07 02:55:54 +00:00
|
|
|
// Find the relevant information for the converter we're registering
|
|
|
|
const ConverterInfo* info = gConverterInfo;
|
|
|
|
const ConverterInfo* limit = gConverterInfo + NUM_CONVERTERS;
|
|
|
|
for ( ; info < limit; ++info) {
|
|
|
|
if (info->mCID.Equals(aInfo->mCID))
|
2001-03-12 20:43:02 +00:00
|
|
|
break;
|
1999-09-28 19:03:20 +00:00
|
|
|
}
|
|
|
|
|
2001-08-07 02:55:54 +00:00
|
|
|
if (info == limit) {
|
|
|
|
NS_ERROR("failed to find converter info");
|
|
|
|
return NS_OK; // so as not to completely kill component registration
|
1999-09-28 19:03:20 +00:00
|
|
|
}
|
|
|
|
|
2001-08-07 02:55:54 +00:00
|
|
|
nsCOMPtr<nsIRegistry> registry = do_GetService(NS_REGISTRY_CONTRACTID);
|
|
|
|
if (! registry)
|
|
|
|
return NS_ERROR_FAILURE;
|
1999-09-28 19:03:20 +00:00
|
|
|
|
2001-08-07 02:55:54 +00:00
|
|
|
// Open the registry
|
2001-02-07 01:21:55 +00:00
|
|
|
rv = registry->OpenWellKnownRegistry(nsIRegistry::ApplicationComponentRegistry);
|
2001-08-07 02:55:54 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
// Register source and destination strings under the key
|
|
|
|
// ``software/netscape/intl/uconv/[cid]''.
|
|
|
|
static NS_NAMED_LITERAL_CSTRING(kConverterKeyPrefix, "software/netscape/intl/uconv/");
|
|
|
|
nsXPIDLCString cid;
|
|
|
|
cid.Adopt(info->mCID.ToString());
|
|
|
|
|
|
|
|
nsRegistryKey key;
|
|
|
|
rv = registry->AddSubtree(nsIRegistry::Common,
|
|
|
|
PromiseFlatCString(kConverterKeyPrefix + cid).get(),
|
|
|
|
&key);
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
registry->SetStringUTF8(key, "source", info->mSource);
|
|
|
|
registry->SetStringUTF8(key, "destination", info->mDestination);
|
1999-09-28 19:03:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-08-07 02:55:54 +00:00
|
|
|
/**
|
|
|
|
* Unregister the extra converter information.
|
|
|
|
*/
|
|
|
|
static NS_IMETHODIMP
|
|
|
|
UnregisterConverter(nsIComponentManager* aCompMgr,
|
|
|
|
nsIFile* aPath,
|
|
|
|
const char* aRegistryLocation,
|
|
|
|
const nsModuleComponentInfo* aInfo)
|
1999-09-28 19:03:20 +00:00
|
|
|
{
|
2001-08-07 02:55:54 +00:00
|
|
|
// XXX TODO: remove converter key
|
|
|
|
return NS_OK;
|
1999-09-28 19:03:20 +00:00
|
|
|
}
|
|
|
|
|
2001-08-07 02:55:54 +00:00
|
|
|
NS_GENERIC_FACTORY_CONSTRUCTOR(nsScriptableUnicodeConverter)
|
1999-09-28 19:03:20 +00:00
|
|
|
|
2001-08-07 02:55:54 +00:00
|
|
|
// The list of components we register
|
|
|
|
static nsModuleComponentInfo gComponents[] = {
|
|
|
|
{ "Charset Conversion Manager", NS_ICHARSETCONVERTERMANAGER_CID,
|
|
|
|
NS_CHARSETCONVERTERMANAGER_CONTRACTID, NS_NewCharsetConverterManager,
|
|
|
|
NS_RegisterConverterManagerData,
|
|
|
|
NS_UnregisterConverterManagerData },
|
|
|
|
|
|
|
|
{ "Unicode Decode Helper", NS_UNICODEDECODEHELPER_CID,
|
|
|
|
NS_UNICODEDECODEHELPER_CONTRACTID, NS_NewUnicodeDecodeHelper },
|
|
|
|
|
|
|
|
{ "Unicode Encode Helper", NS_UNICODEENCODEHELPER_CID,
|
|
|
|
NS_UNICODEENCODEHELPER_CONTRACTID, NS_NewUnicodeEncodeHelper },
|
|
|
|
|
|
|
|
{ "Platform Charset Information", NS_PLATFORMCHARSET_CID,
|
|
|
|
NS_PLATFORMCHARSET_CONTRACTID, NS_NewPlatformCharset },
|
|
|
|
|
|
|
|
{ "Charset Alias Information", NS_CHARSETALIAS_CID,
|
|
|
|
NS_CHARSETALIAS_CONTRACTID, NS_NewCharsetAlias },
|
|
|
|
|
|
|
|
{ NS_CHARSETMENU_PID, NS_CHARSETMENU_CID,
|
|
|
|
NS_RDF_DATASOURCE_CONTRACTID_PREFIX NS_CHARSETMENU_PID,
|
|
|
|
NS_NewCharsetMenu},
|
|
|
|
|
|
|
|
{ "Text To Sub URI Helper", NS_TEXTTOSUBURI_CID,
|
|
|
|
NS_ITEXTTOSUBURI_CONTRACTID, NS_NewTextToSubURI },
|
|
|
|
|
|
|
|
{ "Unicode Encoder / Decoder for Script", NS_ISCRIPTABLEUNICODECONVERTER_CID,
|
|
|
|
NS_ISCRIPTABLEUNICODECONVERTER_CONTRACTID, nsScriptableUnicodeConverterConstructor },
|
|
|
|
|
|
|
|
// Converters
|
|
|
|
{ "ISO-8859-1 To Unicode Converter", NS_ISO88591TOUNICODE_CID,
|
|
|
|
NS_ISO88591TOUNICODE_CONTRACTID, NS_NewISO88591ToUnicode,
|
|
|
|
RegisterConverter, UnregisterConverter },
|
|
|
|
|
|
|
|
{ "windows-1252 To Unicode Converter", NS_CP1252TOUNICODE_CID,
|
|
|
|
NS_CP1252TOUNICODE_CONTRACTID, NS_NewCP1252ToUnicode,
|
|
|
|
RegisterConverter, UnregisterConverter },
|
|
|
|
|
|
|
|
{ "x-mac-roman To Unicode Converter", NS_MACROMANTOUNICODE_CID,
|
|
|
|
NS_MACROMANTOUNICODE_CONTRACTID, NS_NewMacRomanToUnicode,
|
|
|
|
RegisterConverter, UnregisterConverter },
|
|
|
|
|
|
|
|
{ "UTF-8 To Unicode Converter", NS_UTF8TOUNICODE_CID,
|
|
|
|
NS_UTF8TOUNICODE_CONTRACTID, NS_NewUTF8ToUnicode,
|
|
|
|
RegisterConverter, UnregisterConverter },
|
|
|
|
|
|
|
|
{ "Unicode To ISO-8859-1 Converter", NS_UNICODETOISO88591_CID,
|
|
|
|
NS_UNICODETOISO88591_CONTRACTID, NS_NewUnicodeToISO88591,
|
|
|
|
RegisterConverter, UnregisterConverter },
|
|
|
|
|
|
|
|
{ "Unicode To windows-1252 Converter", NS_UNICODETOCP1252_CID,
|
|
|
|
NS_UNICODETOCP1252_CONTRACTID, NS_NewUnicodeToCP1252,
|
|
|
|
RegisterConverter, UnregisterConverter },
|
|
|
|
|
|
|
|
{ "Unicode To x-mac-roman Converter", NS_UNICODETOMACROMAN_CID,
|
|
|
|
NS_UNICODETOMACROMAN_CONTRACTID, NS_NewUnicodeToMacRoman,
|
|
|
|
RegisterConverter, UnregisterConverter },
|
|
|
|
|
|
|
|
{ "Unicode To UTF-8 Converter", NS_UNICODETOUTF8_CID,
|
|
|
|
NS_UNICODETOUTF8_CONTRACTID, NS_NewUnicodeToUTF8,
|
|
|
|
RegisterConverter, UnregisterConverter },
|
|
|
|
};
|
1999-09-28 19:03:20 +00:00
|
|
|
|
2001-08-07 02:55:54 +00:00
|
|
|
NS_IMPL_NSGETMODULE(nsUConvModule, gComponents)
|