Import XPCOMUtils.jsm, as explained previously.
Declare the class (or multiple classes) implementing the component(s).
Create an array of component constructors.
Define the NSGetFactory() or NSGetModule() entry point.
The constructor is a simple method that handles any required initialization tasks.
Declare the class prototype, using a form similar to this.
// |(new MyComponent()).QueryInterface(iid)| in its createInstance().
// [optional] an array of categories to register this component in.
// both aPersist and aReplace params.
// object's contractID is passed as aValue parameter of addCategoryEntry.
// category only on the specified applications.
// [optional] classInfo implementation, e.g. using the generateCI helper.
// generated with the generateQI helper.
Note: The ability to register the component in a category only on specific applications by adding the apps field to a category entry was added in Gecko 2.0.
Notice that the QueryInterface() method implemented by the component simply calls the generateQI() method provided by the XPCOMUtils code module.
Here, we're calling the array components.
categoryManager nsICategoryManager Returns a reference to nsICategoryManager.
A "lazy getter" provides an additional optimization: the value is calculated the first time the getter is called, and is then cached (or memoized), so subsequent accesses return the cached value without recalculating it.
This means that you shouldn't use a lazy getter for a property whose value you expect to change, because the getter will not recalculate the value.
the getter function itself, which returns the value and which will be called just once, the first time code tries to access the property.
Example for this is seen at bottom of this page here.
The object into which to add the new lazy getter function.
The name of the getter function to create.
A function that returns the value the getter should return. This function is called exactly once. this will reference aObject during execution of the function.
Defines a getter on a specified object for a module. The module will not be imported until first use.
The object to define the lazy getter on.
The name of the getter to define on aObject for the module.
The URL used to obtain the module.
The name of the symbol exported by the module. This parameter is optional and defaults to aName.
Defines a function on a specified object which acts as a getter for a service. The service isn't obtained until the first time it's used.
The object into which to add the new lazy service getter function.
The contract to use to obtain the service.
The name of the interface to query the service to.
An array of component constructors.
An optional function that is called after the module is registered. See Post-registration callback.
An optional function that's called before the module is unregistered. See Pre-unregistration callback.
An nsIModule that implements the module.
Generates the NSGetFactory() function along with the factory definition.
A function that will return the factory for the components and can be assigned to NSGetFactory global variable.
Generates the NSGetModule() function along with the module definition. You can use this instead of generateModule() to create both the module and the NSGetModule() function at the same time.
Generates an nsIClassInfo implementation for a component. The returned object should be assigned to the classInfo property of a JS object, the QueryInterface() function generated by generateQI will return it automatically then.
An object containing the optional properties interfaces, contractID, classDescription, classID, flags. This parameter should not be the component itself because that would cause a memory leak.
An nsIClassInfo implementation returning the values of the properties from the classInfo parameter in its various properties.
This method throws an exception with the message "In generateCI, don't use a component for generating classInfo" if classInfo parameter is an XPCOM component.
When the generated method is invoked on that object, it checks to see if the specified IID is listed in the array specified by the interfaces parameter; if it is, this (that is, the object itself) is returned. Otherwise, null is returned.
An array of interfaces implemented by the component.
An optional object to import into; if omitted, the object passed in for the that parameter is used.
The nsISimpleEnumerator instance to iterate over.
The expected interface for each element.
A generator yielding enumerated objects.
The nsIStringEnumerator or nsIUTF8StringEnumerator instance to iterate over.
A generator yielding enumerated strings.
An nsIComponentManager instance to use for managing the component.
An nsIFile instance for... what?
An array of the components, as passed to generateModule().
The function doesn't need to return a value.
The nsIComponentManager instance to use for managing the component.
The array of components passed to generateModule().
This function doesn't need to return a value.