I am working on a plugin that should receive calls from javascript. In particular, it should be able to give a javascript callback function, and javascript should be able to call this function later, at least with a string argument. Javascript looks something like this (ideally):
var callback = null; var setCallback = function(cb) { var callback = cb; }; var input = document.getElementById('my_text_input_field'); input.onkeypress = function(ev) {
I imagine my C code looks something like this:
void SetCallback(void (*callback)(const char*)) { NPVariant npCallback; OBJECT_TO_NPVARIANT(callback, npCallback); NPVariant args[] = { npCallback }; size_t nargs = 1; NPVariant result;
Is that a reasonable start? If so, what do I need to do in the callback function to handle calls? If not, what is the correct way to do something like this, or is this not possible in NPAPI?
Thanks in advance.
source share