Restore scriptable nsIClassInfo.classID but add fast/C++-only classIDNoAlloc; define and use nsIClassInfo::EAGER_CLASSINFO in caps (93792, sr=waterson&jst).

This commit is contained in:
brendan%mozilla.org 2001-08-07 03:59:29 +00:00
Родитель 9b0332584d
Коммит 49c0102cdf
13 изменённых файлов: 144 добавлений и 32 удалений

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

@ -42,6 +42,7 @@
class nsIDocShell;
class nsString;
class nsIClassInfo;
class nsSystemPrincipal;
/////////////////////
// nsIPrincipalKey //
@ -98,6 +99,9 @@ public:
static nsScriptSecurityManager*
GetScriptSecurityManager();
static nsSystemPrincipal*
SystemPrincipalSingletonConstructor();
JSContext* GetCurrentContextQuick();
private:

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

@ -31,6 +31,9 @@ static NS_DEFINE_IID(kIAggregatePrincipalIID, NS_IAGGREGATEPRINCIPAL_IID);
NS_IMPL_QUERY_INTERFACE5_CI(nsAggregatePrincipal, nsIAggregatePrincipal,
nsICertificatePrincipal, nsICodebasePrincipal,
nsIPrincipal, nsISerializable)
NS_IMPL_CI_INTERFACE_GETTER5(nsAggregatePrincipal, nsIAggregatePrincipal,
nsICertificatePrincipal, nsICodebasePrincipal,
nsIPrincipal, nsISerializable)
NSBASEPRINCIPALS_ADDREF(nsAggregatePrincipal);
NSBASEPRINCIPALS_RELEASE(nsAggregatePrincipal);

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

@ -33,6 +33,10 @@ NS_IMPL_QUERY_INTERFACE3_CI(nsCertificatePrincipal,
nsICertificatePrincipal,
nsIPrincipal,
nsISerializable)
NS_IMPL_CI_INTERFACE_GETTER3(nsCertificatePrincipal,
nsICertificatePrincipal,
nsIPrincipal,
nsISerializable)
NSBASEPRINCIPALS_ADDREF(nsCertificatePrincipal);
NSBASEPRINCIPALS_RELEASE(nsCertificatePrincipal);

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

@ -37,6 +37,10 @@ NS_IMPL_QUERY_INTERFACE3_CI(nsCodebasePrincipal,
nsICodebasePrincipal,
nsIPrincipal,
nsISerializable)
NS_IMPL_CI_INTERFACE_GETTER3(nsCodebasePrincipal,
nsICodebasePrincipal,
nsIPrincipal,
nsISerializable)
NSBASEPRINCIPALS_ADDREF(nsCodebasePrincipal);
NSBASEPRINCIPALS_RELEASE(nsCodebasePrincipal);

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

