Bug 1409598 - Change nsIXPCScriptable::className and nsIClassInfo::{contractID,classDescription} from string to AUTF8String. r=froydnj.

This lets us replace moz_xstrdup() of string literals with AssignLiteral(),
among other improvements.

--HG--
extra : rebase_source : 9994d8ccb4f196cf63564b0dac2ae6c4370defb4
This commit is contained in:
Nicholas Nethercote 2017-10-18 13:17:26 +11:00
Родитель 2c90b0f880
Коммит 78030c0e7b
21 изменённых файлов: 134 добавлений и 138 удалений

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

@ -165,19 +165,17 @@ class ClassInfoData
{
public:
ClassInfoData(nsIClassInfo *aClassInfo, const char *aName)
: mClassInfo(aClassInfo),
mFlags(0),
mName(const_cast<char *>(aName)),
mDidGetFlags(false),
mMustFreeName(false)
: mClassInfo(aClassInfo),
mFlags(0),
mName(aName),
mDidGetFlags(false)
{
if (!aName) {
mName.SetIsVoid(true);
}
}
~ClassInfoData()
{
if (mMustFreeName)
free(mName);
}
~ClassInfoData() = default;
uint32_t GetFlags()
{
@ -202,29 +200,26 @@ public:
return !!(GetFlags() & nsIClassInfo::DOM_OBJECT);
}
const char* GetName()
void GetName(nsACString& aName)
{
if (!mName) {
if (mName.IsVoid()) {
if (mClassInfo) {
mClassInfo->GetClassDescription(&mName);
mClassInfo->GetClassDescription(mName);
}
if (mName) {
mMustFreeName = true;
} else {
mName = const_cast<char *>("UnnamedClass");
if (mName.IsVoid()) {
mName.AssignLiteral("UnnamedClass");
}
}
return mName;
aName = mName;
}
private:
nsIClassInfo *mClassInfo; // WEAK
uint32_t mFlags;
char *mName;
nsCString mName;
bool mDidGetFlags;
bool mMustFreeName;
};
/* static */
@ -1315,22 +1310,24 @@ nsScriptSecurityManager::CanCreateWrapper(JSContext *cx,
}
//-- Access denied, report an error
nsAutoCString origin;
nsAutoCString originUTF8;
nsIPrincipal* subjectPrincipal = nsContentUtils::SubjectPrincipal();
GetPrincipalDomainOrigin(subjectPrincipal, origin);
NS_ConvertUTF8toUTF16 originUnicode(origin);
NS_ConvertUTF8toUTF16 classInfoName(objClassInfo.GetName());
GetPrincipalDomainOrigin(subjectPrincipal, originUTF8);
NS_ConvertUTF8toUTF16 originUTF16(originUTF8);
nsAutoCString classInfoNameUTF8;
objClassInfo.GetName(classInfoNameUTF8);
NS_ConvertUTF8toUTF16 classInfoUTF16(classInfoNameUTF8);
nsresult rv;
nsAutoString errorMsg;
if (originUnicode.IsEmpty()) {
const char16_t* formatStrings[] = { classInfoName.get() };
if (originUTF16.IsEmpty()) {
const char16_t* formatStrings[] = { classInfoUTF16.get() };
rv = sStrBundle->FormatStringFromName("CreateWrapperDenied",
formatStrings,
1,
errorMsg);
} else {
const char16_t* formatStrings[] = { classInfoName.get(),
originUnicode.get() };
const char16_t* formatStrings[] = { classInfoUTF16.get(),
originUTF16.get() };
rv = sStrBundle->FormatStringFromName("CreateWrapperDeniedForOrigin",
formatStrings,
2,

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

@ -562,15 +562,14 @@ nsDOMClassInfo::GetScriptableHelper(nsIXPCScriptable **_retval)
}
NS_IMETHODIMP
nsDOMClassInfo::GetContractID(char **aContractID)
nsDOMClassInfo::GetContractID(nsACString& aContractID)
{
*aContractID = nullptr;
aContractID.SetIsVoid(true);
return NS_OK;
}
NS_IMETHODIMP
nsDOMClassInfo::GetClassDescription(char **aClassDescription)
nsDOMClassInfo::GetClassDescription(nsACString& aClassDescription)
{
return GetClassName(aClassDescription);
}
@ -599,10 +598,9 @@ nsDOMClassInfo::GetFlags(uint32_t *aFlags)
// nsIXPCScriptable
NS_IMETHODIMP
nsDOMClassInfo::GetClassName(char **aClassName)
nsDOMClassInfo::GetClassName(nsACString& aClassName)
{
*aClassName = NS_strdup(mData->mClass.name);
aClassName.Assign(mData->mClass.name);
return NS_OK;
}

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

@ -244,18 +244,18 @@ nsHostObjectURI::GetScriptableHelper(nsIXPCScriptable **_retval)
}
NS_IMETHODIMP
nsHostObjectURI::GetContractID(char * *aContractID)
nsHostObjectURI::GetContractID(nsACString& aContractID)
{
// Make sure to modify any subclasses as needed if this ever
// changes.
*aContractID = nullptr;
aContractID.SetIsVoid(true);
return NS_OK;
}
NS_IMETHODIMP
nsHostObjectURI::GetClassDescription(char * *aClassDescription)
nsHostObjectURI::GetClassDescription(nsACString& aClassDescription)
{
*aClassDescription = nullptr;
aClassDescription.SetIsVoid(true);
return NS_OK;
}

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

@ -66,7 +66,7 @@ interface nsIXPConnectWrappedNative;
[uuid(19b70b26-7c3f-437f-a04a-2a8f9e28b617)]
interface nsIXPCScriptable : nsISupports
{
readonly attribute string className;
readonly attribute AUTF8String className;
[notxpcom,nostdcall] uint32_t getScriptableFlags();
[notxpcom,nostdcall] jsClassPtr getClass();
[notxpcom,nostdcall] JSClassPtr getJSClass();

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

@ -23,9 +23,9 @@
/**************************************************************/
NS_IMETHODIMP XPC_MAP_CLASSNAME::GetClassName(char * *aClassName)
NS_IMETHODIMP XPC_MAP_CLASSNAME::GetClassName(nsACString& aClassName)
{
*aClassName = moz_xstrdup(XPC_MAP_QUOTED_CLASSNAME);
aClassName.AssignLiteral(XPC_MAP_QUOTED_CLASSNAME);
return NS_OK;
}

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

@ -140,16 +140,16 @@ nsXPCComponents_Interfaces::GetScriptableHelper(nsIXPCScriptable** retval)
}
NS_IMETHODIMP
nsXPCComponents_Interfaces::GetContractID(char * *aContractID)
nsXPCComponents_Interfaces::GetContractID(nsACString& aContractID)
{
*aContractID = nullptr;
aContractID.SetIsVoid(true);
return NS_ERROR_NOT_AVAILABLE;
}
NS_IMETHODIMP
nsXPCComponents_Interfaces::GetClassDescription(char * *aClassDescription)
nsXPCComponents_Interfaces::GetClassDescription(nsACString& aClassDescription)
{
*aClassDescription = moz_xstrdup("XPCComponents_Interfaces");
aClassDescription.AssignLiteral("XPCComponents_Interfaces");
return NS_OK;
}
@ -344,16 +344,17 @@ nsXPCComponents_InterfacesByID::GetScriptableHelper(nsIXPCScriptable** retval)
}
NS_IMETHODIMP
nsXPCComponents_InterfacesByID::GetContractID(char * *aContractID)
nsXPCComponents_InterfacesByID::GetContractID(nsACString& aContractID)
{
*aContractID = nullptr;
aContractID.SetIsVoid(true);
return NS_ERROR_NOT_AVAILABLE;
}
NS_IMETHODIMP
nsXPCComponents_InterfacesByID::GetClassDescription(char * *aClassDescription)
nsXPCComponents_InterfacesByID::GetClassDescription(
nsACString& aClassDescription)
{
*aClassDescription = moz_xstrdup("XPCComponents_InterfacesByID");
aClassDescription.AssignLiteral("XPCComponents_InterfacesByID");
return NS_OK;
}
@ -550,16 +551,16 @@ nsXPCComponents_Classes::GetScriptableHelper(nsIXPCScriptable** retval)
}
NS_IMETHODIMP
nsXPCComponents_Classes::GetContractID(char * *aContractID)
nsXPCComponents_Classes::GetContractID(nsACString& aContractID)
{
*aContractID = nullptr;
aContractID.SetIsVoid(true);
return NS_ERROR_NOT_AVAILABLE;
}
NS_IMETHODIMP
nsXPCComponents_Classes::GetClassDescription(char * *aClassDescription)
nsXPCComponents_Classes::GetClassDescription(nsACString& aClassDescription)
{
*aClassDescription = moz_xstrdup("XPCComponents_Classes");
aClassDescription.AssignLiteral("XPCComponents_Classes");
return NS_OK;
}
@ -744,16 +745,16 @@ nsXPCComponents_ClassesByID::GetScriptableHelper(nsIXPCScriptable** retval)
}
NS_IMETHODIMP
nsXPCComponents_ClassesByID::GetContractID(char * *aContractID)
nsXPCComponents_ClassesByID::GetContractID(nsACString& aContractID)
{
*aContractID = nullptr;
aContractID.SetIsVoid(true);
return NS_ERROR_NOT_AVAILABLE;
}
NS_IMETHODIMP
nsXPCComponents_ClassesByID::GetClassDescription(char * *aClassDescription)
nsXPCComponents_ClassesByID::GetClassDescription(nsACString& aClassDescription)
{
*aClassDescription = moz_xstrdup("XPCComponents_ClassesByID");
aClassDescription.AssignLiteral("XPCComponents_ClassesByID");
return NS_OK;
}
@ -953,16 +954,16 @@ nsXPCComponents_Results::GetScriptableHelper(nsIXPCScriptable** retval)
}
NS_IMETHODIMP
nsXPCComponents_Results::GetContractID(char * *aContractID)
nsXPCComponents_Results::GetContractID(nsACString& aContractID)
{
*aContractID = nullptr;
aContractID.SetIsVoid(true);
return NS_ERROR_NOT_AVAILABLE;
}
NS_IMETHODIMP
nsXPCComponents_Results::GetClassDescription(char * *aClassDescription)
nsXPCComponents_Results::GetClassDescription(nsACString& aClassDescription)
{
*aClassDescription = moz_xstrdup("XPCComponents_Results");
aClassDescription.AssignLiteral("XPCComponents_Results");
return NS_OK;
}
@ -1122,16 +1123,16 @@ nsXPCComponents_ID::GetScriptableHelper(nsIXPCScriptable** retval)
}
NS_IMETHODIMP
nsXPCComponents_ID::GetContractID(char * *aContractID)
nsXPCComponents_ID::GetContractID(nsACString& aContractID)
{
*aContractID = nullptr;
aContractID.SetIsVoid(true);
return NS_ERROR_NOT_AVAILABLE;
}
NS_IMETHODIMP
nsXPCComponents_ID::GetClassDescription(char * *aClassDescription)
nsXPCComponents_ID::GetClassDescription(nsACString& aClassDescription)
{
*aClassDescription = moz_xstrdup("XPCComponents_ID");
aClassDescription.AssignLiteral("XPCComponents_ID");
return NS_OK;
}
@ -1298,16 +1299,16 @@ nsXPCComponents_Exception::GetScriptableHelper(nsIXPCScriptable** retval)
}
NS_IMETHODIMP
nsXPCComponents_Exception::GetContractID(char * *aContractID)
nsXPCComponents_Exception::GetContractID(nsACString& aContractID)
{
*aContractID = nullptr;
aContractID.SetIsVoid(true);
return NS_ERROR_NOT_AVAILABLE;
}
NS_IMETHODIMP
nsXPCComponents_Exception::GetClassDescription(char * *aClassDescription)
nsXPCComponents_Exception::GetClassDescription(nsACString& aClassDescription)
{
*aClassDescription = moz_xstrdup("XPCComponents_Exception");
aClassDescription.AssignLiteral("XPCComponents_Exception");
return NS_OK;
}
@ -1641,16 +1642,16 @@ nsXPCConstructor::GetScriptableHelper(nsIXPCScriptable** retval)
}
NS_IMETHODIMP
nsXPCConstructor::GetContractID(char * *aContractID)
nsXPCConstructor::GetContractID(nsACString& aContractID)
{
*aContractID = nullptr;
aContractID.SetIsVoid(true);
return NS_ERROR_NOT_AVAILABLE;
}
NS_IMETHODIMP
nsXPCConstructor::GetClassDescription(char * *aClassDescription)
nsXPCConstructor::GetClassDescription(nsACString& aClassDescription)
{
*aClassDescription = moz_xstrdup("XPCConstructor");
aClassDescription.AssignLiteral("XPCConstructor");
return NS_OK;
}
@ -1842,16 +1843,16 @@ nsXPCComponents_Constructor::GetScriptableHelper(nsIXPCScriptable** retval)
}
NS_IMETHODIMP
nsXPCComponents_Constructor::GetContractID(char * *aContractID)
nsXPCComponents_Constructor::GetContractID(nsACString& aContractID)
{
*aContractID = nullptr;
aContractID.SetIsVoid(true);
return NS_ERROR_NOT_AVAILABLE;
}
NS_IMETHODIMP
nsXPCComponents_Constructor::GetClassDescription(char * *aClassDescription)
nsXPCComponents_Constructor::GetClassDescription(nsACString& aClassDescription)
{
*aClassDescription = moz_xstrdup("XPCComponents_Constructor");
aClassDescription.AssignLiteral("XPCComponents_Constructor");
return NS_OK;
}

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

