Writing a Firefox Protocol Handler

So my plan for this year, in addition to posting more, is to alternate posts between Firefox related and non Firefox related. This one is Firefox related. Hopefully you'll find it interesting either way.

Have you ever thought about the things you type before the colon (:) in your browser? Like http, https, ftp or file? These are called schemes or protocols. Firefox add-ons can add new schemes or protocols to the browser. This post will show you how to do that. We're going to assume you have a basic knowledge of JavaScript, but have never written a Firefox add-on.

Rebrand Updated for Firefox 4

I've just updated Rebrand for Firefox 4.

For those that don't know, Rebrand is an add-on for Firefox that creates an XPI that "rebrands" Firefox, Thunderbird and SeaMonkey. You can change all images and product references except for the menu bar on Mac. Disclaimers apply and are displayed on startup.

I've also updated my Netscape rebranding package. Install it to relive the nostalgia that was Netscape Navigator.

The new about dialog looks especially good.

Add-on-Con 2010

Next week is Add-on-Con and it's exciting to see a lot of buzz this year about the event. It's a great time to be an add-on developer, with many browser vendors participating in the space.

This conference is my yearly pilgrimage to the Silicon Valley and will be extra special since my 40th birthday is on Thursday. I'll be there from Tuesday through Friday and I'm looking forward to connecting with old friends and making new ones.

Hope to see you there!

Reimagining the CCK Wizard

When I originally created the CCK Wizard for Firefox, my goal was to keep the user interface as close to the Netscape CCK as possible. Over time, I added new functionality, but I kept holding on to the original design. With Firefox 4 approaching, I think it's time to reimagine what the CCK should be.

I'd really like to try to engage the community in figure out what to do next. What should the UI look like? Is there missing functionality?

So please do me a favor, install the CCK Wizard and post your opinion. I'd love to take the CCK Wizard in a new direction, but I need some helping deciding which way to go.

Creating a Customized Firefox Distribution

You may have heard of the the Firefox Build Your Own Browser Project. On the web page, it says it "is a simple way that your organization can create and distribute a customized version of Firefox." I think BYOB is a great start to solving the distribution problem, but it's missing one key thing - the ability to bundle your own add-ons.

What I'm going to do with this post is explain exactly how BYOB works internally so that you can create your own distribution that has all the customizations you want. There are a some downsides to our method - primarily that we are Windows only and that we can't sign our installers with the Mozilla certificate. But it's the only way we can create a distribution that includes our own add-ons.

Won't Someone Think of the Add-on Developers?

I have been biting my tongue watching all the changes that add-on developers are being required to make for Firefox 4, but the various theme changes that are going in which are going to cause toolbar icons to be scaled up and/or down has put me over the edge. (See bug 583231). A lot of work is going to be required by add-on developers (and artists and others) to work around these and other issues. It doesn't help that these Firefox "betas" are no where near beta quality, and involve major changes with each beta update, which means add-on developers are having to do rework with every "beta."

Interactive Themes

So you may wonder why we called it Personas Interactive.

If you were go to the Brand Thunder Gallery, you would see what we specialize in - creating customized browser experiences for different sports teams, websites, musicians and more.

These browser experiences have evolved over the years in their design, their technology and even their name. But regardless of the technology change, these browser experiences always required the installation of a Firefox add-on and the restart of the browser for every one that you wanted to install.

One of the reasons we created Personas Interactive was to address this issue. With the advent of Personas in Firefox 3.6, we saw the opportunity to take our browser experience to the next level. So one of the core features of Personas Interactive is Interactive Themes.

Interactives Themes take the Enhanced Personas we talked about last time and add interactivity like clickable logos, sidebars, toolbars, feedreaders and more. So instead of just providing people with a picture of your website or brand, you can provide a way for them to connect with you in the browser.

Enhanced Personas

In explaining exactly what a Persona was in my last post, I mentioned that a Persona contains two images - a header and a footer. I also indicated that these images are very large - 3000 pixels wide. You may wonder why that is. Personas is designed to do one thing; take an image and put it in the upper right corner of the browser. It doesn't resize or scale the image. If you resize your browser very wide, you just see more of the image on the left hand side. That 3000 pixels number is a completely arbitrary number that is designed to be the maximum you will resize your browser.

