When we implement a module and access it through Navigator.mozcustommodule
Depending on how the module is implemented, there are several different approaches.
1. XPCOM component (JavaScript implementation):
Configure in Chrome.manifest (Bold section):
Component {ComponentID} custommodule.js contract Contractid {ComponentID} category Javascript-navigator-property Mozcustommodule Contractid
Take Tcpsocket as an example:
Component {cda91b22-6472-11e1-aa11-834fec09cd0a} tcpsocket.jscontract @mozilla. org/tcp-socket;1 { CDA91B22-6472-11E1-AA11-834FEC09CD0A}category Javascript-navigator-property Moztcpsocket @mozilla. org/ Tcp-socket;1
2. XPCOM/C + + implementation:
3. Webidl JavaScript Implementation:
When defining Webidl, specify (bold) by Navigatorproperty:
[navigatorproperty= "Mozcustommodule"]interface CustomModule { // };
Take alarms as an example:
[navigatorproperty= "Mozalarms", jsimplementation= "@mozilla. Org/alarmsmanager;1", Checkpermissions= "Alarms", Pref= "dom.mozAlarms.enabled"]interface alarmsmanager { Domrequest getAll (); Domrequest Add (any date, domstring respecttimezone, optional any data); void Long ID);};
4. Webidl/C + + implementation:
The situation is slightly more complicated and requires some code to be written manually.
(1) Add an attribute to Gecko/dom/webidl/navigator.webidl:
Partial interface Navigator { readonly attribute custommodule mozcustommodule;};
(2) Declare a method in Gecko/dom/base/navigator.h:
Note Method Name:Get + property name (first letter uppercase)
Getmozcustommodule (errorresult& aRv);
(3) The method of implementing the previous declaration in Gecko/dom/base/navigator.cpp:
Getmozcustommodule (errorresult& aRv) { return new custommodule (); }
Todo:
Sample code
(Ffos Gecko)-Several ways of exposing a module to navigator