This page contains some notes on how plugins work internally in Gecko. It is mainly of interest to Gecko developers.
Note: This document documents how trunk works, i.e. Gecko 1.9. No released product uses this specific architecture.
Note: This document describes how things are, not necessarily how things should be. It is not set in stone. Do not use this document for deciding what plugins can rely on. The described sequences are subject to change at any time.
There are some classes involved in plugins:
- embed, object and applet nodes inherit from that class, which provides services for loading various kinds of objects. It takes care of most of the work involved in loading the data and instantiating plugins.
- The frame responsible for displaying plugins
- Glue between plugin code (modules/plugin) and layout code (layout/generic). A refcounted object, contrary to nsObjectFrame.
Note that while nsObjectLoadingContent also deals with images and documents, this document concentrates on plugins.
Sequence of events
- A content node for a plugin DOM element gets created
- In BindToTree (usually) or another function, it calls LoadObject
- LoadObject either notices directly that it is dealing with a plugin, or it starts a network request and notices this in OnStartRequest
- When it realizes that, it tries to create a frame, if aNotify is true and no frame exists yet
- If a frame exists now, it is asked to instantiate the plugin
That was the normal case. If a frame comes into existance independent of that, it tells the content node that it exists now (nsIObjectLoadingContent::hasNewFrame). That function will post an event and when that fires, asks the frame to instantiate the plugin. (The event is necessary because by the time HasNewFrame is called, the frame isn't fully set up yet)
Note: Some of this should move to content
- An instance owner is created
- The window passed to the plugin is adjusted (The NPWindow, https://devedge-temp.mozilla.org/libr...nt.html#999221)
- The plugin host is asked to instantiate the plugin
- This will call back to the instance owner / the object frame in order to create a widget to draw to (if the plugin is not windowless)
- SetWindow is called on the plugin