@ -98,16 +98,16 @@ BackstagePass::GetScriptableHelper(nsIXPCScriptable** retval)
}
NS_IMETHODIMP
BackstagePass::GetContractID(char * *aContractID)
BackstagePass::GetContractID(nsACString& aContractID)
{
*aContractID = nullptr;
aContractID.SetIsVoid(true);
return NS_ERROR_NOT_AVAILABLE;
}
NS_IMETHODIMP
BackstagePass::GetClassDescription(char * *aClassDescription)
BackstagePass::GetClassDescription(nsACString& aClassDescription)
{
*aClassDescription = moz_xstrdup("BackstagePass");
aClassDescription.AssignLiteral("BackstagePass");
return NS_OK;
}

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

@ -172,16 +172,16 @@ nsJARURI::GetScriptableHelper(nsIXPCScriptable **_retval)
}
NS_IMETHODIMP
nsJARURI::GetContractID(char * *aContractID)
nsJARURI::GetContractID(nsACString& aContractID)
{
*aContractID = nullptr;
aContractID.SetIsVoid(true);
return NS_OK;
}
NS_IMETHODIMP
nsJARURI::GetClassDescription(char * *aClassDescription)
nsJARURI::GetClassDescription(nsACString& aClassDescription)
{
*aClassDescription = nullptr;
aClassDescription.SetIsVoid(true);
return NS_OK;
}

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

