Chris Pollett > Students >

    ( Print View )


    [Project Blog]

    [CS297 Proposal]


    [Firefox Plugin-PPT]





    [Firefox Plugin to match h1 tags-ZIP]



    [CS298 Report-PDF]



Deliverable 1 -- Sample Firefox plugin


The first deliverable was to create a sample Firefox test plugin. I created a test plugin that allowed the user to enter a search criteria and the results were displayed. The following steps were done to create a test firefox plugin

Step 1 -- Creating the necessary directory structure

The first step to creating a firefox plugin is to create the right directory structure.The following image explains the directory structure

picture of Firefox plugin directory structure

Step 2 -- Creating the install.rdf

The installer manifest is read by Firefox to get details about our extension. Here is the install.rdf

<?xml version="1.0"?>
<RDF xmlns=""
    <Description about="urn:mozilla:install-manifest">
        <!-- Required Items -->
        <em:name>Tutorial Toolbar</em:name>
        <!-- Optional Items -->
        <em:creator>Vijay Rao</em:creator>
        <em:description>An example toolbar extension.</em:description>       

Step 3 -- Creating the chrome.manifest

The chrome manifest tells Firefox what packages and overlays is provided by our extension. Overlays are layers and extensions added to Firefox.

content tuttoolbar chrome/content/
overlay chrome://browser/content/browser.xul 

Step 4 -- Creating the xul files

The xul file describes the layout and position of the toolbar. It contains various navigation and menu items that provide functionality to the toolbar The following is the root element of the overlay file

<?xml version="1.0"?>
<overlay id="TutTB-Overlay" xmlns="">
The following describes a toolbar item with menu dropdowns
<toolbaritem flex="0">
	<toolbarbutton id="TutTB-MainMenu" type="menu"
				       tooltiptext="Tutorial Toolbar Main Menu">
	    <menuitem label="Google Home Page" accesskey="G" 
		      tooltiptext="Navigate to Google" oncommand="TutTB_LoadURL('')" />                     
	    <menuseparator />                        
	    <menuitem label="Born Geek Website" accesskey="B" 
		      tooltiptext="Navigate to Born Geek" 
		      oncommand="TutTB_LoadURL('')" />

The various XUL elements are added to XUL file to make up the UI component.

Step 5 -- Scripting the Tool

The following line at the top of the toolbar attaches a javascript file to the xul overlay. Javascript can now be used to select the xul elements with id the same way as DHTML. The following piece of code gathers the search terms and passes it to google

function TutTB_Search(event, type)
    // This variable will hold the URL we will browse to
    var URL = "";
    // This variable will tell us whether our search box is empty or not
    var isEmpty = false;

    // Get a handle to our search terms box (the <menulist> element)
    var searchTermsBox = document.getElementById("TutTB-SearchTerms");
// Get the value in the search terms box, trimming whitespace as necessary
    // See the TutTB_TrimString() function farther down in this file for details
    // on how it works.
    var searchTerms = TutTB_TrimString(searchTermsBox.value);

    if(searchTerms.length == 0) // Is the search terms box empty?
        isEmpty = true;         // If so, set the isEmpty flag to true
    else                        // If not, convert the terms to a URL-safe string
        searchTerms = TutTB_ConvertTermsToURI(searchTerms);
    // Now switch on whatever the incoming type value is
    // If the search box is empty, we simply redirect the user to the appropriate
    // place at the Google website. Otherwise, we search for whatever they entered.
    // Build up the URL for an image search
    case "image":
        if(isEmpty) { URL = ""; }
        else        { URL = "" + searchTerms; }
    // Build up the URL for a web search
    case "web":
        if(isEmpty) { URL = ""; }
        else        { URL = "" + searchTerms; }
    // Load the URL in the browser window using the TutTB_LoadURL function