[OOPP] Serialize remaining Cocoa NPAPI events, including keyboard events. b=555300 r=cjones

This commit is contained in:
Josh Aas 2010-03-29 15:27:49 -04:00
Родитель a777551ae6
Коммит 4a2b551b96
3 изменённых файлов: 118 добавлений и 9 удалений

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

@ -79,22 +79,34 @@ struct ParamTraits<mozilla::plugins::NPRemoteEvent>
case NPCocoaEventFocusChanged:
case NPCocoaEventWindowFocusChanged:
case NPCocoaEventScrollWheel:
// Nothing special to do for these events.
break;
aMsg->WriteBytes(&paramCopy, sizeof(paramType));
return;
case NPCocoaEventDrawRect:
// Don't serialize the context pointer
paramCopy.event.data.draw.context = NULL;
break;
aMsg->WriteBytes(&paramCopy, sizeof(paramType));
return;
case NPCocoaEventFlagsChanged:
paramCopy.event.data.key.characters = NULL;
paramCopy.event.data.key.charactersIgnoringModifiers = NULL;
aMsg->WriteBytes(&paramCopy, sizeof(paramType));
return;
case NPCocoaEventKeyDown:
case NPCocoaEventKeyUp:
case NPCocoaEventFlagsChanged:
paramCopy.event.data.key.characters = NULL;
paramCopy.event.data.key.charactersIgnoringModifiers = NULL;
aMsg->WriteBytes(&paramCopy, sizeof(paramType));
WriteParam(aMsg, aParam.event.data.key.characters);
WriteParam(aMsg, aParam.event.data.key.charactersIgnoringModifiers);
return;
case NPCocoaEventTextInput:
paramCopy.event.data.text.text = NULL;
aMsg->WriteBytes(&paramCopy, sizeof(paramType));
WriteParam(aMsg, aParam.event.data.text.text);
return;
default:
// ignore any events we don't expect
return;
NS_NOTREACHED("Attempted to serialize unknown event type.");
return;
}
aMsg->WriteBytes(&paramCopy, sizeof(paramType));
}
static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
@ -106,6 +118,36 @@ struct ParamTraits<mozilla::plugins::NPRemoteEvent>
}
memcpy(aResult, bytes, sizeof(paramType));
switch (aResult->event.type) {
case NPCocoaEventMouseDown:
case NPCocoaEventMouseUp:
case NPCocoaEventMouseMoved:
case NPCocoaEventMouseEntered:
case NPCocoaEventMouseExited:
case NPCocoaEventMouseDragged:
case NPCocoaEventFocusChanged:
case NPCocoaEventWindowFocusChanged:
case NPCocoaEventScrollWheel:
case NPCocoaEventDrawRect:
case NPCocoaEventFlagsChanged:
break;
case NPCocoaEventKeyDown:
case NPCocoaEventKeyUp:
if (!ReadParam(aMsg, aIter, &aResult->event.data.key.characters) ||
!ReadParam(aMsg, aIter, &aResult->event.data.key.charactersIgnoringModifiers)) {
return false;
}
break;
case NPCocoaEventTextInput:
if (!ReadParam(aMsg, aIter, &aResult->event.data.text.text)) {
return false;
}
break;
default:
// ignore any events we don't expect
return false;
}
return true;
}

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

@ -547,6 +547,18 @@ PluginInstanceChild::AnswerNPP_HandleEvent(const NPRemoteEvent& event,
else
*handled = mPluginIface->event(&mData, reinterpret_cast<void*>(&evcopy));
#ifdef XP_MACOSX
// Release any reference counted objects created in the child process.
if (evcopy.type == NPCocoaEventKeyDown ||
evcopy.type == NPCocoaEventKeyUp) {
::CFRelease((CFStringRef)evcopy.data.key.characters);
::CFRelease((CFStringRef)evcopy.data.key.charactersIgnoringModifiers);
}
else if (evcopy.type == NPCocoaEventTextInput) {
::CFRelease((CFStringRef)evcopy.data.text.text);
}
#endif
#ifdef MOZ_X11
if (GraphicsExpose == event.event.type) {
// Make sure the X server completes the drawing before the parent

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

@ -445,6 +445,61 @@ struct ParamTraits<NPString>
}
};
#ifdef XP_MACOSX
template <>
struct ParamTraits<NPNSString*>
{
typedef NPNSString* paramType;
// Empty string writes a length of 0 and no buffer.
// We don't write a NULL terminating character in buffers.
static void Write(Message* aMsg, const paramType& aParam)
{
CFStringRef cfString = (CFStringRef)aParam;
long length = ::CFStringGetLength(cfString);
WriteParam(aMsg, length);
if (length == 0) {
return;
}
// Attempt to get characters without any allocation/conversion.
if (::CFStringGetCharactersPtr(cfString)) {
aMsg->WriteBytes(::CFStringGetCharactersPtr(cfString), length * sizeof(UniChar));
} else {
UniChar *buffer = (UniChar*)moz_xmalloc(length * sizeof(UniChar));
::CFStringGetCharacters(cfString, ::CFRangeMake(0, length), buffer);
aMsg->WriteBytes(buffer, length * sizeof(UniChar));
free(buffer);
}
}
static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
{
long length;
if (!ReadParam(aMsg, aIter, &length)) {
return false;
}
UniChar* buffer = nsnull;
if (length != 0) {
if (!aMsg->ReadBytes(aIter, (const char**)&buffer, length * sizeof(UniChar)) ||
!buffer) {
return false;
}
}
*aResult = (NPNSString*)::CFStringCreateWithBytes(kCFAllocatorDefault, (UInt8*)buffer,
length * sizeof(UniChar),
kCFStringEncodingUTF16, false);
if (!*aResult) {
return false;
}
return true;
}
};
#endif
template <>
struct ParamTraits<NPVariant>
{