@ -681,16 +681,16 @@ RustURL::GetScriptableHelper(nsIXPCScriptable * *_retval)
}
NS_IMETHODIMP
RustURL::GetContractID(char * *aContractID)
RustURL::GetContractID(nsACString& aContractID)
{
*aContractID = nullptr;
aContractID.SetIsVoid(true);
return NS_OK;
}
NS_IMETHODIMP
RustURL::GetClassDescription(char * *aClassDescription)
RustURL::GetClassDescription(nsACString& aClassDescription)
{
*aClassDescription = nullptr;
aClassDescription.SetIsVoid(true);
return NS_OK;
}

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

@ -744,18 +744,18 @@ nsSimpleURI::GetScriptableHelper(nsIXPCScriptable **_retval)
}
NS_IMETHODIMP
nsSimpleURI::GetContractID(char * *aContractID)
nsSimpleURI::GetContractID(nsACString& aContractID)
{
// Make sure to modify any subclasses as needed if this ever
// changes.
*aContractID = nullptr;
aContractID.SetIsVoid(true);
return NS_OK;
}
NS_IMETHODIMP
nsSimpleURI::GetClassDescription(char * *aClassDescription)
nsSimpleURI::GetClassDescription(nsACString& aClassDescription)
{
*aClassDescription = nullptr;
aClassDescription.SetIsVoid(true);
return NS_OK;
}

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

