diff --git a/mozilla/caps/include/nsScriptSecurityManager.h b/mozilla/caps/include/nsScriptSecurityManager.h index 28ecea2d12e..55085f15764 100644 --- a/mozilla/caps/include/nsScriptSecurityManager.h +++ b/mozilla/caps/include/nsScriptSecurityManager.h @@ -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: diff --git a/mozilla/caps/src/nsAggregatePrincipal.cpp b/mozilla/caps/src/nsAggregatePrincipal.cpp index dcec990228c..8a527ed45a8 100644 --- a/mozilla/caps/src/nsAggregatePrincipal.cpp +++ b/mozilla/caps/src/nsAggregatePrincipal.cpp @@ -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); diff --git a/mozilla/caps/src/nsCertificatePrincipal.cpp b/mozilla/caps/src/nsCertificatePrincipal.cpp index 98f2d5cedc6..277b8bfcdbc 100644 --- a/mozilla/caps/src/nsCertificatePrincipal.cpp +++ b/mozilla/caps/src/nsCertificatePrincipal.cpp @@ -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); diff --git a/mozilla/caps/src/nsCodebasePrincipal.cpp b/mozilla/caps/src/nsCodebasePrincipal.cpp index 86af507895d..06b947751c4 100644 --- a/mozilla/caps/src/nsCodebasePrincipal.cpp +++ b/mozilla/caps/src/nsCodebasePrincipal.cpp @@ -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); diff --git a/mozilla/caps/src/nsScriptSecurityManager.cpp b/mozilla/caps/src/nsScriptSecurityManager.cpp index 7393f4e518a..5850bd8fee4 100644 --- a/mozilla/caps/src/nsScriptSecurityManager.cpp +++ b/mozilla/caps/src/nsScriptSecurityManager.cpp @@ -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"; diff --git a/mozilla/caps/src/nsSecurityManagerFactory.cpp b/mozilla/caps/src/nsSecurityManagerFactory.cpp index 7183b26e588..054175fdbce 100644 --- a/mozilla/caps/src/nsSecurityManagerFactory.cpp +++ b/mozilla/caps/src/nsSecurityManagerFactory.cpp @@ -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 - 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); - diff --git a/mozilla/caps/src/nsSystemPrincipal.cpp b/mozilla/caps/src/nsSystemPrincipal.cpp index 80371f13af8..334364000fc 100644 --- a/mozilla/caps/src/nsSystemPrincipal.cpp +++ b/mozilla/caps/src/nsSystemPrincipal.cpp @@ -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); diff --git a/mozilla/dom/src/base/nsDOMClassInfo.cpp b/mozilla/dom/src/base/nsDOMClassInfo.cpp index af4e90478f4..8caaa661fd9 100644 --- a/mozilla/dom/src/base/nsDOMClassInfo.cpp +++ b/mozilla/dom/src/base/nsDOMClassInfo.cpp @@ -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; } diff --git a/mozilla/js/src/xpconnect/src/xpcjsid.cpp b/mozilla/js/src/xpconnect/src/xpcjsid.cpp index 880cff8c67d..dbc79855bb6 100644 --- a/mozilla/js/src/xpconnect/src/xpcjsid.cpp +++ b/mozilla/js/src/xpconnect/src/xpcjsid.cpp @@ -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()); } } diff --git a/mozilla/xpcom/components/nsGenericFactory.cpp b/mozilla/xpcom/components/nsGenericFactory.cpp index 889db8f2fbb..8adda5c43b4 100644 --- a/mozilla/xpcom/components/nsGenericFactory.cpp +++ b/mozilla/xpcom/components/nsGenericFactory.cpp @@ -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 fact; nsresult rv = NS_NewGenericFactory(getter_AddRefs(fact), desc); if (NS_FAILED(rv)) return rv; diff --git a/mozilla/xpcom/components/nsIClassInfo.idl b/mozilla/xpcom/components/nsIClassInfo.idl index 112ba22f82f..3f56287fd27 100644 --- a/mozilla/xpcom/components/nsIClassInfo.idl +++ b/mozilla/xpcom/components/nsIClassInfo.idl @@ -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? diff --git a/mozilla/xpcom/glue/nsGenericFactory.cpp b/mozilla/xpcom/glue/nsGenericFactory.cpp index 889db8f2fbb..8adda5c43b4 100644 --- a/mozilla/xpcom/glue/nsGenericFactory.cpp +++ b/mozilla/xpcom/glue/nsGenericFactory.cpp @@ -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 fact; nsresult rv = NS_NewGenericFactory(getter_AddRefs(fact), desc); if (NS_FAILED(rv)) return rv; diff --git a/mozilla/xpcom/io/nsFastLoadFile.cpp b/mozilla/xpcom/io/nsFastLoadFile.cpp index 1ce49142d3c..53c63829ba7 100644 --- a/mozilla/xpcom/io/nsFastLoadFile.cpp +++ b/mozilla/xpcom/io/nsFastLoadFile.cpp @@ -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;