Tuesday, October 23, 2007

My O.1 Experience

What is the metrics extension you ask? Well, the general idea of the metrics extension is to collect browser usage data. Although the metrics extension is not yet complete, they want to keep track of UI interaction, Usage of Features (bookmarks, extensions, themes.....), Memory usage/effectiveness, system configurations, and other related subjects. It will not however, collect any personal data that is identifiable to the user; everything will just be appended to a non-identifiable unique ID to distinguish different browsers.

For most of my 0.1 release, I have to created a small server script to the metrics extension. This basically involved my server script to recieve requests from the metrics extension and do the following - recieve uploaded data, or send back a config file. Currently, the data sent to the server is just uncompressed and saved into a file to read manually; however, in the future, it will be stored in a database infrastructure and hopefully used to display the data in many ways. For a better understanding of my o.1 release please check out it's wiki - Metrics Server Collection Wiki and to get a working version of the extension please follow these instructions How to enable Firefox Metrics extension.

The experience I had working on my project was quite different from most of my other classes at Seneca. The project required me to work with a massive existing code base, creating patches, debugging, server scripting, and http response headers. The experience was something else and I believe I have gained a better understanding of how my future career experience will be like. In addition, the project has also given me the opportunity to learn about working in an open source environment and the real idea behind community. I would suggest that all student at least try to do something in the open source community once.

Monday, October 22, 2007

How to Enable Firefox Metrics Extension

Before reading this guide, please make sure that you understand how to Patch and build Firefox. The steps will basically assume that you have knowledge of building Firefox and will skip basic information. If you don't understand how to Patch or build Firefox please refer to the "Resources" below.

Basic steps to install & enable the Firefox Metrics Extension

1. Checkout a nightly build from the Mozilla CVS.

2. Patch the metrics extension with this patch
--Metrics Patch--

3. Add the following to the .mozconfig
ac_add_options --enable-extensions=metrics


4. Build Firefox.

5. Go into the "dist/bin/extensions/metrics@mozilla.org/defaults/preferences" folder and edit the metrics.js. It should look like this.

pref("metrics.upload.enable", true);
pref("metrics.upload.uri", "http://matrix.senecac.on.ca/~sljung/metrics/metrics.cgi");
pref("metrics.event-count", 0);


6. Start the Firefox build.

Resources
MDC Build Guide
Guide to Build Firefox in Windows (Blog)
Seneca Lab in Patching
Guide to Patching & Building (Blog)

Thursday, October 18, 2007

Watching a Bugzilla User

For my weekly assignment, I decided to watch Vlad for a week. It was quite interesting to see how many e-mails I would get on a daily basis. In fact, I recieved emails faster than and in more quantity then the spam that goes to my mail. From it, I believe that my user, more or less, watches specific types of bugs. Most of the e-mails I recieved about bugs were on things related to graphics. Not sure if that's the right term; however, most of the subjects were on things like SVG, APNG, CGBITMAPS, canvas, etc....

I actually found most of the bugs interesting and hope that probably in the future I may be more involved in trying to fix them. For now, I will basically do research and learn more there is to all things Moz.

Monday, October 15, 2007

Firefox Extension - File I/O

For my blog post today, I will briefly explain how to write data to a file in a Firefox extension. This can be used for error logging or whatever your purpose. One of my projects has required me to produce XML documents on the local machine; therefore, I have used it for that. Please remember that this is all done using javascript.

The first part of the code basically needs to find the extensions file path. To most, this is within the mozilla profile folder. This is needed if you want to keep the file in the same folder as your extension. Otherwise, you could leave it out or give it a different file path. Id is used to hold the id of my extension.

//get extensions file path
const id = "sample@foo.net";
var extension = Components.classes["@mozilla.org/extensions/manager;1"]
.getService(Components.interfaces.nsIExtensionManager)
.getInstallLocation(id)
.getItemLocation(id);


The second part of the code is used to check whether or not you have the proper permissions to write a file to the local machine. I have not thoroughly tested this though.

try
{
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
}
catch (e)
{
alert("Permission to write to file was denied.");
}


Next, I create a variable to hold my file path (just easier for me); this is done using the extension path that we found earlier. Then create the proper components needed to write the file. First we need nsILocalFile, which to my understanding is like creating an instance of a file object. This needs a path which is basically the filepath I created. Then you need to create it.

//create proper path for xml file
var theFile = extension.path + "\\" + "metrics.xml";
//create component for file writing
var file = Components.classes["@mozilla.org/file/local;1"]
.createInstance(Components.interfaces.nsILocalFile);
file.initWithPath( theFile );
if(file.exists() == false) //check to see if file exists
{
alert("creating file...");
file.create( Components.interfaces.nsIFile.NORMAL_FILE_TYPE, 420);
}


Now, we create an output stream; nsIFileOutputStream, and give it the proper modes. As shown in my comments, I have chosen to do only write, create file if not exists, and truncate which basically deletes the content (leave this out and add 0x10 if you want to append to a file).
Then, you write to the file; giving the content and the length of the content, and close close the stream.

//create file output stream and use write/create/truncate mode
//0x02 writing, 0x08 create file, 0x20 truncate length if exist
var stream = Components.classes["@mozilla.org/network/file-output-stream;1"]
.createInstance(Components.interfaces.nsIFileOutputStream);

stream.init(file, 0x02 | 0x08 | 0x20, 0666, 0);

//write data to file then close output stream
var content = this.xmldoc;
stream.write(content, content.length);
stream.close();


For more information on File I/O you can find it at
Mozilla Developer Center


Also check out the XPCOM reference at XUL Planet
. This is basically where I go to research each component used.