From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- .../ipdl/creating_a_new_protocol/index.html | 32 ++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 files/zh-cn/mozilla/ipdl/creating_a_new_protocol/index.html (limited to 'files/zh-cn/mozilla/ipdl/creating_a_new_protocol/index.html') diff --git a/files/zh-cn/mozilla/ipdl/creating_a_new_protocol/index.html b/files/zh-cn/mozilla/ipdl/creating_a_new_protocol/index.html new file mode 100644 index 0000000000..d256886913 --- /dev/null +++ b/files/zh-cn/mozilla/ipdl/creating_a_new_protocol/index.html @@ -0,0 +1,32 @@ +--- +title: 创建一个新的协议 +slug: Mozilla/IPDL/Creating_a_New_Protocol +translation_of: Mozilla/IPDL/Creating_a_New_Protocol +--- +

这是有关如何向构建中添加新IPDL协议的详细信息的快速入门。您应该首先了解IPDL的工作原理

+ +

创建协议文件

+ +

协议文件应与实现它的代码位于同一目录中。协议名称以P开头,并且协议文件必须命名为PProtocolName.ipdl。IPDL协议应位于mozilla命名空间或子命名空间中。

+ +

要将文件连接到构建,需要将IPDL文件添加到最近的moz.build文件中的IPDL_SOURCES。有关示例,请参见 dom/ipc/moz.build 

+ +

协议层次结构

+ +

除非您正在从事某些特殊项目,否则您的协议将适合多进程插件或选项卡的协议层次结构。插件的顶级协议是PPluginModule。选项卡的顶级协议是PContent。您应该知道哪种协议将管理新协议,以及会导致哪些生存期问题。如有疑问,请在#content频道中询问IRC。

+ +

建立新协议

+ +

要构建新的协议声明并生成标头,请在ipc/ipdl中创建:

+ +
make -C objdir/ipc/ipdl
+ +

如果存在协议级别的错误,则IPDL编译器将打印相关的错误消息并停止。要查看生成的标题,请在中查看objdir/ipc/ipdl/_ipdlheaders

+ +

创建实现

+ +

C ++实现从IPDL生成的抽象类PNewProtocolParent和PNewProtocolChild继承。它必须实现抽象方法以在每一侧接收适当的消息。可以从生成的PNewProtocolParent.h和PNewProtocolChild.h标头中读取方法签名。

+ +

编写测试

+ +

PBrowser管理的协议必须使用带有的mochitest-chrome测试框架进行测试<browser remote="true">出于测试目的,可以在JPW包装器上使用同步调用。使用xpcshell测试框架可以测试与特定窗口无关的协议,该框架在Electrolysis中具有其他原语,用于在内容过程中启动和运行JS命令。

-- cgit v1.2.3-54-g00ecf