The Inside Track on Firefox Development.

« March 2006 | Main | May 2006 »

April 26, 2006

A Journey Through Feed Handling

One of the areas of focus for us for Firefox 2 is Feed Handling. With this release we are seeking to make feeds more useful to more users, and along the way to that goal improve on some of the shortcomings of Firefox 1.x. My plans are outlined in this newsgroup posting.

What this post is about however is not about UI design but about implementation. This has been a very interesting journey so far, and I’ve learned a lot about our networking APIs in the process. Thanks much to darin, bz and biesi for the help.

Here I’m going to focus on the first of two interesting aspects of the requirements described in my newsgroup posting: showing a display page when feed links are loaded.

Towards the end of Firefox 1.5, a prototype feed pretty printer was landed. It had very many problems, and was removed. The solution was a hack – it observed every page load and tried to guess if the content was a feed or not. It guessed wrong many times because of the various types feeds are (incorrectly) served as, was jarring to use (since it appeared only after the feed document had initially loaded and potentially displayed some content to the user) and had many issues.

For Firefox 2, I wanted to approach this from a different angle. I wanted to integrate this well, using the APIs exposed by our system, for clean code, but also to prove that it could be done.

Content Sniffing

The problem with detecting feeds is that very many feeds are served with incorrect or overly generic Content-Types. Some are served as text/html which is clearly wrong, but others are served as application/xml or text/xml which is not incorrect, just not specific enough. We can’t attempt to parse every candidate Content-Type as a feed just to see if it is, since that would significantly impact our performance. We also can’t restrict ourselves to Feed types, since that would leave us not detecting a lot of feeds, and still be incorrect.

So, what we needed to do was implement a content sniffer. Biesi added support to nsBaseChannel and nsHttpChannel for third party content sniffers to be consulted during document loads. By adding an entry under the net-content-sniffers category, a component implementing nsIContentSniffer can be asked during any load that includes the flag LOAD_CALL_TYPE_SNIFFERS (i.e. any load within a docshell or frame) for their take on what the Content-Type of the document is.

The content sniffer is given a chunk of the data. It was here that I discovered that data can be compressed with Content-Encoding: gzip, and this level is low level enough that it is not already decompressed. So I had to invoke another stream converter on the compressed data to get the real data out.

At this point, I could run some checks against the data, based on the heuristic defined in Microsoft’s Windows RSS Publisher’s Guide. (For web content interoperability, copying is good). If the data looked to be feed content, I informed the caller that the content type was really a special type, application/vnd.mozilla.maybe.feed.

I also take care not to coerce my special type when the URI is loaded by view-source, since this causes syntax highlighting not to work correctly otherwise.

Stream Converters

Gecko handles various types internally, but my maybe.feed type wasn’t one of them. I needed to find a way of saying that content with that type should be loaded in the browser window, but with some special modifications. I needed to implement a stream converter, and register it somehow. After some time spent messing around with the browser’s content listener implementation in browser.js, I found out that that code wasn’t really used at all and should be gotten rid of.

I had a conversation with Boris and he described the way the URILoader handles unknown types. It’s a six step process that involves a couple of different interfaces and begins in nsDocumentOpenInfo::DispatchContent. This function handles figuring out where content is loaded and what happens to it.

The first check is to see if the content must be handled by a helper application, as specified by a Content-Disposition response header. If this is set the entire process below is short-circuited and we skip directly to step 6, handle with the External Helper Application Service (hereforth refered to as “EHAS”).

  1. First, the DocShell’s URIContentListener is given a chance to handle it. This takes care of types internal to Gecko. If the DSURIContentListener wants to handle it, then DispatchContent returns successfully. We are not an internal type, so we do not want to register our feed handler here.
  2. Second, the list of URIContentListeners held by the URILoader are enumerated, and each asked if they want to handle the content. These content listeners have no reference back to the DocShell that was handling the load, so this is not useful to us either as we cannot output anything that the user will be able to see.
  3. Third, the set of URIContentListeners registered using the “external-uricontentlisteners” category are tried. This step involves the same limitations of the second step – no access to the DocShell, and is thus useless to us for the feed case.
  4. The fourth step is to see if there is a component implementing nsIContentListener registered under the @mozilla.org/uriloader/content-handler;1?type=<type> contract id. If there is one, its handleContent method is invoked. This is not useful to us.
  5. The fifth step is the one that works for us. If nothing so far has handled the content, the URILoader tries to find a stream converter from the unknown type to the “wildcard” type - */*. If one exists, it will construct it and use it to display data in the DocShell. Viola!
  6. For the interested, the sixth step should the previous five had failed is to hand the process over to the External Helper App Service for handling by a desktop application or download to disk.

So, I wrote a component implementing nsIStreamConverter and registered it for the conversion from my maybe.feed type to */*. Sure enough, it was invoked. In my asyncConvert implementation, I cache a reference to the nsIStreamListener that is passed as an argument, this is the DocShell’s listener and is needed later, to display the XUL page.

