When the user opens a page that contains embedded data of a media type that invokes a plug-in, the browser will check for a plug-in with a matching MIME type, so you need to decide and set the MIME type and file extension for the plug-in first. For example:
char* NP_GetMIMEDescription()
{
return NPP_GetMIMEDescription();
}
char* NPP_GetMIMEDescription(void)
{
return (char *)"application/your-npruntime-scriptable-plugin:.yourExt:Your scriptable plugin";
}
The browser calls NP_Initialize
when a plug-in is loaded and before the first instance is created. Use this function to allocate the memory and resources shared by all instances of your plug-in.
NPError OSCALL NP_Initialize()
{
}
After the last plug-in instance is deleted, the browser calls NP_Shutdown
, which releases the memory or resources allocated by NP_Initialize
.
NPError OSCALL NP_Shutdown()
{
}
In the initialization process, the browser passes the plug-in two tables of function pointers for all API calls:
One table lists all API calls from the plug-in to the browser. This table is filled out by the browser before the initialization call. For example:
NPNetscapeFuncs YourNPNFuncs; //Global Variable
...
YourNPNFuncs.size = pFuncs->size;
YourNPNFuncs.version = pFuncs->version;
YourNPNFuncs.geturlnotify = pFuncs->geturlnotify;
YourNPNFuncs.geturl = pFuncs->geturl;
...
The other table lists all API calls from the browser to the plug-in. This table is filled out by the plug-in during the initialization call.For example:
pluginFuncs->version = (NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR;
pluginFuncs->size = sizeof(NPPluginFuncs);
pluginFuncs->newp = NPP_NewProcPtr(NPP_New);
pluginFuncs->destroy = NPP_DestroyProcPtr(NPP_Destroy);
...
After initialization, the plug-in instance is created. The plug-in instance is created with NPP_New
and destroyed with NPP_Destroy
. NPP_New
informs the plug-in of the creation of a new instance with the specified MIME type. You can allocate instance-specific private data at this time.
The browser calls NPP_Destroy
when a plug-in instance is deleted, usually because the user has left the page containing the instance, closed the window, or quit the application. If this is the last instance created by a plug-in, NP_Shutdown
is called.
You should not perform any graphics operations in NPP_Destroy
because the instance window is no longer guaranteed to be valid. Also, be sure to delete any private instance-specific information stored in the plug-in's instance->pdata.
See Initialization and Destruction for more information about using these methods.