user1807338
user1807338

Reputation: 195

how to get NPObject from NPObject JS wrapper class

Function in NP API plugin creates NPObject and returns into javascript. Then javascript variable with returned NPObject is used as parameter for some other function of plugin. e.g.

var obj = plugin.GetObject()

plugin.UseObject( obj )

But in second function (UseObject) value of parameter is not original NPObject but NPObject JS wrapper class. Is there way to get original NPObject from instance of NPObject JS wrapper class?

Upvotes: 2

Views: 1288

Answers (1)

taxilian
taxilian

Reputation: 14324

Short answer: you can't.

More involved answer: Some browsers will give you the originating object, but most these days won't, and there is no way to dereference past their opaque NPObject interface to get back to the underlying object.

Alternate solution: Instead of trying to get it that way, add a unique id to your NPObject and a global map to the pointer. Then when you get an NPObject that you think might be the object, call a method (or get a property) to get the unique ID and then you can look up the pointer.

this is the only method that I've found that works consistently across all browsers.

Upvotes: 4

Related Questions