nsIJetpack 编辑

js/jetpack/nsIJetpack.idlScriptable This interface enables communication between the chrome process and a remote Jetpack process. 1.0 66 Introduced Gecko 2.0 Inherits from: nsISupports Last changed in Gecko 2.0 (Firefox 4 / Thunderbird 3.3 / SeaMonkey 2.1)

Method overview

void sendMessage(in AString aMessageName /* [optional] in jsval v1, [optional] in jsval v2, ... */);
void registerReceiver(in AString aMessageName, in jsval aReceiver);
void unregisterReceiver(in AString aMessageName, in jsval aReceiver);
void unregisterReceivers(in AString aMessageName);
void evalScript(in AString aScript);
nsIVariant createHandle();
void destroy();

Methods

sendMessage()

This method asynchronously sends a message to the Jetpack process.

void sendMessage(
  in AString aMessageName,
  [optional] in jsval v1, Optional
  [optional] in jsval v2, Optional
  ...
);
Parameters
aMessageName
The name of the message to send.
v1, v2, ... Optional
JavaScript values to send with the message; they must be either JSON-serializable types or handles.

registerReceiver()

This registers a callback to be triggered whenever the Jetpack process sends a particular message.

Note: Multiple callbacks may be registered for the same message; they will all be triggered.
void registerReceiver(
  in AString aMessageName,
  in jsval aReceiver
);
Parameters
aMessageName
The name of the message from the Jetpack process on which the callback is triggered.
aReceiver
A JavaScript function. The first argument passed to it is the name of the message, and all arguments following it are either JSON-serializable types or handles. If the message was sent synchronously from the Jetpack process via callMessage(), then the return value of this function is passed back to the Jetpack process.

unregisterReceiver()

This unregisters a callback previously registered with registerReceiver()

void unregisterReceiver(
  in AString aMessageName,
  in jsval aReceiver
);
Parameters
aMessageName
The name of the message on which the callback should no longer be triggered.
aReceiver
The JavaScript function that should no longer be triggered.

unregisterReceivers()

This unregisters all callbacks previously registered with registerReceiver() for a particular message.

void unregisterReceivers(
  in AString aMessageName
);
Parameters
aMessageName
The name of the message to unregister all callbacks from.

evalScript()

This asynchronously sends code to the Jetpack process for evaluation. The code will be evaluated using at least JavaScript 1.8.1.

When evaluated, the script's global scope will include all privileged APIs.

Individual lines of the form //@line 1 "foo.js" can be used to specify filename and line number information for debugging purposes.

void evalScript(
  in AString aScript
);
Parameters
aScript
The full contents of the script to evaluate in the Jetpack process.

createHandle()

This creates an opaque handle that can transparently be exchanged between processes.

nsIVariant createHandle();
Parameters

None.

Return value

The new handle.

destroy()

This terminates the Jetpack process.

void destroy();
Parameters

None.

Special Messages

If an exception goes uncaught in the Jetpack process, it will be reported to the chrome process via a message with the name core:exception. The message comes with one argument, which represents the exception object that was thrown.

Warning: bug 589308 prevents this message from being sent in some situations.

History

See bug 556846 for details.

See also

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:106 次

字数:7409

最后编辑:8年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文