Search code examples
npapi

How to pass plain NPAPI Plugin class Object to javascript


I have my Plugin.cpp class in my NPAPI Plugin i want to pass this class object to javascript function as follows ::

function testData(){
 var obj = data.getObject();

//data is an object created in javascript, getObject is implemented in Plugin.cpp, in Invoke method, inside getObject i have to return the Plugin Class Object . obj i have to access Plugin methods.

  initFS(obj);

}

function initFS(obj) {
  obj.testFunc(); //testFunc method is in the Plugin
}

Thanks in advance !!


Solution

  • You just need to create an additional NPObject and put it in the NPVariant that you send as a parameter to the InvokeDefault call.

    Remember that when you call InvokeDefault and hand it off to Javascript the browser will retain the object if it needs to hold onto it so you'll need to do a Release when you are done with the object to avoid a memory leak.

    See http://npapi.com/memory

    See also http://npapi.com/tutorial3