Search code examples
c++npapipoco-libraries

Cannot use POCO Timer in NPAPI plugin


I have implemented an NPAPI plugin which works in Firefox. Next, I tried adding a method which accepts a function from the JavaScript side as a callback.

Initially I tried to call this callback method immediately in the same method, which did exactly nothing on the JavaScript side.

I then tried to implement a timer using Poco::Util::Timer and TimerTask. When trying to instantiate a Timer or TimerTask in any fashion in the code, Firefox will no longer load the plugin. In about:plugins there is no trace of the plugin.

To my knowledge there is no way to figure out why a plugin doesn't get loaded, nor have I found any references on what is and isn't allowed when implementing an NPAPI plugin.

Any pointers will be most helpful. I can post code if required.


Solution

  • The main thing you need to understand about a NPAPI plugin is that you can't interact with the browser in any way from an alternate thread.

    I'd go back to your first test first, though, because calling the NPObject passed in (using InvokeDefault) should have worked if you do it immediately.

    My guess is that with your timers you're probably either running on a different thread or you're trying to usurp the message loop in the plugin thread, both of which will cause you issues. Have you looked at FireBreath? FireBreath 1 would probably give you everything you need without needing to know all the implementation details of NPAPI.