@ -1942,10 +1942,11 @@ nsScriptSecurityManager::~nsScriptSecurityManager(void)
delete mPrincipals;
}
static nsScriptSecurityManager *ssecMan = NULL;
nsScriptSecurityManager *
nsScriptSecurityManager::GetScriptSecurityManager()
{
static nsScriptSecurityManager *ssecMan = NULL;
if (!ssecMan)
{
ssecMan = new nsScriptSecurityManager();
@ -1977,6 +1978,19 @@ nsScriptSecurityManager::GetScriptSecurityManager()
return ssecMan;
}
// Currently this nsGenericFactory constructor is used only from FastLoad
// (XPCOM object deserialization) code, when "creating" the system principal
// singleton.
static nsSystemPrincipal *
nsScriptSecurityManager::SystemPrincipalSingletonConstructor()
{
nsIPrincipal *sysprin = nsnull;
if (ssecMan)
ssecMan->GetSystemPrincipal(&sysprin);
return NS_STATIC_CAST(nsSystemPrincipal*, sysprin);
}
const char* nsScriptSecurityManager::sJSEnabledPrefName = "javascript.enabled";
const char* nsScriptSecurityManager::sJSMailEnabledPrefName = "javascript.allow.mailnews";
const char* nsScriptSecurityManager::sPrincipalPrefix = "capability.principal";

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

@ -299,18 +299,8 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(nsAggregatePrincipal)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsCertificatePrincipal)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsCodebasePrincipal)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsSecurityNameSet)
static nsSystemPrincipal *GetSystemPrincipal()
{
nsIPrincipal *sysprin = nsnull;
nsCOMPtr<nsIScriptSecurityManager>
secmgr(do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID));
if (secmgr)
secmgr->GetSystemPrincipal(&sysprin);
return NS_STATIC_CAST(nsSystemPrincipal*, sysprin);
}
NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsSystemPrincipal, GetSystemPrincipal)
NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsSystemPrincipal,
nsScriptSecurityManager::SystemPrincipalSingletonConstructor)
NS_DECL_CLASSINFO(nsAggregatePrincipal)
@ -361,47 +351,89 @@ RegisterSecurityNameSet(nsIComponentManager *aCompMgr,
return rv;
}
static nsModuleComponentInfo components[] =
{
{ NS_SCRIPTSECURITYMANAGER_CLASSNAME,
NS_SCRIPTSECURITYMANAGER_CID,
NS_SCRIPTSECURITYMANAGER_CONTRACTID,
Construct_nsIScriptSecurityManager,
RegisterSecurityNameSet
RegisterSecurityNameSet,
nsnull,
nsnull,
nsnull,
nsnull,
nsnull,
nsIClassInfo::MAIN_THREAD_ONLY
},
{ NS_AGGREGATEPRINCIPAL_CLASSNAME,
NS_AGGREGATEPRINCIPAL_CID,
NS_AGGREGATEPRINCIPAL_CONTRACTID,
nsAggregatePrincipalConstructor
nsAggregatePrincipalConstructor,
nsnull,
nsnull,
nsnull,
NS_CI_INTERFACE_GETTER_NAME(nsAggregatePrincipal),
nsnull,
&NS_CLASSINFO_NAME(nsAggregatePrincipal),
nsIClassInfo::MAIN_THREAD_ONLY | nsIClassInfo::EAGER_CLASSINFO
},
{ NS_CERTIFICATEPRINCIPAL_CLASSNAME,
NS_CERTIFICATEPRINCIPAL_CID,
NS_CERTIFICATEPRINCIPAL_CONTRACTID,
nsCertificatePrincipalConstructor
nsCertificatePrincipalConstructor,
nsnull,
nsnull,
nsnull,
NS_CI_INTERFACE_GETTER_NAME(nsCertificatePrincipal),
nsnull,
&NS_CLASSINFO_NAME(nsCertificatePrincipal),
nsIClassInfo::MAIN_THREAD_ONLY | nsIClassInfo::EAGER_CLASSINFO
},
{ NS_CODEBASEPRINCIPAL_CLASSNAME,
NS_CODEBASEPRINCIPAL_CID,
NS_CODEBASEPRINCIPAL_CONTRACTID,
nsCodebasePrincipalConstructor
nsCodebasePrincipalConstructor,
nsnull,
nsnull,
nsnull,
NS_CI_INTERFACE_GETTER_NAME(nsCodebasePrincipal),
nsnull,
&NS_CLASSINFO_NAME(nsCodebasePrincipal),
nsIClassInfo::MAIN_THREAD_ONLY | nsIClassInfo::EAGER_CLASSINFO
},
{ NS_SYSTEMPRINCIPAL_CLASSNAME,
NS_SYSTEMPRINCIPAL_CID,
NS_SYSTEMPRINCIPAL_CONTRACTID,
nsSystemPrincipalConstructor
nsSystemPrincipalConstructor,
nsnull,
nsnull,
nsnull,
NS_CI_INTERFACE_GETTER_NAME(nsSystemPrincipal),
nsnull,
&NS_CLASSINFO_NAME(nsSystemPrincipal),
nsIClassInfo::SINGLETON | nsIClassInfo::MAIN_THREAD_ONLY |
nsIClassInfo::EAGER_CLASSINFO
},
{ "Security Script Name Set",
NS_SECURITYNAMESET_CID,
NS_SECURITYNAMESET_CONTRACTID,
nsSecurityNameSetConstructor
nsSecurityNameSetConstructor,
nsnull,
nsnull,
nsnull,
nsnull,
nsnull,
nsnull,
nsIClassInfo::MAIN_THREAD_ONLY
}
};
NS_IMPL_NSGETMODULE(nsSecurityManagerModule, components);

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

