admin管理员组文章数量:1421303
I'm writing a web browser plugin (NPAPI.)
My plugin starts a worker thread, and as the worker progresses, I'd like to pass events back to Javascript. But because of the NPAPI threading model, it's not legal for the worker thread to call back into NPAPI directly, so the worker thread can't invoke Javascript.
One solution to this is the NPN_PluginThreadAsyncCall function. But this is a relatively new function. For example, it's supported only from Firefox 3 on.
Is there any way to get async event delivery/javascript execution from an NPAPI plugin without using NPN_PluginThreadAsyncCall? What did people do before this function was added?
I'm writing a web browser plugin (NPAPI.)
My plugin starts a worker thread, and as the worker progresses, I'd like to pass events back to Javascript. But because of the NPAPI threading model, it's not legal for the worker thread to call back into NPAPI directly, so the worker thread can't invoke Javascript.
One solution to this is the NPN_PluginThreadAsyncCall function. But this is a relatively new function. For example, it's supported only from Firefox 3 on.
Is there any way to get async event delivery/javascript execution from an NPAPI plugin without using NPN_PluginThreadAsyncCall? What did people do before this function was added?
Share Improve this question asked Dec 19, 2009 at 3:48 GeoffGeoff 4,6525 gold badges27 silver badges29 bronze badges1 Answer
Reset to default 5The answer is yes... and no...
If you need to support older browsers (pre firefox 3), you can implement the NPN_PluginThreadAsyncCall function yourself. On windows, you can do that by creating a data structure that can hold the function pointer and the void* opaque pointer, and then post a custom message to the main window with a pointer to your data structure as the LPARAM.
The main window WINPPROC runs on the UI thread, which is the thread that can talk to Javascript. So, when you get that message in your WINPROC, you simply cast the LPARAM back to the pointer, call the method with the opaque data, and then free the data structure.
On Mac, you can do a similar thing with a queue to store the events in, and then on the NULL event (which gets sent by Mac OS about every tick) check to see if anything is in it. If so, pop it off, call the method, free it, and keep going.
There is probably a way to do it on linux as well, but I don't know what it is.
You can find an example of the windows version in the firebreath project.
The handling of the winproc message is in this file: https://github./firebreath/FireBreath/blob/master/src/PluginWindow/Win/PluginWindowWin.cpp
The event and data structure are defined in its header file: https://github./firebreath/FireBreath/blob/master/src/PluginWindow/Win/PluginWindowWin.h
And the method for firing that event is here:
void ActiveXBrowserHost::ScheduleAsyncCall(void (*func)(void *), void *userData)
{
if (m_hWnd != NULL)
::PostMessage(m_hWnd, WM_ASYNCTHREADINVOKE, NULL,
(LPARAM)new FB::WINDOWS_ASYNC_EVENT(func, userData));
}
本文标签: Generating async Javascript events from browser plugin (NPAPI)Stack Overflow
版权声明:本文标题:Generating async Javascript events from browser plugin (NPAPI) - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745347704a2654573.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论