Parsing Data

With bug 325080, Robert Sayre has been working on an all-purpose multi-format Feed parser for Mozilla applications. Part of the API exposed through nsIFeedProcessor is the ability to asynchronously funnel data through it. In my nsIStreamListener methods on my Stream Converter, I forward the data on to the Feed Processor, which does a lot of magic to abstract away the differences between the various feed formats.

Opening the Preview Page

Once the data is parsed, I open a channel to the XUL page using the cached DocShell listener above. This results in the page being loaded in the browser window. I set the originalURI property of the chrome channel to the URI of the feed, which makes sure that the location bar shows the URI of the feed, not the URI of the XUL page.

From the Preview Page, I needed to be able to get at the feed data so that I could show the title, etc. However the feed was parsed in the stream converter, and there was no conduit between the converter and the resulting XUL document. So I used a singleton service for registering parsed feed documents and used that to effectively pass the parsed feed over to the XUL document. One problem remained – if I register a parsed nsIFeedResult with my result service for a specific URI, how do I get that result again from the XUL document, if I don’t know the URI anymore?

The truth was amusing – I did know the URI. Since I set the originalURI property to be the URI of the feed document, window.location.href in the XUL document actually pointed to the feed URI. So I was able to pass that to my result service to get the parsed result.

That’s A Wrap

And that’s it. There are many details involved in the construction of the XUL page, and the various handling options available to feeds, but those are outside the scope of this post. I just wanted to share my experiences using the Gecko APIs for content handling. With a few tweaks to support content sniffing and some bug fixes elsewhere, this entire system was developed in the application layer, meaning that an extension could implement this kind of thing if it wanted. That’s impressive flexibility!

Later on, I’ll talk about how I implemented support for handling feeds with web services.

Posted by ben at 6:29 PM | Comments (10)

Firefox 2 Is Cool

A lot of people read my previous post and came to a very reasonable conclusion: "If you take Places out of Firefox 2, shouldn't it be called Firefox 1.6?"

I don't agree that Places was the one and only thing that sold Firefox 2 though. I took a look through the Firefox 2 Requirements page to look at some of the other stuff that's going on. Reading that document, I think I can see now why people are down in the dumps about no-places Firefox 2. I don't think that document necessarily does the best possible job of capturing the excitement I have about some of the Firefox 2 features we're pursuing.

For the past week or so, I've been toting around a printout of another document, which I wrote because I wanted to convey some of the vision I have of the Firefox 2 product as a whole - a more holistic view as it were.

Safer, Faster, Better

If you take a look at the black buttons stacked in the right column of this page, you'll see that one of them reads "Safer, Faster, Better." I don't knowwho came up with that one but it's a good tag line. It has a certain cadence about it. People have attached lots of these to Firefox in the past - "Take Back the Web" was the one I came up with, there's "Rediscover the Web", the FirefoxFlicks project has yielded a few good ones too - I like "Web For All". But "Safer, Faster, Better" is not just a tag line, it can also map into a set of themes for product development.

So, taking a look at the Requirements page, I attempted to do that. My document wasn't a comprehensive collection of everything on that page, I was focused more on the things immediately visible to most users. I guess my problem with the Requirements page has always been its very engineering/technical focus. The result of this is that the priority of items tend to reflect how difficult something is to implement, or where it lies in the development cycle, not necessarily the impact on the user. What I ended up with I guess is a sort of "Shadow PRD" that reflects what I personally thought was cool about Firefox 2, and what I wanted to get out of it.

A copy of the document is here.
Some notes:

  • Assume the scratched out section for "Retracing Your Steps" will be part of a future release.
  • The priorities shown are my opinion, and relate to potential impact on the user.
  • The document does not represent all of the work being done, just a readily marketable subset.

All in all, I think there's easily enough here to justify a "2" designation. That's just my opinion though. I also think whole numbers are probably easier for the general populace to understand than decimals.