@ -32,6 +32,7 @@
NS_IMPL_QUERY_INTERFACE2_CI(nsSystemPrincipal, nsIPrincipal, nsISerializable)
NS_IMPL_CI_INTERFACE_GETTER2(nsSystemPrincipal, nsIPrincipal, nsISerializable)
NSBASEPRINCIPALS_ADDREF(nsSystemPrincipal);
NSBASEPRINCIPALS_RELEASE(nsSystemPrincipal);

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

@ -1718,7 +1718,14 @@ nsDOMClassInfo::GetClassDescription(char **aClassDescription)
}
NS_IMETHODIMP
nsDOMClassInfo::GetClassID(nsCID *aClassID)
nsDOMClassInfo::GetClassID(nsCID **aClassID)
{
*aClassID = nsnull;
return NS_OK;
}
NS_IMETHODIMP
nsDOMClassInfo::GetClassIDNoAlloc(nsCID *aClassID)
{
return NS_ERROR_NOT_AVAILABLE;
}

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

@ -956,7 +956,7 @@ nsJSCID::HasInstance(nsIXPConnectWrappedNative *wrapper,
if(ci)
{
nsID cid;
if(NS_SUCCEEDED(ci->GetClassID(&cid)))
if(NS_SUCCEEDED(ci->GetClassIDNoAlloc(&cid)))
*bp = cid.Equals(*mDetails.GetID());
}
}

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

