I am writing scriptable plugin and I am sure lot of people must have
faced similar problem.
I need to pass Array from Javascript and return Array of NPObjects to
Javascript from NPAPI plugin. But there is not documentation about how
this is achieved.
please reply if you think of something or have documentation links or
sample code.
cheers,
Digambar
> I need to pass Array from Javascript and return Array of NPObjects to
> Javascript from NPAPI plugin. But there is not documentation about how
> this is achieved.
An Array is just a JS object, so you can script it like any other NPObject.
For example:
To create a new Array object:
* get NPNVWindowNPObject
* call NPN_Evaluate(npp, windowobject, "new Array()", resultvariant);
To fill it with objects:
NPVariant[3] arrayitems;
for (int i = 0; i < 3; ++i) {
NPIdentifier id = NPN_GetIntIdentifier(i);
NPN_SetProperty(npp, arrayobject, id, &arrayitems[i]);
};
etc...
--BDS
Say Object - Note which has date and string as properties. From
JAVAScript, there is call to get complete list of notes. So Plugin
need to create object big enough to hold all notes with
NPN_createObject ( ) i.e. in allocate sizeofNOTE X number of notes is
allocated and returned. When there is access to Note[n],
NPN_GetProperty returns pointer to specific Object.
- Digambar
this actually is not too hard. I want to first add something to the
previous post; while NPN_Evaluate does get the job done, it would
really be better to just call NPN_Invoke(npp, windowobject,
NPN_GetStringIdentifier("Array"), ...)
The reason is that firefox seems to handle things differently when you
evaluate them; it's as if you injected that javascript into the page.
you can actually see it with Firebug; thus, eventually, it could take
up resources if you make calls like that a lot. Also, it seems to be
much slower. Avoid using Evaluate whenever you can -- which has
always been good javascript etiquite.
So, once you have created your Array (because the result will be an
NPObject with that object, just call NPN_Invoke on the array NPObject
with push (easier to deal with than a for loop and indexes) for each
NPObject that you have created that you want to be accessible to the
page. Remember to call NPN_RetainObject whenever you store an
NPObject in a NPVariant to go to the page.
Good luck, hope that helps.