Firefox has never been about date driven development (within reason). The changes with Places should not be seen as a change in this sentiment. What we're about is high quality software development with real advantages to
users, and I think that with the updated plan we're still on a trajectory that supports and encourages that, perhaps more firmly now than before.

And that's it from today's "Ben waits for the tinderboxen to clear" report.

Posted by ben at 2:34 PM | Comments (58)

April 24, 2006

Firefox 2 Content Update

When we began work on Firefox 2, we decided to focus on a development branch, a continuation of the Mozilla 1.8 branch. The reason for doing this was that there was to be a lot of significant architectural changes going on on the trunk, with the prospect of a new rendering back end, a rearchitecture of reflow in layout, and various other things. Shipping a Firefox 2 release in 2006 off of this code did not seem possible.

As a result, we decided to pursue a release focused on application level improvements, on a separate branch. Going into it, we knew the perils of multi-branch development. We knew the divergences that would inevitably form between branch and trunk. We had experience from the painful development of Firefox 1.0 on the Aviary branch. We resolved to be more methodical about our commits, but we knew to expect some pain. The goal was to produce a high value release in short enough time so that we could all return to the trunk and help build new features that utilize the back end being developed there, to help shake them out.

Late last year, we put together a list of things to pursue for the Firefox 2 release. A month or so ago, we got together as a group and formalized this more in a Firefox 2 PRD. We had scheduled four major pre-release milestones, two alphas and two betas. We have already shipped one alpha. The intent of the second is to be "Feature Complete".

The people driving the various sub-projects on the Requirements list get together weekly to check status. As the weeks have gone by, it has become clear to us that the most complex feature on the plan is Places. It is easily an order of magnitude more complex than anything else on the plan. Places is a great feature and it has been exciting watching its capabilities grow. We are looking forward to the capabilities that it will expose. What we have learned though is that the work required to complete Places is probably too substantial to gate the Firefox 2 release. It falls more into the "significant rearchitecture" category of feature that's generally been targeted at Firefox 3.

What we have decided to do is as follows:

  • We will disable places on the 1.8 branch, reverting the user interface and back end to Firefox 1.x functionality.
  • We will continue to aggressively develop the capabilities of Places on the 1.9 trunk. Places will remain enabled here.

We think this is a good decision for two reasons:

  • It reduces the pressure on the Places team to deliver a lot of bug fixes and additional features on the very immediate timeframe required by the Firefox 2 testing releases. It is my opinion that doing so would impact the quality of the feature, if we did not add at least a couple more alpha cycles to the process. This decision provides us with an opportunity to really make the architecture and user interface of Places reach their full potential.
  • It allows us as a group to circle around and consider the content of the Firefox 2 release holistically, identify high impact at risk areas and spend some more time on them. One of those for me was Feed Handling.

Michael Schroepfer of the Mozilla Corporation has a newsgroup posting with additional information. His thread is also the most appropriate forum for discussion of this topic.

I have been working on refining some of the messaging surrounding feature content and prioritization on the PRD. I will post the initial results of that here soon.

Posted by ben at 9:30 AM | Comments (31)

April 16, 2006

Did I Mention...

... that I hate this computer?

While I'm at it... the up arrow key cap fell off after about three weeks, in early 2004. About six months later I lost the little rubber membrane thing that made it slightly easier to push the arrow. Since then, I've been typing by pushing down on the little connection thingy on the keyboard tray.

It's been shedding pieces of plastic too. I've never dropped the computer once, but pieces of the shell have begun to snap off.

When I first got it, when the secondary battery was in place, when the primary drained the machine would hibernate, even though the secondary was present! Pretty awful bug to ship with. There was never a solution that I could find. Speaking of batteries, the primary battery is pretty much toast... it won't go for more than 5 minutes before shutting down. It began doing this at around the 12-18 month mark. And the battery light permanently flashes orange whenever the system is on.

Why don't I call the hotline? I guess I'll have to, before my warranty runs out. I don't because it usually involves 45 minutes on hold or explaining to someone who only has a script to read from that the issue involving a missing up arrow doesn't require restarting Windows or running some stupid diagnostic tool. I could have paid more for "premium support" at build-time but I found that concept sort of insulting: why should I have to pay extra to speak to someone who is smart and doesn't think I'm a moron?

