This commit is contained in:
kipp%netscape.com 1999-09-28 00:44:47 +00:00
Родитель e8f13ffdd6
Коммит c631df256f
8 изменённых файлов: 1935 добавлений и 0 удалений

Просмотреть файл

@ -0,0 +1,376 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (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/NPL/
*
* 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 Communicator client code.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*/
#include "nsCOMPtr.h"
#include "nsIGenericFactory.h"
#include "nsIModule.h"
#include "nsParserCIID.h"
#include "nsParser.h"
#include "nsILoggingSink.h"
#include "nsWellFormedDTD.h"
#include "CNavDTD.h"
#include "nsXIFDTD.h"
static NS_DEFINE_IID(kParserCID, NS_PARSER_IID);
static NS_DEFINE_IID(kParserNodeCID, NS_PARSER_NODE_IID);
static NS_DEFINE_IID(kLoggingSinkCID, NS_LOGGING_SINK_IID);
static NS_DEFINE_CID(kWellFormedDTDCID, NS_WELLFORMEDDTD_CID);
static NS_DEFINE_CID(kNavDTDCID, NS_CNAVDTD_CID);
static NS_DEFINE_CID(kXIFDTDCID, NS_XIF_DTD_CID);
struct Components {
const char* mDescription;
const nsID* mCID;
};
static Components gComponents[] = {
{ "Parser", &kParserCID },
{ "ParserNode", &kParserNodeCID },
{ "Logging sink", &kLoggingSinkCID },
{ "Well formed DTD", &kWellFormedDTDCID },
{ "Navigator HTML DTD", &kNavDTDCID },
{ "XIF DTD", &kXIFDTDCID },
};
#define NUM_COMPONENTS (sizeof(gComponents) / sizeof(gComponents[0]));
// Factory method to create new instances of nsParser
static nsresult
CreateNewParser(nsISupports* aOuter, REFNSIID aIID, void **aResult)
{
if (!aResult) {
return NS_ERROR_INVALID_POINTER;
}
if (aOuter) {
*aResult = nsnull;
return NS_NOINTERFACE;
}
nsParser* inst = new nsParser();
if (!inst) {
*aResult = nsnull;
return NS_ERROR_OUT_OF_MEMORY;
}
nsresult rv = inst->QueryInterface(aIID, aResult);
if (NS_FAILED(rv)) {
*aResult = nsnull;
delete inst;
}
return rv;
}
// Factory method to create new instances of nsParserNode
static nsresult
CreateNewParserNode(nsISupports* aOuter, REFNSIID aIID, void **aResult)
{
if (!aResult) {
return NS_ERROR_INVALID_POINTER;
}
if (aOuter) {
*aResult = nsnull;
return NS_NOINTERFACE;
}
nsCParserNode* inst = new nsCParserNode();
if (!inst) {
*aResult = nsnull;
return NS_ERROR_OUT_OF_MEMORY;
}
nsresult rv = inst->QueryInterface(aIID, aResult);
if (NS_FAILED(rv)) {
*aResult = nsnull;
delete inst;
}
return rv;
}
// Factory method to create new instances of nsILoggingSink
static nsresult
CreateNewLoggingSink(nsISupports* aOuter, REFNSIID aIID, void **aResult)
{
if (!aResult) {
return NS_ERROR_INVALID_POINTER;
}
if (aOuter) {
*aResult = nsnull;
return NS_NOINTERFACE;
}
nsIContentSink* inst;
nsresult rv = NS_NewHTMLLoggingSink(&inst);
if (NS_FAILED(rv)) {
*aResult = nsnull;
return NS_ERROR_OUT_OF_MEMORY;
}
rv = inst->QueryInterface(aIID, aResult);
if (NS_FAILED(rv)) {
*aResult = nsnull;
}
NS_RELEASE(inst); // get rid of extra refcnt
return rv;
}
// Factory method to create new instances of nsWellFormedDTD
static nsresult
CreateNewWellFormedDTD(nsISupports* aOuter, REFNSIID aIID, void **aResult)
{
if (!aResult) {
return NS_ERROR_INVALID_POINTER;
}
if (aOuter) {
*aResult = nsnull;
return NS_NOINTERFACE;
}
nsIDTD* inst;
nsresult rv = NS_NewWellFormed_DTD(&inst);
if (NS_FAILED(rv)) {
*aResult = nsnull;
return NS_ERROR_OUT_OF_MEMORY;
}
rv = inst->QueryInterface(aIID, aResult);
if (NS_FAILED(rv)) {
*aResult = nsnull;
}
NS_RELEASE(inst); // get rid of extra refcnt
return rv;
}
// Factory method to create new instances of nsNavHTMLDTD
static nsresult
CreateNewNavHTMLDTD(nsISupports* aOuter, REFNSIID aIID, void **aResult)
{
if (!aResult) {
return NS_ERROR_INVALID_POINTER;
}
if (aOuter) {
*aResult = nsnull;
return NS_NOINTERFACE;
}
nsIDTD* inst;
nsresult rv = NS_NewNavHTMLDTD(&inst);
if (NS_FAILED(rv)) {
*aResult = nsnull;
return NS_ERROR_OUT_OF_MEMORY;
}
rv = inst->QueryInterface(aIID, aResult);
if (NS_FAILED(rv)) {
*aResult = nsnull;
}
NS_RELEASE(inst); // get rid of extra refcnt
return rv;
}
// Factory method to create new instances of nsXIFDTD
static nsresult
CreateNewXIFDTD(nsISupports* aOuter, REFNSIID aIID, void **aResult)
{
if (!aResult) {
return NS_ERROR_INVALID_POINTER;
}
if (aOuter) {
*aResult = nsnull;
return NS_NOINTERFACE;
}
nsIDTD* inst;
nsresult rv = NS_NewXIFDTD(&inst);
if (!inst) {
*aResult = nsnull;
return NS_ERROR_OUT_OF_MEMORY;
}
rv = inst->QueryInterface(aIID, aResult);
if (NS_FAILED(rv)) {
*aResult = nsnull;
}
NS_RELEASE(inst); // get rid of extra refcnt
return rv;
}
//----------------------------------------------------------------------
class nsParserModule : public nsIModule {
public:
nsParserModule();
virtual ~nsParserModule();
NS_DECL_ISUPPORTS
NS_DECL_NSIMODULE
nsresult Initialize();
protected:
void Shutdown();
PRBool mInitialized;
};
static NS_DEFINE_IID(kIModuleIID, NS_IMODULE_IID);
nsParserModule::nsParserModule()
: mInitialized(PR_FALSE)
{
NS_INIT_ISUPPORTS();
}
nsParserModule::~nsParserModule()
{
Shutdown();
}
NS_IMPL_ISUPPORTS(nsParserModule, kIModuleIID)
nsresult
nsParserModule::Initialize()
{
return NS_OK;
}
void
nsParserModule::Shutdown()
{
}
NS_IMETHODIMP
nsParserModule::GetClassObject(nsIComponentManager *aCompMgr,
const nsCID& aClass,
const nsIID& aIID,
void** r_classObj)
{
nsresult rv;
if (!mInitialized) {
rv = Initialize();
if (NS_FAILED(rv)) {
return rv;
}
mInitialized = PR_TRUE;
}
nsCOMPtr<nsIGenericFactory> fact;
if (aClass.Equals(kParserCID)) {
rv = NS_NewGenericFactory(getter_AddRefs(fact), CreateNewParser);
}
else if (aClass.Equals(kParserNodeCID)) {
rv = NS_NewGenericFactory(getter_AddRefs(fact), CreateNewParserNode);
}
else if (aClass.Equals(kLoggingSinkCID)) {
rv = NS_NewGenericFactory(getter_AddRefs(fact), CreateNewLoggingSink);
}
else if (aClass.Equals(kWellFormedDTDCID)) {
rv = NS_NewGenericFactory(getter_AddRefs(fact), CreateNewWellFormedDTD);
}
else if (aClass.Equals(kNavDTDCID)) {
rv = NS_NewGenericFactory(getter_AddRefs(fact), CreateNewNavHTMLDTD);
}
else if (aClass.Equals(kXIFDTDCID)) {
rv = NS_NewGenericFactory(getter_AddRefs(fact), CreateNewXIFDTD);
}
else {
rv = NS_ERROR_FACTORY_NOT_REGISTERED;
}
if (fact) {
rv = fact->QueryInterface(aIID, r_classObj);
}
return rv;
}
NS_IMETHODIMP
nsParserModule::RegisterSelf(nsIComponentManager *aCompMgr,
nsIFileSpec* aPath,
const char* registryLocation,
const char* componentType)
{
nsresult rv = NS_OK;
Components* cp = gComponents;
Components* end = cp + NUM_COMPONENTS;
while (cp < end) {
rv = aCompMgr->RegisterComponentSpec(*cp->mCID, cp->mDescription,
nsnull, aPath, PR_TRUE, PR_TRUE);
if (NS_FAILED(rv)) {
#ifdef DEBUG
printf("nsParserModule: unable to register %s component => %x\n",
cp->mDescription, rv);
#endif
break;
}
cp++;
}
return rv;
}
NS_IMETHODIMP
nsParserModule::UnregisterSelf(nsIComponentManager *aCompMgr,
nsIFileSpec* aPath,
const char* registryLocation)
{
Components* cp = gComponents;
Components* end = cp + NUM_COMPONENTS;
while (cp < end) {
nsresult rv = aCompMgr->UnregisterComponentSpec(*cp->mCID, aPath);
if (NS_FAILED(rv)) {
#ifdef DEBUG
printf("nsParserModule: unable to unregister %s component => %x\n",
cp->mDescription, rv);
#endif
}
cp++;
}
return NS_OK;
}
NS_IMETHODIMP
nsParserModule::CanUnload(nsIComponentManager *aCompMgr, PRBool *okToUnload)
{
if (!okToUnload) {
return NS_ERROR_INVALID_POINTER;
}
*okToUnload = PR_FALSE;
return NS_ERROR_FAILURE;
}
//----------------------------------------------------------------------
#if 0
static nsParserModule *gModule = NULL;
extern "C" NS_EXPORT nsresult NSGetModule(nsIComponentManager *servMgr,
nsIFileSpec* location,
nsIModule** return_cobj)
{
nsresult rv = NS_OK;
NS_ASSERTION(return_cobj, "Null argument");
NS_ASSERTION(gModule == NULL, "nsParserModule: Module already created.");
// Create an initialize the layout module instance
nsParserModule *m = new nsParserModule();
if (!m) {
return NS_ERROR_OUT_OF_MEMORY;
}
// Increase refcnt and store away nsIModule interface to m in return_cobj
rv = m->QueryInterface(nsIModule::GetIID(), (void**)return_cobj);
if (NS_FAILED(rv)) {
delete m;
m = nsnull;
}
gModule = m; // WARNING: Weak Reference
return rv;
}
#endif

Просмотреть файл

@ -0,0 +1,387 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (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/NPL/
*
* 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 Communicator client code.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*/
#include "nsCOMPtr.h"
#include "nsLayoutModule.h"
#include "nsLayoutCID.h"
#include "nsIComponentManager.h"
#include "nsNeckoUtil.h"
#include "nsICSSStyleSheet.h"
#include "nsICSSLoader.h"
#include "nsHTMLAtoms.h"
#include "nsCSSKeywords.h" // to addref/release table
#include "nsCSSProps.h" // to addref/release table
#include "nsCSSAtoms.h" // to addref/release table
#include "nsColorNames.h" // to addref/release table
#ifdef INCLUDE_XUL
#include "nsXULAtoms.h"
#endif
#include "nsLayoutAtoms.h"
#include "nsDOMCID.h"
#include "nsIScriptContext.h"
#include "nsINameSpaceManager.h"
#include "nsIScriptNameSetRegistry.h"
#include "nsIScriptNameSpaceManager.h"
#include "nsIScriptExternalNameSet.h"
#include "nsIDocumentEncoder.h"
// XXX
#include "nsIServiceManager.h"
// URL for the "user agent" style sheet
#define UA_CSS_URL "resource:/res/ua.css"
static nsLayoutModule *gModule = NULL;
extern "C" NS_EXPORT nsresult NSGetModule(nsIComponentManager *servMgr,
nsIFileSpec* location,
nsIModule** return_cobj)
{
nsresult rv = NS_OK;
NS_ASSERTION(return_cobj, "Null argument");
NS_ASSERTION(gModule == NULL, "nsLayoutModule: Module already created.");
// Create an initialize the layout module instance
nsLayoutModule *m = new nsLayoutModule();
if (!m) {
return NS_ERROR_OUT_OF_MEMORY;
}
// Increase refcnt and store away nsIModule interface to m in return_cobj
rv = m->QueryInterface(nsIModule::GetIID(), (void**)return_cobj);
if (NS_FAILED(rv)) {
delete m;
m = nsnull;
}
gModule = m; // WARNING: Weak Reference
return rv;
}
//----------------------------------------------------------------------
static NS_DEFINE_IID(kIScriptNameSetRegistryIID, NS_ISCRIPTNAMESETREGISTRY_IID);
static NS_DEFINE_IID(kCScriptNameSetRegistryCID, NS_SCRIPT_NAMESET_REGISTRY_CID);
static NS_DEFINE_IID(kIScriptNameSpaceManagerIID, NS_ISCRIPTNAMESPACEMANAGER_IID);
static NS_DEFINE_IID(kIScriptExternalNameSetIID, NS_ISCRIPTEXTERNALNAMESET_IID);
class LayoutScriptNameSet : public nsIScriptExternalNameSet {
public:
LayoutScriptNameSet();
virtual ~LayoutScriptNameSet();
NS_DECL_ISUPPORTS
NS_IMETHOD InitializeClasses(nsIScriptContext* aScriptContext);
NS_IMETHOD AddNameSet(nsIScriptContext* aScriptContext);
};
LayoutScriptNameSet::LayoutScriptNameSet()
{
NS_INIT_REFCNT();
}
LayoutScriptNameSet::~LayoutScriptNameSet()
{
}
NS_IMPL_ISUPPORTS(LayoutScriptNameSet, kIScriptExternalNameSetIID);
NS_IMETHODIMP
LayoutScriptNameSet::InitializeClasses(nsIScriptContext* aScriptContext)
{
return NS_OK;
}
NS_IMETHODIMP
LayoutScriptNameSet::AddNameSet(nsIScriptContext* aScriptContext)
{
nsresult result = NS_OK;
nsIScriptNameSpaceManager* manager;
static NS_DEFINE_IID(kHTMLImageElementCID, NS_HTMLIMAGEELEMENT_CID);
static NS_DEFINE_IID(kHTMLOptionElementCID, NS_HTMLOPTIONELEMENT_CID);
result = aScriptContext->GetNameSpaceManager(&manager);
if (NS_OK == result) {
result = manager->RegisterGlobalName("HTMLImageElement",
kHTMLImageElementCID,
PR_TRUE);
if (NS_FAILED(result)) {
NS_RELEASE(manager);
return result;
}
result = manager->RegisterGlobalName("HTMLOptionElement",
kHTMLOptionElementCID,
PR_TRUE);
if (NS_FAILED(result)) {
NS_RELEASE(manager);
return result;
}
NS_RELEASE(manager);
}
return result;
}
//----------------------------------------------------------------------
static NS_DEFINE_IID(kIModuleIID, NS_IMODULE_IID);
nsICSSStyleSheet* nsLayoutModule::gUAStyleSheet;
nsIScriptNameSetRegistry* nsLayoutModule::gRegistry;
nsLayoutModule::nsLayoutModule()
: mInitialized(PR_FALSE)
{
NS_INIT_ISUPPORTS();
#ifdef DEBUG_kipp
printf("*** Creating layout module %p\n", this);
#endif
}
nsLayoutModule::~nsLayoutModule()
{
Shutdown();
#ifdef DEBUG_kipp
printf("*** Destroying layout module %p\n", this);
#endif
}
NS_IMPL_ISUPPORTS(nsLayoutModule, kIModuleIID)
// Perform our one-time intialization for this module
nsresult
nsLayoutModule::Initialize()
{
if (mInitialized) {
return NS_OK;
}
// Register all of our atoms once
nsCSSAtoms::AddRefAtoms();
nsCSSKeywords::AddRefTable();
nsCSSProps::AddRefTable();
nsColorNames::AddRefTable();
nsHTMLAtoms::AddRefAtoms();
#ifdef INCLUDE_XUL
nsXULAtoms::AddRefAtoms();
#endif
// Load the UA style sheet
nsCOMPtr<nsIURI> uaURL;
nsresult rv = NS_NewURI(getter_AddRefs(uaURL), UA_CSS_URL);
if (NS_SUCCEEDED(rv)) {
nsCOMPtr<nsICSSLoader> cssLoader;
rv = NS_NewCSSLoader(getter_AddRefs(cssLoader));
if (cssLoader) {
PRBool complete;
rv = cssLoader->LoadAgentSheet(uaURL, gUAStyleSheet, complete,
nsnull, nsnull);
}
}
if (NS_FAILED(rv)) {
#ifdef DEBUG
printf("*** open of %s failed: error=%x\n", UA_CSS_URL, rv);
#endif
return rv;
}
// XXX Initialize the script name set thingy-ma-jigger
if (!gRegistry) {
rv = nsServiceManager::GetService(kCScriptNameSetRegistryCID,
kIScriptNameSetRegistryIID,
(nsISupports**) &gRegistry);
if (NS_SUCCEEDED(rv)) {
LayoutScriptNameSet* nameSet = new LayoutScriptNameSet();
gRegistry->AddExternalNameSet(nameSet);
}
}
return rv;
}
// Shutdown this module, releasing all of the module resources
void
nsLayoutModule::Shutdown()
{
// Release all of our atoms
nsColorNames::ReleaseTable();
nsCSSProps::ReleaseTable();
nsCSSKeywords::ReleaseTable();
nsCSSAtoms::ReleaseAtoms();
nsHTMLAtoms::ReleaseAtoms();
#ifdef INCLUDE_XUL
nsXULAtoms::ReleaseAtoms();
#endif
NS_IF_RELEASE(gRegistry);
NS_IF_RELEASE(gUAStyleSheet);
}
NS_IMETHODIMP
nsLayoutModule::GetClassObject(nsIComponentManager *aCompMgr,
const nsCID& aClass,
const nsIID& aIID,
void** r_classObj)
{
nsresult rv;
if (!mInitialized) {
rv = Initialize();
if (NS_FAILED(rv)) {
return rv;
}
mInitialized = PR_TRUE;
}
nsIFactory* f = new nsLayoutFactory(aClass);
if (!f) {
return NS_ERROR_OUT_OF_MEMORY;
}
rv = f->QueryInterface(aIID, r_classObj);
if (NS_FAILED(rv)) {
delete f;
}
return rv;
}
//----------------------------------------
struct Components {
const char* mDescription;
nsID mCID;
const char* mProgID;
};
// The list of components we register
static Components gComponents[] = {
{ "Namespace manager", NS_NAMESPACEMANAGER_CID, nsnull, },
{ "Event listener manager", NS_EVENTLISTENERMANAGER_CID, nsnull, },
{ "Frame utility", NS_FRAME_UTIL_CID, nsnull, },
{ "Print preview context", NS_PRINT_PREVIEW_CONTEXT_CID, nsnull, },
{ "Layout debugger", NS_LAYOUT_DEBUGGER_CID, nsnull, },
{ "HTML document", NS_HTMLDOCUMENT_CID, nsnull, },
{ "HTML style sheet", NS_HTMLSTYLESHEET_CID, nsnull, },
{ "HTML-CSS style sheet", NS_HTML_CSS_STYLESHEET_CID, nsnull, },
{ "XML document", NS_XMLDOCUMENT_CID, nsnull, },
{ "Image document", NS_IMAGEDOCUMENT_CID, nsnull, },
{ "CSS parser", NS_CSSPARSER_CID, nsnull, },
{ "CSS loader", NS_CSS_LOADER_CID, nsnull, },
{ "HTML element factory", NS_HTML_ELEMENT_FACTORY_CID, nsnull, },
{ "Text element", NS_TEXTNODE_CID, nsnull, },
{ "Selection", NS_SELECTION_CID, nsnull, },
{ "Frame selection", NS_FRAMESELECTION_CID, nsnull, },
{ "Range", NS_RANGE_CID, nsnull, },
{ "Content iterator", NS_CONTENTITERATOR_CID, nsnull, },
{ "Subtree iterator", NS_SUBTREEITERATOR_CID, nsnull, },
// XXX ick
{ "HTML image element", NS_HTMLIMAGEELEMENT_CID, nsnull, },
{ "HTML option element", NS_HTMLOPTIONELEMENT_CID, nsnull, },
{ "Presentation shell", NS_PRESSHELL_CID, nsnull, },
// XXX end ick
{ "HTML document encoder", NS_TEXT_ENCODER_CID,
NS_DOC_ENCODER_PROGID_BASE "text/html", },
{ "Plaintext document encoder", NS_TEXT_ENCODER_CID,
NS_DOC_ENCODER_PROGID_BASE "text/plain", },
{ "XIF document encoder", NS_TEXT_ENCODER_CID,
NS_DOC_ENCODER_PROGID_BASE "text/xif", },
};
#define NUM_COMPONENTS (sizeof(gComponents) / sizeof(gComponents[0]))
NS_IMETHODIMP
nsLayoutModule::RegisterSelf(nsIComponentManager *aCompMgr,
nsIFileSpec* aPath,
const char* registryLocation,
const char* componentType)
{
nsresult rv = NS_OK;
#ifdef DEBUG
printf("*** Registering layout components\n");
#endif
Components* cp = gComponents;
Components* end = cp + NUM_COMPONENTS;
while (cp < end) {
rv = aCompMgr->RegisterComponentSpec(cp->mCID, cp->mDescription,
cp->mProgID, aPath, PR_TRUE, PR_TRUE);
if (NS_FAILED(rv)) {
#ifdef DEBUG
printf("nsLayoutModule: unable to register %s component => %x\n",
cp->mDescription, rv);
#endif
break;
}
cp++;
}
rv = RegisterDocumentFactories(aCompMgr, aPath);
return rv;
}
NS_IMETHODIMP
nsLayoutModule::UnregisterSelf(nsIComponentManager* aCompMgr,
nsIFileSpec* aPath,
const char* registryLocation)
{
#ifdef DEBUG
printf("*** Unregistering layout components\n");
#endif
Components* cp = gComponents;
Components* end = cp + NUM_COMPONENTS;
while (cp < end) {
nsresult rv = aCompMgr->UnregisterComponentSpec(cp->mCID, aPath);
if (NS_FAILED(rv)) {
#ifdef DEBUG
printf("nsLayoutModule: unable to unregister %s component => %x\n",
cp->mDescription, rv);
#endif
}
cp++;
}
UnregisterDocumentFactories(aCompMgr, aPath);
return NS_OK;
}
NS_IMETHODIMP
nsLayoutModule::CanUnload(nsIComponentManager *aCompMgr, PRBool *okToUnload)
{
if (!okToUnload) {
return NS_ERROR_INVALID_POINTER;
}
*okToUnload = PR_FALSE;
return NS_ERROR_FAILURE;
}

Просмотреть файл

@ -0,0 +1,77 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (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/NPL/
*
* 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 Communicator client code.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*/
#ifndef nsLayoutModule_h___
#define nsLayoutModule_h___
#include "nslayout.h"
#include "nsIModule.h"
class nsICSSStyleSheet;
class nsIScriptNameSetRegistry;
// Module implementation for the layout library
class nsLayoutModule : public nsIModule
{
public:
nsLayoutModule();
virtual ~nsLayoutModule();
NS_DECL_ISUPPORTS
NS_DECL_NSIMODULE
nsresult Initialize();
static nsICSSStyleSheet* GetUAStyleSheet() {
return gUAStyleSheet;
}
protected:
void Shutdown();
nsresult RegisterDocumentFactories(nsIComponentManager* aCompMgr,
nsIFileSpec* aPath);
void UnregisterDocumentFactories(nsIComponentManager* aCompMgr,
nsIFileSpec* aPath);
PRBool mInitialized;
// static nsIFactory* gFactory;
static nsICSSStyleSheet* gUAStyleSheet;
static nsIScriptNameSetRegistry* gRegistry;
};
//----------------------------------------------------------------------
class nsLayoutFactory : public nsIFactory
{
public:
nsLayoutFactory(const nsCID &aClass);
NS_DECL_ISUPPORTS
NS_DECL_NSIFACTORY
protected:
virtual ~nsLayoutFactory();
nsCID mClassID;
};
#endif /* nsLayoutModule_h___ */

Просмотреть файл

@ -0,0 +1,207 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http:/www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "nsJPGModule.h"
#include "nsJPGDecoder.h"
#include "nsIComponentManager.h"
#include "nsIGenericFactory.h"
#include "nsISupports.h"
#include "nsCOMPtr.h"
static NS_DEFINE_CID(kJPGDecoderCID, NS_JPGDECODER_CID);
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
//////////////////////////////////////////////////////////////////////
// Module Global
//
// This is used by the module to count object. Constructors and
// destructors of objects created by this module need to
// inc/dec the object count for the module. Unload decision will
// be taken based on this.
//
// Constructor:
// gModule->IncrementObjCount();
//
// Descructor:
// gModule->DecrementObjCount();
//
// WARNING: This is weak reference. XPCOM guarantees that this module
// object will be deleted just before the dll is unloaded. Hence,
// holding a weak reference is ok.
static nsJPGModule *gModule = NULL;
//////////////////////////////////////////////////////////////////////
// Module entry point
extern "C" NS_EXPORT nsresult NSGetModule(nsIComponentManager *servMgr,
nsIFileSpec* location,
nsIModule** return_cobj)
{
nsJPGModule *module;
nsresult rv = NS_OK;
NS_ASSERTION(return_cobj, "Null argument");
NS_ASSERTION(gModule == NULL, "nsJPGModule: Module already created.");
module = new nsJPGModule;
if (module == NULL) return NS_ERROR_OUT_OF_MEMORY;
rv = module->QueryInterface(nsIModule::GetIID(), (void **)return_cobj);
if (NS_FAILED(rv))
{
delete module;
module = NULL;
}
// WARNING: Weak Reference
gModule = module;
return rv;
}
//////////////////////////////////////////////////////////////////////
// JPG Decoder Factory using nsIGenericFactory
static NS_IMETHODIMP
nsJPGDecoderCreateInstance(nsISupports *aOuter, REFNSIID aIID, void **aResult)
{
JPGDecoder *dec = NULL;
*aResult = NULL;
il_container* ic = NULL;
if (aOuter && !aIID.Equals(kISupportsIID))
return NS_NOINTERFACE;
ic = new il_container();
if (!ic)
{
return NS_ERROR_OUT_OF_MEMORY;
}
dec = new JPGDecoder(ic);
if (!dec)
{
delete ic;
return NS_ERROR_OUT_OF_MEMORY;
}
nsresult res = dec->QueryInterface(aIID, aResult);
if (NS_FAILED(res))
{
*aResult = NULL;
delete dec;
}
delete ic; /* is a place holder */
return res;
}
//////////////////////////////////////////////////////////////////////
// JPG Decoder Module Implementation
NS_IMPL_ISUPPORTS(nsJPGModule, nsIModule::GetIID())
nsJPGModule::nsJPGModule(void)
: mObjCount(-1), mClassObject(NULL)
{
NS_INIT_ISUPPORTS();
}
nsJPGModule::~nsJPGModule(void)
{
NS_ASSERTION(mObjCount <= 0, "Module released while having outstanding objects.");
if (mClassObject)
{
int refcnt;
NS_RELEASE2(mClassObject, refcnt);
NS_ASSERTION(refcnt == 0, "nsJPGModule::~nsJPGModule() ClassObject refcount nonzero");
}
}
//
// The class object for us is just the factory and nothing more.
//
NS_IMETHODIMP
nsJPGModule::GetClassObject(nsIComponentManager *aCompMgr, const nsCID & aClass,
const nsIID &aIID, void **r_classObj)
{
nsresult rv;
if( !aClass.Equals(kJPGDecoderCID))
return NS_ERROR_FACTORY_NOT_REGISTERED;
// If this aint the first time, return the cached class object
if (mClassObject == NULL)
{
nsCOMPtr<nsIGenericFactory> fact;
rv = NS_NewGenericFactory(getter_AddRefs(fact), nsJPGDecoderCreateInstance);
if (NS_FAILED(rv)) return rv;
// Store the class object in our global
rv = fact->QueryInterface(NS_GET_IID(nsISupports), (void **)&mClassObject);
if (NS_FAILED(rv)) return rv;
}
rv = mClassObject->QueryInterface(aIID, r_classObj);
return rv;
}
NS_IMETHODIMP
nsJPGModule::RegisterSelf(nsIComponentManager *aCompMgr,
nsIFileSpec *location,
const char *registryLocation,
const char *componentType)
{
nsresult rv;
rv = aCompMgr->RegisterComponentSpec(kJPGDecoderCID,
"Netscape JPGDec",
"component://netscape/image/decoder&type=image/jpeg",
location, PR_TRUE, PR_TRUE);
return rv;
}
NS_IMETHODIMP
nsJPGModule::UnregisterSelf(nsIComponentManager *aCompMgr,
nsIFileSpec *location,
const char *registryLocation)
{
nsresult rv;
rv = aCompMgr->UnregisterComponentSpec(kJPGDecoderCID, location);
return rv;
}
NS_IMETHODIMP
nsJPGModule::CanUnload(nsIComponentManager *aCompMgr, PRBool *okToUnload)
{
if (mObjCount < 0)
{
// Dll doesn't count objects.
return NS_ERROR_FAILURE;
}
PRBool unloadable = PR_FALSE;
if (mObjCount == 0)
{
// This dll can be unloaded now
unloadable = PR_TRUE;
}
if (okToUnload) *okToUnload = unloadable;
return NS_OK;
}

Просмотреть файл

@ -0,0 +1,45 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http:/www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef nsJPGModule_h___
#define nsJPGModule_h___
#include "nsIModule.h"
class nsJPGModule : public nsIModule
{
public:
NS_DECL_ISUPPORTS
// Construction, Init and desstruction
nsJPGModule();
virtual ~nsJPGModule();
// nsIModule Interfaces
NS_DECL_NSIMODULE
// Facility for counting object instances
int IncrementObjCount() { if (mObjCount == -1) mObjCount = 0; return ++mObjCount; }
int DecrementObjCount() { if (mObjCount == -1) mObjCount = 0; return --mObjCount; }
int GetObjCount() { return mObjCount; }
private:
int mObjCount;
nsISupports* mClassObject;
};
#endif /* nsJPGModule_h___ */

Просмотреть файл

@ -0,0 +1,376 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (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/NPL/
*
* 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 Communicator client code.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*/
#include "nsCOMPtr.h"
#include "nsIGenericFactory.h"
#include "nsIModule.h"
#include "nsParserCIID.h"
#include "nsParser.h"
#include "nsILoggingSink.h"
#include "nsWellFormedDTD.h"
#include "CNavDTD.h"
#include "nsXIFDTD.h"
static NS_DEFINE_IID(kParserCID, NS_PARSER_IID);
static NS_DEFINE_IID(kParserNodeCID, NS_PARSER_NODE_IID);
static NS_DEFINE_IID(kLoggingSinkCID, NS_LOGGING_SINK_IID);
static NS_DEFINE_CID(kWellFormedDTDCID, NS_WELLFORMEDDTD_CID);
static NS_DEFINE_CID(kNavDTDCID, NS_CNAVDTD_CID);
static NS_DEFINE_CID(kXIFDTDCID, NS_XIF_DTD_CID);
struct Components {
const char* mDescription;
const nsID* mCID;
};
static Components gComponents[] = {
{ "Parser", &kParserCID },
{ "ParserNode", &kParserNodeCID },
{ "Logging sink", &kLoggingSinkCID },
{ "Well formed DTD", &kWellFormedDTDCID },
{ "Navigator HTML DTD", &kNavDTDCID },
{ "XIF DTD", &kXIFDTDCID },
};
#define NUM_COMPONENTS (sizeof(gComponents) / sizeof(gComponents[0]));
// Factory method to create new instances of nsParser
static nsresult
CreateNewParser(nsISupports* aOuter, REFNSIID aIID, void **aResult)
{
if (!aResult) {
return NS_ERROR_INVALID_POINTER;
}
if (aOuter) {
*aResult = nsnull;
return NS_NOINTERFACE;
}
nsParser* inst = new nsParser();
if (!inst) {
*aResult = nsnull;
return NS_ERROR_OUT_OF_MEMORY;
}
nsresult rv = inst->QueryInterface(aIID, aResult);
if (NS_FAILED(rv)) {
*aResult = nsnull;
delete inst;
}
return rv;
}
// Factory method to create new instances of nsParserNode
static nsresult
CreateNewParserNode(nsISupports* aOuter, REFNSIID aIID, void **aResult)
{
if (!aResult) {
return NS_ERROR_INVALID_POINTER;
}
if (aOuter) {
*aResult = nsnull;
return NS_NOINTERFACE;
}
nsCParserNode* inst = new nsCParserNode();
if (!inst) {
*aResult = nsnull;
return NS_ERROR_OUT_OF_MEMORY;
}
nsresult rv = inst->QueryInterface(aIID, aResult);
if (NS_FAILED(rv)) {
*aResult = nsnull;
delete inst;
}
return rv;
}
// Factory method to create new instances of nsILoggingSink
static nsresult
CreateNewLoggingSink(nsISupports* aOuter, REFNSIID aIID, void **aResult)
{
if (!aResult) {
return NS_ERROR_INVALID_POINTER;
}
if (aOuter) {
*aResult = nsnull;
return NS_NOINTERFACE;
}
nsIContentSink* inst;
nsresult rv = NS_NewHTMLLoggingSink(&inst);
if (NS_FAILED(rv)) {
*aResult = nsnull;
return NS_ERROR_OUT_OF_MEMORY;
}
rv = inst->QueryInterface(aIID, aResult);
if (NS_FAILED(rv)) {
*aResult = nsnull;
}
NS_RELEASE(inst); // get rid of extra refcnt
return rv;
}
// Factory method to create new instances of nsWellFormedDTD
static nsresult
CreateNewWellFormedDTD(nsISupports* aOuter, REFNSIID aIID, void **aResult)
{
if (!aResult) {
return NS_ERROR_INVALID_POINTER;
}
if (aOuter) {
*aResult = nsnull;
return NS_NOINTERFACE;
}
nsIDTD* inst;
nsresult rv = NS_NewWellFormed_DTD(&inst);
if (NS_FAILED(rv)) {
*aResult = nsnull;
return NS_ERROR_OUT_OF_MEMORY;
}
rv = inst->QueryInterface(aIID, aResult);
if (NS_FAILED(rv)) {
*aResult = nsnull;
}
NS_RELEASE(inst); // get rid of extra refcnt
return rv;
}
// Factory method to create new instances of nsNavHTMLDTD
static nsresult
CreateNewNavHTMLDTD(nsISupports* aOuter, REFNSIID aIID, void **aResult)
{
if (!aResult) {
return NS_ERROR_INVALID_POINTER;
}
if (aOuter) {
*aResult = nsnull;
return NS_NOINTERFACE;
}
nsIDTD* inst;
nsresult rv = NS_NewNavHTMLDTD(&inst);
if (NS_FAILED(rv)) {
*aResult = nsnull;
return NS_ERROR_OUT_OF_MEMORY;
}
rv = inst->QueryInterface(aIID, aResult);
if (NS_FAILED(rv)) {
*aResult = nsnull;
}
NS_RELEASE(inst); // get rid of extra refcnt
return rv;
}
// Factory method to create new instances of nsXIFDTD
static nsresult
CreateNewXIFDTD(nsISupports* aOuter, REFNSIID aIID, void **aResult)
{
if (!aResult) {
return NS_ERROR_INVALID_POINTER;
}
if (aOuter) {
*aResult = nsnull;
return NS_NOINTERFACE;
}
nsIDTD* inst;
nsresult rv = NS_NewXIFDTD(&inst);
if (!inst) {
*aResult = nsnull;
return NS_ERROR_OUT_OF_MEMORY;
}
rv = inst->QueryInterface(aIID, aResult);
if (NS_FAILED(rv)) {
*aResult = nsnull;
}
NS_RELEASE(inst); // get rid of extra refcnt
return rv;
}
//----------------------------------------------------------------------
class nsParserModule : public nsIModule {
public:
nsParserModule();
virtual ~nsParserModule();
NS_DECL_ISUPPORTS
NS_DECL_NSIMODULE
nsresult Initialize();
protected:
void Shutdown();
PRBool mInitialized;
};
static NS_DEFINE_IID(kIModuleIID, NS_IMODULE_IID);
nsParserModule::nsParserModule()
: mInitialized(PR_FALSE)
{
NS_INIT_ISUPPORTS();
}
nsParserModule::~nsParserModule()
{
Shutdown();
}
NS_IMPL_ISUPPORTS(nsParserModule, kIModuleIID)
nsresult
nsParserModule::Initialize()
{
return NS_OK;
}
void
nsParserModule::Shutdown()
{
}
NS_IMETHODIMP
nsParserModule::GetClassObject(nsIComponentManager *aCompMgr,
const nsCID& aClass,
const nsIID& aIID,
void** r_classObj)
{
nsresult rv;
if (!mInitialized) {
rv = Initialize();
if (NS_FAILED(rv)) {
return rv;
}
mInitialized = PR_TRUE;
}
nsCOMPtr<nsIGenericFactory> fact;
if (aClass.Equals(kParserCID)) {
rv = NS_NewGenericFactory(getter_AddRefs(fact), CreateNewParser);
}
else if (aClass.Equals(kParserNodeCID)) {
rv = NS_NewGenericFactory(getter_AddRefs(fact), CreateNewParserNode);
}
else if (aClass.Equals(kLoggingSinkCID)) {
rv = NS_NewGenericFactory(getter_AddRefs(fact), CreateNewLoggingSink);
}
else if (aClass.Equals(kWellFormedDTDCID)) {
rv = NS_NewGenericFactory(getter_AddRefs(fact), CreateNewWellFormedDTD);
}
else if (aClass.Equals(kNavDTDCID)) {
rv = NS_NewGenericFactory(getter_AddRefs(fact), CreateNewNavHTMLDTD);
}
else if (aClass.Equals(kXIFDTDCID)) {
rv = NS_NewGenericFactory(getter_AddRefs(fact), CreateNewXIFDTD);
}
else {
rv = NS_ERROR_FACTORY_NOT_REGISTERED;
}
if (fact) {
rv = fact->QueryInterface(aIID, r_classObj);
}
return rv;
}
NS_IMETHODIMP
nsParserModule::RegisterSelf(nsIComponentManager *aCompMgr,
nsIFileSpec* aPath,
const char* registryLocation,
const char* componentType)
{
nsresult rv = NS_OK;
Components* cp = gComponents;
Components* end = cp + NUM_COMPONENTS;
while (cp < end) {
rv = aCompMgr->RegisterComponentSpec(*cp->mCID, cp->mDescription,
nsnull, aPath, PR_TRUE, PR_TRUE);
if (NS_FAILED(rv)) {
#ifdef DEBUG
printf("nsParserModule: unable to register %s component => %x\n",
cp->mDescription, rv);
#endif
break;
}
cp++;
}
return rv;
}
NS_IMETHODIMP
nsParserModule::UnregisterSelf(nsIComponentManager *aCompMgr,
nsIFileSpec* aPath,
const char* registryLocation)
{
Components* cp = gComponents;
Components* end = cp + NUM_COMPONENTS;
while (cp < end) {
nsresult rv = aCompMgr->UnregisterComponentSpec(*cp->mCID, aPath);
if (NS_FAILED(rv)) {
#ifdef DEBUG
printf("nsParserModule: unable to unregister %s component => %x\n",
cp->mDescription, rv);
#endif
}
cp++;
}
return NS_OK;
}
NS_IMETHODIMP
nsParserModule::CanUnload(nsIComponentManager *aCompMgr, PRBool *okToUnload)
{
if (!okToUnload) {
return NS_ERROR_INVALID_POINTER;
}
*okToUnload = PR_FALSE;
return NS_ERROR_FAILURE;
}
//----------------------------------------------------------------------
#if 0
static nsParserModule *gModule = NULL;
extern "C" NS_EXPORT nsresult NSGetModule(nsIComponentManager *servMgr,
nsIFileSpec* location,
nsIModule** return_cobj)
{
nsresult rv = NS_OK;
NS_ASSERTION(return_cobj, "Null argument");
NS_ASSERTION(gModule == NULL, "nsParserModule: Module already created.");
// Create an initialize the layout module instance
nsParserModule *m = new nsParserModule();
if (!m) {
return NS_ERROR_OUT_OF_MEMORY;
}
// Increase refcnt and store away nsIModule interface to m in return_cobj
rv = m->QueryInterface(nsIModule::GetIID(), (void**)return_cobj);
if (NS_FAILED(rv)) {
delete m;
m = nsnull;
}
gModule = m; // WARNING: Weak Reference
return rv;
}
#endif

423
rdf/build/nsRDFModule.cpp Normal file
Просмотреть файл

@ -0,0 +1,423 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "nsCOMPtr.h"
#include "nsRDFModule.h"
#include "nsIFactory.h"
#include "nsIGenericFactory.h"
#include "nsILocalStore.h"
#include "nsIRDFContainer.h"
#include "nsIRDFContainerUtils.h"
#include "nsIRDFCompositeDataSource.h"
#include "nsIRDFContentModelBuilder.h"
#include "nsIRDFContentSink.h"
#include "nsIRDFDocument.h"
#include "nsIRDFService.h"
#include "nsIXULContentSink.h"
#include "nsISupports.h"
#include "nsRDFBaseDataSources.h"
#include "nsRDFBuiltInDataSources.h"
#include "nsIRDFFileSystem.h"
#include "nsRDFCID.h"
#include "nsIComponentManager.h"
#include "rdf.h"
#include "nsIXULContentUtils.h"
#include "nsIXULSortService.h"
#include "nsIXULDocumentInfo.h"
#include "nsIXULPopupListener.h"
#include "nsIXULKeyListener.h"
#include "nsIXULCommandDispatcher.h"
#include "nsIServiceManager.h"
static NS_DEFINE_CID(kComponentManagerCID, NS_COMPONENTMANAGER_CID);
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID);
static NS_DEFINE_CID(kGenericFactoryCID, NS_GENERICFACTORY_CID);
static NS_DEFINE_CID(kLocalStoreCID, NS_LOCALSTORE_CID);
static NS_DEFINE_CID(kRDFCompositeDataSourceCID, NS_RDFCOMPOSITEDATASOURCE_CID);
static NS_DEFINE_CID(kRDFContainerCID, NS_RDFCONTAINER_CID);
static NS_DEFINE_CID(kRDFContainerUtilsCID, NS_RDFCONTAINERUTILS_CID);
static NS_DEFINE_CID(kRDFContentSinkCID, NS_RDFCONTENTSINK_CID);
static NS_DEFINE_CID(kRDFDefaultResourceCID, NS_RDFDEFAULTRESOURCE_CID);
static NS_DEFINE_CID(kRDFFileSystemDataSourceCID, NS_RDFFILESYSTEMDATASOURCE_CID);
static NS_DEFINE_CID(kRDFSearchDataSourceCID, NS_RDFSEARCHDATASOURCE_CID);
static NS_DEFINE_CID(kRDFFindDataSourceCID, NS_RDFFINDDATASOURCE_CID);
static NS_DEFINE_CID(kRDFFTPDataSourceCID, NS_RDFFTPDATASOURCE_CID);
static NS_DEFINE_CID(kRDFInMemoryDataSourceCID, NS_RDFINMEMORYDATASOURCE_CID);
static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
static NS_DEFINE_CID(kRDFXMLDataSourceCID, NS_RDFXMLDATASOURCE_CID);
static NS_DEFINE_CID(kRDFXULBuilderCID, NS_RDFXULBUILDER_CID);
static NS_DEFINE_CID(kXULContentSinkCID, NS_XULCONTENTSINK_CID);
static NS_DEFINE_CID(kXULContentUtilsCID, NS_XULCONTENTUTILS_CID);
static NS_DEFINE_CID(kXULDocumentCID, NS_XULDOCUMENT_CID);
static NS_DEFINE_CID(kXULSortServiceCID, NS_XULSORTSERVICE_CID);
static NS_DEFINE_CID(kXULDocumentInfoCID, NS_XULDOCUMENTINFO_CID);
static NS_DEFINE_CID(kXULPopupListenerCID, NS_XULPOPUPLISTENER_CID);
static NS_DEFINE_CID(kXULKeyListenerCID, NS_XULKEYLISTENER_CID);
static NS_DEFINE_CID(kXULCommandDispatcherCID, NS_XULCOMMANDDISPATCHER_CID);
static NS_DEFINE_CID(kXULTemplateBuilderCID, NS_XULTEMPLATEBUILDER_CID);
//----------------------------------------------------------------------
// Functions used to create new instances of a given object by the
// generic factory.
#define MAKE_CTOR(_func,_new,_ifname) \
static nsresult \
CreateNew##_func(nsISupports* aOuter, REFNSIID aIID, void **aResult) \
{ \
if (!aResult) { \
return NS_ERROR_INVALID_POINTER; \
} \
if (aOuter) { \
*aResult = nsnull; \
return NS_ERROR_NO_AGGREGATION; \
} \
nsI##_ifname* inst; \
nsresult rv = NS_New##_new(&inst); \
if (NS_FAILED(rv)) { \
*aResult = nsnull; \
return NS_ERROR_OUT_OF_MEMORY; \
} \
rv = inst->QueryInterface(aIID, aResult); \
if (NS_FAILED(rv)) { \
*aResult = nsnull; \
} \
NS_RELEASE(inst); /* get rid of extra refcnt */ \
return rv; \
}
extern nsresult
NS_NewDefaultResource(nsIRDFResource** aResult);
MAKE_CTOR(RDFService,RDFService,RDFService)
MAKE_CTOR(XULSortService,XULSortService,XULSortService)
MAKE_CTOR(XULPopupListener,XULPopupListener,XULPopupListener)
MAKE_CTOR(XULKeyListener,XULKeyListener,XULKeyListener)
MAKE_CTOR(XULCommandDispatcher,XULCommandDispatcher,XULCommandDispatcher)
MAKE_CTOR(RDFXMLDataSource,RDFXMLDataSource,RDFDataSource)
MAKE_CTOR(RDFFileSystemDataSource,RDFFileSystemDataSource,RDFDataSource)
MAKE_CTOR(RDFFTPDataSource,RDFFTPDataSource,RDFDataSource)
MAKE_CTOR(RDFCompositeDataSource,RDFCompositeDataSource,RDFCompositeDataSource)
MAKE_CTOR(RDFContainer,RDFContainer,RDFContainer)
MAKE_CTOR(RDFContainerUtils,RDFContainerUtils,RDFContainerUtils)
MAKE_CTOR(XULDocument,XULDocument,RDFDocument)
MAKE_CTOR(XULDocumentInfo,XULDocumentInfo,XULDocumentInfo)
MAKE_CTOR(XULTemplateBuilder,XULTemplateBuilder,RDFContentModelBuilder)
MAKE_CTOR(RDFXULBuilder,RDFXULBuilder,RDFContentModelBuilder)
MAKE_CTOR(RDFContentSink,RDFContentSink,RDFContentSink)
MAKE_CTOR(XULContentSink,XULContentSink,XULContentSink)
MAKE_CTOR(RDFDefaultResource,DefaultResource,RDFResource)
MAKE_CTOR(LocalStore,LocalStore,LocalStore)
//----------------------------------------------------------------------
static NS_DEFINE_IID(kIModuleIID, NS_IMODULE_IID);
nsRDFModule::nsRDFModule()
: mInitialized(PR_FALSE)
{
NS_INIT_ISUPPORTS();
}
nsRDFModule::~nsRDFModule()
{
Shutdown();
}
NS_IMPL_ISUPPORTS(nsRDFModule, kIModuleIID)
// Perform our one-time intialization for this module
nsresult
nsRDFModule::Initialize()
{
if (mInitialized) {
return NS_OK;
}
return NS_OK;
}
// Shutdown this module, releasing all of the module resources
void
nsRDFModule::Shutdown()
{
}
NS_IMETHODIMP
nsRDFModule::GetClassObject(nsIComponentManager *aCompMgr,
const nsCID& aClass,
const nsIID& aIID,
void** r_classObj)
{
nsresult rv;
// Defensive programming: Initialize *r_classObj in case of error below
if (!r_classObj) {
return NS_ERROR_INVALID_POINTER;
}
*r_classObj = NULL;
if (!mInitialized) {
rv = Initialize();
if (NS_FAILED(rv)) {
return rv;
}
mInitialized = PR_TRUE;
}
nsCOMPtr<nsIGenericFactory> fact;
// Note: these are in the same order as the registration table
// below, not in frequency of use order.
if (aClass.Equals(kRDFCompositeDataSourceCID)) {
rv = NS_NewGenericFactory(getter_AddRefs(fact), CreateNewRDFCompositeDataSource);
}
else if (aClass.Equals(kRDFFileSystemDataSourceCID)) {
rv = NS_NewGenericFactory(getter_AddRefs(fact), CreateNewRDFFileSystemDataSource);
}
else if (aClass.Equals(kRDFFTPDataSourceCID)) {
rv = NS_NewGenericFactory(getter_AddRefs(fact), CreateNewRDFFTPDataSource);
}
else if (aClass.Equals(kRDFInMemoryDataSourceCID)) {
rv = NS_NewGenericFactory(getter_AddRefs(fact), NS_NewRDFInMemoryDataSource);
}
else if (aClass.Equals(kLocalStoreCID)) {
rv = NS_NewGenericFactory(getter_AddRefs(fact), CreateNewLocalStore);
}
else if (aClass.Equals(kRDFXMLDataSourceCID)) {
rv = NS_NewGenericFactory(getter_AddRefs(fact), CreateNewRDFXMLDataSource);
}
else if (aClass.Equals(kRDFDefaultResourceCID)) {
rv = NS_NewGenericFactory(getter_AddRefs(fact), CreateNewRDFDefaultResource);
}
else if (aClass.Equals(kRDFContentSinkCID)) {
rv = NS_NewGenericFactory(getter_AddRefs(fact), CreateNewRDFContentSink);
}
else if (aClass.Equals(kRDFContainerCID)) {
rv = NS_NewGenericFactory(getter_AddRefs(fact), CreateNewRDFContainer);
}
else if (aClass.Equals(kRDFContainerUtilsCID)) {
rv = NS_NewGenericFactory(getter_AddRefs(fact), CreateNewRDFContainerUtils);
}
else if (aClass.Equals(kRDFServiceCID)) {
rv = NS_NewGenericFactory(getter_AddRefs(fact), CreateNewRDFService);
}
else if (aClass.Equals(kXULSortServiceCID)) {
rv = NS_NewGenericFactory(getter_AddRefs(fact), CreateNewXULSortService);
}
else if (aClass.Equals(kXULTemplateBuilderCID)) {
rv = NS_NewGenericFactory(getter_AddRefs(fact), CreateNewXULTemplateBuilder);
}
else if (aClass.Equals(kRDFXULBuilderCID)) {
rv = NS_NewGenericFactory(getter_AddRefs(fact), CreateNewRDFXULBuilder);
}
else if (aClass.Equals(kXULContentSinkCID)) {
rv = NS_NewGenericFactory(getter_AddRefs(fact), CreateNewXULContentSink);
}
else if (aClass.Equals(kXULDocumentCID)) {
rv = NS_NewGenericFactory(getter_AddRefs(fact), CreateNewXULDocument);
}
else if (aClass.Equals(kXULDocumentInfoCID)) {
rv = NS_NewGenericFactory(getter_AddRefs(fact), CreateNewXULDocumentInfo);
}
else if (aClass.Equals(kXULPopupListenerCID)) {
rv = NS_NewGenericFactory(getter_AddRefs(fact), CreateNewXULPopupListener);
}
else if (aClass.Equals(kXULKeyListenerCID)) {
rv = NS_NewGenericFactory(getter_AddRefs(fact), CreateNewXULKeyListener);
}
else if (aClass.Equals(kXULCommandDispatcherCID)) {
rv = NS_NewGenericFactory(getter_AddRefs(fact), CreateNewXULCommandDispatcher);
}
else if (aClass.Equals(kXULContentUtilsCID)) {
rv = NS_NewGenericFactory(getter_AddRefs(fact), NS_NewXULContentUtils);
}
else {
rv = NS_ERROR_FACTORY_NOT_REGISTERED;
#ifdef DEBUG
char* cs = aClass.ToString();
printf("+++ nsRDFModule: unable to create factory for %s\n", cs);
nsCRT::free(cs);
#endif
}
if (fact) {
rv = fact->QueryInterface(aIID, r_classObj);
}
return rv;
}
//----------------------------------------
struct Components {
const char* mDescription;
nsID mCID;
const char* mProgID;
};
// The list of components we register
static Components gComponents[] = {
// register our build-in datasources:
{ "RDF Composite Data Source", kRDFCompositeDataSourceCID,
NS_RDF_DATASOURCE_PROGID_PREFIX "composite-datasource", },
{ "RDF File System Data Source", kRDFFileSystemDataSourceCID,
NS_RDF_DATASOURCE_PROGID_PREFIX "files", },
{ "RDF FTP Data Source", kRDFFTPDataSourceCID,
NS_RDF_DATASOURCE_PROGID_PREFIX "ftp", },
{ "RDF In-Memory Data Source", kRDFInMemoryDataSourceCID,
NS_RDF_DATASOURCE_PROGID_PREFIX "in-memory-datasource", },
{ "Local Store", kLocalStoreCID,
NS_RDF_DATASOURCE_PROGID_PREFIX "local-store", },
{ "RDF XML Data Source", kRDFXMLDataSourceCID,
NS_RDF_DATASOURCE_PROGID_PREFIX "xml-datasource", },
// register our built-in resource factories:
{ "RDF Default Resource Factory", kRDFDefaultResourceCID,
// Note: default resource factory has no name= part
NS_RDF_RESOURCE_FACTORY_PROGID, },
// register all the other rdf components:
{ "RDF Content Sink", kRDFContentSinkCID,
NS_RDF_PROGID "/content-sink", },
{ "RDF Container", kRDFContainerCID,
NS_RDF_PROGID "/container", },
{ "RDF Container Utilities", kRDFContainerUtilsCID,
NS_RDF_PROGID "/container-utils", },
{ "RDF Service", kRDFServiceCID,
NS_RDF_PROGID "/rdf-service", },
{ "XUL Sort Service", kXULSortServiceCID,
NS_RDF_PROGID "/xul-sort-service", },
{ "XUL Template Builder", kXULTemplateBuilderCID,
NS_RDF_PROGID "/xul-template-builder", },
{ "RDF XUL Builder", kRDFXULBuilderCID,
NS_RDF_PROGID "/xul-builder", },
{ "XUL Content Sink", kXULContentSinkCID,
NS_RDF_PROGID "/xul-content-sink", },
{ "XUL Document", kXULDocumentCID,
NS_RDF_PROGID "/xul-document", },
{ "XUL Document Info", kXULDocumentInfoCID,
NS_RDF_PROGID "/xul-document-info", },
{ "XUL PopupListener", kXULPopupListenerCID,
NS_RDF_PROGID "/xul-popup-listener", },
{ "XUL KeyListener", kXULKeyListenerCID,
NS_RDF_PROGID "/xul-key-listener", },
{ "XUL CommandDispatcher", kXULCommandDispatcherCID,
NS_RDF_PROGID "/xul-command-dispatcher", },
{ "XUL Content Utilities", kXULContentUtilsCID,
NS_RDF_PROGID "/xul-content-utils", },
};
#define NUM_COMPONENTS (sizeof(gComponents) / sizeof(gComponents[0]))
NS_IMETHODIMP
nsRDFModule::RegisterSelf(nsIComponentManager *aCompMgr,
nsIFileSpec* aPath,
const char* registryLocation,
const char* componentType)
{
nsresult rv = NS_OK;
#ifdef DEBUG
printf("*** Registering rdf components\n");
#endif
Components* cp = gComponents;
Components* end = cp + NUM_COMPONENTS;
while (cp < end) {
rv = aCompMgr->RegisterComponentSpec(cp->mCID, cp->mDescription,
cp->mProgID, aPath, PR_TRUE,
PR_TRUE);
if (NS_FAILED(rv)) {
#ifdef DEBUG
printf("nsRDFModule: unable to register %s component => %x\n",
cp->mDescription, rv);
#endif
break;
}
cp++;
}
return rv;
}
NS_IMETHODIMP
nsRDFModule::UnregisterSelf(nsIComponentManager* aCompMgr,
nsIFileSpec* aPath,
const char* registryLocation)
{
#ifdef DEBUG
printf("*** Unregistering rdf components\n");
#endif
Components* cp = gComponents;
Components* end = cp + NUM_COMPONENTS;
while (cp < end) {
nsresult rv = aCompMgr->UnregisterComponentSpec(cp->mCID, aPath);
if (NS_FAILED(rv)) {
#ifdef DEBUG
printf("nsRDFModule: unable to unregister %s component => %x\n",
cp->mDescription, rv);
#endif
}
cp++;
}
return NS_OK;
}
NS_IMETHODIMP
nsRDFModule::CanUnload(nsIComponentManager *aCompMgr, PRBool *okToUnload)
{
if (!okToUnload) {
return NS_ERROR_INVALID_POINTER;
}
*okToUnload = PR_FALSE;
return NS_ERROR_FAILURE;
}
//----------------------------------------------------------------------
static nsRDFModule *gModule = NULL;
extern "C" NS_EXPORT nsresult NSGetModule(nsIComponentManager *servMgr,
nsIFileSpec* location,
nsIModule** return_cobj)
{
nsresult rv = NS_OK;
NS_ASSERTION(return_cobj, "Null argument");
NS_ASSERTION(gModule == NULL, "nsRDFModule: Module already created.");
// Create an initialize the layout module instance
nsRDFModule *m = new nsRDFModule();
if (!m) {
return NS_ERROR_OUT_OF_MEMORY;
}
// Increase refcnt and store away nsIModule interface to m in return_cobj
rv = m->QueryInterface(nsIModule::GetIID(), (void**)return_cobj);
if (NS_FAILED(rv)) {
delete m;
m = nsnull;
}
gModule = m; // WARNING: Weak Reference
return rv;
}

44
rdf/build/nsRDFModule.h Normal file
Просмотреть файл

@ -0,0 +1,44 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (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/NPL/
*
* 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 Communicator client code.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*/
#ifndef nsRDFModule_h___
#define nsRDFModule_h___
#include "rdf.h"
#include "nsIModule.h"
// Module implementation for the rdf library
class nsRDFModule : public nsIModule
{
public:
nsRDFModule();
virtual ~nsRDFModule();
NS_DECL_ISUPPORTS
NS_DECL_NSIMODULE
nsresult Initialize();
protected:
void Shutdown();
PRBool mInitialized;
};
#endif /* nsRDFModule_h___ */