@ -2971,16 +2971,16 @@ nsSocketTransport::GetScriptableHelper(nsIXPCScriptable **_retval)
}
NS_IMETHODIMP
nsSocketTransport::GetContractID(char * *aContractID)
nsSocketTransport::GetContractID(nsACString& aContractID)
{
*aContractID = nullptr;
aContractID.SetIsVoid(true);
return NS_OK;
}
NS_IMETHODIMP
nsSocketTransport::GetClassDescription(char * *aClassDescription)
nsSocketTransport::GetClassDescription(nsACString& aClassDescription)
{
*aClassDescription = nullptr;
aClassDescription.SetIsVoid(true);
return NS_OK;
}

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

@ -3838,16 +3838,16 @@ nsStandardURL::GetScriptableHelper(nsIXPCScriptable **_retval)
}
NS_IMETHODIMP
nsStandardURL::GetContractID(char * *aContractID)
nsStandardURL::GetContractID(nsACString& aContractID)
{
*aContractID = nullptr;
aContractID.SetIsVoid(true);
return NS_OK;
}
NS_IMETHODIMP
nsStandardURL::GetClassDescription(char * *aClassDescription)
nsStandardURL::GetClassDescription(nsACString& aClassDescription)
{
*aClassDescription = nullptr;
aClassDescription.SetIsVoid(true);
return NS_OK;
}

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