And I don't want a Thinkpad either. I hate those computers. They have old-fashioned 4:3 displays, and the function key and left Ctrl key are reversed. I know I could map them differently but why would I? Why couldn't IBM just have designed the product correctly in the first place? Oh, and I'd sooner drink paint than run the awful IBM access connections software to connect to a wireless network, or deal with the fact that the Num Lock key seems to reset to ON every time the system is rebooted.

Why doesn't someone make the perfect laptop? I'd be interested to hear from someone how long the compile times are for FirefoxDebug on a 2.16GHz MacBook Pro...

Posted by ben at 7:11 PM | Comments (22)

I Hate This Computer

I have been fighting with this computer for the past few days to do a build with a few patches applied.

First, I managed to get a certain distance with a branch build, compiling with Visual C++ 6.0. But soon I realized there were too many dependencies that were trunk specific, so I had to build trunk. About a quarter of the way through my build died, of course, compiling from the same shell, wrong version of VC6.0 for Cairo/Thebes.

Starting over again with the VC7 tools, another failure towards the end. Some sort of cyclic dependency check error. Clobber and restart. Now I forgot one of my patches had a configure change, and the process begins anew, I have effectively clobbered.

When I bought this machine, a Dell Precision M60 with a Pentium M 1.7GHz processor, a 7200rpm disk and a gig of RAM, it could compile Firefox start to stop in 21 minutes. Now it takes over an hour.

The situation is better on my Google-supplied workstation, but for how long? Over time, Windows reaches a point of being completely useless for anything aside from the most basic activities. What's the effect? I had planned to work both days this weekend on Firefox 2 features. Instead I spent the whole time fighting one of the most frustrating fights possible, and have achieved nothing. I hate Windows. I hate this computer.

Posted by ben at 6:58 PM | Comments (13)

Miscommunications

