Re: Serializing NPAPI without plugin vendor cooperation
Chris Jones <[email protected]>
| Newsgroups | gmane.comp.mozilla.devel.dom |
|---|---|
| Message-ID | <[email protected]> |
Chris Jones wrote:
> (2) Provide "event loop atomicity" to the plugin. That is, guarantee
> that all calls the plugin makes to NPN_* functions during each native
> event callback are atomic. We can provide this (sanely) only if we can
> inject special events into the plugin's native event loop, on all
> platforms. If this is possible, we remove relaxation (ii) above.
>
It just struck me that we already have a simplistic way to "inject"
these events: NPN_PluginThreadAsyncCall().
The way this would work is as follows.
Content process Plugin process
----------------------- -----------------------
[Native event occurs]
Plugin callback invoked
Plugin calls NPN_Foo
Gecko code calls
NPN_PluginThreadAsyncCall(UnblockContent, NULL), enqueues native event
Gecko code sends IPC messages NPN_Foo
recv NPN_Foo
compute
send reply
spin nested event loop, only process IPC messages from that
particular Plugin
Gecko code recv reply to NPN_Foo
Gecko return from NPN_Foo
Plugin compute ...
Plugin calls NPN_Bar
Gecko sends NPN_Bar
recv NPN_Bar
send reply
Gecko recv reply
Gecko returns NPN_Bar
// ...
Plugin returns to event loop
[Next native event: process AsyncCalls]
Gecko UnblockContent callback invoked
Gecko send async IPC message Unblock
recv Unblock
quit nested loop
// continue // continue
The effect of this process is that as soon as the plugin calls NPN_Foo
above, it "locks NPAPI" for that particular content process. No other
plugins can call NPAPI functions, and the content page is stalled. When
the plugin returns to its event loop, at some point thereafter the Gecko
event to process NPN_PluginThreadAsyncCall callbacks will be dequeued.
When the UnblockContent callback is invoked, it will "unlock" NPAPI by
sending a message back to the content process.
This shouldn't be terribly hard to implement.
Cheers,
Chris