Step 2: Initializing/destroying plug-in, and creating plug-in instance

2.1  Set the MIME type for the plug-in.

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";
}

2.2  Initialize/Destroy the plug-in

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:

2.3  Create/Destroy a new instance of the plug-in

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.