My laptop was running pretty slowly yesterday so I decided to scan the Add/Remove Programs list to clear out the cruft. Things were really chugging along. I sequentially uninstalled several pieces of software, and the process was very dissatisfying. I became more and more enfuriated at my computer as it proceeded. Here are some of the nuisances:

  • I could only remove one thing at a time.
  • Many pieces of software used the Windows Installer system which seemed to take forever and report very inconsistent progress (I know, Firefox isn't the best at this in its installer, either)
  • Most annoyingly, the uninstaller apps all reported themselves as performing a variety of actions that I never requested, as explanations for what they were doing during long periods of inactivity and progress-bar freeze. Common excuses were "Windows is Configuring " and "InstallShield is preparing a report on ".

You know, I never asked for blah to be "configured." I never asked for a report on bleh (What am I, a manager? Where is the report anyway? Does it have the appropriate cover sheet?) I just want the software gone. I'm getting really tired of excuses from software like this. Windows software seems to be getting worse and worse. On Mac, the typical way to remove a program is to drag it into the trash can. I can even do that to several programs at once! I do however have to be able to afford a Mac (I can, I have one). Many folk aren't as fortunate as I.

As a side note, I read an interesting article in Forbes a few weeks ago criticizing Microsoft for its delays shipping Vista, and asking why wouldn't you just side-step all the trouble and buy a Mac, since the odds were good many people would have to upgrade their PC anyway just to get the whiz-bang in Vista. The article side-swiped open source desktop initiatives, asking where the viable free alternative was. I think that was an interesting point, and especially so since the capabilities of Linux systems have come an awesome distance in the past few years but there have been few distributions or desktop environments that IMO make the most of all of those.

Posted by ben at 6:05 PM | Comments (9)

April 10, 2006

Firefox Version Numbers

Mike Beltzner explains Firefox version numbering. i.e. Firefox 3 RTM is not "out".

Posted by ben at 8:38 AM | Comments (4)

April 7, 2006

Our Next Challenge?

The past year or so has been interesting. In this time, I've been able to meet a lot of new people and learn a lot of new things. Most importantly is that for the first time in as long as I can remember, I have had a chance to see the Mozilla project from the outside, as it would appear to someone who was trying to build on Mozilla technology or contribute directly to a project, but was not part of Netscape "back in the day" or an employee of the Mozilla Foundation/Corporation itself.

It's been an illuminating experience. From a technical perspective, it helped highlight APIs that I had developed without a clear understanding of how they would be used. The Extension Installation API was one example of this, and we were able to make some great improvements to it in 2005.

But perhaps more importantly it has shed some light on how people perceive Mozilla as an open source project. These perceptions are not the sort of things people express explicitly. You have to notice them.

The Difficulty of Involvement

This is sort of the uber-perception. I think some of the reasons for this include the following:

Where is the Discussion?

Which newsgroup/mailing list/IRC channel/wiki/talk page/bug/forum page do I need to track in order to know what's going on in a specific area? The answer is unsatisfactorily complex.

The traditional method of joining a project in the OSS world (where you join lists and IRC channels and lurk for a while, gradually ramping up your contributions) scales uneasily to a project the size of Mozilla. The amount of data a mere mortal would have to absorb in order to be productive quickly is staggering. I have in the past jocularly referred to it as the "learning wall". I wonder how many people just give up.

Madness to Method?

As a large project, Mozilla has thousands of source files across hundreds of directories. One of my coworkers here at Google commented that he tried to find something as simple as the browser window code a couple of years ago and couldn't, because it lived under the thoughtfully named "xpfe".

There's not a huge amount of documentation - and I'm not just talking about public API docs. I'm talking about the much needed diagrams that show how the various building blocks fit together, and in-code documentation for pretty much anything that isn't intuitive (which is a lot). I've written as little of this as anyone else.

Tone

In the past, I have not done the best I could to establish a tone for discourse that is conducive to productive development. My tendency was to snap when provoked. I made two mistakes of judgement here, one was ignoring the effect that this sort of thing would have on those watching, aside from the victim. The other was to think that regardless of the tone set by my actions, we as a group could work through any negative effects. Any work we relied on others for we could do ourselves. Or we could hire through it.

The Joy of Code

The flaw with this is that when your project's contributions come solely from companies, for better or for worse the activities of those paid contributors will align in some way with the interests of those companies. What this does not always allow for is the pursuit of the sort of improvements that are outside the scope of these interests. Such things often include raising general code quality, speculative feature development, feature polish and detail etc. I don't mean to say that companies are against these things, but they're often not the primary concern during a release crunch. And what companies like to have is shipping software.

Alternately, even in the absence of corporate support, if there is not enough redundancy that the same set of folk has to do the grunt work over and over, the risk of burnout is high.

I feel this because I have been incredibly "plan" focused over the past few years, formally during my time at Netscape and less formally but no less importantly during the run up to Firefox 1.0 and 1.5. What I notice is that I no longer have time to work on the sort of interesting side projects that I used to enjoy doing when I was first starting out.

For example, about six years ago I discovered a bug in the Bookmarks menu shortly after scrolling was implemented. When you moused into a submenu for a folder that was in the scrolled section, the sub menu popup was pushed off the bottom of the screen. I took a couple of days to learn the menu positioning code and fix the math error that was causing the bug. The exercise was good for me in a number of ways: I learned more about another section of the code, my general expertise was raised, and well.. I fixed the bug that was bothering
me.

I think we need to have a project that is accessible to volunteers for this reason. We also need to provide a way to allow those volunteers to grow if they want to, so that if you're one of the folk at the center you can have a chance to step aside for a moment and take a breather and code for the pure joy of it.

Full time paid contributors will always be a part of Open Source development. But I don't think release-focused agendas will ever be a substitute for the passion of folk who participate because of the joy of exploration and of contribution.

Looking Outward, Looking Forward

As a project, we have made overtures towards being a more inclusive lot. For some of the reasons I've listed here, I think as a project we're still more inward looking than outward. How many of us have thought about what we want to be doing in 5 years? Will we always be doing this? Will our roles remain the same? My opinion is that it's fast becoming time for us to start considering making personal sacrifices in our short term conveniences to make the project more accessible to new people. Do I know what we need to do? Not exactly. But I have some ideas: find ways to make our discussions, our public faces, and our code more accessible.

With Firefox we did an excellent job of building a world class product that people wanted to use. We have a new challenge now, one that is larger and scope and in the long run in my opinion considerably more important because the long term success of products like Firefox depend on it. How will we grow a world class development community? How will we ensure that the freedoms we enjoy are protected, forever?

Posted by ben at 9:22 AM | Comments (17)

April 4, 2006

Congrats Relicensing Project!

Gerv announces that the Relicensing project is complete. Congrats Gerv and everyone else who doggedly pursued this over the years. Part of Mozilla's mission is preserving choice, and making our code available under a variety of flexible licenses helps ensure that by allowing other projects to make use of it. This was a formidable task and a great accomplishment.

Posted by ben at 7:15 AM | Comments (2)