Bug 522122. Electrolysis: Forawrd windows events to windowless plugins. r=cjones,karlt

This gets windowless plugin events mostly working. We don't forward IME events because
they are much more complicated.
This commit is contained in:
Jeff Muizelaar 2009-10-27 15:58:33 -04:00
parent 39b3aac40a
commit 31d0efb7ae
7 changed files with 126 additions and 15 deletions

View File

@ -41,28 +41,125 @@
#include "npapi.h"
namespace mozilla {
#pragma message(__FILE__ ": This is only a stub implementation IMPLEMENT ME")
namespace plugins {
// We use an NPRemoteEvent struct so that we can store the extra data on
// the stack so that we don't need to worry about managing the memory.
struct NPRemoteEvent
{
NPEvent event;
union {
NPRect rect;
WINDOWPOS windowpos;
} lParamData;
};
}
}
namespace IPC {
template <>
struct ParamTraits<NPEvent>
struct ParamTraits<mozilla::plugins::NPRemoteEvent>
{
typedef NPEvent paramType;
typedef mozilla::plugins::NPRemoteEvent paramType;
static void Write(Message* aMsg, const paramType& aParam)
{
// Make a non-const copy of aParam so that we can muck with
// its insides for tranport
paramType paramCopy;
paramCopy.event = aParam.event;
// We can't blindly ipc events because they may sometimes contain
// pointers to memory in the sending process. For example, the
// WM_IME_CONTROL with the IMC_GETCOMPOSITIONFONT message has lParam
// set to a pointer to a LOGFONT structure.
switch (paramCopy.event.event) {
case WM_WINDOWPOSCHANGED:
// The lParam paramter of WM_WINDOWPOSCHANGED holds a pointer to
// a WINDOWPOS structure that contains information about the
// window's new size and position
paramCopy.lParamData.windowpos = *(reinterpret_cast<WINDOWPOS*>(paramCopy.event.lParam));
break;
case WM_PAINT:
// The lParam paramter of WM_PAINT holds a pointer to an NPRect
// structure specifying the bounding box of the update area.
paramCopy.lParamData.rect = *(reinterpret_cast<NPRect*>(paramCopy.event.lParam));
break;
// the white list of events that we will ipc to the client
case WM_CHAR:
case WM_SYSCHAR:
case WM_KEYUP:
case WM_SYSKEYUP:
case WM_KEYDOWN:
case WM_SYSKEYDOWN:
case WM_DEADCHAR:
case WM_SYSDEADCHAR:
case WM_CONTEXTMENU:
case WM_CUT:
case WM_COPY:
case WM_PASTE:
case WM_CLEAR:
case WM_UNDO:
case WM_MOUSEMOVE:
case WM_LBUTTONDOWN:
case WM_MBUTTONDOWN:
case WM_RBUTTONDOWN:
case WM_LBUTTONUP:
case WM_MBUTTONUP:
case WM_RBUTTONUP:
case WM_LBUTTONDBLCLK:
case WM_MBUTTONDBLCLK:
case WM_RBUTTONDBLCLK:
case WM_SETFOCUS:
case WM_KILLFOCUS:
break;
// ignore any events we don't expect
default:
return;
}
aMsg->WriteBytes(&paramCopy, sizeof(paramType));
}
static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
{
const char* bytes = 0;
if (!aMsg->ReadBytes(aIter, &bytes, sizeof(paramType))) {
return false;
}
memcpy(aResult, bytes, sizeof(paramType));
if (aResult->event.event == WM_PAINT) {
// restore the lParam to point at the NPRect
aResult->event.lParam = reinterpret_cast<LPARAM>(&aResult->lParamData.rect);
} else if (aResult->event.event == WM_WINDOWPOSCHANGED) {
// restore the lParam to point at the WINDOWPOS
aResult->event.lParam = reinterpret_cast<LPARAM>(&aResult->lParamData.windowpos);
}
return true;
}
static void Log(const paramType& aParam, std::wstring* aLog)
{
aLog->append(L"(WINEvent)");
}
};
} // namespace IPC

View File

