I am writing a simple napapi plugin where I have to print the value passed from javascript function in html page. But I am facing problem while doing it. It works properly on firefox. But I want to do it on qt fancybrowser example. The value printed is always 0 no matter whatever value I pass in javascript code.
The javascript code is as follows :
<html>
.....
<script>
function process_data()
{
PluginObject = document.getElementById("Object");
var i =100;
if(PluginObject){
ret = PluginObject.process_Data(i);
}
}
</script>
....
</html>
The plugin code is as follows :
.....
bool ScriptableObject::process_Data(const NPVariant* args, uint32_t argCount, NPVariant* result)
{
printf(" process_Data\n");
printf("\t argCount : %d\n",argCount);
int tempi =args[0].value.intValue;
int tempf =args[0].value.doubleValue;
printf("type: %d type: %u\n",args[0].type,args[0].type);
printf("tempi : %d tempf : %f\n",tempi,tempf);
}
......
The output is as follows :
process_Data
argCount : 1
type: 4 type: 4
tempi : 0 tempf : 0.000000
Actually it should print 100 which is the value passed in var i from javascript.
Any suggestions/comments are welcome
Thanks in advance
From here http://code.google.com/p/chromium/issues/detail?id=68175 and here https://bugs.webkit.org/show_bug.cgi?id=49036 I understand that it is bug in WEB kit, so I add next in "npruntime.h":
on web(from javascript) I use parseInt(myVal,10) for all int values that passed to plugin. Check it on Google Chrome and Safari.
When providing a number argument to a NPAPI method, it is undefined whether you will receive a
Int32
orDouble
variant, so you have to handle both cases in your code.Furthermore, the
NPVARIANT_TO_*
macros only extract the respective value - they don't do any conversion.To extract an integer from any numeric argument, you have to write your own code, e.g. something like: