Pregunta

I've made a simple NPRuntime plugin calls Javascript function when it loaded. Based example is seamonkey's and it works fine on Google Chrome but it doesn't on FireFox.

I traced code to find what is wrong and I found this line.

NPObject* window;
NPError err = NPN_GetValue(pNPP, NPNVWindowNPObject, &window);
if (!window)
    _log("Can not get DOM window %d", err);

err returns NPERR_INVALID_PARAM.

This simple example might work fine old version of Firefox I guess... 12.0? 13.0? (I'm not sure) Now I'm using FireFox 15.0 which is latest version.

Any help will be appreciated.

¿Fue útil?

Solución

So it looks like your real question is about how to call javascript stuff from another thread, since you can't make NPN_ calls from other threads. The short answer is that you can't; the longer, more complicated answer is that it's a pain but it can be done.

NPAPI has a function called NPN_PluginThreadAsyncCall. It accepts two parameters; the first is a function pointer that returns void and accepts a void*, and the second is the void* that will be passed to that function. You can call this function from any thread and it will cause your callback to be called back on the main thread "sometime soon".

The trick is to make sure that your void* gives you all the data you need to get back to whatever you need to access during that call. The bigger trick is to make this seem synchronous if that's what you need. The first can be done with pointers and making sure you clean up after yourself; the second can be done with a mutex and a signal, if you're clever.

This is a tricky and difficult thing to get right. If it's an option, you might consider using FireBreath because it does all of that for you. Particularly since FireBreath has workarounds for the various random browsers that don't support NPN_PluginThreadAsyncCall (like some versions of Opera and Safari 5.1 and later).

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top