firemail

标题: Creating the Component Code [打印本页]

作者: hechengjin    时间: 2015-9-15 17:16
标题: Creating the Component Code
本帖最后由 hechengjin 于 2015-9-15 17:28 编辑

组件是分层的.每一个XPCOM组件都有三部分.从内到外, 第一个对象是XPCOM对象. 这个对象包含了交互逻辑, 负责载入network, 执行一个监听载入过程或新content type的接口。
XPCOM的上层是 nsIFactory 对象. nsIFactory是对XPCOM的基本抽象.通过CreateInstance与XPCOM对象进行交互, 返回一个匹配给定的CID 和IID 的两个对象.如下图:





Onion Peel View of XPCOM Component Creation
最外层是nsIModule对象. 他提供了对nsIFactory 的进一步抽象, 而且可能允许多个nsIFactory对象. 关键点是这个接口的方法getClassObject返回的不一定非要是nsIFactory. nsIModule 也可以用来询问 XPCOM 对象的细节. This is very useful if the caller is required to know information about the component like its threading module, whether or not it's a singleton, its implementation language, and so forth. 这是可以使用接口nsIClassInfo.
IID 接口ID
CID  类ID
Creating the Component Code
注册相关接口:
nsIModule and nsIFactory
当 XPCOM 第一次发现你的组件(via XPInstall or regxpcom, both of which are discussed in Component Installation Overview), 第一件事是装载你的库并找到符号NSGetModule. 当这个专用的入口被调用, 它被传送XPCOM's Component Manager和组件存在的共享库位置.
Component Manager是一个是XPCOM实现的用来包含建立对象和提供一些所有组件的综合信息的接口。磁盘的位置是通过另外一个接口 nsIFile传送的.
三个主要的组件管理接口, nsIComponentManager, nsIServiceManager, and nsIComponentRegistrar, are described below:








欢迎光临 firemail (http://www.firemail.wang:8088/) Powered by Discuz! X3