зеркало из https://github.com/mozilla/pjs.git
Add helper functions that make it easier to cache factories. b=261310 r=darin
This commit is contained in:
Родитель
71167f1f9e
Коммит
f26ae219a5
|
@ -212,12 +212,7 @@ nsCSSScanner::~nsCSSScanner()
|
|||
nsresult rv = CallGetService(NS_CONSOLESERVICE_CONTRACTID, &gConsoleService);
|
||||
NS_ENSURE_SUCCESS(rv, PR_FALSE);
|
||||
|
||||
nsCOMPtr<nsIComponentManager> compMgr;
|
||||
rv = NS_GetComponentManager(getter_AddRefs(compMgr));
|
||||
NS_ENSURE_SUCCESS(rv, PR_FALSE);
|
||||
rv = compMgr->GetClassObjectByContractID(NS_SCRIPTERROR_CONTRACTID,
|
||||
NS_GET_IID(nsIFactory),
|
||||
(void**)&gScriptErrorFactory);
|
||||
rv = CallGetClassObject(NS_SCRIPTERROR_CONTRACTID, &gScriptErrorFactory);
|
||||
NS_ENSURE_SUCCESS(rv, PR_FALSE);
|
||||
NS_ASSERTION(gConsoleService && gScriptErrorFactory,
|
||||
"unexpected null pointer without failure");
|
||||
|
@ -287,10 +282,9 @@ void nsCSSScanner::OutputError()
|
|||
// Log it to the JavaScript console
|
||||
|
||||
if (InitGlobals()) {
|
||||
nsCOMPtr<nsIScriptError> errorObject;
|
||||
nsresult rv =
|
||||
gScriptErrorFactory->CreateInstance(nsnull, NS_GET_IID(nsIScriptError),
|
||||
getter_AddRefs(errorObject));
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIScriptError> errorObject =
|
||||
do_CreateInstance(gScriptErrorFactory, &rv);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
rv = errorObject->Init(mError.get(),
|
||||
NS_ConvertASCIItoUCS2(mFileName.get()).get(),
|
||||
|
|
|
@ -212,12 +212,7 @@ nsCSSScanner::~nsCSSScanner()
|
|||
nsresult rv = CallGetService(NS_CONSOLESERVICE_CONTRACTID, &gConsoleService);
|
||||
NS_ENSURE_SUCCESS(rv, PR_FALSE);
|
||||
|
||||
nsCOMPtr<nsIComponentManager> compMgr;
|
||||
rv = NS_GetComponentManager(getter_AddRefs(compMgr));
|
||||
NS_ENSURE_SUCCESS(rv, PR_FALSE);
|
||||
rv = compMgr->GetClassObjectByContractID(NS_SCRIPTERROR_CONTRACTID,
|
||||
NS_GET_IID(nsIFactory),
|
||||
(void**)&gScriptErrorFactory);
|
||||
rv = CallGetClassObject(NS_SCRIPTERROR_CONTRACTID, &gScriptErrorFactory);
|
||||
NS_ENSURE_SUCCESS(rv, PR_FALSE);
|
||||
NS_ASSERTION(gConsoleService && gScriptErrorFactory,
|
||||
"unexpected null pointer without failure");
|
||||
|
@ -287,10 +282,9 @@ void nsCSSScanner::OutputError()
|
|||
// Log it to the JavaScript console
|
||||
|
||||
if (InitGlobals()) {
|
||||
nsCOMPtr<nsIScriptError> errorObject;
|
||||
nsresult rv =
|
||||
gScriptErrorFactory->CreateInstance(nsnull, NS_GET_IID(nsIScriptError),
|
||||
getter_AddRefs(errorObject));
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIScriptError> errorObject =
|
||||
do_CreateInstance(gScriptErrorFactory, &rv);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
rv = errorObject->Init(mError.get(),
|
||||
NS_ConvertASCIItoUCS2(mFileName.get()).get(),
|
||||
|
|
|
@ -533,22 +533,15 @@ nsViewManager::CreateRegion(nsIRegion* *result)
|
|||
nsresult rv;
|
||||
|
||||
if (!mRegionFactory) {
|
||||
nsCOMPtr<nsIComponentManager> compMgr;
|
||||
rv = NS_GetComponentManager(getter_AddRefs(compMgr));
|
||||
|
||||
if (NS_SUCCEEDED(rv))
|
||||
rv = compMgr->GetClassObject(kRegionCID,
|
||||
NS_GET_IID(nsIFactory),
|
||||
getter_AddRefs(mRegionFactory));
|
||||
|
||||
if (!mRegionFactory) {
|
||||
mRegionFactory = do_GetClassObject(kRegionCID, &rv);
|
||||
if (NS_FAILED(rv)) {
|
||||
*result = nsnull;
|
||||
return NS_ERROR_FAILURE;
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
|
||||
nsIRegion* region = nsnull;
|
||||
rv = mRegionFactory->CreateInstance(nsnull, NS_GET_IID(nsIRegion), (void**)®ion);
|
||||
rv = CallCreateInstance(mRegionFactory, ®ion);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
rv = region->Init();
|
||||
*result = region;
|
||||
|
|
|
@ -39,6 +39,7 @@
|
|||
// Global Static Component Manager Methods
|
||||
// (for when you need to link with xpcom)
|
||||
|
||||
#include "nsXPCOM.h"
|
||||
#include "nsIComponentManagerObsolete.h"
|
||||
#include "nsComponentManagerObsolete.h"
|
||||
|
||||
|
@ -69,6 +70,17 @@ nsComponentManager::GetClassObject(const nsCID &aClass, const nsIID &aIID,
|
|||
return cm->GetClassObject(aClass, aIID, aResult);
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsComponentManager::GetClassObjectByContractID(const char *aContractID,
|
||||
const nsIID &aIID,
|
||||
void **aResult)
|
||||
{
|
||||
nsCOMPtr<nsIComponentManager> cm;
|
||||
nsresult rv = NS_GetComponentManager(getter_AddRefs(cm));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
return cm->GetClassObjectByContractID(aContractID, aIID, aResult);
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsComponentManager::ContractIDToClassID(const char *aContractID,
|
||||
nsCID *aClass)
|
||||
|
|
|
@ -1,185 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (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/MPL/
|
||||
*
|
||||
* 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 XPCOM.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
||||
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
#ifndef nsComponentManagerObsolete_h___
|
||||
#define nsComponentManagerObsolete_h___
|
||||
|
||||
#include "nsIComponentManager.h"
|
||||
#include "nsIComponentManagerObsolete.h"
|
||||
|
||||
class nsIEnumerator;
|
||||
class nsIFactory;
|
||||
class nsIFile;
|
||||
////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
|
||||
//
|
||||
// Functions, classes, interfaces and types in this file are
|
||||
// obsolete. Use at your own risk.
|
||||
// Please see nsIComponentManager.idl for the supported interface
|
||||
// to the component manager.
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// God save me from this evilness. Below is a very bad
|
||||
// function. Its out var is really a nsIComponentManagerObsolete
|
||||
// but it has been cast to a nsIComponentManager.
|
||||
// The reason for such uglyness is that this function is require for
|
||||
// backward compatiblity of some plugins. This funciton will
|
||||
// be removed at some point.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
extern NS_COM nsresult
|
||||
NS_GetGlobalComponentManager(nsIComponentManager* *result);
|
||||
|
||||
|
||||
|
||||
|
||||
class NS_COM nsComponentManager {
|
||||
public:
|
||||
static nsresult Initialize(void);
|
||||
|
||||
// Finds a factory for a specific class ID
|
||||
static nsresult FindFactory(const nsCID &aClass,
|
||||
nsIFactory **aFactory);
|
||||
|
||||
// Get the singleton class object that implements the CID aClass
|
||||
static nsresult GetClassObject(const nsCID &aClass, const nsIID &aIID,
|
||||
void **aResult);
|
||||
|
||||
// Finds a class ID for a specific Program ID
|
||||
static nsresult ContractIDToClassID(const char *aContractID,
|
||||
nsCID *aClass);
|
||||
|
||||
// Finds a Program ID for a specific class ID
|
||||
// caller frees the result with delete[]
|
||||
static nsresult CLSIDToContractID(nsCID *aClass,
|
||||
char* *aClassName,
|
||||
char* *aContractID);
|
||||
|
||||
// Creates a class instance for a specific class ID
|
||||
static nsresult CreateInstance(const nsCID &aClass,
|
||||
nsISupports *aDelegate,
|
||||
const nsIID &aIID,
|
||||
void **aResult);
|
||||
|
||||
// Convenience routine, creates a class instance for a specific ContractID
|
||||
static nsresult CreateInstance(const char *aContractID,
|
||||
nsISupports *aDelegate,
|
||||
const nsIID &aIID,
|
||||
void **aResult);
|
||||
|
||||
// Manually registry a factory for a class
|
||||
static nsresult RegisterFactory(const nsCID &aClass,
|
||||
const char *aClassName,
|
||||
const char *aContractID,
|
||||
nsIFactory *aFactory,
|
||||
PRBool aReplace);
|
||||
|
||||
// Manually register a dynamically loaded component.
|
||||
// The libraryPersistentDescriptor is what gets passed to the library
|
||||
// self register function from ComponentManager. The format of this string
|
||||
// is the same as nsIFile::GetPath()
|
||||
//
|
||||
// This function will go away in favour of RegisterComponentSpec. In fact,
|
||||
// it internally turns around and calls RegisterComponentSpec.
|
||||
static nsresult RegisterComponent(const nsCID &aClass,
|
||||
const char *aClassName,
|
||||
const char *aContractID,
|
||||
const char *aLibraryPersistentDescriptor,
|
||||
PRBool aReplace,
|
||||
PRBool aPersist);
|
||||
|
||||
// Register a component using its FileSpec as its identification
|
||||
// This is the more prevalent use.
|
||||
static nsresult RegisterComponentSpec(const nsCID &aClass,
|
||||
const char *aClassName,
|
||||
const char *aContractID,
|
||||
nsIFile *aLibrary,
|
||||
PRBool aReplace,
|
||||
PRBool aPersist);
|
||||
|
||||
// Register a component using its dllName. This could be a dll name with
|
||||
// no path so that LD_LIBRARY_PATH on unix or PATH on win can load it. Or
|
||||
// this could be a code fragment name on the Mac.
|
||||
static nsresult RegisterComponentLib(const nsCID &aClass,
|
||||
const char *aClassName,
|
||||
const char *aContractID,
|
||||
const char *adllName,
|
||||
PRBool aReplace,
|
||||
PRBool aPersist);
|
||||
|
||||
|
||||
// Manually unregister a factory for a class
|
||||
static nsresult UnregisterFactory(const nsCID &aClass,
|
||||
nsIFactory *aFactory);
|
||||
|
||||
// Manually unregister a dynamically loaded component
|
||||
static nsresult UnregisterComponent(const nsCID &aClass,
|
||||
const char *aLibrary);
|
||||
|
||||
// Manually unregister a dynamically loaded component
|
||||
static nsresult UnregisterComponentSpec(const nsCID &aClass,
|
||||
nsIFile *aLibrarySpec);
|
||||
|
||||
// Unload dynamically loaded factories that are not in use
|
||||
static nsresult FreeLibraries(void);
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// DLL registration support
|
||||
|
||||
// If directory is NULL, then AutoRegister will try registering components
|
||||
// in the default components directory.
|
||||
static nsresult AutoRegister(PRInt32 when, nsIFile* directory);
|
||||
static nsresult AutoRegisterComponent(PRInt32 when, nsIFile *component);
|
||||
static nsresult AutoUnregisterComponent(PRInt32 when, nsIFile *component);
|
||||
|
||||
// Is the given CID currently registered?
|
||||
static nsresult IsRegistered(const nsCID &aClass,
|
||||
PRBool *aRegistered);
|
||||
|
||||
// Get an enumeration of all the CIDs
|
||||
static nsresult EnumerateCLSIDs(nsIEnumerator** aEmumerator);
|
||||
|
||||
// Get an enumeration of all the ContractIDs
|
||||
static nsresult EnumerateContractIDs(nsIEnumerator** aEmumerator);
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif
|
|
@ -1,196 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (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/MPL/
|
||||
*
|
||||
* 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.org Code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
||||
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#ifndef nsComponentManagerUtils_h__
|
||||
#define nsComponentManagerUtils_h__
|
||||
|
||||
/*
|
||||
* Do not include this file directly. Instead,
|
||||
* |#include "nsIComponentManager.h"|.
|
||||
*/
|
||||
|
||||
#ifndef nsCOMPtr_h__
|
||||
#include "nsCOMPtr.h"
|
||||
#endif
|
||||
|
||||
#ifndef nsComponentManagerObsolete_h___
|
||||
#include "nsComponentManagerObsolete.h"
|
||||
#endif
|
||||
|
||||
#define NS_COMPONENTMANAGER_CID \
|
||||
{ /* 91775d60-d5dc-11d2-92fb-00e09805570f */ \
|
||||
0x91775d60, \
|
||||
0xd5dc, \
|
||||
0x11d2, \
|
||||
{0x92, 0xfb, 0x00, 0xe0, 0x98, 0x05, 0x57, 0x0f} \
|
||||
}
|
||||
|
||||
class NS_COM nsCreateInstanceByCID : public nsCOMPtr_helper
|
||||
{
|
||||
public:
|
||||
nsCreateInstanceByCID( const nsCID& aCID, nsISupports* aOuter, nsresult* aErrorPtr )
|
||||
: mCID(aCID),
|
||||
mOuter(aOuter),
|
||||
mErrorPtr(aErrorPtr)
|
||||
{
|
||||
// nothing else to do here
|
||||
}
|
||||
|
||||
virtual nsresult NS_FASTCALL operator()( const nsIID&, void** ) const;
|
||||
|
||||
private:
|
||||
const nsCID& mCID;
|
||||
nsISupports* mOuter;
|
||||
nsresult* mErrorPtr;
|
||||
};
|
||||
|
||||
class NS_COM nsCreateInstanceByContractID : public nsCOMPtr_helper
|
||||
{
|
||||
public:
|
||||
nsCreateInstanceByContractID( const char* aContractID, nsISupports* aOuter, nsresult* aErrorPtr )
|
||||
: mContractID(aContractID),
|
||||
mOuter(aOuter),
|
||||
mErrorPtr(aErrorPtr)
|
||||
{
|
||||
// nothing else to do here
|
||||
}
|
||||
|
||||
virtual nsresult NS_FASTCALL operator()( const nsIID&, void** ) const;
|
||||
|
||||
private:
|
||||
const char* mContractID;
|
||||
nsISupports* mOuter;
|
||||
nsresult* mErrorPtr;
|
||||
};
|
||||
|
||||
inline
|
||||
const nsCreateInstanceByCID
|
||||
do_CreateInstance( const nsCID& aCID, nsresult* error = 0 )
|
||||
{
|
||||
return nsCreateInstanceByCID(aCID, 0, error);
|
||||
}
|
||||
|
||||
inline
|
||||
const nsCreateInstanceByCID
|
||||
do_CreateInstance( const nsCID& aCID, nsISupports* aOuter, nsresult* error = 0 )
|
||||
{
|
||||
return nsCreateInstanceByCID(aCID, aOuter, error);
|
||||
}
|
||||
|
||||
inline
|
||||
const nsCreateInstanceByContractID
|
||||
do_CreateInstance( const char* aContractID, nsresult* error = 0 )
|
||||
{
|
||||
return nsCreateInstanceByContractID(aContractID, 0, error);
|
||||
}
|
||||
|
||||
inline
|
||||
const nsCreateInstanceByContractID
|
||||
do_CreateInstance( const char* aContractID, nsISupports* aOuter, nsresult* error = 0 )
|
||||
{
|
||||
return nsCreateInstanceByContractID(aContractID, aOuter, error);
|
||||
}
|
||||
|
||||
// type-safe shortcuts for calling |CreateInstance|
|
||||
template <class DestinationType>
|
||||
inline
|
||||
nsresult
|
||||
CallCreateInstance( const nsCID &aClass,
|
||||
nsISupports *aDelegate,
|
||||
DestinationType** aDestination )
|
||||
{
|
||||
NS_PRECONDITION(aDestination, "null parameter");
|
||||
|
||||
return nsComponentManager::CreateInstance(aClass, aDelegate,
|
||||
NS_GET_IID(DestinationType),
|
||||
NS_REINTERPRET_CAST(void**, aDestination));
|
||||
}
|
||||
|
||||
template <class DestinationType>
|
||||
inline
|
||||
nsresult
|
||||
CallCreateInstance( const nsCID &aClass,
|
||||
DestinationType** aDestination )
|
||||
{
|
||||
NS_PRECONDITION(aDestination, "null parameter");
|
||||
|
||||
return nsComponentManager::CreateInstance(aClass, nsnull,
|
||||
NS_GET_IID(DestinationType),
|
||||
NS_REINTERPRET_CAST(void**, aDestination));
|
||||
}
|
||||
|
||||
template <class DestinationType>
|
||||
inline
|
||||
nsresult
|
||||
CallCreateInstance( const char *aContractID,
|
||||
nsISupports *aDelegate,
|
||||
DestinationType** aDestination )
|
||||
{
|
||||
NS_PRECONDITION(aContractID, "null parameter");
|
||||
NS_PRECONDITION(aDestination, "null parameter");
|
||||
|
||||
return nsComponentManager::CreateInstance(aContractID,
|
||||
aDelegate,
|
||||
NS_GET_IID(DestinationType),
|
||||
NS_REINTERPRET_CAST(void**, aDestination));
|
||||
}
|
||||
|
||||
template <class DestinationType>
|
||||
inline
|
||||
nsresult
|
||||
CallCreateInstance( const char *aContractID,
|
||||
DestinationType** aDestination )
|
||||
{
|
||||
NS_PRECONDITION(aContractID, "null parameter");
|
||||
NS_PRECONDITION(aDestination, "null parameter");
|
||||
|
||||
return nsComponentManager::CreateInstance(aContractID, nsnull,
|
||||
NS_GET_IID(DestinationType),
|
||||
NS_REINTERPRET_CAST(void**, aDestination));
|
||||
}
|
||||
|
||||
/* keys for registry use */
|
||||
extern const char xpcomKeyName[];
|
||||
extern const char xpcomComponentsKeyName[];
|
||||
extern const char lastModValueName[];
|
||||
extern const char fileSizeValueName[];
|
||||
extern const char nativeComponentType[];
|
||||
extern const char staticComponentType[];
|
||||
|
||||
#endif /* nsComponentManagerUtils_h__ */
|
||||
|
||||
|
|
@ -87,6 +87,64 @@ nsCreateInstanceByContractID::operator()( const nsIID& aIID, void** aInstancePtr
|
|||
return status;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsCreateInstanceFromFactory::operator()( const nsIID& aIID, void** aInstancePtr ) const
|
||||
{
|
||||
nsresult status;
|
||||
if ( mFactory )
|
||||
status = mFactory->CreateInstance(mOuter, aIID, aInstancePtr);
|
||||
else
|
||||
status = NS_ERROR_NULL_POINTER;
|
||||
|
||||
if ( NS_FAILED(status) )
|
||||
*aInstancePtr = 0;
|
||||
if ( mErrorPtr )
|
||||
*mErrorPtr = status;
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsGetClassObjectByCID::operator()( const nsIID& aIID, void** aInstancePtr ) const
|
||||
{
|
||||
nsCOMPtr<nsIComponentManager> compMgr;
|
||||
nsresult status = NS_GetComponentManager(getter_AddRefs(compMgr));
|
||||
if (compMgr)
|
||||
status = compMgr->GetClassObject(mCID, aIID, aInstancePtr);
|
||||
else if (NS_SUCCEEDED(status))
|
||||
status = NS_ERROR_UNEXPECTED;
|
||||
|
||||
if ( NS_FAILED(status) )
|
||||
*aInstancePtr = 0;
|
||||
|
||||
if ( mErrorPtr )
|
||||
*mErrorPtr = status;
|
||||
return status;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsGetClassObjectByContractID::operator()( const nsIID& aIID, void** aInstancePtr ) const
|
||||
{
|
||||
nsresult status;
|
||||
if ( mContractID ) {
|
||||
nsCOMPtr<nsIComponentManager> compMgr;
|
||||
status = NS_GetComponentManager(getter_AddRefs(compMgr));
|
||||
if (compMgr)
|
||||
status = compMgr->GetClassObjectByContractID(mContractID,
|
||||
aIID, aInstancePtr);
|
||||
else if (NS_SUCCEEDED(status))
|
||||
status = NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
else
|
||||
status = NS_ERROR_NULL_POINTER;
|
||||
|
||||
if ( NS_FAILED(status) )
|
||||
*aInstancePtr = 0;
|
||||
if ( mErrorPtr )
|
||||
*mErrorPtr = status;
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsGetServiceByCID::operator()( const nsIID& aIID, void** aInstancePtr ) const
|
||||
|
|
|
@ -73,9 +73,9 @@ public:
|
|||
virtual nsresult NS_FASTCALL operator()( const nsIID&, void** ) const;
|
||||
|
||||
private:
|
||||
const nsCID& mCID;
|
||||
nsISupports* mOuter;
|
||||
nsresult* mErrorPtr;
|
||||
const nsCID& mCID;
|
||||
nsISupports* mOuter;
|
||||
nsresult* mErrorPtr;
|
||||
};
|
||||
|
||||
class NS_COM nsCreateInstanceByContractID : public nsCOMPtr_helper
|
||||
|
@ -85,18 +85,38 @@ public:
|
|||
: mContractID(aContractID),
|
||||
mOuter(aOuter),
|
||||
mErrorPtr(aErrorPtr)
|
||||
{
|
||||
// nothing else to do here
|
||||
}
|
||||
{
|
||||
// nothing else to do here
|
||||
}
|
||||
|
||||
virtual nsresult NS_FASTCALL operator()( const nsIID&, void** ) const;
|
||||
|
||||
private:
|
||||
const char* mContractID;
|
||||
const char* mContractID;
|
||||
nsISupports* mOuter;
|
||||
nsresult* mErrorPtr;
|
||||
nsresult* mErrorPtr;
|
||||
};
|
||||
|
||||
class NS_COM nsCreateInstanceFromFactory : public nsCOMPtr_helper
|
||||
{
|
||||
public:
|
||||
nsCreateInstanceFromFactory( nsIFactory* aFactory, nsISupports* aOuter, nsresult* aErrorPtr )
|
||||
: mFactory(aFactory),
|
||||
mOuter(aOuter),
|
||||
mErrorPtr(aErrorPtr)
|
||||
{
|
||||
// nothing else to do here
|
||||
}
|
||||
|
||||
virtual nsresult NS_FASTCALL operator()( const nsIID&, void** ) const;
|
||||
|
||||
private:
|
||||
nsIFactory* mFactory;
|
||||
nsISupports* mOuter;
|
||||
nsresult* mErrorPtr;
|
||||
};
|
||||
|
||||
|
||||
inline
|
||||
const nsCreateInstanceByCID
|
||||
do_CreateInstance( const nsCID& aCID, nsresult* error = 0 )
|
||||
|
@ -125,6 +145,74 @@ do_CreateInstance( const char* aContractID, nsISupports* aOuter, nsresult* error
|
|||
return nsCreateInstanceByContractID(aContractID, aOuter, error);
|
||||
}
|
||||
|
||||
inline
|
||||
const nsCreateInstanceFromFactory
|
||||
do_CreateInstance( nsIFactory* aFactory, nsresult* error = 0 )
|
||||
{
|
||||
return nsCreateInstanceFromFactory(aFactory, 0, error);
|
||||
}
|
||||
|
||||
inline
|
||||
const nsCreateInstanceFromFactory
|
||||
do_CreateInstance( nsIFactory* aFactory, nsISupports* aOuter, nsresult* error = 0 )
|
||||
{
|
||||
return nsCreateInstanceFromFactory(aFactory, aOuter, error);
|
||||
}
|
||||
|
||||
|
||||
class NS_COM nsGetClassObjectByCID : public nsCOMPtr_helper
|
||||
{
|
||||
public:
|
||||
nsGetClassObjectByCID( const nsCID& aCID, nsresult* aErrorPtr )
|
||||
: mCID(aCID),
|
||||
mErrorPtr(aErrorPtr)
|
||||
{
|
||||
// nothing else to do here
|
||||
}
|
||||
|
||||
virtual nsresult NS_FASTCALL operator()( const nsIID&, void** ) const;
|
||||
|
||||
private:
|
||||
const nsCID& mCID;
|
||||
nsresult* mErrorPtr;
|
||||
};
|
||||
|
||||
class NS_COM nsGetClassObjectByContractID : public nsCOMPtr_helper
|
||||
{
|
||||
public:
|
||||
nsGetClassObjectByContractID( const char* aContractID, nsresult* aErrorPtr )
|
||||
: mContractID(aContractID),
|
||||
mErrorPtr(aErrorPtr)
|
||||
{
|
||||
// nothing else to do here
|
||||
}
|
||||
|
||||
virtual nsresult NS_FASTCALL operator()( const nsIID&, void** ) const;
|
||||
|
||||
private:
|
||||
const char* mContractID;
|
||||
nsresult* mErrorPtr;
|
||||
};
|
||||
|
||||
/**
|
||||
* do_GetClassObject can be used to improve performance of callers
|
||||
* that call |CreateInstance| many times. They can cache the factory
|
||||
* and call do_CreateInstance or CallCreateInstance with the cached
|
||||
* factory rather than having the component manager retrieve it every
|
||||
* time.
|
||||
*/
|
||||
inline const nsGetClassObjectByCID
|
||||
do_GetClassObject( const nsCID& aCID, nsresult* error = 0 )
|
||||
{
|
||||
return nsGetClassObjectByCID(aCID, error);
|
||||
}
|
||||
|
||||
inline const nsGetClassObjectByContractID
|
||||
do_GetClassObject( const char* aContractID, nsresult* error = 0 )
|
||||
{
|
||||
return nsGetClassObjectByContractID(aContractID, error);
|
||||
}
|
||||
|
||||
// type-safe shortcuts for calling |CreateInstance|
|
||||
template <class DestinationType>
|
||||
inline
|
||||
|
@ -183,6 +271,59 @@ CallCreateInstance( const char *aContractID,
|
|||
NS_REINTERPRET_CAST(void**, aDestination));
|
||||
}
|
||||
|
||||
template <class DestinationType>
|
||||
inline
|
||||
nsresult
|
||||
CallCreateInstance( nsIFactory *aFactory,
|
||||
nsISupports *aDelegate,
|
||||
DestinationType** aDestination )
|
||||
{
|
||||
NS_PRECONDITION(aFactory, "null parameter");
|
||||
NS_PRECONDITION(aDestination, "null parameter");
|
||||
|
||||
return aFactory->CreateInstance(aDelegate,
|
||||
NS_GET_IID(DestinationType),
|
||||
NS_REINTERPRET_CAST(void**, aDestination));
|
||||
}
|
||||
|
||||
template <class DestinationType>
|
||||
inline
|
||||
nsresult
|
||||
CallCreateInstance( nsIFactory *aFactory,
|
||||
DestinationType** aDestination )
|
||||
{
|
||||
NS_PRECONDITION(aFactory, "null parameter");
|
||||
NS_PRECONDITION(aDestination, "null parameter");
|
||||
|
||||
return aFactory->CreateInstance(nsnull,
|
||||
NS_GET_IID(DestinationType),
|
||||
NS_REINTERPRET_CAST(void**, aDestination));
|
||||
}
|
||||
|
||||
template <class DestinationType>
|
||||
inline
|
||||
nsresult
|
||||
CallGetClassObject( const nsCID &aClass,
|
||||
DestinationType** aDestination )
|
||||
{
|
||||
NS_PRECONDITION(aDestination, "null parameter");
|
||||
|
||||
return nsComponentManager::GetClassObject(aClass,
|
||||
NS_GET_IID(DestinationType), NS_REINTERPRET_CAST(void**, aDestination));
|
||||
}
|
||||
|
||||
template <class DestinationType>
|
||||
inline
|
||||
nsresult
|
||||
CallGetClassObject( const char* aContractID,
|
||||
DestinationType** aDestination )
|
||||
{
|
||||
NS_PRECONDITION(aDestination, "null parameter");
|
||||
|
||||
return nsComponentManager::GetClassObjectByContractID(aContractID,
|
||||
NS_GET_IID(DestinationType), NS_REINTERPRET_CAST(void**, aDestination));
|
||||
}
|
||||
|
||||
/* keys for registry use */
|
||||
extern const char xpcomKeyName[];
|
||||
extern const char xpcomComponentsKeyName[];
|
||||
|
|
Загрузка…
Ссылка в новой задаче