From b77a0092b04f739cd1924ebbe94762ba60f7bd0c Mon Sep 17 00:00:00 2001 From: "pnunn%netscape.com" Date: Mon, 20 Mar 2000 23:29:21 +0000 Subject: [PATCH] No bug#. Changes so generic factory code is used. r: pavlov git-svn-id: svn://10.0.0.236/trunk@63490 18797224-902f-48f8-a5cc-f745e15eee43 --- .../modules/libimg/jpgcom/nsJPGDecoder.cpp | 40 +++- mozilla/modules/libimg/jpgcom/nsJPGDecoder.h | 2 + mozilla/modules/libimg/jpgcom/nsJPGModule.cpp | 186 +----------------- 3 files changed, 42 insertions(+), 186 deletions(-) diff --git a/mozilla/modules/libimg/jpgcom/nsJPGDecoder.cpp b/mozilla/modules/libimg/jpgcom/nsJPGDecoder.cpp index 129dc336b54..52d978acc76 100644 --- a/mozilla/modules/libimg/jpgcom/nsJPGDecoder.cpp +++ b/mozilla/modules/libimg/jpgcom/nsJPGDecoder.cpp @@ -21,7 +21,7 @@ */ /* -*- Mode: C; tab-width: 4 -*- - * nsJPGDecoder.cpp --- interface to gif decoder + * nsJPGDecoder.cpp --- interface to JPG decoder */ @@ -29,21 +29,47 @@ #include "nsJPGDecoder.h" #include "jpeg.h" -/*-----------class----------------*/ -/*-------------------------------------------------*/ + +////////////////////////////////////////////////////////////////////// +// JPG Decoder Implementation + +NS_IMPL_ISUPPORTS1(JPGDecoder, nsIImgDecoder); JPGDecoder::JPGDecoder(il_container* aContainer) { NS_INIT_REFCNT(); ilContainer = aContainer; -}; - +} JPGDecoder::~JPGDecoder(void) { -}; +} -NS_IMPL_ISUPPORTS(JPGDecoder, NS_GET_IID(nsIImgDecoder)) + +NS_METHOD +JPGDecoder::Create(nsISupports *aOuter, REFNSIID aIID, void **aResult) +{ + nsresult rv; + if (aOuter) return NS_ERROR_NO_AGGREGATION; + + il_container *ic = new il_container(); + if (!ic) return NS_ERROR_OUT_OF_MEMORY; + + JPGDecoder *decoder = new JPGDecoder(ic); + if (!decoder) { + delete ic; + return NS_ERROR_OUT_OF_MEMORY; + } + + NS_ADDREF(decoder); + rv = decoder->QueryInterface(aIID, aResult); + NS_RELEASE(decoder); + + /* why are we creating and destroying this object for no reason? */ + delete ic; /* is a place holder */ + + return rv; +} /*------------------------------------------------------*/ /* api functions diff --git a/mozilla/modules/libimg/jpgcom/nsJPGDecoder.h b/mozilla/modules/libimg/jpgcom/nsJPGDecoder.h index c3486ecb9ff..da8a0ced018 100644 --- a/mozilla/modules/libimg/jpgcom/nsJPGDecoder.h +++ b/mozilla/modules/libimg/jpgcom/nsJPGDecoder.h @@ -37,6 +37,8 @@ public: NS_DECL_ISUPPORTS + static NS_METHOD Create(nsISupports *aOuter, REFNSIID aIID, void **aResult); + /* stream */ NS_IMETHOD ImgDInit(); diff --git a/mozilla/modules/libimg/jpgcom/nsJPGModule.cpp b/mozilla/modules/libimg/jpgcom/nsJPGModule.cpp index a0015ba09d9..f25da7d2bbb 100644 --- a/mozilla/modules/libimg/jpgcom/nsJPGModule.cpp +++ b/mozilla/modules/libimg/jpgcom/nsJPGModule.cpp @@ -21,7 +21,6 @@ * Pierre Phaneuf */ -#include "nsJPGModule.h" #include "nsJPGDecoder.h" #include "nsIComponentManager.h" #include "nsIGenericFactory.h" @@ -29,184 +28,13 @@ #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, - nsIFile* aPath, - nsIModule** return_cobj) +static nsModuleComponentInfo components[] = { - nsJPGModule *module; - nsresult rv = NS_OK; + { "JPEG Decoder", + NS_JPGDECODER_CID, + "component://netscape/image/decoder&type=image/jpeg", + JPGDecoder::Create } +}; - 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(NS_GET_IID(nsIModule), (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, NS_GET_IID(nsIModule)) - -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 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, - nsIFile* aPath, - const char *registryLocation, - const char *componentType) -{ - nsresult rv; - rv = aCompMgr->RegisterComponentSpec(kJPGDecoderCID, - "Netscape JPGDec", - "component://netscape/image/decoder&type=image/jpeg", - aPath, PR_TRUE, PR_TRUE); - return rv; -} - -NS_IMETHODIMP -nsJPGModule::UnregisterSelf(nsIComponentManager *aCompMgr, - nsIFile* aPath, - const char *registryLocation) -{ - nsresult rv; - rv = aCompMgr->UnregisterComponentSpec(kJPGDecoderCID, aPath); - 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; -} +NS_IMPL_NSGETMODULE("nsJPGModule", components)