Back to index

lightning-sunbird  0.9+nobinonly
nsNativeCharDetDll.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *   Pierre Phaneuf <pp@ludusdesign.com>
00024  *
00025  * Alternatively, the contents of this file may be used under the terms of
00026  * either of the GNU General Public License Version 2 or later (the "GPL"),
00027  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00028  * in which case the provisions of the GPL or the LGPL are applicable instead
00029  * of those above. If you wish to allow use of your version of this file only
00030  * under the terms of either the GPL or the LGPL, and not to allow others to
00031  * use your version of this file under the terms of the MPL, indicate your
00032  * decision by deleting the provisions above and replace them with the notice
00033  * and other provisions required by the GPL or the LGPL. If you do not delete
00034  * the provisions above, a recipient may use your version of this file under
00035  * the terms of any one of the MPL, the GPL or the LGPL.
00036  *
00037  * ***** END LICENSE BLOCK ***** */
00038 
00039 #include "nsICharsetAlias.h"
00040 
00041 #include "pratom.h"
00042 #include "nsNativeCharDetDll.h"
00043 #include "nsISupports.h"
00044 #include "nsIComponentManager.h"
00045 #include "nsIFactory.h"
00046 #include "nsIServiceManager.h"
00047 #include "nsCOMPtr.h"
00048 #include "nsICharsetDetector.h"
00049 #include "nsIStringCharsetDetector.h"
00050 #include "nsNativeDetectors.h"
00051 
00052 
00053 static NS_DEFINE_CID(kJANativeDetectorCID,         NS_JA_NATIVE_DETECTOR_CID);
00054 static NS_DEFINE_CID(kJANativeStringDetectorCID,   NS_JA_NATIVE_STRING_DETECTOR_CID);
00055 static NS_DEFINE_CID(kKONativeDetectorCID,         NS_KO_NATIVE_DETECTOR_CID);
00056 static NS_DEFINE_CID(kKONativeStringDetectorCID,   NS_KO_NATIVE_STRING_DETECTOR_CID);
00057 static NS_DEFINE_CID(kComponentManagerCID, NS_COMPONENTMANAGER_CID);
00058 static NS_DEFINE_IID(kFactoryIID, NS_IFACTORY_IID);
00059 
00060 extern "C" NS_EXPORT nsresult NSGetFactory(nsISupports* aServMgr,
00061                                            const nsCID &aClass,
00062                                            const char *aClassName,
00063                                            const char *aContractID,
00064                                            nsIFactory **aFactory)
00065 {
00066   if (aFactory == NULL) {
00067     return NS_ERROR_NULL_POINTER;
00068   }
00069 
00070   nsIFactory *factory = nsnull;
00071   if (aClass.Equals(kJANativeDetectorCID)) {
00072     ;
00073     //bug#13844 disable this until find out the reason of the freeze
00074     //factory = NEW_JA_NATIVEDETECTOR_FACTORY();
00075   } else if (aClass.Equals(kJANativeStringDetectorCID)) {
00076     factory = NEW_JA_STRING_NATIVEDETECTOR_FACTORY();
00077   } else if (aClass.Equals(kKONativeDetectorCID)) {
00078     ;factory = NEW_KO_NATIVEDETECTOR_FACTORY();
00079   } else if (aClass.Equals(kKONativeStringDetectorCID)) {
00080     factory = NEW_KO_STRING_NATIVEDETECTOR_FACTORY();
00081   }
00082 
00083   if(nsnull != factory) {
00084     nsresult res = factory->QueryInterface(kFactoryIID, (void **) aFactory);
00085     if (NS_FAILED(res)) {
00086       *aFactory = NULL;
00087       delete factory;
00088     }
00089     return res;
00090   }
00091   return NS_NOINTERFACE;
00092 }
00093 
00094 extern "C" NS_EXPORT PRBool NSCanUnload(nsISupports* aServMgr) {
00095   return PR_FALSE;
00096 }
00097 extern "C" NS_EXPORT nsresult NSRegisterSelf(nsISupports* aServMgr, const char *path)
00098 {
00099   nsresult rv;
00100 
00101   nsCOMPtr<nsIServiceManager> servMgr(do_QueryInterface(aServMgr, &rv));
00102   if (NS_FAILED(rv)) return rv;
00103 
00104   nsCOMPtr<nsIComponentManager> compMgr = do_GetService(kComponentManagerCID, &rv);
00105   if (NS_FAILED(rv)) return rv;
00106 
00107   rv = compMgr->RegisterComponent(kJANativeDetectorCID, 
00108                                   "Native JA Charset Detector", 
00109                                   NS_CHARSET_DETECTOR_CONTRACTID_BASE "jams", 
00110                                   path,
00111                                   PR_TRUE, PR_TRUE);
00112 
00113   rv = compMgr->RegisterComponent(kJANativeStringDetectorCID, 
00114                                   "Native JA String Charset Detector", 
00115                                   NS_STRCDETECTOR_CONTRACTID_BASE "jams", 
00116                                   path,
00117                                   PR_TRUE, PR_TRUE);
00118 
00119   rv = compMgr->RegisterComponent(kKONativeDetectorCID, 
00120                                   "Native KO Charset Detector", 
00121                                   NS_CHARSET_DETECTOR_CONTRACTID_BASE "koms", 
00122                                   path,
00123                                   PR_TRUE, PR_TRUE);
00124 
00125   rv = compMgr->RegisterComponent(kKONativeStringDetectorCID, 
00126                                   "Native KO String Charset Detector", 
00127                                   NS_STRCDETECTOR_CONTRACTID_BASE "koms", 
00128                                   path,
00129                                   PR_TRUE, PR_TRUE);
00130   return rv;
00131 }
00132 
00133 extern "C" NS_EXPORT nsresult NSUnregisterSelf(nsISupports* aServMgr, const char *path)
00134 {
00135   nsresult rv;
00136 
00137   nsCOMPtr<nsIServiceManager> servMgr(do_QueryInterface(aServMgr, &rv));
00138   if (NS_FAILED(rv)) return rv;
00139 
00140   nsCOMPtr<nsIComponentManager> compMgr = do_GetService(kComponentManagerCID, &rv);
00141   if (NS_FAILED(rv)) return rv;
00142 
00143   rv = compMgr->UnregisterComponent(kJANativeDetectorCID, path);
00144   rv = compMgr->UnregisterComponent(kJANativeStringDetectorCID, path);
00145   rv = compMgr->UnregisterComponent(kKONativeDetectorCID, path);
00146   rv = compMgr->UnregisterComponent(kKONativeStringDetectorCID, path);
00147 
00148   return rv;
00149 }
00150