@ -48,6 +48,19 @@
#include "npapi.h"
namespace mozilla {
namespace plugins {
struct NPRemoteEvent {
NPEvent event;
};
}
}
//
// XEvent is defined as a union of all more specific X*Events.
// Luckily, as of xorg 1.6.0 / X protocol 11 rev 0, the only pointer
@ -68,9 +81,9 @@
namespace IPC {
template <>
struct ParamTraits<NPEvent> // synonym for XEvent
struct ParamTraits<mozilla::plugins::NPRemoteEvent> // synonym for XEvent
{
typedef NPEvent paramType;
typedef mozilla::plugins::NPRemoteEvent paramType;
static void Write(Message* aMsg, const paramType& aParam)
{
@ -86,7 +99,7 @@ struct ParamTraits<NPEvent> // synonym for XEvent
}
memcpy(aResult, bytes, sizeof(paramType));
SetXDisplay(*aResult);
SetXDisplay(aResult->event);
return true;
}

View File

@ -46,8 +46,8 @@ include protocol "PStreamNotify.ipdl";
include "mozilla/plugins/PluginMessageUtils.h";
using NPError;
using NPEvent;
using NPRemoteWindow;
using NPRemoteEvent;
using NPReason;
using NPRect;
@ -77,7 +77,7 @@ child:
rpc NPP_GetValue_NPPVpluginScriptableNPObject()
returns (PPluginScriptableObject value, NPError result);
rpc NPP_HandleEvent(NPEvent event)
rpc NPP_HandleEvent(NPRemoteEvent event)
returns (int16_t handled);
parent:

View File

@ -94,7 +94,7 @@ PluginInstanceChild::NPN_GetValue(NPNVariable aVar,
switch(aVar) {
case NPNVSupportsWindowless:
#if defined(OS_LINUX)
#if defined(OS_LINUX) || defined(OS_WIN)
*((NPBool*)aValue) = true;
#else
*((NPBool*)aValue) = false;
@ -307,7 +307,7 @@ PluginInstanceChild::AnswerNPP_GetValue_NPPVpluginScriptableNPObject(
}
bool
PluginInstanceChild::AnswerNPP_HandleEvent(const NPEvent& event,
PluginInstanceChild::AnswerNPP_HandleEvent(const NPRemoteEvent& event,
int16_t* handled)
{
_MOZ_LOG(__FUNCTION__);
@ -320,7 +320,7 @@ PluginInstanceChild::AnswerNPP_HandleEvent(const NPEvent& event,
#endif
// plugins might be fooling with these, make a copy
NPEvent evcopy = event;
NPEvent evcopy = event.event;
*handled = mPluginIface->event(&mData, reinterpret_cast<void*>(&evcopy));
#ifdef MOZ_X11
@ -407,7 +407,7 @@ PluginInstanceChild::AnswerNPP_SetWindow(const NPRemoteWindow& aWindow,
mWindow.y = aWindow.y;
mWindow.width = aWindow.width;
mWindow.height = aWindow.height;
mWindow.type = NPWindowTypeWindow;
mWindow.type = aWindow.type;
*rv = mPluginIface->setwindow(&mData, &mWindow);
if (*rv == NPERR_NO_ERROR) {

View File

@ -82,7 +82,7 @@ protected:
NPError* result);
virtual bool
AnswerNPP_HandleEvent(const NPEvent& event, int16_t* handled);
AnswerNPP_HandleEvent(const NPRemoteEvent& event, int16_t* handled);
virtual PPluginScriptableObjectChild*
AllocPPluginScriptableObject();

View File

@ -432,6 +432,8 @@ PluginInstanceParent::NPP_HandleEvent(void* event)
_MOZ_LOG(__FUNCTION__);
NPEvent* npevent = reinterpret_cast<NPEvent*>(event);
NPRemoteEvent npremoteevent;
npremoteevent.event = *npevent;
#if defined(MOZ_X11)
if (GraphicsExpose == npevent->type) {
@ -451,7 +453,7 @@ PluginInstanceParent::NPP_HandleEvent(void* event)
#endif
int16_t handled;
if (!CallNPP_HandleEvent(*npevent, &handled)) {
if (!CallNPP_HandleEvent(npremoteevent, &handled)) {
return 0; // no good way to handle errors here...
}
return handled;

View File

@ -90,7 +90,6 @@ struct NPRemoteWindow
#endif /* XP_UNIX */
};
// XXX maybe not the best place for these. better one?
#define VARSTR(v_) case v_: return #v_