Commit dfc45a6a authored by Jean-Paul Saman's avatar Jean-Paul Saman

mozilla: deliver async events under windows

In the windows gecko-sdk the call NPN_PluginThreadAsyncCall() is not supported, so the code most resort to an older method of sending async events from the plugin to the browser.
Source: http://stackoverflow.com/questions/1931883/generating-async-javascript-events-from-browser-plugin-npapi
parent 041b6f0f
...@@ -41,6 +41,7 @@ ...@@ -41,6 +41,7 @@
#elif defined(XP_WIN) #elif defined(XP_WIN)
/* windows headers */ /* windows headers */
# include <winbase.h> # include <winbase.h>
extern void ScheduleAsyncCall(HWND p_hwnd, void (*func)(void *), void *userData);
#else #else
#warning "locking not implemented for this platform" #warning "locking not implemented for this platform"
#endif #endif
...@@ -210,9 +211,12 @@ void EventObj::callback(const libvlc_event_t* event) ...@@ -210,9 +211,12 @@ void EventObj::callback(const libvlc_event_t* event)
void VlcPlugin::event_callback(const libvlc_event_t* event, void *param) void VlcPlugin::event_callback(const libvlc_event_t* event, void *param)
{ {
VlcPlugin *plugin = (VlcPlugin*)param; VlcPlugin *plugin = (VlcPlugin*)param;
#if defined(XP_UNIX)
plugin->events.callback(event); plugin->events.callback(event);
#if defined(XP_UNIX)
NPN_PluginThreadAsyncCall(plugin->getBrowser(), eventAsync, plugin); NPN_PluginThreadAsyncCall(plugin->getBrowser(), eventAsync, plugin);
#elif defined(XP_WIN)
HWND hwnd = (HWND)plugin->getWindow().window;
ScheduleAsyncCall(hwnd, eventAsync, plugin);
#else #else
#warning NPN_PluginThreadAsyncCall not implemented yet. #warning NPN_PluginThreadAsyncCall not implemented yet.
printf("No NPN_PluginThreadAsyncCall(), doing nothing."); printf("No NPN_PluginThreadAsyncCall(), doing nothing.");
......
/***************************************************************************** /*****************************************************************************
* vlcplugin.h: a VLC plugin for Mozilla * vlcplugin.h: a VLC plugin for Mozilla
***************************************************************************** *****************************************************************************
* Copyright (C) 2002-2009 the VideoLAN team * Copyright (C) 2002-2010 the VideoLAN team
* $Id$ * $Id$
* *
* Authors: Samuel Hocevar <sam@zoy.org> * Authors: Samuel Hocevar <sam@zoy.org>
......
...@@ -727,10 +727,33 @@ void NPP_Print( NPP instance, NPPrint* printInfo ) ...@@ -727,10 +727,33 @@ void NPP_Print( NPP instance, NPPrint* printInfo )
* Windows-only methods * Windows-only methods
*****************************************************************************/ *****************************************************************************/
#if defined(XP_WIN) #if defined(XP_WIN)
#define WM_ASYNCTHREADINVOKE WM_USER + 1
struct WINDOWS_ASYNC_EVENT
{
WINDOWS_ASYNC_EVENT(void (*f)(void *), void *ud)
: func(f), userData(ud) { }
void (*func)(void *);
void *userData;
};
void ScheduleAsyncCall(HWND p_hwnd, void (*func)(void *), void *userData)
{
if (p_hwnd != NULL)
::PostMessage(p_hwnd, WM_ASYNCTHREADINVOKE, NULL,
(LPARAM)new ::WINDOWS_ASYNC_EVENT(func, userData));
}
static LRESULT CALLBACK Manage( HWND p_hwnd, UINT i_msg, WPARAM wpar, LPARAM lpar ) static LRESULT CALLBACK Manage( HWND p_hwnd, UINT i_msg, WPARAM wpar, LPARAM lpar )
{ {
VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(GetWindowLongPtr(p_hwnd, GWLP_USERDATA)); VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(GetWindowLongPtr(p_hwnd, GWLP_USERDATA));
if (i_msg == WM_ASYNCTHREADINVOKE) {
WINDOWS_ASYNC_EVENT *evt = static_cast<WINDOWS_ASYNC_EVENT*>((void*)lpar);
evt->func(evt->userData);
return S_OK;
}
switch( i_msg ) switch( i_msg )
{ {
case WM_ERASEBKGND: case WM_ERASEBKGND:
......
...@@ -78,4 +78,8 @@ int16_t NPP_HandleEvent( NPP instance, void * event ); ...@@ -78,4 +78,8 @@ int16_t NPP_HandleEvent( NPP instance, void * event );
#endif #endif
#endif #endif
#ifdef XP_WIN
void ScheduleAsyncCall(HWND p_hwnd, void (*func)(void *), void *userData);
#endif /* XP_WIN */
#endif #endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment