0

I am developing NPAPI Plugin for embedded native browser (Linux) . I want one callback function from javascript that will invoke callback function in my plugin . As per the events generated by pressing the keys of keyboard . I have to send events continously to the browser window. I am completely new to this needs help .

Thanks in advance .

Georg Fritzsche
  • 97,545
  • 26
  • 194
  • 236
r_tex
  • 77
  • 9

1 Answers1

2

If you are using FireBreath, the documentation on firing events already covers this.

If you are writing a plain NPAPI plugin, your plugin should implement addEventListener(type, listener, ...) & removeEventListener().
As you already know how to add scriptable functions to your plugin, you just need to add support for these two.

For addEventListener() you get the following arguments:

  • type - should be a string that identifies the event
  • listener - should be an object, retain & store it
  • useCapture - should be a boolean, optional, if not present assume false

To store the listeners you could e.g. use a multimap<SomeStringType,NPObject*> member, with the event string as your key and the listener object as the value. Don't forget to retain the listener.

To fire an event you then get the equal_range() for it and use NPN_InvokeDefault() with the listener objects.

removeEventListener() receives the same arguments as addEventListener() and you should then erase() the specified listener for that event string. Don't forget to release the listener object.

To honor useCapture extend the above accordingly.

Georg Fritzsche
  • 97,545
  • 26
  • 194
  • 236
  • I am using plain NPAPI , can u please explain by example . How to add event listener and fire default method of all stored listener NPN_InvokeDefault(). If possible any link to refer . Thanks in advance. – r_tex Jul 31 '12 at 02:22
  • 1
    @r_tex, have you read [this tutorial on providing interfaces to JS](http://colonelpanic.net/2009/08/building-a-firefox-plugin-part-three/)? – Georg Fritzsche Jul 31 '12 at 17:43
  • Thanks , For the link Yes i have gone through this link, and implemented already working plugin where i am able to call plugin methods from javascript. Flow is as follows -> Created one class ScriptablePluginObjectBase derived from NPObject, then Created one class ScriptablePluginObject derived from ScriptablePluginObjectBase, Inside ScriptablePluginObject's invoke method i am calling methods that r called from javascript. Sorry i am new to this , can u please tell me how to write addEventListener, removeEventListener and add/remove the listener parameter(NP Object) to/from a per-type list. – r_tex Aug 01 '12 at 16:43
  • Okk I got it , how to do it . – r_tex Sep 06 '12 at 16:32