@ -115,7 +115,17 @@ NS_IMETHODIMP nsGenericFactory::GetClassDescription(char * *aClassDescription)
return NS_OK;
}
NS_IMETHODIMP nsGenericFactory::GetClassID(nsCID *aClassID)
NS_IMETHODIMP nsGenericFactory::GetClassID(nsCID * *aClassID)
{
*aClassID =
NS_REINTERPRET_CAST(nsCID*,
nsMemory::Clone(&mInfo->mCID, sizeof mInfo->mCID));
if (! *aClassID)
return NS_ERROR_OUT_OF_MEMORY;
return NS_OK;
}
NS_IMETHODIMP nsGenericFactory::GetClassIDNoAlloc(nsCID *aClassID)
{
*aClassID = mInfo->mCID;
return NS_OK;
@ -225,10 +235,15 @@ nsGenericModule::Initialize()
// Eagerly populate factory/class object hash for entries
// without constructors. If we didn't, the class object would
// never get created.
// never get created. Also create the factory, which doubles
// as the class object, if the EAGER_CLASSINFO flag was given.
// This allows objects to be created (within their modules)
// via operator new rather than CreateInstance, yet still be
// QI'able to nsIClassInfo.
nsModuleComponentInfo* desc = mComponents;
for (PRUint32 i = 0; i < mComponentCount; i++) {
if (!desc->mConstructor) {
if (!desc->mConstructor ||
(desc->mFlags & nsIClassInfo::EAGER_CLASSINFO)) {
nsCOMPtr<nsIGenericFactory> fact;
nsresult rv = NS_NewGenericFactory(getter_AddRefs(fact), desc);
if (NS_FAILED(rv)) return rv;

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

@ -77,10 +77,18 @@ interface nsIClassInfo : nsISupports
/**
* A class ID through which an instance of this class can be created
* (or accessed as a service, if |flags & SINGLETON|). If the class does
* not have a CID, it should return NS_ERROR_NOT_AVAILABLE.
* (or accessed as a service, if |flags & SINGLETON|), or null.
*/
readonly attribute nsCID classID;
readonly attribute nsCIDPtr classID;
/**
* Also a class ID through which an instance of this class can be created
* (or accessed as a service, if |flags & SINGLETON|). If the class does
* not have a CID, it should return NS_ERROR_NOT_AVAILABLE. This attribute
* exists so C++ callers can avoid allocating and freeing a CID, as would
* happen if they used classID.
*/
[notxpcom] readonly attribute nsCID classIDNoAlloc;
/**
* Return language type from list in nsIProgrammingLanguage
@ -96,6 +104,7 @@ interface nsIClassInfo : nsISupports
const PRUint32 MAIN_THREAD_ONLY = 1 << 2;
const PRUint32 DOM_OBJECT = 1 << 3;
const PRUint32 PLUGIN_OBJECT = 1 << 4;
const PRUint32 EAGER_CLASSINFO = 1 << 5;
// XXX what else might we want to add?

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

@ -115,7 +115,17 @@ NS_IMETHODIMP nsGenericFactory::GetClassDescription(char * *aClassDescription)
return NS_OK;
}
NS_IMETHODIMP nsGenericFactory::GetClassID(nsCID *aClassID)
NS_IMETHODIMP nsGenericFactory::GetClassID(nsCID * *aClassID)
{
*aClassID =
NS_REINTERPRET_CAST(nsCID*,
nsMemory::Clone(&mInfo->mCID, sizeof mInfo->mCID));
if (! *aClassID)
return NS_ERROR_OUT_OF_MEMORY;
return NS_OK;
}
NS_IMETHODIMP nsGenericFactory::GetClassIDNoAlloc(nsCID *aClassID)
{
*aClassID = mInfo->mCID;
return NS_OK;
@ -225,10 +235,15 @@ nsGenericModule::Initialize()
// Eagerly populate factory/class object hash for entries
// without constructors. If we didn't, the class object would
// never get created.
// never get created. Also create the factory, which doubles
// as the class object, if the EAGER_CLASSINFO flag was given.
// This allows objects to be created (within their modules)
// via operator new rather than CreateInstance, yet still be
// QI'able to nsIClassInfo.
nsModuleComponentInfo* desc = mComponents;
for (PRUint32 i = 0; i < mComponentCount; i++) {
if (!desc->mConstructor) {
if (!desc->mConstructor ||
(desc->mFlags & nsIClassInfo::EAGER_CLASSINFO)) {
nsCOMPtr<nsIGenericFactory> fact;
nsresult rv = NS_NewGenericFactory(getter_AddRefs(fact), desc);
if (NS_FAILED(rv)) return rv;

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

@ -282,6 +282,9 @@ nsFastLoadFileReader::SetChecksum(PRUint32 aChecksum)
NS_IMETHODIMP
nsFastLoadFileReader::ComputeChecksum(PRUint32 *aResult)
{
*aResult = mHeader.mChecksum;
return NS_OK;
#if 0
PRUint32 saveChecksum = mHeader.mChecksum;
mHeader.mChecksum = 0;
NS_AccumulateFastLoadChecksum(&mHeader.mChecksum,
@ -330,6 +333,7 @@ nsFastLoadFileReader::ComputeChecksum(PRUint32 *aResult)
*aResult = mHeader.mChecksum;
mHeader.mChecksum = saveChecksum;
return rv;
#endif
}
NS_IMETHODIMP
@ -1812,7 +1816,7 @@ nsFastLoadFileWriter::WriteObjectCommon(nsISupports* aObject,
return NS_ERROR_FAILURE;
nsCID slowCID;
rv = classInfo->GetClassID(&slowCID);
rv = classInfo->GetClassIDNoAlloc(&slowCID);
if (NS_FAILED(rv)) return rv;
NSFastLoadID fastCID;