(Ffos Gecko)-Several ways of exposing a module to navigator

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.