Wednesday, December 22, 2004

Firefox 101

So to prove to all you doubters out there that I am not just a MicroSerf I decided to make my first post about the most excellent browser Firefox. Of course I have never used it before so I had to get cranking. So where do I get this wonderful product? That part was easy. Type FireFox into the Google bar and you get a direct link to Fire Fox. Well so far so good.

The download and install on my MicroSerf windows machine was quick and easy. It even offered to import my Microsoft Explorer items. How nice. The browser came right up. It seems pretty fast too. I would not hesitate to say it is several times faster than Explorer. So I decide to go for a real test: Will it just play a Macromedia file? Nope. It failed that test. Not one to give up I decide to give it another chance. I go to the Macromedia Flash Download page, download and install the Firefox version, restart Firefox, and it all works out. Not too shabby.

Now I did not download Firefox just to play with a new browser. I wanted to figure out how there plug-ins worked. The real fun of Firefox is writing add-on’s. In this area Firefox is no help at all. I had to find a third party site called Roachfiend to help me out.

So what does every programmer do first? HELLO WORLD! Yeah baby! Roachfiend has a nice starter demo to show you what you can do. Please go to his site and download the XPI file so you can follow along. The first thing I learned was an XPI file was just a zip file with a different name. Ok. We have all seen this. EAR.WAR.JAR. Should I go on?

Apparently every extension consists of three items.

install.js: provided for backwards compatibility with version 0.9 and earlier.
install.rdf: descriptor file
helloworld.jar: actual program

In the install.rfd there are several items. The majority of them are self explanatory. The tag is a GUID that uniquely identifies your application. There are plenty of tools to generate a unique GUID for you.

The iconURL and aboutURL tags are optional and you can leave them out if you want. They provide the “About” functionality for your extension. The package tag points to your application files and the skin tag is optional if you want to skin your application.

Now on to the application. It must be packaged up as a .jar file. Apparently the jar file has to have a directory called crome and all of your source files go under there. If you look at the helloworld.jar file you will notice that the package directory has the following files:

about.xul: contains code for the about box.
contents.rdf: location of all the files
helloWorldOverlay.js: application code
helloWorldOverlay.xul: application look

The about.xul and helloWorldOverlay.xul files are XML files that define the forms that we are working with. The GUI if you will. You should learn XUL if you are going to be working with Firefox extensions. I would start with Mozilla’s programming guide. I sure will!

The helloWorldOverlay.js is the code to show the “Hello World” popup. It is a simple javascript alert box. The contents.rdf file just tells the browser the location of your extension files.

The skins directory provides a way for you to use custom images, etc, in your plugin. I am not going to go into too much detail. It is setup basically the same way as the code section.

Once you have created your files, and packed them into the .jar file, and .xpi file all that is left is to install the extension. It is very easy. Just choose File->Open in the browser, and choose to install it. It also appears as if these extensions are turned of in safe mode. So just make sure you run Firefox in the normal mode.

This was an intro to Firefox and many thanks to the Roach Fiend. In the future I will update you with any interesting projects I do with Firefox.

0 Comments:

Post a Comment

<< Home