mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-04 02:57:38 +00:00
Adding nsGIFModule as a result of xpcom review of gif.
This commit is contained in:
parent
967a7ea8e9
commit
cbd3d7a376
@ -33,6 +33,7 @@ EXTRA_LIBS =
|
||||
|
||||
CPPSRCS = \
|
||||
gif.cpp \
|
||||
nsGIFModule.cpp \
|
||||
nsGIFDecoder.cpp \
|
||||
nsGIFCallback.cpp \
|
||||
dllcompat.cpp \
|
||||
|
@ -20,9 +20,7 @@
|
||||
* nsGIFDecoder.cpp --- interface to gif decoder
|
||||
*/
|
||||
|
||||
#include "nsIImgDecoder.h" // include if_struct.h Needs to be included first
|
||||
#include "nsGIFDecoder.h"
|
||||
#include "gif.h"
|
||||
|
||||
/*--- needed for autoregistry ---*/
|
||||
#include "nsIComponentManager.h"
|
||||
@ -39,32 +37,6 @@ static NS_DEFINE_CID(kComponentManagerCID, NS_COMPONENTMANAGER_CID);
|
||||
static NS_DEFINE_CID(kGIFDecoderCID, NS_GIFDECODER_CID);
|
||||
static NS_DEFINE_IID(kIImgDecoderIID, NS_IIMGDECODER_IID);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// GIF Decoder Definition
|
||||
|
||||
class GIFDecoder : public nsIImgDecoder
|
||||
{
|
||||
public:
|
||||
GIFDecoder(il_container* aContainer);
|
||||
virtual ~GIFDecoder();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
/* stream */
|
||||
NS_IMETHOD ImgDInit();
|
||||
|
||||
NS_IMETHOD ImgDWriteReady();
|
||||
NS_IMETHOD ImgDWrite(const unsigned char *buf, int32 len);
|
||||
NS_IMETHOD ImgDComplete();
|
||||
NS_IMETHOD ImgDAbort();
|
||||
|
||||
NS_IMETHOD_(il_container *) SetContainer(il_container *ic){ilContainer = ic; return ic;}
|
||||
NS_IMETHOD_(il_container *) GetContainer() {return ilContainer;}
|
||||
|
||||
|
||||
private:
|
||||
il_container* ilContainer;
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// GIF Decoder Implementation
|
||||
@ -129,110 +101,5 @@ GIFDecoder::ImgDAbort()
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// GIF Decoder Factory using nsIGenericFactory
|
||||
|
||||
static NS_IMETHODIMP
|
||||
nsGIFDecoderCreateInstance(nsISupports *aOuter, REFNSIID aIID, void **aResult)
|
||||
{
|
||||
GIFDecoder *gifdec = NULL;
|
||||
*aResult = NULL;
|
||||
il_container* ic = NULL;
|
||||
|
||||
NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
|
||||
if (aOuter && !aIID.Equals(kISupportsIID))
|
||||
return NS_NOINTERFACE;
|
||||
|
||||
ic = new il_container();
|
||||
if (!ic)
|
||||
{
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
gifdec = new GIFDecoder(ic);
|
||||
if (!gifdec)
|
||||
{
|
||||
delete ic;
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
nsresult res = gifdec->QueryInterface(aIID, aResult);
|
||||
if (NS_FAILED(res))
|
||||
{
|
||||
*aResult = NULL;
|
||||
delete gifdec;
|
||||
}
|
||||
delete ic; /* is a place holder */
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Module Object Creation Entry points
|
||||
|
||||
extern "C" NS_EXPORT nsresult
|
||||
NSGetFactory(nsISupports* serviceMgr,
|
||||
const nsCID &aClass,
|
||||
const char *aClassName,
|
||||
const char *aProgID,
|
||||
nsIFactory **aFactory)
|
||||
{
|
||||
if( !aClass.Equals(kGIFDecoderCID))
|
||||
return NS_ERROR_FACTORY_NOT_REGISTERED;
|
||||
|
||||
nsCOMPtr<nsIGenericFactory> fact;
|
||||
nsresult rv = NS_NewGenericFactory(getter_AddRefs(fact), nsGIFDecoderCreateInstance);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = fact->QueryInterface(kIFactoryIID, (void **)aFactory);
|
||||
return rv;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Module Registration Entrypoints
|
||||
|
||||
extern "C" NS_EXPORT nsresult
|
||||
NSRegisterSelf(nsISupports* aServMgr, const char *path)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
nsCOMPtr<nsIServiceManager> servMgr(do_QueryInterface(aServMgr, &rv));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsIComponentManager* compMgr;
|
||||
rv = servMgr->GetService(kComponentManagerCID,
|
||||
nsIComponentManager::GetIID(),
|
||||
(nsISupports**)&compMgr);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
if ((rv = compMgr->RegisterComponent(kGIFDecoderCID,
|
||||
"Netscape GIFDec",
|
||||
"component://netscape/image/decoder&type=image/gif", path, PR_TRUE, PR_TRUE)
|
||||
) != NS_OK) {
|
||||
return rv;
|
||||
}
|
||||
(void)servMgr->ReleaseService(kComponentManagerCID, compMgr);
|
||||
return rv;
|
||||
|
||||
}
|
||||
|
||||
extern "C" NS_EXPORT nsresult NSUnregisterSelf(nsISupports* aServMgr, const char *path)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
nsCOMPtr<nsIServiceManager> servMgr(do_QueryInterface(aServMgr, &rv));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsIComponentManager* compMgr;
|
||||
rv = servMgr->GetService(kComponentManagerCID,
|
||||
nsIComponentManager::GetIID(),
|
||||
(nsISupports**)&compMgr);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = compMgr->UnregisterComponent(kGIFDecoderCID, path);
|
||||
|
||||
(void)servMgr->ReleaseService(kComponentManagerCID, compMgr);
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
|
@ -22,6 +22,10 @@
|
||||
#ifndef _nsGIFDec_h
|
||||
#define _nsGIFDec_h
|
||||
|
||||
#include "nsISupports.h"
|
||||
#include "nsIImgDecoder.h"
|
||||
#include "gif.h"
|
||||
|
||||
#define NS_GIFDECODER_CID \
|
||||
{ 0x0d471b70, 0xbaf5, 0x11d2, \
|
||||
{ 0x80, 0x2c, 0x00, 0x60, 0x08, 0x8f, 0x91, 0xa3 } }
|
||||
@ -31,4 +35,31 @@
|
||||
{ 0x402b190, 0xbbd0, 0x11d2, \
|
||||
{ 0x80, 0x2c, 0x00, 0x60, 0x08, 0x8f, 0x91, 0xa3 } }
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// GIF Decoder Definition
|
||||
|
||||
class GIFDecoder : public nsIImgDecoder
|
||||
{
|
||||
public:
|
||||
GIFDecoder(il_container* aContainer);
|
||||
virtual ~GIFDecoder();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
/* stream */
|
||||
NS_IMETHOD ImgDInit();
|
||||
|
||||
NS_IMETHOD ImgDWriteReady();
|
||||
NS_IMETHOD ImgDWrite(const unsigned char *buf, int32 len);
|
||||
NS_IMETHOD ImgDComplete();
|
||||
NS_IMETHOD ImgDAbort();
|
||||
|
||||
NS_IMETHOD_(il_container *) SetContainer(il_container *ic){ilContainer = ic; return ic;}
|
||||
NS_IMETHOD_(il_container *) GetContainer() {return ilContainer;}
|
||||
|
||||
|
||||
private:
|
||||
il_container* ilContainer;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
205
modules/libimg/gifcom/nsGIFModule.cpp
Normal file
205
modules/libimg/gifcom/nsGIFModule.cpp
Normal file
@ -0,0 +1,205 @@
|
||||
/* -*- 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 "nsGIFModule.h"
|
||||
#include "nsGIFDecoder.h"
|
||||
#include "nsIComponentManager.h"
|
||||
#include "nsIGenericFactory.h"
|
||||
#include "nsISupports.h"
|
||||
#include "nsCOMPtr.h"
|
||||
|
||||
static NS_DEFINE_CID(kGIFDecoderCID, NS_GIFDECODER_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 nsGIFModule *gModule = NULL;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Module entry point
|
||||
|
||||
extern "C" NS_EXPORT nsresult NSGetModule(nsIComponentManager *servMgr,
|
||||
nsIFileSpec* location,
|
||||
nsIModule** return_cobj)
|
||||
{
|
||||
nsGIFModule *gifModule;
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
NS_ASSERTION(return_cobj, "Null argument");
|
||||
NS_ASSERTION(gModule == NULL, "nsGIFModule: Module already created.");
|
||||
|
||||
gifModule = new nsGIFModule;
|
||||
if (gifModule == NULL) return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
rv = gifModule->QueryInterface(nsIModule::GetIID(), (void **)return_cobj);
|
||||
|
||||
if (NS_FAILED(rv))
|
||||
{
|
||||
delete gifModule;
|
||||
gifModule = NULL;
|
||||
}
|
||||
|
||||
// WARNING: Weak Reference
|
||||
gModule = gifModule;
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// GIF Decoder Factory using nsIGenericFactory
|
||||
|
||||
static NS_IMETHODIMP
|
||||
nsGIFDecoderCreateInstance(nsISupports *aOuter, REFNSIID aIID, void **aResult)
|
||||
{
|
||||
GIFDecoder *gifdec = 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;
|
||||
}
|
||||
gifdec = new GIFDecoder(ic);
|
||||
if (!gifdec)
|
||||
{
|
||||
delete ic;
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
nsresult res = gifdec->QueryInterface(aIID, aResult);
|
||||
if (NS_FAILED(res))
|
||||
{
|
||||
*aResult = NULL;
|
||||
delete gifdec;
|
||||
}
|
||||
delete ic; /* is a place holder */
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// GIF Decoder Module Implementation
|
||||
|
||||
NS_IMPL_ISUPPORTS(nsGIFModule, nsIModule::GetIID())
|
||||
|
||||
nsGIFModule::nsGIFModule(void)
|
||||
: mObjCount(-1), mClassObject(NULL)
|
||||
{
|
||||
NS_INIT_ISUPPORTS();
|
||||
}
|
||||
|
||||
nsGIFModule::~nsGIFModule(void)
|
||||
{
|
||||
NS_ASSERTION(mObjCount <= 0, "Module released while having outstanding objects.");
|
||||
if (mClassObject)
|
||||
{
|
||||
int refcnt;
|
||||
NS_RELEASE2(mClassObject, refcnt);
|
||||
NS_ASSERTION(refcnt == 0, "nsGIFModule::~nsGIFModule() ClassObject refcount nonzero");
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// The class object for us is just the factory and nothing more.
|
||||
//
|
||||
NS_IMETHODIMP
|
||||
nsGIFModule::GetClassObject(nsIComponentManager *aCompMgr, const nsCID & aClass,
|
||||
nsISupports **r_classObj)
|
||||
{
|
||||
if( !aClass.Equals(kGIFDecoderCID))
|
||||
return NS_ERROR_FACTORY_NOT_REGISTERED;
|
||||
|
||||
// If this aint the first time, return the cached class object
|
||||
if (mClassObject)
|
||||
{
|
||||
NS_ADDREF(mClassObject);
|
||||
*r_classObj = mClassObject;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIGenericFactory> fact;
|
||||
nsresult rv = NS_NewGenericFactory(getter_AddRefs(fact), nsGIFDecoderCreateInstance);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = fact->QueryInterface(nsIFactory::GetIID(), (void **)&mClassObject);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = fact->QueryInterface(kISupportsIID, (void **)r_classObj);
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGIFModule::RegisterSelf(nsIComponentManager *aCompMgr, nsIFileSpec *location)
|
||||
{
|
||||
nsresult rv;
|
||||
rv = aCompMgr->RegisterComponentSpec(kGIFDecoderCID,
|
||||
"Netscape GIFDec",
|
||||
"component://netscape/image/decoder&type=image/gif",
|
||||
location, PR_TRUE, PR_TRUE);
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGIFModule::UnregisterSelf(nsIComponentManager *aCompMgr, nsIFileSpec *location)
|
||||
{
|
||||
nsresult rv;
|
||||
rv = aCompMgr->UnregisterComponentSpec(kGIFDecoderCID, location);
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGIFModule::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;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
46
modules/libimg/gifcom/nsGIFModule.h
Normal file
46
modules/libimg/gifcom/nsGIFModule.h
Normal file
@ -0,0 +1,46 @@
|
||||
/* -*- 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 "nsIModule.h"
|
||||
|
||||
class nsGIFModule : public nsIModule
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// Construction, Init and desstruction
|
||||
nsGIFModule();
|
||||
virtual ~nsGIFModule();
|
||||
|
||||
// nsIModule Interfaces
|
||||
NS_IMETHOD GetClassObject(nsIComponentManager *aCompMgr, const nsCID & aClass,
|
||||
nsISupports **r_classObj);
|
||||
NS_IMETHOD RegisterSelf(nsIComponentManager *aCompMgr, nsIFileSpec *location);
|
||||
NS_IMETHOD UnregisterSelf(nsIComponentManager *aCompMgr, nsIFileSpec *location);
|
||||
NS_IMETHOD CanUnload(nsIComponentManager *aCompMgr, PRBool *okToUnload);
|
||||
|
||||
|
||||
// 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;
|
||||
};
|
Loading…
Reference in New Issue
Block a user