Bug 1240904 - Remove ParamTraits for NPString and NPVariant. r=bsmedberg

These are unused. PPluginScriptableObject uses its own Variant type
for IPC. Furthermore, there is a bug in ParamTraits<NPString>::Read
that ends up copying out uninitialized memory.
This commit is contained in:
Andrew McCreight 2016-01-26 11:29:00 +01:00
Родитель 1859d04f33
Коммит d079897c17
1 изменённых файлов: 0 добавлений и 174 удалений

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

@ -408,44 +408,6 @@ struct ParamTraits<mozilla::plugins::NPRemoteWindow>
}
};
template <>
struct ParamTraits<NPString>
{
typedef NPString paramType;
static void Write(Message* aMsg, const paramType& aParam)
{
WriteParam(aMsg, aParam.UTF8Length);
aMsg->WriteBytes(aParam.UTF8Characters,
aParam.UTF8Length * sizeof(NPUTF8));
}
static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
{
if (ReadParam(aMsg, aIter, &aResult->UTF8Length)) {
int byteCount = aResult->UTF8Length * sizeof(NPUTF8);
if (!byteCount) {
aResult->UTF8Characters = "\0";
return true;
}
const char* messageBuffer = nullptr;
mozilla::UniquePtr<char[]> newBuffer(new char[byteCount]);
if (newBuffer && aMsg->ReadBytes(aIter, &messageBuffer, byteCount )) {
memcpy((void*)messageBuffer, newBuffer.get(), byteCount);
aResult->UTF8Characters = newBuffer.release();
return true;
}
}
return false;
}
static void Log(const paramType& aParam, std::wstring* aLog)
{
aLog->append(StringPrintf(L"%s", aParam.UTF8Characters));
}
};
#ifdef XP_MACOSX
template <>
struct ParamTraits<NPNSString*>
@ -611,142 +573,6 @@ struct ParamTraits<NSCursorInfo>
};
#endif // #ifdef XP_MACOSX
template <>
struct ParamTraits<NPVariant>
{
typedef NPVariant paramType;
static void Write(Message* aMsg, const paramType& aParam)
{
if (NPVARIANT_IS_VOID(aParam)) {
aMsg->WriteInt(0);
return;
}
if (NPVARIANT_IS_NULL(aParam)) {
aMsg->WriteInt(1);
return;
}
if (NPVARIANT_IS_BOOLEAN(aParam)) {
aMsg->WriteInt(2);
WriteParam(aMsg, NPVARIANT_TO_BOOLEAN(aParam));
return;
}
if (NPVARIANT_IS_INT32(aParam)) {
aMsg->WriteInt(3);
WriteParam(aMsg, NPVARIANT_TO_INT32(aParam));
return;
}
if (NPVARIANT_IS_DOUBLE(aParam)) {
aMsg->WriteInt(4);
WriteParam(aMsg, NPVARIANT_TO_DOUBLE(aParam));
return;
}
if (NPVARIANT_IS_STRING(aParam)) {
aMsg->WriteInt(5);
WriteParam(aMsg, NPVARIANT_TO_STRING(aParam));
return;
}
NS_ERROR("Unsupported type!");
}
static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
{
int type;
if (!aMsg->ReadInt(aIter, &type)) {
return false;
}
switch (type) {
case 0:
VOID_TO_NPVARIANT(*aResult);
return true;
case 1:
NULL_TO_NPVARIANT(*aResult);
return true;
case 2: {
bool value;
if (ReadParam(aMsg, aIter, &value)) {
BOOLEAN_TO_NPVARIANT(value, *aResult);
return true;
}
} break;
case 3: {
int32_t value;
if (ReadParam(aMsg, aIter, &value)) {
INT32_TO_NPVARIANT(value, *aResult);
return true;
}
} break;
case 4: {
double value;
if (ReadParam(aMsg, aIter, &value)) {
DOUBLE_TO_NPVARIANT(value, *aResult);
return true;
}
} break;
case 5: {
NPString value;
if (ReadParam(aMsg, aIter, &value)) {
STRINGN_TO_NPVARIANT(value.UTF8Characters, value.UTF8Length,
*aResult);
return true;
}
} break;
default:
NS_ERROR("Unsupported type!");
}
return false;
}
static void Log(const paramType& aParam, std::wstring* aLog)
{
if (NPVARIANT_IS_VOID(aParam)) {
aLog->append(L"[void]");
return;
}
if (NPVARIANT_IS_NULL(aParam)) {
aLog->append(L"[null]");
return;
}
if (NPVARIANT_IS_BOOLEAN(aParam)) {
LogParam(NPVARIANT_TO_BOOLEAN(aParam), aLog);
return;
}
if (NPVARIANT_IS_INT32(aParam)) {
LogParam(NPVARIANT_TO_INT32(aParam), aLog);
return;
}
if (NPVARIANT_IS_DOUBLE(aParam)) {
LogParam(NPVARIANT_TO_DOUBLE(aParam), aLog);
return;
}
if (NPVARIANT_IS_STRING(aParam)) {
LogParam(NPVARIANT_TO_STRING(aParam), aLog);
return;
}
NS_ERROR("Unsupported type!");
}
};
template <>
struct ParamTraits<mozilla::plugins::IPCByteRange>
{