This architecture creates problems.

  • The file sizes of the images can be very large.
  • If you have a repetitive image, you have to cut and paste it to make it 3000 pixels wide.
  • If you want to use an existing image, you'll have to do something to convert it to 3000 pixels wide.
  • You can't guarantee that anything appears in the upper left corner.
  • You can't have more than one background image.

All of these problems have already been solved by CSS, but none of the CSS to do anything to background images is available in Personas. That's where the Enhanced Personas feature of Personas Interactive comes in.

Enhanced Personas adds additional attributes to the Personas JSON that gives you all the things that CSS backgrounds have to offer. This includes multiple background images! Here are the attributes we've added:

backgroundImage
Specifies the URL of an image or multiple images that will be used for the background. Multiple images are separated by a comma. The images are drawn from right to left, so the left most image appears on top. We aren't using the actual CSS syntax here, so don't put url('...') around the images.
backgroundPosition
Specifies the position of the images in backgroundImage using standard CSS rules. These rules are separated by a comma.

backgroundRepeat
Specifies the repeat of the images in backgroundImage using standard CSS rules. These rules are separated by a comma.

backgroundSize
Dpecifies the size of the images in backgroundImage using standard CSS rules. These rules are separated by a comma.

backgroundColor
Whereas accentcolor in the original Personas specification is used for both the titlebar and the background of the browser, we allow you to specify just the background color. It is never used for the titlebar. If you specify both a backgroundColor and an accentcolor, accentcolor is used for the titlebar, and backgroundColor is used for the background of the browser.

textShadow
One of the other areas that causes problems with Personas is the area of text shadows. We've provided an additional attribute to let you control the text shadow. Personas determines the color of the text shadow to use for your Persona by computing the luminance of the textcolor specified in your Persona.

let luminance = 0.2126 * r + 0.7152 * g + 0.0722 * b;

If the luminance is less than or equal to 110, it makes your text shadow light, otherwise it makes your text shadow dark. We've made textShadow an attribute that you can specify, and you can give it three values: dark, bright or none. You can experiment with these three values to see which one makes your text look good on your Persona.

Summing it all up

So what does all this give us? The ability to create a Persona that takes full advantage of CSS. If you hover over the preview images below with Personas Interactive installed, you'll see examples of Enhanced Personas in action. Each of these Enhanced Personas has an image on the left, an image on the right and a repeating image for the background. If you install them, you can resize the browser and see that the images stay in both corners of the browser. I've deliberately placed breaks in the background image so you can see the repeat. You'll also notice that I've used a different text shadow option for each of the Personas. See if you can figure out which value I used.

Enhanced Persona Demo 1attachPersona(document.getElementById("enhancedpersonademo1-preview"));Enhanced Persona Demo 2attachPersona(document.getElementById("enhancedpersonademo2-preview"));Enhanced Persona Demo 3attachPersona(document.getElementById("enhancedpersonademo3-preview"));Enhanced Persona Demo 4attachPersona(document.getElementById("enhancedpersonademo4-preview"));

Enhanced Persona Demo 5attachPersona(document.getElementById("enhancedpersonademo5-preview"));Enhanced Persona Demo 6attachPersona(document.getElementById("enhancedpersonademo6-preview"));Enhanced Persona Demo 7attachPersona(document.getElementById("enhancedpersonademo7-preview"));Enhanced Persona Demo 8attachPersona(document.getElementById("enhancedpersonademo8-preview"));

Here are some other things to keep in mind with Enhanced Personas.

backgroundImage is a required attribute. This means that even if you use the other attributes, if backgroundImage isn't specified, they won't be honored. The only exception to this is textShadow.

You can create an Enhanced Persona that works with Firefox out of the box. Just specify both a headerURL and a backgroundImage. Personas Interactive users will get the Enhanced Persona.

For our next installment, we're going to talk about the hallmark of Personas Interactive, Interactive Themes and Interactive Personas.

This is part three in my series about Personas Interactive from Brand Thunder. If you missed the first two, they are Introduction to Personas Interactive and What is a Persona?

Personas Interactive

Brand Thunder released a new theme for the Goblins web comic today. While it's a great theme and I'm excited to have it out there, I'm more excited about how we're delivering it. Goblins is the first theme we are delivering on our new Personas Interactive platform.

Personas Interactive is a new add-on that allows us to deliver all of our interactive themes with one click in the same way that Personas works. In the next week or so, it will be available as a standalone download. Right now you can get it by downloading the Goblins theme.

But Personas Interactive isn't just about interactive themes. It provides major enhancements to Personas within Firefox and adds support for Enhanced Personas (more on that later). I'd like to take a few posts to talk about what we've done with Personas Interactive. First we're going to talk about what we've done to Personas; then we're going to talk about Enhanced Personas and Interactive Themes/Interactive Personas. We'll finish the series up by going into details about how web developers can use our new features.

Let's start with what we've done to Personas within Firefox.

We've removed the limits

Firefox currently has a limit of eight Personas. We've completely removed that limit. You can have as many Personas installed as you would like.

We've removed the limitations

Firefox prevented Personas from working with any theme but the default theme. We've removed that limitation. They don't always work right, but at least you can try.

We've removed the lock-in

Firefox uses the same permission model for Personas that it does for the installation of extensions. What this means is that if you give a site permission to install Personas, you're also giving it permission to install extensions. For this reason, Firefox does not make it easy for you to enable other sites to provide previews and host Personas. We've created a new permission model for Personas so you can give a site permission to preview Personas knowing that all they can do is preview and install Personas. Now any site can host a Personas gallery! We'll be providing more detail in the next week on how to do this or if you want to get started now, send me an email. And if you want to see this in action, check out design noir.

We've updated the look (on Windows)

Personas on Windows just don't look right. With the gray tab and the extra dark tab strip, they just don't pop like they do on the Mac. We've updated the Personas look on Windows to be more consistent.

We've given you the choice

We've added additional configuration options so that you can make your Personas look the way you want them. If you wish you could see just a little more of your Persona, add some space. If you don't want the titlebar to change color on Mac, turn it off. If text shadows make your Persona look bad, turn them off.

We've added some really cool stuff

We've enabled site specific Personas. Any website can put one line in their HTML so that people see a Persona when they viewing that site. Of course they have to ask your permission! If you want to check this out, you can load my blog with Personas Interactive installed.

In my next post, I'll be covering Enhanced Personas. The best analogy I can give is that Personas are like a bumper sticker on your browser. For the artist, Enhanced Personas give you a palette so you can size, position and repeat any number of images on the background to create a design that's exactly what you want and that resizes with the browser. I think you'll like it.

One more note - Brand Thunder brings you VERY cool themes and extensions for FREE, but each takes a team of designers and developers. Brand Thunder themes include Bing as the default search engine since our primary revenue source is our search partners, Bing and Ask, so please give them a try.

And before you ask, we're hard at work on Firefox 4 support. We hope to have something in the next few weeks.

Customizing the Firefox Installer on Windows

One of the questions I get asked a lot is how to customize the Firefox installer on Windows and how to bundle extensions with it. I've spent the past few days learning a great deal about this subject, so I thought I would take this opportunity to provide a refresher on working with the Firefox installer on Windows. I'm going to do it as a Q&A so hopefully folks will get answers to the common questions they have.

Standard disclaimer: Under no circumstances should you use this information to create a custom Firefox install and redistribute it to anyone outside your organization. If you want more information, you can consult the Mozilla Foundation Trademark Policy.

What tools do I need to work with the Firefox installer?

The primary tool you need is 7-Zip. I install the MozillaBuild package which gives me all the tools I need. Even though the Firefox Installer is NSIS based, we will not need to use NSIS for most customizations. I'll talk a little bit about the end about what kinds of things you would need NSIS to do.

How do I unpack the Firefox installer?

