(Ffos Gecko)-Several ways of registering a XPCOM Component

Source: Internet
Author: User

1. JavaScript Component

(1) Add a customcomponent.manifest

inch customcomponent.jscomponent {e6b866e3-41b2-4f05-a4d2-3d4bde0f7ef8} components/ Customcomponent.jscontract @foobar/customcomponent;1 {e6b866e3-41b2-4f05-a4d2-3d4bde0f7ef8}category Profile-after-change customcomponent @foobar/customcomponent;1

(2) Export a nsgetfactory () function

Components.utils.import ("RESOURCE://GRE/MODULES/XPCOMUTILS.JSM");functioncustomcomponent () {}customcomponent.prototype= {  //This must match whatever are in chrome.manifest!ClassID:Components.ID ("{E6b866e3-41b2-4f05-a4d2-3d4bde0f7ef8}"), QueryInterface:XPCOMUtils.generateQI ([Components.interfaces.nsICustomComponent]),/*nsicustomcomponent implementation goes here*/  ...};//The following line is a XPCOM uses to create components. Each component prototype//must has a. ClassID which is used to create it.if(xpcomutils.generatensgetfactory) {const nsgetfactory=xpcomutils.generatensgetfactory ([customcomponent]);  This. Nsgetfactory =xpcomutils.generatensgetfactory ([customcomponent]);} Else {    //For Mozilla 1.9.2 (Firefox 3.6)    varNsgetmodule =Xpcomutils.generatensgetmodule ([customcomponent]);}

(3) Add to Moz.build

# Extra_components installs components written JavaScript to# dist/bin/+ =    [' Customcomponent.js ',    ' customcomponent.manifest ',]

Reference:https://developer.mozilla.org/en-us/docs/mozilla/javascript_code_modules/xpcomutils.jsm

2. C + + Component

Copy from Gecko/xpcom/sample/nssamplemodule.cpp

//////////////////////////////////////////////////////////////////////////Define the Contructor function for the object Nssampleimpl////What this does is defines a function nssampleimplconstructor which we//Would specific in the nsmodulecomponentinfo table. This function would//be used by the generic factory to create a instance of Nssampleimpl.////Note:this creates an instance of Nssampleimpl by using the default//Constructor Nssampleimpl::nssampleimpl ()//ns_generic_factory_constructor (Nssampleimpl)//The following line defines a kns_sample_cid CID variable.ns_define_named_cid (ns_sample_cid);//Build a table of ClassIDs (CIDs) which is implemented by the This module. CIDs//should be completely unique UUIDs.//Each entry have the form {CID, service, Factoryproc, Constructorproc}//where Factoryproc is usually nullptr.Static ConstMozilla::module::cidentry ksamplecids[] = {  { &kns_sample_cid,false, nullptr, Nssampleimplconstructor}, {nullptr}};//Build a table which maps contract IDs to CIDs.//a contract is a string which identifies a particular set of functionality. In some//cases an extension component may override the contract ID of a builtin Gecko component//To modify or extend functionality.Static ConstMozilla::module::contractidentry ksamplecontracts[] ={{Ns_sample_contractid,&Kns_sample_cid}, {nullptr}};//Category entries is category/key/value triples which can be used//To register contract ID as content handlers or to observe certain//notifications. Most modules don't need to register any category//Entries:this is just a sample of what you ' d do it.//@see Nsicategorymanager For information on retrieving category data.Static ConstMozilla::module::categoryentry ksamplecategories[] = {  { "my-category","My-key", Ns_sample_contractid}, {nullptr}};Static ConstMozilla::module Ksamplemodule ={mozilla::module::kversion, ksamplecids, ksamplecontracts, ksamplecategories};//The following line implements the One-and-only ' nsmodule ' symbol exported from this//shared library.Nsmodule_defn (nssamplemodule) = &Ksamplemodule;//The following line implements the One-and-only "Nsgetmodule" symbol//For compatibility with Mozilla 1.9.2. You should//If you need a binary which are backwards-compatible and if you use//interfaces carefully across multiple versions.Ns_impl_mozilla192_nsgetmodule (&ksamplemodule)

(Ffos Gecko)-Several ways of registering a XPCOM Component

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.