Changes

Jump to: navigation, search

Real World Mozilla Adding Chrome to FirstXpcom Lab

121 bytes removed, 23:51, 24 November 2008
Integrating with the build systetm
* '''Extension ID:''' firstxpcomchrome@senecac.on.ca
* '''Version:''' 0.1
* '''Target Applications''' Firefox Minimum Version=2.0.0.* Maximum Version=3.0a3pre
After clicking '''Create Extension''', navigate to your desktop and locate the generated file, '''firstxpcomchrome.zip'''. Extract this file somewhere (e.g., '''c:\temp\firstxpcomchrome''').
Now create a file in your profile's extension folder (%Application Data%\Mozilla\Firefox\Profile\''<development_profile>''\extensions) named '''firstxpcomchrome@senecac.on.ca'''. This file should contain the full path to your unzipped extension (perhaps '''c:\temp\firstxpcomchrome'''), and must include a trailing slash. Here is one way to do it:
$ cd Application\ Data/Mozilla/Firefox/Profiles/''development_profile''/extensions
$ echo c:\temp\firstxpcomchrome \ > firstxpcomchrome@senecac.on.ca
Restart Firefox and try out your new extension. By default you should have a new red menu item, '''Tools > Your localized menuitem''' (you should also see '''firstxpcomchrome''' listed in the '''Add-on manager''', along with '''firstxpcom''').
</pre>
Using [http://developer.mozilla.org/en/docs/Themes themes] and [http://developer.mozilla.org/en/docs/Localization localization] are topics in their own right. We'll discuss them again in future labs.
== 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.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.
The '''onOK''' function occurs when the user clicks the accept button (i.e., OK). When this happens the values from the textboxes are obtained and packaged up in the '''out''' parameter we sent in earlier. This is how we pass values back to the main window, and our extension code in '''firstxpcomchrome'''.
= Integrating with the build systetm =
'''TODO''' -- see http://developer.mozilla.org/en/docs/JAR_Manifests for a discussion of jar.mn files in the build system.
=Reflections=

Navigation menu