I have to implement HTML5 AsyncFileAPI
using plain NPAPI
. Also Callback mechanism for Microsoft Gamepad key events.
Problem I am facing is how to implement threadcallasync
and seemlessly send data to javascript from plain NPAPI plugin. Some useful links or working code will be appreciated. I am new in NPAPI plugin. threadcallasync I have to implement in Linux, have seen some links to implement in windows.
I would definitely recommend using FireBreath for creating your plugin; it would solve most of the hard stuff for you, and you can find tutorials on how to do async calls.
Should you choose not to do that basically you just have to pass in a javascript function, which in NPAPI will be an NPObject, and then when your action is done use NPN_InvokeDefault on the callback NPObject. You will, of course, need to do this on the main thread, which will require some method of sending a message to the main thread to tell it to make the call.
Generally speaking NPN_PluginThreadAsyncCall does this; you give it a function pointer and a void* with the data you'll need and it'll call your function on the main thread. Unfortunately Safari 5.1 on both windows and mac seems to have dropped support for this function. An alternate on windows is to create a message HWND and PostMessage to it with the opaque pointer in the LPARAM. On Mac you can just use PerformSelectorOnMainThread or an NSTimer. I'm not sure how to do that on linux.
Of course, FireBreath takes care of all of that for you and just wraps the callback in a JSObjectPtr which can be called from any thread... you call it and firebreath will make the call on the correct thread for you. it will also work on IE... but that's up to you. I try to give other options, since I wrote most of FireBreath and I'm a bit biased.
(Just because I'm biased does not mean I'm wrong)
good luck!