Back to index

lightning-sunbird  0.9+nobinonly
nsParserModule.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 Communicator client 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 "nsIAtom.h"
00040 #include "nsString.h"
00041 #include "nspr.h"
00042 #include "nsCOMPtr.h"
00043 #include "nsIGenericFactory.h"
00044 #include "nsIModule.h"
00045 #include "nsParserCIID.h"
00046 #include "nsParser.h"
00047 #include "CNavDTD.h"
00048 #include "COtherDTD.h"
00049 #include "nsHTMLEntities.h"
00050 #include "nsHTMLTokenizer.h"
00051 //#include "nsTextTokenizer.h"
00052 #include "nsElementTable.h"
00053 #include "nsParserService.h"
00054 #include "nsSAXAttributes.h"
00055 #include "nsSAXLocator.h"
00056 #include "nsSAXXMLReader.h"
00057 
00058 #ifdef MOZ_VIEW_SOURCE
00059 #include "nsViewSourceHTML.h"
00060 #endif
00061 
00062 #if defined(NS_DEBUG) || defined(MOZ_PERF_METRICS)
00063 #include "nsLoggingSink.h"
00064 #include "nsExpatDriver.h"
00065 #endif
00066 
00067 //----------------------------------------------------------------------
00068 
00069 #if defined(NS_DEBUG) || defined(MOZ_PERF_METRICS)
00070 NS_GENERIC_FACTORY_CONSTRUCTOR(nsLoggingSink)
00071 NS_GENERIC_FACTORY_CONSTRUCTOR(nsExpatDriver)
00072 #endif
00073 
00074 NS_GENERIC_FACTORY_CONSTRUCTOR(nsParser)
00075 NS_GENERIC_FACTORY_CONSTRUCTOR(CNavDTD)
00076 NS_GENERIC_FACTORY_CONSTRUCTOR(CTransitionalDTD)
00077 NS_GENERIC_FACTORY_CONSTRUCTOR(nsParserService)
00078 
00079 #ifdef MOZ_VIEW_SOURCE
00080 NS_GENERIC_FACTORY_CONSTRUCTOR(CViewSourceHTML)
00081 #endif
00082 
00083 NS_GENERIC_FACTORY_CONSTRUCTOR(nsSAXAttributes)
00084 NS_GENERIC_FACTORY_CONSTRUCTOR(nsSAXLocator)
00085 NS_GENERIC_FACTORY_CONSTRUCTOR(nsSAXXMLReader)
00086 
00087 static const nsModuleComponentInfo gComponents[] = {
00088 
00089 #if defined(NS_DEBUG) || defined(MOZ_PERF_METRICS)
00090   { "Logging sink", NS_LOGGING_SINK_CID, NULL, nsLoggingSinkConstructor },
00091   { "Expat Driver", NS_EXPAT_DRIVER_CID, NULL, nsExpatDriverConstructor },
00092 #endif
00093 
00094   { "Parser", NS_PARSER_CID, NULL, nsParserConstructor },
00095   { "Navigator HTML DTD", NS_CNAVDTD_CID, NULL, CNavDTDConstructor },
00096   { "Transitional DTD", NS_CTRANSITIONAL_DTD_CID, NULL,
00097     CTransitionalDTDConstructor },
00098 #ifdef MOZ_VIEW_SOURCE
00099   { "ViewSource DTD", NS_VIEWSOURCE_DTD_CID, NULL, CViewSourceHTMLConstructor },
00100 #endif
00101   { "ParserService",
00102     NS_PARSERSERVICE_CID,
00103     NS_PARSERSERVICE_CONTRACTID,
00104     nsParserServiceConstructor
00105   },
00106   {
00107     NS_SAXATTRIBUTES_CLASSNAME,
00108     NS_SAXATTRIBUTES_CID,
00109     NS_SAXATTRIBUTES_CONTRACTID,
00110     nsSAXAttributesConstructor
00111   },
00112   {
00113     NS_SAXLOCATOR_CLASSNAME,
00114     NS_SAXLOCATOR_CID,
00115     NS_SAXLOCATOR_CONTRACTID,
00116     nsSAXLocatorConstructor
00117   },
00118   
00119   {
00120     NS_SAXXMLREADER_CLASSNAME,
00121     NS_SAXXMLREADER_CID,
00122     NS_SAXXMLREADER_CONTRACTID,
00123     nsSAXXMLReaderConstructor
00124   }
00125 };
00126 
00127 static PRBool gInitialized = PR_FALSE;
00128 
00129 PR_STATIC_CALLBACK(nsresult)
00130 Initialize(nsIModule* aSelf)
00131 {
00132   if (!gInitialized) {
00133     nsresult rv = nsHTMLTags::AddRefTable();
00134     NS_ENSURE_SUCCESS(rv, rv);
00135 
00136     rv = nsHTMLEntities::AddRefTable();
00137     if (NS_FAILED(rv)) {
00138       nsHTMLTags::ReleaseTable();
00139       return rv;
00140     }
00141 #ifdef NS_DEBUG
00142     CheckElementTable();
00143 #endif
00144     CNewlineToken::AllocNewline();
00145     gInitialized = PR_TRUE;
00146   }
00147 
00148   return nsParser::Init();
00149 }
00150 
00151 PR_STATIC_CALLBACK(void)
00152 Shutdown(nsIModule* aSelf)
00153 {
00154   if (gInitialized) {
00155     nsHTMLTags::ReleaseTable();
00156     nsHTMLEntities::ReleaseTable();
00157     nsDTDContext::ReleaseGlobalObjects();
00158     nsParser::Shutdown();
00159     CNewlineToken::FreeNewline();
00160     gInitialized = PR_FALSE;
00161   }
00162 }
00163 
00164 NS_IMPL_NSGETMODULE_WITH_CTOR_DTOR(nsParserModule, gComponents, Initialize, Shutdown)