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.