Mozilla components

firefox plugin development December 15th, 2010

Mozilla products are built based on XPCOM, a cross platform component object model. To build a mozilla product, one can make use of already available components and build additional required components. What does this mean? Mozilla components represent callable modules which are exposed to the outer world through interfaces which are XPCOM compatible.

Short example of mozilla components:

For sake of argument, assume that there is no global scoped function called “alert()” in javascript which generates a popup message. The only way of creating a popup box is to access a mozilla component as below:

var sample = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].
getService(Components.interfaces.nsIPromptService);
sample.alert(null, “Window Title”, “Alert Message”);

So in a world where “alert()” was never an openly callable function, mozilla components like the one mentioned above which is aptly named as “prompt-service” expose functionalities that can be accessed from outside.

XPCOM was developed so that different components can be developed in different languages and can all be exposed to each other via common interfaces. Hence you can imagine developing mozilla components in Javascript, C++, python and other languages as long as they maintain XPCOM interfaces appropriately. XPCOM interfaces for mozilla components are based on IDL which is an interface description language. Learn more about IDL here .

If you want to know all the mozilla components available on your firefox, you can install the XPCOM Viewer plugin. The following image shows the mozilla components installed in my firefox installation. All these components expose functions that can be accessed as we did in the above example. Since it is cross platform you will be able to find ways to access them across many languages.

Mozilla components in firefox