I am trying to pass an array from plugin to Javascript. But I am unable to do it. I have referred to other post of similar kind where the solution given was to first get the Dom window object and then to invoke the function using NPN_Invoke with NPN_GetStringIdentifier("array") and then Push the array elements. But when I tried it, its crashing on NPN_Invoke. I am unable to find out why, Is it because NPObject of Dom is not having any method related to 'array' or some other reason?
Here is my plugin code...(My array data is 0,1,2,...9 The value of i in loop)
bool ScriptableObject::method_process_getarray_intval(const NPVariant* args, uint32_t argCount, NPVariant* result)
{
printf("\n DATATYPE method_process_getarray_intval");
NPObject DomWin;
NPVariant Array;
NPError l_RetErr;
bool l_RetBool;
NPIdentifier l_NPId;
//Get the Window Object
l_RetErr = NPN_GetValue(m_npp,NPNVWindowNPObject,&DomWin);
if(l_RetErr == NPERR_NO_ERROR)
printf("\n \t Got the Dom Window Object");
else
printf("\n \t Error occured while getting the Dom Window Object");
//Get the Array by invoking DomWin using ARRAY method of browser
//Get string Identifier for Array
l_NPId = NPN_GetStringIdentifier("Array");
l_RetBool = NPN_Invoke(m_npp,&DomWin,l_NPId,NULL,0,&Array);
if(l_RetBool)
printf("\n \t Invoked for Array");
else
printf("\n \t Error while Invoking for Array");
//Fill the array elements using PUSH method of Array NPVariant
l_NPId = NPN_GetStringIdentifier("push");
for(int i = 0;i < 10; i++)
{
NPVariant *arg =(NPVariant *) g_browser->memalloc(sizeof(NPVariant));
INT32_TO_NPVARIANT(i,*arg);
NPVariant result;
l_RetBool= NPN_Invoke(m_npp,Array.value.objectValue,l_NPId,arg,1,&result);
if(l_RetBool)
printf("\n \t Invoked for Array i : %d",i);
else
printf("\n \t Error while Invoking for Array i :%d",i);
}
return true;
}
And my html page look like this. I dont know if this is right. Please let me know if there are any corrections...
<html>
<script type="text/javascript">
var inarray ;
function handleEvent(e) {
...
if (e.keyCode == 55)
{
document.getElementById('arrayint_ele_get').innerHTML = inarray;
process_getintarray(inarray);
}
}
</script>
<script type="text/javascript">
function process_getintarray(inarray)
{
if(obj)
{
obj.process_getarray_intval(inarray);
}
}
</script>
<body onload="init()" onkeydown="handleEvent(event)">
<div id="sq" style="width:50px;height:50px;position:relative;left:0px;border:1px solid #333333;background-color:#FF0000"></div>
......
<div style="position:absolute;left:100px;top:10px"> PLUGIN-SCRIPTS </div>
<div id ="arrayint_ele_get" style="position:absolute;left:100px;top:300px"> ARRAY_GETINT VAL </div>
.....
</body>
</html>
Any suggestions are welcome....