Revision 30543 of Jetpack Processes

  • Revision slug: Jetpack_Processes
  • Revision title: Jetpack Processes
  • Revision id: 30543
  • Created:
  • Creator: Avarma
  • Is current revision? No
  • Comment 282 words added, 5 words removed
Tags: 

Revision Content

Jetpack processes are created by nsIJetpackService interfaces, and their parent chrome process communicates with them via a nsIJetpack interface.

These processes are relatively lightweight, don't have access to XPCOM, and can innately do little other than compute. Messaging facilities that allow them to communicate with their parent chrome process are the only means by which they can be endowed with any real power.

Privileged APIs

When script is evaluated in a Jetpack process via a call to nsIJetpack.evalScript(), the script's global scope is endowed with the following privileged APIs:

sendMessage(aMessageName [, v1 [, v2 [, ...]]])
Similar to nsIJetpack.sendMessage(), this function asynchronously sends a message to the chrome process.
callMessage(aMessageName [, v1 [, v2 [, ...]]])
This function is like sendMessage() but sends the message synchronously. It returns an Array whose elements are the return values of each receiver in the chrome process that was triggered by the message.
registerReceiver(aMessageName, aReceiver)
Similar to nsIJetpack.registerReceiver(), this function registers a callback that's triggered when the chrome process sends a message with the given name.
unregisterReceiver(aMessageName, aReceiver)
Similar to nsIJetpack.unregisterReceiver(), this function unregisters a callback previously registered with registerReceiver().
unregisterReceivers(aMessageName)
Similar to nsIJetpack.unregisterReceivers(), this function unregisters all callbacks for the given message name.
createHandle()
Similar to nsIJetpack.createHandle(), this function creates a new handle and returns it.
createSandbox()
This creates a new JavaScript sandbox and returns its global scope. This global scope does not contain privileged APIs, or any non-standard JavaScript objects for that matter, though new globals can be endowed by simply attaching them to the global scope as properties.
evalInSandbox(aSandbox, aScript)
Evaluates the given script contents in the given sandbox's global scope. At minimum, JavaScript 1.8.1 is used. Individual lines of the form //@line 1 "foo.js" can be used to specify filename and line number information for debugging purposes.
gc()
Synchronously performs garbage collection.

Handles

Revision Source

<p>Jetpack processes are created by <code><a href="/en/nsIJetpackService">nsIJetpackService</a></code> interfaces, and their parent chrome process communicates with them via a <code><a href="/en/nsIJetpackService">nsIJetpack</a></code> interface.</p>
<p>These processes are relatively lightweight, don't have access to XPCOM, and can innately do little other than compute. Messaging facilities that allow them to communicate with their parent chrome process are the only means by which they can be endowed with any real power.</p>
<h2 name="Privileged_APIs">Privileged APIs</h2>
<p>When script is evaluated in a Jetpack process via a call to <code><a href="/en/nsIJetpack#evalScript()">nsIJetpack.evalScript()</a></code>, the script's global scope is endowed with the following privileged APIs:</p>
<dl> <dt><code>sendMessage(aMessageName [, v1 [, v2 [, ...]]])</code></dt> <dd>Similar to <code><a href="/en/nsIJetpack#sendMessage()">nsIJetpack.sendMessage()</a></code>, this function asynchronously sends a message to the chrome process.</dd> <dt><code>callMessage(aMessageName [, v1 [, v2 [, ...]]])</code></dt> <dd>This function is like <code>sendMessage()</code> but sends the message synchronously. It returns an <code>Array</code> whose elements are the return values of each receiver in the chrome process that was triggered by the message.</dd> <dt><code>registerReceiver(aMessageName, aReceiver)</code></dt> <dd>Similar to <code><a href="/en/nsIJetpack#registerReceiver()">nsIJetpack.registerReceiver()</a></code>, this function registers a callback that's triggered when the chrome process sends a message with the given name.</dd> <dt><code>unregisterReceiver(aMessageName, aReceiver)</code></dt> <dd>Similar to <code><a href="/en/nsIJetpack#unregisterReceiver()">nsIJetpack.unregisterReceiver()</a></code>, this function unregisters a callback previously registered with <code>registerReceiver()</code>.</dd> <dt><code>unregisterReceivers(aMessageName)</code></dt> <dd>Similar to <code><a href="/en/nsIJetpack#unregisterReceivers()">nsIJetpack.unregisterReceivers()</a></code>, this function unregisters all callbacks for the given message name.</dd> <dt><code>createHandle()</code></dt> <dd>Similar to <code><a href="/en/nsIJetpack#createHandle()">nsIJetpack.createHandle()</a></code>, this function creates a new handle and returns it.</dd> <dt><code>createSandbox()</code></dt> <dd>This creates a new JavaScript sandbox and returns its global scope. This global scope does <em>not</em> contain privileged APIs, or any non-standard JavaScript objects for that matter, though new globals can be endowed by simply attaching them to the global scope as properties.</dd> <dt><code>evalInSandbox(aSandbox, aScript)</code></dt> <dd>Evaluates the given script contents in the given sandbox's global scope. At minimum, JavaScript 1.8.1 is used. Individual lines of the form <code>//@line 1 "foo.js"</code> can be used to specify filename and line number information for debugging purposes.</dd> <dt><code>gc()</code></dt> <dd>Synchronously performs garbage collection.</dd>
</dl>
<h2>Handles</h2>
Revert to this revision