Sunday, September 28, 2008

OSD600 Week 4 Labs

So our task for this week in OSD600 was to find out how a functionality worked in Firefox searching through the source code, and to apply a patch to Firefox. Applying a patch was very simply and straight forward, however, I found searching through the Firefox code slightly annoying.

To start off, I'll talk about patching. Patching was very simple and straight forward. I simply followed Mozilla's instructions to patch Firefox, and everything worked magically. There were very little problems using their commands to apply patches. One thing I did run into was my hg command wouldn't work when attempting to create a diff. The error message I received was "abort: There is no Mercurial repository here (.hg not found)!" I'm going to assume that's because I never downloaded my Firefox source using mercurial. Oh well, cvs worked... so that's fine. My main focus for this semester isn't Firefox anyways, it's Thunderbird. The hg command seems to work fine there.

All in all, patching was a breeze.

Now, I decided to search for source code based upon the back button. Despite hearing that it's usually not a good idea to post source code in a Blog, I'm going to completely ignore that and do it anyways. These were some of the "interesting" findings I found when searching through the source code for the Back Button:

/toolkit/content/widgets/browser.xml || webNavigation.canGoBack
/browser/base/content/tabbrowser.xml || this.mCurrentBrowser.goBack()
/browser/base/content/browser.js

1410 function BrowserBack(aEvent) {
1411 var where = whereToOpenLink(aEvent, false, true);
1412
1413 if (where == "current") {
1414 try {
1415 gBrowser.goBack();
1416 }
1417 catch(ex) {
1418 }
1419 }
1420 else {
1421 var sessionHistory = getWebNavigation().sessionHistory;
1422 var currentIndex = sessionHistory.index;
1423 var entry = sessionHistory.getEntryAtIndex(currentIndex - 1, false);
1424 var url = entry.URI.spec;
1425 openUILinkIn(url, where);
1426 }
1427 }




/docshell/base/nsIWebNavigation.idl

/**
48 * The nsIWebNavigation interface defines an interface for navigating the web.
49 * It provides methods and attributes to direct an object to navigate to a new
50 * location, stop or restart an in process load, or determine where the object
51 * has previously gone.
52 *
53 * @status UNDER_REVIEW
54 */


[scriptable, uuid(F5D9E7B0-D930-11d3-B057-00A024FFC08C)]
56 interface nsIWebNavigation : nsISupports
57 {
58 /**
59 * Indicates if the object can go back. If true this indicates that
60 * there is back session history available for navigation.
61 */
62 readonly attribute boolean canGoBack;


/**
71 * Tells the object to navigate to the previous session history item. When a
72 * page is loaded from session history, all content is loaded from the cache
73 * (if available) and page state (such as form values and scroll position) is
74 * restored.
75 *
76 * @throw NS_ERROR_UNEXPECTED
77 * Indicates that the call was unexpected at this time, which implies
78 * that canGoBack is false.
79 */
80 void goBack();



/browser/locales/en-US/chrome/browser/browser.dtd (View Hg log or Hg annotations)

* line 72 --






The interesting thing that I noticed is that there doesn't seem to be one place where "GoBack" is defined. It seems that the page back functionality is defined multiple times throughout the source code, which seems a bit messy to me. Perhaps there is one specific place that GoBack is defined absolutely, but I just couldn't seem to find it.

One other interesting thing I did find was there seemed to be two different back functionalities for "Browser" and "Browser Tabs". It makes more sense to me that "Browser Tabs" GoBack was what I was mainly looking for, because the majority of my browsing is done through Firefox tabs. Also, if you take a look at some of the source code I posted above, example here:

[scriptable, uuid(F5D9E7B0-D930-11d3-B057-00A024FFC08C)]
56 interface nsIWebNavigation : nsISupports
57 {
58 /**
59 * Indicates if the object can go back. If true this indicates that
60 * there is back session history available for navigation.
61 */
62 readonly attribute boolean canGoBack;

Throughout the Mozilla source code there's continuous checks on the GoBack functions to determine whether or not the tab in question can actually go back. Naturally, this just makes sense.

All in all, searching through the Firefox source code seemed to be time consuming, as well as confusing at times. The hardest part was determining where the "Beginning" and "End" of the GoBack function actually occurred. Right now, I'm still not too sure where it actually "begins". However, finding everything in between was fairly simple.

No comments: