← Older edit
Newer edit →
D-Bus and other Linux desktop integration improvements
5,441 bytes added
14:32, 15 December 2006
XPCOM Tutorial and info
=== XPCOM Tutorial and info ===
XPCOM itself provides a set of core components and classes, e.g. file and memory management, threads, basic data structures (strings, arrays, variants), etc. The majority of XPCOM components is not part of this core set and is provided by other parts of the platform (e.g. Gecko or Necko) or by an application or even by an extension.
For D-Bus to work in Mozilla environment we need to create C++ XPCOM components to access the methods with in the D-Bus framework. To create a C++ XPCOM component we need to create the implementation file and component modules for the required methods. Once the components are done we can create interface definition file to connect with the XPCOM components. Follow the steps how to create C++ XPCOM component are listed below.
* C++ Compiler
* GNU make
* Perl 5
====Create the Component====
1. Download the Gecko SDK.
a. You can find it at ftp://ftp.mozilla.org/pub/mozilla.org/mozilla/releases/mozilla1.7.13
b. You can choose a different Mozilla release if you like.
c. Extract the SDK to a local directory.
2. Create a GUID for the main interface.
a. You can use the uuidgen utility to generate the unique 128 bit number. Or
b. You can use one of the special “bots” on IRC at the irc.mozilla.org server (irc://irc.mozilla.org/#mozilla).
3. Create the interface definition file – ImyComponent.idl
a. Use the following template add methods and attributes to the interface.
b. Fill in the GUID you have generated.
int MyMethod(in int a, in int b);
4. Generate the interface header and typelib files out of the interface definition file.
a. Use the xpidl utility that comes with Gecko SDK.
b. Substitute the “_DIR_” in the following commands with the full path to the xpcom/idl directory found under the Gecko SDK main directory.
c. xpidl -m hearer -I_DIR_ IMyComponent.idl will created the IMyComponent.h hearder file.
d. xpidl -m typelib -I_DIR_ IMyComponent.idl will create the IMyComponent.xpt typelib file.
5. The interface header file IMyComponent.h contains templates for building the component header and implementation files. You can copy and paste the templates to create these files, changing only the component name.
6. Create the component header file “MyComponent.h”.
a. Start by inserting double includsion protection code (#ifndef _My_COMPONENT_H_ ….).
b. Add #include “IMyComponent.h” to include the interface definition.
c. Create a GUID for the component.
d. Add the following lines, which define the component name, contract ID, and GUID:
#define MY_COMPONENT_CONTRACTID “@mydomain.com/XPCOMSample/MyComponent;1”
#define MY_COMPONENT_CLASSNAME “A Simple XPCOM Sample”
#define MY_COMPONENT_CID _YOU_COMPONENT_GUID_
e. Copy the header template from IMyComponent.h (starting with /*Header file */) into the MyComponent.h file.
f. Replace all the instances of _MYCLASS_ with the name of the component.
7. Create the component implementation file “MyComponent.cpp”.
a. Add #include “MyComponent.h” to include the component definitions.
b. Copy the implementation template from IMyComponent.h (starting with /*Implementation file */) into the MyComponent.cpp file.
c. Replace all the instances of _MYCLASS_ with the name of the component.
d. Add method implementation code.
8. Create the module definitions file “MyComponentModule.cpp”
a. Add #include “nsIGenericFactory.h” to include Mozilla GenericFactory definitions.
b. Add #include “MyComponent.h” to include the component definitions.
c. Add NS_GENERIC_FACTORY_CONSTRUCTIOR(MyComponent) to define the constructor for the component.
static nsModuleComponentInfo components =
to define the class name, contract ID and GUID of the component.
e. Add NS_IMPL_NSGETMODULE(“MyComponentsMoudle”, components) to export the above information to Mozilla.
9. Create a custom makefiles.
====Building the Component====
1. Build the component.
a. Navigate to the src directory.
b. Issues the make command. MyComponent.so file is created.
2. Register the new component with Mozilla.
a. Copy MyComponent.so and IMyComponent.xpt file to the Mozilla components directory.
b. This directory is typically located at ~/firefox/components (or ~/mozilla/components).
c. Run the regxpcom -x COMPONENTS_DIR command supplied with the Gecko SDK to register the new component where COMPONENT_DIR is the component directory.
d. Delete the xpti.dat and compreg.dat file form the Mozilla profile directory. These files will be automatically rebuilt by Mozilla the next time it is restarted.
e. The profile directory is typically located at:~/mozilla/firefox/default.????
3. Test the new component.
=== DBUS Tutorial and info ===
Retrieved from "
SICT AR Meeting Area
get involved with CDOT
as a Student
as an Open Source Community Member
as a Company
Real World Mozilla
Course Project List
Potential Course Projects
About CDOT Wiki