For a long time ago, share the document. However, gecko2.0 is now available, so some details may change. Currently, gecko2.0 has not been studied. To be continued.
Objective: To understand the idea of JS implementing XPCOM.
The JS-implemented XPCOM and xpt must be placed in a folder, that is, the components folder.
(Similarly, the C ++-implemented XPCOM (DLL file) must be placed in the same folder as xpt, which is also under the components folder ).
Document URL:
Http://developer.mozilla.org/en/How_to_Build_an_XPCOM_Component_in_Javascript
Compile command settings:
{Sdk_dir}/bin/xpidl-M typelib-w-v-I {sdk_dir}/IDL-e helloworld. xpt helloworld. IDL
Example of compiling command:
D:/sourcecode/xulrunner-SDK/xulrunner-sdk-1.9/SeaMonkey-xulrunner-SDK/bin/xpidl
-M typelib-w-v-I
D:/sourcecode/xulrunner-SDK/xulrunner-sdk-1.9/SeaMonkey-xulrunner-SDK/IDL
-E
D:/log/imservice. xpt
D:/imservice. IDL
Problems encountered during compilation:
1. coding problem: xp idl does not recognize UTF-8. A little dizzy.
2. The path cannot contain spaces.
Add instances with multiple interfaces to a component:
IMService. idl
# Include "nsISupports. idl"
[Scriptable, uuid (EED9537B-E056-4f0d-834A-6AEDF8E5B14A)]
Interface ceopIIMService: nsISupports {
};
[Scriptable, uuid (3CBED3C4-A0D8-11DD-AF3E-E43F56D89593)]
Interface ceopIIMAccountService: nsISupports {
};
IMService. js
Components. utils. import ("resource: // gre/modules/XPCOMUtils. jsm ");
// Utils
Const Cc = Components. classes;
Const Ci = Components. interfaces;
/*************************************** ********************
Class definition
**************************************** *******************/
// Class constructor
Function IMService (){}
// Class definition
IMService. prototype = {
// Properties required for XPCOM registration:
Classdescription: "ce imservice ",
Classid: components. ID ("{AD3F34D6-9688-11DD-B0C5-F7CC56D89593 }"),
Contractid: "@ c.cn/imservice1_1 ",
QueryInterface: xpcomutils. generateqi ([CI. ceopiimservice, CI. ceopiimaccountservice
]),
.....
};
VaR components = [imservice];
Function nsgetmodule (compmgr, filespec ){
Return xpcomutils. generatemodule (components );
}
(Haha, a component that contains multiple interfaces is complete .)