зеркало из https://github.com/mozilla/gecko-dev.git
[OOPP] Serialize remaining Cocoa NPAPI events, including keyboard events. b=555300 r=cjones
This commit is contained in:
Родитель
a777551ae6
Коммит
4a2b551b96
|
@ -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(¶mCopy, sizeof(paramType));
|
||||
return;
|
||||
case NPCocoaEventDrawRect:
|
||||
// Don't serialize the context pointer
|
||||
paramCopy.event.data.draw.context = NULL;
|
||||
break;
|
||||
aMsg->WriteBytes(¶mCopy, sizeof(paramType));
|
||||
return;
|
||||
case NPCocoaEventFlagsChanged:
|
||||
paramCopy.event.data.key.characters = NULL;
|
||||
paramCopy.event.data.key.charactersIgnoringModifiers = NULL;
|
||||
aMsg->WriteBytes(¶mCopy, sizeof(paramType));
|
||||
return;
|
||||
case NPCocoaEventKeyDown:
|
||||
case NPCocoaEventKeyUp:
|
||||
case NPCocoaEventFlagsChanged:
|
||||
paramCopy.event.data.key.characters = NULL;
|
||||
paramCopy.event.data.key.charactersIgnoringModifiers = NULL;
|
||||
aMsg->WriteBytes(¶mCopy, 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(¶mCopy, 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(¶mCopy, 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>
|
||||
{
|
||||
|
|
Загрузка…
Ссылка в новой задаче