Answering questions by looking at code

A contributor recently asked a question in #introduction that I couldn’t answer immediately, but I suspected that I could find the answer without too much work. I also decided to write down the steps I took and the reasons I took them, with the intent of creating a worked example of finding answers in the Firefox code.

The question: how do I determine if a given URI pointing to an RSS feed is subscribed as a live bookmark?

My first instinct when looking for code I have never touched before is to start with the visible strings in the Firefox interface. In this case, I went to and clicked on the RSS feed button to take me to the RSS feed viewer. Under the options for possible subscriptions, there is the “Live Bookmarks” choice. I’m going to find the code that handles subscribing a live bookmark, which should lead me to the way to find out if a feed is currently subscribed.

So, off to MXR:^[^\0]*%24&hitlimit=&tree=mozilla-central

Strings are usually stored in special localized files, where the actual string is referred to by a unique name. In this case, we’re looking at, which shows us that some code should be using the name liveBookmarks to show the localized string in the feed viewer window.

Let’s look that up:^[^\0]*%24&hitlimit=&tree=mozilla-central

Out of the results, subscribe.xml sounds like something I want to read:

Unfortunately, that line turns out to be not very interesting. However, let’s see what we can find for liveBookmarksMenuItem, which sounds like it might be the item for the live bookmarks option in the dropdown:

Let’s look at FeedWriter.js from the results:

Woah, that’s a lot of code! Let’s take a step back – we care about the subscribing action right now. Going back to subscribe.xml (, notice that the button is called subscribeButton. That sounds really useful! Let’s look in feedwriter.js again for that (just a regular ctr+f operation):

Now, let’s find the function subscribe (ctr+f for subscribe:, as that’s commonly how member functions are defined in the Firefox source):

Reading the source of subscribe(), we come to

We can see the definition of addToClientReader at Let’s look at what else is defined here – this seems to be implementing the nsIFeedResultService interface, so we can look up the nsIFeedResultService.idl file in MXR:

Unfortunately, the service seems to be dealing with actual feed contents, and it doesn’t look like there’s a direct function to help us – let’s step back and see how addToClientReader is implemented. is an important line – let’s look at addLiveBookmark (I just clicked the name again):

Take a look at This shows us how a bookmark dialog is created, but not the actual subscription process. However, the important part is line 471, which shows us the type "livemark". Let’s search for that string and see what other code uses it:

Woah! There are a lot of results! Since I’m not certain what I’m looking for at this point, I find the best thing to do here is to scan all the results quickly, looking for interesting snippets or filenames before opening any particular file. Partway down, there’s a file called test_bug636917_isLivemark.js (

Searching for livemarks in this file, we find line 2234 which defines the livemarks object as the nsILivemarkService service. Let’s look that up!

First the idl definition, to see if this service will be useful: There’s a method called getLivemarkIdForFeedURI (, which looks to be exactly what we want – it gives us a -1 result for a non-registered feed and another number for a registered one.

So, to sum up – we have found a service that will take a URI and return a value that can be used to determine whether a given feed is a subscribed livemark, and we have learned that livemarks are the internal name for Live Bookmarks. The only bit remaining now is to get access to this service, but we can either use PlacesUtils.livemarks for that (if we import PlacesUtils.jsm), or just use a normal getService call. These are just details; the hard part of answering the original question is complete!

One Response to “Answering questions by looking at code”

  1. Hello, its good piece of writing about media print,
    we all know media is a wonderful source of data.

Leave a Reply