ChromeMessageBroadcaster
Message managers in the chrome process that have a one-to-many relationship with objects in the content process are ChromeMessageBroadcaster
objects. They implement the following interfaces:
These objects have a number of subordinate "children", which may themselves be ChromeMessageBroadcaster
objects, or may be ChromeMessageSender
objects. You can get the number of children using the childCount
attribute, and access a particular child using the getChildAt()
function.
To send messages, ChromeMessageBroadcaster
objects implement broadcastAsyncMessage()
, which sends the message to every corresponding object in the content process. For example, the window message manager's broadcastAsyncMessage()
function sends the message to every browser frame in that browser window.
Correspondingly, ChromeMessageBroadcaster
objects can listen for messages using addMessageListener()
: if they do this, they'll receive messages sent to all of their children. For example, if you add a listener to the window message manager, you'll get messages from every browser frame in that browser window.
ChromeMessageBroadcaster
objects can load scripts into the content process:
loadFrameScript()
is used by frame message managers to load scripts into browser framesloadProcessScript()
is used by process message managers to load scripts into content processes.
Scripts are loaded into every corresponding object in the content process. For example, if you call loadFrameScript()
on the window message manager, and the window has three tabs open, then it will load the script three times, once into every open tab.
ChromeMessageSender
Message managers in the chrome process that have a one to one relationship with objects in the content process are ChromeMessageSender
objects. They implement the following interfaces:
nsIProcessChecker
nsIFrameScriptLoader
nsIProcessScriptLoader
nsIMessageListenerManager
nsIMessageSender
Browser message managers and parent process message managers are both ChromeMessageSender
objects. Browser message managers map to a single browser frame (essentially, content tab) in the content process, while parent process message managers map to a single child process.
To send messages to their correspondent in the content process ChromeMessageSender
objects implement sendAsyncMessage()
. For example, the frame message manager's sendAsyncMessage()
function sends the message to the corresponding ContentFrameMessageManager
, from which it is relayed to any frame scripts that have registered message listeners.
ChromeMessageSender
objects can listen for messages from their correspondent using addMessageListener()
. For example, if you add a listener to the browser message manager, you'll get messages from frame scripts loaded into its corresponding frame.
ChromeMessageSender
objects can load scripts into the content process can load scripts into the content process:
loadFrameScript()
is used by browser message managers to load a script into the corresponding browser frameloadProcessScript()
is used by parent process message managers to load scripts into the corresponding content process.
ContentProcessMessageManager
There's one ContentProcessMessageManager
for each content process. It implements the following interfaces:
nsIMessageListenerManager
nsIMessageSender
nsISyncMessageSender
nsIContentProcessMessageManager
It is the global object for any process scripts loaded into the content process, and is also available through Services.jsm.
To send messages to the chrome process, ContentProcessMessageManager
objects implement two functions: sendAsyncMessage()
and sendSyncMessage()
. These messages are received in the chrome process by the parent process message manager and the global parent process message manager.
Note that while messaging from chrome to content process must be asynchronous, messaging from content to chrome process is allowed to be synchronous. This is because blocking the content process on a response from chrome is less serious than blocking the chrome process.
ContentProcessMessageManager
objects can listen for messages from the chrome process using addMessageListener()
.
ContentFrameMessageManager
There's one ContentFrameMessageManager
in the content process for each open browser tab. It implements the following interfaces:
nsIDOMEventTarget
nsIMessageListenerManager
nsIMessageSender
nsISyncMessageSender
nsIContentFrameMessageManager
The global object for frame scripts is a ContentFrameMessageManager
object. They enable frame scripts to:
- access the DOM window hosted by their tab using the
content
attribute - access the top-level docshell using the
docShell
attribute - listen to DOM events using
addEventListener()
- receive messages from the chrome using
addMessageListener()
- send asynchronous or synchronous messages to chrome using
sendAsyncMessage()
orsendSyncMessage()
- access privileged objects using the
Components
object.