Changes

Jump to: navigation, search

Real World Mozilla Adding Chrome to FirstXpcom Lab

30 bytes added, 22:50, 24 November 2008
Adding our own code
this.initialized = true;
this.firstxpcom = Components.classes["@senecac.on.ca/firstxpcom;1"]
.createInstance(Components.interfaces.IFirstXpcom);
this.firstxpcom.name = "First XPCOM";
// Use the Alerts Service to display the results to the user.
var alertsService = Components.classes["@mozilla.org/alerts-service;1"]
.getService(Components.interfaces.nsIAlertsService);
alertsService.showAlertNotification(null, this.firstxpcom.name, this.total,
false, "", null);
this.firstxpcom = Components.classes["@senecac.on.ca/firstxpcom;1"]
.'''createInstance'''(Components.interfaces.IFirstXpcom);
var alertsService = Components.classes["@mozilla.org/alerts-service;1"]
.'''getService'''(Components.interfaces.nsIAlertsService);
In the former case we use '''createInstance''', which gives us a new unique instance. In the latter, we use '''getService''', which returns a shared instance of an existing component (i.e., a Singleton). Unlike IFirstXpcom, which can be created many times by different callers, the nsIAlertsService is a shared component, because only one pop-up message at a time can be shown to the user.

Navigation menu