Search code examples
macosgoogle-chrome-extensionnpapi

npp_destroy gets called immediately after npp_new


I am trying to make a NPAPI plugin for chrome on Mac. I have written a basic npapi plugin and a basic manifest.json and background.html to load it. My background.html has a embed tag to fetch the plugin by Mimetype.

Now when I load my unpackaged extension from Chrome and try to debug the c++ code (in xcode4), I found that the functions are getting called in following order:

  1. NP_Initialize
  2. NP_GetEntryPoints
  3. NPP_New
  4. NPP_Destroy

After this when I click on the extension icon, the popup.html should get executed. My popup.html has these lines:

line 1:

var pluginObj = document.getElementById("pluginId");

line 2:

pluginObj.Myfunction();

But on line 1, NP_Getvalue() function doesnt get called and so a "scriptable NPObject" is not instantiated. On line 2, the Chrome JavaScript console says:

Error in event handler for 'undefined': Object #<HTMLEmbedElement> has no method 'Myfunction' TypeError: Object #<HTMLEmbedElement> has no method 'Myfunction'

Why does the NPP_Destroy functions gets called immediately after the NPP_New function?


Solution

  • Have you done drawing and event model negotiation in your plugin? Starting with Chrome 22 for Mac, the long-deprecated QuickDraw and Carbon models are no longer supported, and if your plugin doesn't negotiate modern models, it will be destroyed just after init. See here for example code that does this.

    (Yes, it's unfortunate that the default models for 32-bit plugins are the old, deprecated models, but there's no way to change that in the spec due to all the existing plugins that expect the old behavior.)