Re: NPAPI race conditions due to IPC
[email protected] Tue, 3 Mar 2015 12:00:51 -0800 (PST)
| Newsgroups | gmane.comp.mozilla.devel.plugins |
|---|---|
| Message-ID | <[email protected]> |
Across multiple browsers the startup order you're using has long been unreliable; you can't be guaranteed that the plugin will be instantiated the line after you insert it into the DOM. There are a couple of ways I've seen this solved: 1) Do a setTimeout to give the browser a little time to load it up; you could even poll until your method is available to see if it's started up yet 2) My preferred way is to add a param tag with the name of a global javascript function to call once the plugin is loaded. In your plugin once it has loaded just call that method, optionally giving it the NPObject as a parameter. This is my preferred method; you can even set a timeout so that if the plugin doesn't load you can decide to do something about it. Even if the good folks at Mozilla fix the testcase for you (and I'm not convinced this is a "bug" as such) it won't fix Safari or Opera; Chrome of course is dropping NPAPI support next month. - Richard FireBreath.org On Monday, March 2, 2015 at 3:31:34 AM UTC-7, [email protected] wrote: > Hi, > > I have a plugin which can create two types of scriptable objects and I can add one to another using JavaScript and id association in the plugin. I create one in HTML and the other one in JS. Example: > > HTML: > <embed id="a" type="application/x-a"> > > JS: > b = document.createElement("embed"); > renderer.setAttribute("type", "application/x-b"); > > a = documenet.getElementById("a"); > a.add(b); > > > The problem which I am having is that NPN_Invoke for object a is called before NPP_New for object b. This is also visible in the invoke function because the _class member of the object which is given in the add function still has the default values. > If I call a function of b than the NPP_New function is called before NPN_Invoke. > The id association is done by trying to call a function of the object with NPN_Invoke: > > C++: > > NPIdentifier identifier = NPN_GetStringIdentifier(GETID); > if (!NPN_Invoke(npp, object, identifier, 0, 0, &variant)) { > return 0; > } > obj = Manager.get(NPVARIANT_TO_INT32(variant); > > The problem disappears when dom.ipc.plugins.enabled is set to false. > > > Could this be a problem caused by IPC? Is there a way to flush all the changes from javascript to the C++ code? > > Thanks in advance, > > Cosmin