@ -432,16 +432,16 @@ TransportSecurityInfo::GetScriptableHelper(nsIXPCScriptable **_retval)
}
NS_IMETHODIMP
TransportSecurityInfo::GetContractID(char * *aContractID)
TransportSecurityInfo::GetContractID(nsACString& aContractID)
{
*aContractID = nullptr;
aContractID.SetIsVoid(true);
return NS_OK;
}
NS_IMETHODIMP
TransportSecurityInfo::GetClassDescription(char * *aClassDescription)
TransportSecurityInfo::GetClassDescription(nsACString& aClassDescription)
{
*aClassDescription = nullptr;
aClassDescription.SetIsVoid(true);
return NS_OK;
}

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

@ -1538,16 +1538,16 @@ nsNSSCertificate::GetScriptableHelper(nsIXPCScriptable** _retval)
}
NS_IMETHODIMP
nsNSSCertificate::GetContractID(char** aContractID)
nsNSSCertificate::GetContractID(nsACString& aContractID)
{
*aContractID = nullptr;
aContractID.SetIsVoid(true);
return NS_OK;
}
NS_IMETHODIMP
nsNSSCertificate::GetClassDescription(char** aClassDescription)
nsNSSCertificate::GetClassDescription(nsACString& aClassDescription)
{
*aClassDescription = nullptr;
aClassDescription.SetIsVoid(true);
return NS_OK;
}

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

