I'm trying to code a hello world example of an NPAPI plugin. I implemented all the basics functions needed and i have added a Get_String() function that return a hello world string.
After building, the browser can detect the plugin and all information related to but I can't call my Get_String() function from JavaScript! Here Some Code : plugin.c
#define PLUGIN_NAME "Name Plugin"
#define PLUGIN_DESCRIPTION " Plugin Description"
#define PLUGIN_VERSION "1.0"
static NPNetscapeFuncs* sBrowserFuncs = NULL;
NP_EXPORT(NPError)
NP_Initialize(NPNetscapeFuncs* bFuncs, NPPluginFuncs* pFuncs)
{
sBrowserFuncs = bFuncs;
if (pFuncs->size < (offsetof(NPPluginFuncs, setvalue) + sizeof(void*)))
return NPERR_INVALID_FUNCTABLE_ERROR;
pFuncs->newp = NPP_New;
pFuncs->destroy = NPP_Destroy;
return NPERR_NO_ERROR;
}
NP_EXPORT(char*)
NP_GetPluginVersion()
{
return PLUGIN_VERSION;
}
NP_EXPORT(const char*)
NP_GetMIMEDescription()
{
return "application/my-plugin::";
}
NP_EXPORT(NPError)
NP_GetValue(void* future, NPPVariable aVariable, void* aValue) {
switch (aVariable) {
case NPPVpluginNameString:
*((char**)aValue) = PLUGIN_NAME;
break;
case NPPVpluginDescriptionString:
*((char**)aValue) = PLUGIN_DESCRIPTION;
break;
default:
return NPERR_INVALID_PARAM;
break;
}
return NPERR_NO_ERROR;
}
NP_EXPORT(NPError)
NP_Shutdown()
{
return NPERR_NO_ERROR;
}
NPError NPP_New(NPMIMEType pluginType, NPP instance, uint16_t mode, int16_t argc, char* argn[], char* argv[], NPSavedData* saved)
{
return NPERR_NO_ERROR;
}
NPError NPP_Destroy(NPP instance, NPSavedData** save)
{
return NPERR_NO_ERROR;
}
char* Get_String()
{
return "hello world from Get function" ;
}
void Set(NPObject object){}
test.html
<doctype html>
<html>
<head>
<script>
var plugin = document.getElementById("plugin");
console.log(plugin.Get_String());
</script>
</head>
<embed id="plugin" type="application/typemine-plugin">
<body>
</body>
</html>