The Firefox installer is created using 7-Zip. So you can grab any of the Windows installers that end in EXE and unpack them. Any of the Windows installers on the Firefox download page will work. Once you've downloaded the EXE, create a temporary directory and type:

7z x "Firefox Setup 3.6.3.exe"


This will unpack the contents of the installer so we can modify it.

How do I bundle my extension with the Firefox installer?

Bundling your extension with the Firefox installer is just a matter of putting it in the right place. Then when we package up the installer at the end, it will get installed along with Firefox. For most extensions, the right place is nonlocalized/extensions. Inside that directory, create a subdirectory that corresponds to the ID of the extension you want to preinstall with Firefox. Then unzip the XPI into that directory. You can find the ID by looking at the install.rdf file inside the XPI. You can add as many extensions as you want into the installer.

What are some useful extensions I can bundle with Firefox

I've created two extensions that create interesting things to bundle with Firefox. The first is the CCK Wizard. The CCK Wizard can be used to change various defaults in Firefox so that you can customize it for deployment in your organization. The second is Rebrand. Rebrand allows you to change the internal branding used in Firefox.

Can I change the names used in the installer?

Yes, you can change the names used in the installer. To do this, you need to create a directory called distribution inside the localized directory that was created when you unpacked the installer. Create a file called setup.ini in this directory. Here's what it looks like:

[Branding]
BrandFullName=Mike's Browser
BrandShortName=Browser


BrandFullName will be used to replace "Mozilla Firefox" and BrandShortName will be used to replace "Firefox".

Can I change the images used in the installer?

Yes, you can change the images used in the installer. In that same directory where you put the setup.ini, you can put two files, modern-wizard.bmp and modern-header.bmp. The first images corresponds to the large image on the first page of the installer. The second image corresponds to the small image that is used on later pages of the installer. You can use the linked images as a reference to know what size to make these images.

How do I repackage the installer?

To repackage the installer, first you need to zip up the changes that you made. Type:

7z a -r -t7z app.7z -mx -m0=BCJ2 -m1=LZMA:d24 -m2=LZMA:d19 -m3=LZMA:d19 -mb0:1 -mb0s1:2 -mb0s2:3


This will create a file called app.7z that has all the changes we made. Now we need to package that file with some other files to create the final EXE. We'll need the file 7zSD.sfx which you can download from Mozilla. And we'll need a file called app.tag which you can create. It looks like this:

;!@Install@!UTF-8!
Title="Mozilla Firefox"
RunProgram="setup.exe"
;!@InstallEnd@!


Once we have these files, we can run the command:

copy /B 7zSD.sfx+app.tag+app.7z our_new_installer.exe


to package them all as an EXE. Don't forget the /B. It indicates that the files are binary so Windows won't put an EOF marker on them.

Can I change the defaults that are set in the installer like the install directory or the checkboxes?

At this time, there is no way to change the defaults in the installer without rebuilding the installer. There's a bug open on this with a patch, so hopefully this will be fixed for Firefox 4.

Can I make my totally rebranded Firefox coexist nicely with an existing Firefox?

There are a couple ways to do this. The easiest way is to use the -no-remote parameter when you start Firefox. This causes the Firefox you are starting to not connect to the Firefox that is currently running. When you do this, you have to specify a different profile using the -P parameter. Alternatively, you can change the internal identifiers that Firefox uses. Then it will be considered to be a completely different browser. If you choose to do this, you should be aware that you will not receive updates and there will be other side effects. This is not a decision that should be taken lightly. Also, your profiles will be stored in different locations as well. If you want to do this, check out the file application.ini in the nonlocalized directory. The variables you want to change are Vendor and Name. Again, you do this at your own risk.

What can I do if I'm willing to rebuild the installer with NSIS?

If you are willing to rebuild the installer, you can change things like the name of the entry in the Add/Remove programs list, as well as the install directory and other defaults. This is a nontrivial exercise because some of the required files are built as part of the Mozilla build proces and are not available in the build tree. If you're really interested in doing this, you can contact Kaply Consulting and we can talk about it.

I hope this answered some questions folks have. If anyone has any more questions, please don't hesistate to ask.