@ -294,16 +294,16 @@ nsSSLStatus::GetScriptableHelper(nsIXPCScriptable** aHelper)
}
NS_IMETHODIMP
nsSSLStatus::GetContractID(char** aContractID)
nsSSLStatus::GetContractID(nsACString& aContractID)
{
*aContractID = nullptr;
aContractID.SetIsVoid(true);
return NS_OK;
}
NS_IMETHODIMP
nsSSLStatus::GetClassDescription(char** aClassDescription)
nsSSLStatus::GetClassDescription(nsACString& aClassDescription)
{
*aClassDescription = nullptr;
aClassDescription.SetIsVoid(true);
return NS_OK;
}

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

@ -63,16 +63,16 @@ public:
}
NS_IMETHOD
GetContractID(char **_contractID) override
GetContractID(nsACString& aContractID) override
{
*_contractID = nullptr;
aContractID.SetIsVoid(true);
return NS_OK;
}
NS_IMETHOD
GetClassDescription(char **_desc) override
GetClassDescription(nsACString& aDesc) override
{
*_desc = nullptr;
aDesc.SetIsVoid(true);
return NS_OK;
}

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

@ -66,16 +66,16 @@ public:
}
NS_IMETHOD
GetContractID(char **_contractID) override
GetContractID(nsACString& aContractID) override
{
*_contractID = nullptr;
aContractID.SetIsVoid(true);
return NS_OK;
}
NS_IMETHOD
GetClassDescription(char **_desc) override
GetClassDescription(nsACString& aDesc) override
{
*_desc = nullptr;
aDesc.SetIsVoid(true);
return NS_OK;
}

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

@ -36,17 +36,17 @@ GenericClassInfo::GetScriptableHelper(nsIXPCScriptable** aHelper)
}
NS_IMETHODIMP
GenericClassInfo::GetContractID(char** aContractID)
GenericClassInfo::GetContractID(nsACString& aContractID)
{
NS_ERROR("GetContractID not implemented");
*aContractID = nullptr;
aContractID.SetIsVoid(true);
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
GenericClassInfo::GetClassDescription(char** aDescription)
GenericClassInfo::GetClassDescription(nsACString& aDescription)
{
*aDescription = nullptr;
aDescription.SetIsVoid(true);
return NS_ERROR_NOT_IMPLEMENTED;
}

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

@ -1206,16 +1206,16 @@ _class::GetScriptableHelper(nsIXPCScriptable** _retval) \
} \
\
NS_IMETHODIMP \
_class::GetContractID(char** _contractID) \
_class::GetContractID(nsACString& _contractID) \
{ \
*_contractID = nullptr; \
_contractID.SetIsVoid(true); \
return NS_OK; \
} \
\
NS_IMETHODIMP \
_class::GetClassDescription(char** _classDescription) \
_class::GetClassDescription(nsACString& _classDescription) \
{ \
*_classDescription = nullptr; \
_classDescription.SetIsVoid(true); \
return NS_OK; \
} \
\

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

@ -36,14 +36,14 @@ interface nsIClassInfo : nsISupports
/**
* A contract ID through which an instance of this class can be created
* (or accessed as a service, if |flags & SINGLETON|), or null.
* (or accessed as a service, if |flags & SINGLETON|), or null/void.
*/
readonly attribute string contractID;
readonly attribute AUTF8String contractID;
/**
* A human readable string naming the class, or null.
* A human readable string naming the class, or null/void.
*/
readonly attribute string classDescription;
readonly attribute AUTF8String classDescription;
/**
* A class ID through which an instance of this class can be created

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

@ -143,16 +143,16 @@ nsThreadClassInfo::GetScriptableHelper(nsIXPCScriptable** aResult)
}
NS_IMETHODIMP
nsThreadClassInfo::GetContractID(char** aResult)
nsThreadClassInfo::GetContractID(nsACString& aResult)
{
*aResult = nullptr;
aResult.SetIsVoid(true);
return NS_OK;
}
NS_IMETHODIMP
nsThreadClassInfo::GetClassDescription(char** aResult)
nsThreadClassInfo::GetClassDescription(nsACString& aResult)
{
*aResult = nullptr;
aResult.SetIsVoid(true);
return NS_OK;
}