<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Mozilla Add-ons Blog &#187; documentation</title>
	<atom:link href="http://blog.mozilla.com/addons/category/documentation/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.mozilla.com/addons</link>
	<description>Official Blog of Mozilla Add-ons</description>
	<lastBuildDate>Mon, 23 Nov 2009 23:08:19 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Add-on development just got easier</title>
		<link>http://blog.mozilla.com/addons/2009/09/29/add-on-development-just-got-easier/</link>
		<comments>http://blog.mozilla.com/addons/2009/09/29/add-on-development-just-got-easier/#comments</comments>
		<pubDate>Wed, 30 Sep 2009 06:56:35 +0000</pubDate>
		<dc:creator>Justin Scott (fligtar)</dc:creator>
				<category><![CDATA[developers]]></category>
		<category><![CDATA[documentation]]></category>
		<category><![CDATA[releases]]></category>
		<category><![CDATA[features]]></category>

		<guid isPermaLink="false">http://blog.mozilla.com/addons/?p=977</guid>
		<description><![CDATA[We&#8217;re very excited to announce that we&#8217;ve just launched the Add-on Developer Hub (beta), the one-stop-shop for add-on developers to find out why they&#8217;d want to make an add-on, how to make an add-on, and manage their add-on listings.

Developer Hub
Back in May, we posted about our plans for a developer-focused website in response to feedback [...]<script type="text/javascript">SHARETHIS.addEntry({ title: "Add-on development just got easier", url: "http://blog.mozilla.com/addons/2009/09/29/add-on-development-just-got-easier/" });</script>]]></description>
			<content:encoded><![CDATA[<p>We&#8217;re very excited to announce that we&#8217;ve just launched the <a href="https://addons.mozilla.org/developers">Add-on Developer Hub (beta)</a>, the one-stop-shop for add-on developers to find out why they&#8217;d want to make an add-on, how to make an add-on, and manage their add-on listings.</p>
<p><img src="http://blog.mozilla.com/addons/files/2009/09/hub-logo1.png" alt="Developer Hub Logo" style="float: right;" /></p>
<h3>Developer Hub</h3>
<p>Back in May, we <a href="http://blog.mozilla.com/addons/2009/05/10/hello-add-on-developers/">posted</a> about our plans for a developer-focused website in response to feedback we received from add-on developers. The new Developer Hub has something for everyone &#8212; whether you&#8217;re just getting started or have already made twenty add-ons.</p>
<p>New documentation features of the Hub include:</p>
<ul>
<li><strong>Getting Started</strong> &#8211; an introduction to add-on development with links to important resources</li>
<li><strong>How-to Library</strong> &#8211; tutorials, articles, videos, and walk-throughs on add-on development topics</li>
<li><strong>API &#038; Language Reference</strong> &#8211; official API and language references</li>
<li><strong>Case Studies</strong> &#8211; stories of successful Firefox add-ons</li>
<li><strong>Add-on Policies</strong> &#8211; all of our add-on policies in one up-to-date location</li>
<li><strong>Search</strong> &#8211; search the best add-on development resources in one place: documentation, forums, newsgroups, reputable blog posts, and more</li>
</ul>
<p>We&#8217;ve also introduced some new tools, with more planned for the coming months:</p>
<ul>
<li><strong>Add-on Builder</strong> &#8211; auto-generate add-on packaging by entering basic information and picking UI parts</li>
<li><strong>Add-on Validator</strong> &#8211; add-ons can now be validated even if they&#8217;re not hosted on AMO</li>
</ul>
<p>One of the most important goals of the new Hub is to bring the add-ons community closer together. With that in mind, the Hub features:</p>
<ul>
<li><strong>Add-ons Forum</strong> &#8211; interact with other add-on developers and get help</li>
<li><strong>Newsletter</strong> &#8211; about:addons is our monthly newsletter</li>
<li><strong>Developer News &#038; Promos</strong> &#8211; relevant news and important information is now prominent throughout the Hub</li>
<li><strong>Upcoming Events</strong> &#8211; find out when an add-on event is coming to your area</li>
</ul>
<h3>Developer Tools &#038; News Feed</h3>
<p>The tools developers use to submit and manage their add-ons on addons.mozilla.org are now part of the Developer Hub, and we&#8217;ve added a cool new way to stay up to date with what&#8217;s happening with your add-ons: the add-on news feed.</p>
<p>Any time something of note happens to an add-on, it is recorded in the news feed for the developer to see. This includes developer and editor actions like editing an add-on, submitting a new version, and approving a new version, but also includes user actions such as reviews and collections.</p>
<p>The news feed is available via RSS for one or all of your add-ons.</p>
<p><img src="http://blog.mozilla.com/addons/files/2009/09/newsfeed.png" alt="News feed screenshot"/></p>
<h3>Search Revamp</h3>
<p>As part of this release, we&#8217;ve also re-worked our AMO search engine from scratch to provide much more accurate results. This is a huge and much anticipated improvement, and will be covered in detail in a <a href="http://spindrop.us/2009/09/30/amo-search-powered-by-sphinx/">separate blog post</a>.</p>
<p>A big thanks goes to everyone who made this release possible, from the developers, testers, and designers to those who helped review documentation and content.</p>
<p><a href="http://sharethis.com/item?&wp=2.8.6&amp;publisher=7e0eb025-1057-4238-a77c-a634ef8a9d63&amp;title=Add-on+development+just+got+easier&amp;url=http%3A%2F%2Fblog.mozilla.com%2Faddons%2F2009%2F09%2F29%2Fadd-on-development-just-got-easier%2F">ShareThis</a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.mozilla.com/addons/2009/09/29/add-on-development-just-got-easier/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Coming Up for AMO</title>
		<link>http://blog.mozilla.com/addons/2009/08/20/coming-up-for-amo/</link>
		<comments>http://blog.mozilla.com/addons/2009/08/20/coming-up-for-amo/#comments</comments>
		<pubDate>Fri, 21 Aug 2009 01:44:27 +0000</pubDate>
		<dc:creator>Justin Scott (fligtar)</dc:creator>
				<category><![CDATA[compatibility]]></category>
		<category><![CDATA[developers]]></category>
		<category><![CDATA[documentation]]></category>
		<category><![CDATA[end users]]></category>
		<category><![CDATA[policy]]></category>
		<category><![CDATA[features]]></category>
		<category><![CDATA[roadmap]]></category>

		<guid isPermaLink="false">http://blog.mozilla.com/addons/?p=799</guid>
		<description><![CDATA[We launched Collections in June, Contributions in July, and the response to both has been amazing. What&#8217;s next for AMO? Here are some summaries of our upcoming projects.
Collections Phase II
We&#8217;ve had over 27,000 collections created and 6.5 million add-on downloads from those collections since the launch on June 10. We want to add a number [...]<script type="text/javascript">SHARETHIS.addEntry({ title: "Coming Up for AMO", url: "http://blog.mozilla.com/addons/2009/08/20/coming-up-for-amo/" });</script>]]></description>
			<content:encoded><![CDATA[<p>We launched <a href="http://blog.mozilla.com/addons/2009/06/10/introducing-add-on-collections/">Collections</a> in June, <a href="http://blog.mozilla.com/addons/2009/07/15/firefox-add-ons-contributions-pilot/">Contributions</a> in July, and the response to both has been amazing. What&#8217;s next for AMO? Here are some summaries of our upcoming projects.</p>
<h3>Collections Phase II</h3>
<p><a href="http://docs.google.com/Doc?docid=0Acwo2Bn17-PrZGZudHRobnJfMGdrMmM5cmdx&#038;hl=en"><img src="http://blog.mozilla.com/addons/files/2009/08/collections-thumb.png" alt="Screenshot of recommended add-ons box" style="float: right;"/></a>We&#8217;ve had over 27,000 collections created and 6.5 million add-on downloads from those collections since the launch on June 10. We want to add a number of new collection features to the website and Add-on Collector extension, including:</p>
<ul>
<li>collection ratings</li>
<li>statistics dashboard for collection creators</li>
<li>add-on recommendations based on collection data</li>
<li>recently viewed collections</li>
<li>Thunderbird &#038; Fennec support for the Add-on Collector</li>
</ul>
<p>Check out <a href="http://docs.google.com/Doc?docid=0Acwo2Bn17-PrZGZudHRobnJfMGdrMmM5cmdx&#038;hl=en">this spec</a> for all the details planned for this second phase. If you have feedback on this, please post it in <a href="http://groups.google.com/group/mozilla.dev.amo/browse_thread/thread/d212c87127e95052">this newsgroup thread</a>. The website features above are included in AMO 5.0.9, which should be released at the end of next week.</p>
<h3>Add-on Developer Hub</h3>
<p><a href="http://people.mozilla.com/~jscott/developer-hub/mockups/"><img src="http://blog.mozilla.com/addons/files/2009/08/developer-thumb.png" alt="Developer Hub Homepage Mock-up" style="float: right; padding: 0 0 10px 10px;"/></a>In May, we <a href="http://blog.mozilla.com/addons/2009/05/10/hello-add-on-developers/">posted</a> about our plans for a new one-stop-shop for add-on developers. Whether you&#8217;re someone new to Firefox and not sure if you want to write an extension, a long-time developer looking to stay up-to-date on add-on news and documentation, or an add-on author wanting to update your AMO listings, the Add-on Developer Hub at AMO will be the place to go.</p>
<p>Among the features of the new developer area are:</p>
<ul>
<li>add-on case studies</li>
<li>AMO policies</li>
<li>how-to library/portal</li>
<li>API/Language reference links</li>
<li>add-on builder (extension skeletons with working UI components)</li>
<li>add-on validator</li>
</ul>
<p>You can see some mock-ups of what the new site will look like <a href="http://people.mozilla.com/~jscott/developer-hub/mockups/">here</a>, or view the <a href="http://docs.google.com/Doc?docid=0Ad7mAOXgEBZyZGRzNnZ3YjRfMjBnc3Y1YnhkNA&#038;hl=en">spec</a> for all the details. Please post any feedback in <a href="http://groups.google.com/group/mozilla.dev.amo/browse_thread/thread/cd74bce53525895b">this newsgroup thread</a>. We&#8217;re planning this for AMO 5.1, which should be released in late September.</p>
<h3>Disclosure of Add-on Practices</h3>
<p><a href="http://docs.google.com/Doc?docid=0Acwo2Bn17-PrZGZudHRobnJfOGhka2RocGdk&#038;hl=en"><img src="http://blog.mozilla.com/addons/files/2009/08/disclosure-thumb.png" alt="Disclosure of Add-on Practices checkboxes" style="float: right; padding: 0 0 10px 10px;"/></a>Many add-on authors, individuals and companies alike, invest large amounts of time and effort into their add-ons, and wish to be compensated for their work. Although we have launched the Contributions feature for authors to accept donations from users, some authors have partnered with companies to support the continued development of their add-on in exchange for the add-on making certain changes to Firefox. We enacted a <a href="http://blog.mozilla.com/addons/2009/05/01/no-surprises/">No Surprises</a> policy in an effort to protect user choice, but unfortunately continue to find surprises.</p>
<p>We feel it is necessary for users to know about certain add-on practices that an add-on employs prior to installation. These practices must be disclosed in a clear and consistent way across AMO. Our plan for this is described in <a href="http://docs.google.com/Doc?docid=0Acwo2Bn17-PrZGZudHRobnJfOGhka2RocGdk&#038;hl=en">this spec</a>. Please post any feedback in <a href="http://groups.google.com/group/mozilla.dev.amo/browse_thread/thread/ae79da95c634ae02">this newsgroup thread</a>.</p>
<h3>Add-on Compatibility Reporter</h3>
<p><a href="http://docs.google.com/Doc?docid=0Acwo2Bn17-PrZGZudHRobnJfMTFnbTRqcDlkcg&#038;hl=en"><img src="http://blog.mozilla.com/addons/files/2009/08/reporter-thumb.png" alt="Compatibility Reporter Mock-up" style="float: right; padding: 0 0 10px 10px;"/></a>New versions of Firefox are always in the works, and the lead-up to a final release can be hectic for both add-on developers and the AMO team as we try to encourage everyone to test and update their add-ons in the new version. We&#8217;ve come up with an idea for an Add-on Compatibility Reporter extension that would be bundled with alpha and beta builds of Firefox and facilitate add-on testing and reporting.</p>
<p>If you have add-ons installed that don&#8217;t work, you can report that to AMO. If you have incompatible add-ons installed that work fine, you can report that to us too. We&#8217;ll look at all the submitted reports and email developers when we think we know whether the add-on is compatible with that Firefox version, or if it&#8217;s not compatible and what problems users are having.</p>
<p>For all the details, you can <a href="http://docs.google.com/Doc?docid=0Acwo2Bn17-PrZGZudHRobnJfMTFnbTRqcDlkcg&#038;hl=en">read the spec</a>. If you have feedback, please post in <a href="http://groups.google.com/group/mozilla.dev.amo/browse_thread/thread/d98b88a96f153b01">this newsgroup thread</a>.</p>
<p>As you can see, we have a lot going on, including several projects not mentioned here. Stay tuned to the newsgroup and this blog for the latest on add-ons.</p>
<p><a href="http://sharethis.com/item?&wp=2.8.6&amp;publisher=7e0eb025-1057-4238-a77c-a634ef8a9d63&amp;title=Coming+Up+for+AMO&amp;url=http%3A%2F%2Fblog.mozilla.com%2Faddons%2F2009%2F08%2F20%2Fcoming-up-for-amo%2F">ShareThis</a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.mozilla.com/addons/2009/08/20/coming-up-for-amo/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Hello, add-on developers!</title>
		<link>http://blog.mozilla.com/addons/2009/05/10/hello-add-on-developers/</link>
		<comments>http://blog.mozilla.com/addons/2009/05/10/hello-add-on-developers/#comments</comments>
		<pubDate>Sun, 10 May 2009 19:48:06 +0000</pubDate>
		<dc:creator>Justin Scott (fligtar)</dc:creator>
				<category><![CDATA[developers]]></category>
		<category><![CDATA[documentation]]></category>
		<category><![CDATA[roadmap]]></category>

		<guid isPermaLink="false">http://blog.mozilla.com/addons/?p=576</guid>
		<description><![CDATA[In our recent developer survey, one of the largest pain points identified by respondents was a lack of documentation and resources for extension developers. A contributing factor to this problem is that much of the available documentation and tutorials are spread across the Internet and that there&#8217;s no easy way to start developing an add-on [...]<script type="text/javascript">SHARETHIS.addEntry({ title: "Hello, add-on developers!", url: "http://blog.mozilla.com/addons/2009/05/10/hello-add-on-developers/" });</script>]]></description>
			<content:encoded><![CDATA[<p>In our recent <a href="http://blog.mozilla.com/addons/2009/03/13/survey-results-are-in/">developer survey</a>, one of the largest pain points identified by respondents was a lack of documentation and resources for extension developers. A contributing factor to this problem is that much of the available documentation and tutorials are spread across the Internet and that there&#8217;s no easy way to start developing an add-on from the add-ons website. Here&#8217;s our plan to change that.</p>
<p>developer.amo will be a site dedicated to add-on developers, rich with documentation, tutorials, and community involvement. With this site, we hope to:</p>
<ul>
<li>Give new developers a starting point for creating an add-on</li>
<li>Give existing developers a place to stay up-to-date on add-on development news, plans, and features</li>
<li>Make development easier with documentation, tutorials, and examples all in one place</li>
<li>Build a community of add-on developers to promote an exchange of ideas</li>
</ul>
<p>From this one site, it should be possible for someone brand new to Mozilla add-on development to:</p>
<ul>
<li>find out why they would want to build a Firefox extension by reading case studies</li>
<li>see examples of how add-ons work</li>
<li>learn how to make a basic extension, and how to build that extension out into what they want</li>
<li>get support when they have questions</li>
<li>upload their add-on to AMO and have it accepted the first time (because policies will be readily accessible and easy to understand)</li>
</ul>
<p>We&#8217;ve come up with an initial featureset we think will go a long way towards improving the developer experience, but would like input from the community before we get started. You can see our list of initial ideas <a href="https://wiki.mozilla.org/AMO:Projects/developer.AMO/Features">on our wiki</a>.</p>
<p>If you have thoughts on these features or other ideas, please let us know on the <a href="http://groups.google.com/group/mozilla.dev.amo/topics">AMO newsgroup</a>.</p>
<p><b>Edit</b>: There seems to be some confusion about the relationship of this proposed site to MDC. As described in the wiki page above, there will be no new documentation hosted on this site. Rather, it will aggregate/link to existing documentation available on MDC and other resources. Any new documentation written as part of this site will still be hosted on MDC. developer.AMO will serve as a portal between AMO and add-on documentation, of which many articles are available on MDC.</p>
<p><a href="http://sharethis.com/item?&wp=2.8.6&amp;publisher=7e0eb025-1057-4238-a77c-a634ef8a9d63&amp;title=Hello%2C+add-on+developers%21&amp;url=http%3A%2F%2Fblog.mozilla.com%2Faddons%2F2009%2F05%2F10%2Fhello-add-on-developers%2F">ShareThis</a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.mozilla.com/addons/2009/05/10/hello-add-on-developers/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Video Tutorial &#8211; Extensions Bootcamp: Zero to &#8220;Hello World&#8221; in 45 Minutes</title>
		<link>http://blog.mozilla.com/addons/2009/03/18/video-tutorial-extensions-bootcamp-zero-to-hello-world-in-45-minutes/</link>
		<comments>http://blog.mozilla.com/addons/2009/03/18/video-tutorial-extensions-bootcamp-zero-to-hello-world-in-45-minutes/#comments</comments>
		<pubDate>Wed, 18 Mar 2009 15:23:57 +0000</pubDate>
		<dc:creator>rbango</dc:creator>
				<category><![CDATA[developers]]></category>
		<category><![CDATA[documentation]]></category>
		<category><![CDATA[tutorials]]></category>

		<guid isPermaLink="false">http://blog.mozilla.com/addons/?p=415</guid>
		<description><![CDATA[Mozilla&#8217;s Myk Melez created a great video introduction to add-on development for Mozilla&#8217;s Design Challenge Spring 09. If you&#8217;ve be looking for a video walk-through, Myk just served it up for you.
Grok extensions, set up your development environment, and make your first one. We&#8217;ll explain how extensions integrate into Firefox and what they can do, [...]<script type="text/javascript">SHARETHIS.addEntry({ title: "Video Tutorial &#8211; Extensions Bootcamp: Zero to &#8220;Hello World&#8221; in 45 Minutes", url: "http://blog.mozilla.com/addons/2009/03/18/video-tutorial-extensions-bootcamp-zero-to-hello-world-in-45-minutes/" });</script>]]></description>
			<content:encoded><![CDATA[<p>Mozilla&#8217;s Myk Melez created a great video introduction to add-on development for <a href="http://labs.mozilla.com/2009/01/introducing-the-design-challenge/">Mozilla&#8217;s Design Challenge Spring 09</a>. If you&#8217;ve be looking for a video walk-through, Myk just served it up for you.</p>
<blockquote><p>Grok extensions, set up your development environment, and make your first one. We&#8217;ll explain how extensions integrate into Firefox and what they can do, show you how to set up an environment to ease their development, and walk you through the making of a simple &#8220;Hello World!&#8221; extension. Bring your laptop and prepare to follow along. By the end of this session, you&#8217;ll be an extension developer.</p>
</blockquote>
<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="400" height="219" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://vimeo.com/moogaloop.swf?clip_id=3740324&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1" /><embed type="application/x-shockwave-flash" width="400" height="219" src="http://vimeo.com/moogaloop.swf?clip_id=3740324&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1" allowscriptaccess="always" allowfullscreen="true"></embed></object><br />
<a href="http://vimeo.com/3740324">Extension Bootcamp (Mozilla Labs Design Challenge: Spring 09)</a> from <a href="http://vimeo.com/mozconcept">Mozilla Labs &#8211; Concept Series</a> on <a href="http://vimeo.com">Vimeo</a>.</p>
<p>Now combine the video with <a href="http://blog.mozilla.com/addons/2009/01/28/how-to-develop-a-firefox-extension/">Robert Nyman&#8217;s step-by-step add-on tutorial</a> and the newly released <a href="https://developer.mozilla.org/En/Firefox_addons_dev_guide">Firefox Add-ons Developer Guide</a> and you&#8217;ll be well on your way to honing your add-on development skills.</p>
<p><a href="http://sharethis.com/item?&wp=2.8.6&amp;publisher=7e0eb025-1057-4238-a77c-a634ef8a9d63&amp;title=Video+Tutorial+%26%238211%3B+Extensions+Bootcamp%3A+Zero+to+%26%238220%3BHello+World%26%238221%3B+in+45+Minutes&amp;url=http%3A%2F%2Fblog.mozilla.com%2Faddons%2F2009%2F03%2F18%2Fvideo-tutorial-extensions-bootcamp-zero-to-hello-world-in-45-minutes%2F">ShareThis</a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.mozilla.com/addons/2009/03/18/video-tutorial-extensions-bootcamp-zero-to-hello-world-in-45-minutes/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Firefox Add-ons Developer Guide (beta release) &#8211; Calling all Add-on Developers!</title>
		<link>http://blog.mozilla.com/addons/2009/03/11/firefox-add-ons-developer-guide/</link>
		<comments>http://blog.mozilla.com/addons/2009/03/11/firefox-add-ons-developer-guide/#comments</comments>
		<pubDate>Wed, 11 Mar 2009 16:17:07 +0000</pubDate>
		<dc:creator>Paul Rouget</dc:creator>
				<category><![CDATA[developers]]></category>
		<category><![CDATA[documentation]]></category>
		<category><![CDATA[tutorials]]></category>

		<guid isPermaLink="false">http://blog.mozilla.com/addons/?p=367</guid>
		<description><![CDATA[Summary: The Firefox  Add-ons Developer Guide is  now released in beta.  We are now  searching  for  contributors,  if  you want  to  help,  please  see instructions below.
Firefox Add-ons Developer Guide &#8211; beta release
It&#8217;s with  great excitement that we  announce today the beta  release of the Firefox Add-ons Developer Guide. This  guide, is based on an [...]<script type="text/javascript">SHARETHIS.addEntry({ title: "Firefox Add-ons Developer Guide (beta release) &#8211; Calling all Add-on Developers!", url: "http://blog.mozilla.com/addons/2009/03/11/firefox-add-ons-developer-guide/" });</script>]]></description>
			<content:encoded><![CDATA[<p><strong>Summary</strong>: The <a href="https://developer.mozilla.org/En/Firefox_addons_dev_guide">Firefox  Add-ons Developer Guide</a> is  now released in beta.  We are now  searching  for  contributors,  if  you want  to  help,  please  see instructions below.</p>
<h3>Firefox Add-ons Developer Guide &#8211; beta release</h3>
<p>It&#8217;s with  great excitement that we  announce today the beta  release of the Firefox Add-ons Developer Guide. This  guide, is based on an earlier tutorial written and printed for  an Add-ons conference organized by our colleagues in Japan back in June 2007,  and has now been updated for the Firefox  3.5  release.  The  document  will  guide  and  assist  add-ons aficionados around the world, eager to develop their own Firefox add-on. Its catered  to all types  of user,  from the experienced  developer who needs a little push in the right  direction, to the new beginner keen to get his hands dirty, but not sure where to begin.</p>
<h3>The content of the guide</h3>
<p>The guide is divided into 6 chapters and one appendix:</p>
<p><a href="https://developer.mozilla.org/En/Firefox_addons_dev_guide">Top page</a></p>
<ol>
<li><a href="https://developer.mozilla.org/En/Firefox_addons_developer_guide/Introduction_to_Extensions">Introduction to extensions</a></li>
<li><a href="https://developer.mozilla.org/En/Firefox_addons_developer_guide/Technologies_used_in_developing_extensions">Technologies used in developing extensions</a></li>
<li><a href="https://developer.mozilla.org/En/Firefox_addons_developer_guide/Introduction_to_XUL%E2%80%94How_to_build_a_more_intuitive_UI">Introduction to XUL: How to build a more intuitive UI</a></li>
<li><a href="https://developer.mozilla.org/En/Firefox_addons_developer_guide/Using_XPCOM%E2%80%94Implementing_advanced_processes">Using XPCOM: Implementing advanced processes</a></li>
<li><a href="https://developer.mozilla.org/En/Firefox_addons_developer_guide/Let%27s_build_a_Firefox_extension">Let&#8217;s build a Firefox extension</a></li>
<li><a href="https://developer.mozilla.org/En/Firefox_addons_developer_guide/Firefox_extensions_and_XUL_applications">Firefox extensions and XUL applications</a></li>
<li><a href="https://developer.mozilla.org/Appendix_2%3a_What_you_should_know_about_open-source_software_licenses">Appendix: What you should know about open-source software licenses</a></li>
</ol>
<h3>State of the document</h3>
<p>As  described, this  is a  beta  version of  the document.  The text  of the  guide has  been  thoroughly revised,  and is  now  open to  further contributions, corrections  and modifications. Paul Rouget  of Mozilla&#8217;s evangelism  team  is coordinating  the  project  and will  be  regularly reviewing  and integrating  contributions from  the community.  Feedback will be incorporated, ready for final release a few weeks before Firefox 3.5.</p>
<h3>How to contribute</h3>
<p>If you  would like to  help, first, please  read through the  <a href="https://developer.mozilla.org/Talk:En/Firefox_addons_developer_guide">task list</a>. The guide is hosted on <a href="https://developer.mozilla.org">MDC</a>, which is a wiki, so feel free to add content and fix mistakes. If you would  like to provide comments and suggestion, or if you want to ask questions, please do so through the <a href="http://groups.google.fr/group/mozilla.dev.mdc/topics">MDC forum</a>.</p>
<p>If you would like to propose a deep modification, please, first, discuss it via the forum.</p>
<h3>Thanks</h3>
<p>Thanks a lot to the <a href="https://developer.mozilla.org/En/Firefox_addons_developer_guide/License_authors">original authors</a>:</p>
<ul>
<li> Hideyuki Emura</li>
<li> Hiroshi &#8220;Piro&#8221; Shimoda</li>
<li> Taiga Gomibuchi</li>
<li> Taro Matsuzawa</li>
<li> Yutaka Kachi</li>
</ul>
<p>&#8230; and Erwan Loisant, Andrew Williamson and Brian King for their useful reviews.</p>
<p>The license of the guide is <a href="http://creativecommons.org/licenses/by-sa/2.1/jp/deed.en">Attribution-Share Alike 2.1 Japan</a>.</p>
<h3>Calling all Add-on Developers!</h3>
<p>Mozilla Add-ons developers out there, if  you would like to help improve</p>
<p>this guide  and make it become  &#8220;the&#8221; reference for those  interested in developing a Firefox  add-on, take a peek  at the guide, drop  us a line and tell us  what you would change, add, delete  or improve. <a href="https://developer.mozilla.org/En/Firefox_addons_developer_guide">The Firefox Add-on Developer Guide</a> will always be a work in progress, so please help</p>
<p>improve it today !</p>
<p><a href="http://sharethis.com/item?&wp=2.8.6&amp;publisher=7e0eb025-1057-4238-a77c-a634ef8a9d63&amp;title=Firefox+Add-ons+Developer+Guide+%28beta+release%29+%26%238211%3B+Calling+all+Add-on+Developers%21&amp;url=http%3A%2F%2Fblog.mozilla.com%2Faddons%2F2009%2F03%2F11%2Ffirefox-add-ons-developer-guide%2F">ShareThis</a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.mozilla.com/addons/2009/03/11/firefox-add-ons-developer-guide/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>How to develop a Firefox extension</title>
		<link>http://blog.mozilla.com/addons/2009/01/28/how-to-develop-a-firefox-extension/</link>
		<comments>http://blog.mozilla.com/addons/2009/01/28/how-to-develop-a-firefox-extension/#comments</comments>
		<pubDate>Wed, 28 Jan 2009 22:46:49 +0000</pubDate>
		<dc:creator>rbango</dc:creator>
				<category><![CDATA[developers]]></category>
		<category><![CDATA[documentation]]></category>
		<category><![CDATA[guest posts]]></category>
		<category><![CDATA[tutorials]]></category>

		<guid isPermaLink="false">http://blog.mozilla.com/addons/?p=271</guid>
		<description><![CDATA[
.code {
	background: #eee;
	width: 96%;
	padding: 1em 2%;
	overflow: auto;
}

Reposted with permission from Robert Nyman:
Admit that you have always wanted to know how to develop a Firefox extension but never had the time to learn.  Here I will walk you through and at the end of the article we will have created a fully functional Firefox extension!

Our [...]<script type="text/javascript">SHARETHIS.addEntry({ title: "How to develop a Firefox extension", url: "http://blog.mozilla.com/addons/2009/01/28/how-to-develop-a-firefox-extension/" });</script>]]></description>
			<content:encoded><![CDATA[<style>
.code {
	background: #eee;
	width: 96%;
	padding: 1em 2%;
	overflow: auto;
}
</style>
<p><em><strong>Reposted with permission from <a href="http://www.robertnyman.com/2009/01/24/how-to-develop-a-firefox-extension/">Robert Nyman</a>:</strong></em></p>
<p>Admit that you have always wanted to know how to develop a Firefox extension but never had the time to learn. <img src='http://www.robertnyman.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley'> Here I will walk you through and at the end of the article we will have created a fully functional Firefox extension!</p>
<p><span id="more-1110"></span></p>
<h2>Our objective</h2>
<p>We will create a Firefox extension to find all links in the current web page, highlight those which have a <code>target</code> attribute and alert you how many links it found. The good part is that once you have done this, you have both an understanding of Firefox extension development as well as a blueprint for any extension you would want to develop in the future.</p>
<p><span id="more-271"></span></p>
<h2>What you need &#8211; setting up the developing environment</h2>
<p>First, let&#8217;s start with setting up your development environment. You need Firefox (duh) and basically whatever code editor you prefer. Then, there are some recommended things to do to prepare Firefox:</p>
<h3>Create a different development profile</h3>
<p>The first step is to create a different profile in Firefox, since you will do some settings and changes that you probably don&#8217;t want for your regular profile. In my case, I&#8217;ve created a new development profile named &#8220;dev&#8221;. The steps to do this are:</p>
<h4>Profile manager on Windows</h4>
<p>Open the Windows Start menu and choose the Run option (on Vista, it might not be there &#8211; just press <kbd>Windows key</kbd> + <kbd>R</kbd> in that case). In the run dialog, write <code>firefox -P</code> and press <kbd>enter</kbd>/click OK. Choose Create Profile in the dialog and follow the steps.</p>
<h4>Profile manager on Mac</h4>
<p>Open the Terminal (located under /Applications/Utilities) and type in <code>/Applications/Firefox.app/Contents/MacOS/firefox -profilemanager</code>. Choose Create Profile in the dialog and follow the steps.</p>
<h4>Profile manager on Linux</h4>
<p>Open a terminal, use <code><span class="lowercase"><acronym title="Compact Disk">CD</acronym></span></code> to navigate to your Firefox directory and then enter <code>./firefox -profilemanager</code>. Choose Create Profile in the dialog and follow the steps.</p>
<h3>Configuration settings for Firefox</h3>
<p>Open Firefox through the Profile Manager (process described above, or set the development profile as default during extension development). Then enter <code>about:config</code> in the address bar. It will warn you about changing settings, but it&#8217;s ok since what you will do is only minor changes for development. You can filter the existing settings, and if any of the below settings don&#8217;t exist, you can just create them.</p>
<h4>Recommended settings</h4>
<p>These are good to enable extension errors in the Firefox Error Console (Tools &gt; Error Console), disable XUL caching and such.</p>
<ul>
<li><code>javascript.options.showInConsole = true</code></li>
<li><code>nglayout.debug.disable_xul_cache = true</code></li>
<li><code>browser.dom.window.dump.enabled = true</code></li>
</ul>
<h4>Optional settings</h4>
<p>These aren&#8217;t necessary, but they might help you out. Personally, I don&#8217;t use these.</p>
<ul>
<li><code>javascript.options.strict = true</code></li>
<li><code>extensions.logging.enabled = true</code></li>
</ul>
<h2>Point your Firefox extensions directory to your extension</h2>
<p>Instead of constantly preparing and reinstalling your extension, there&#8217;s a simple way to add a pointer from your Firefox extensions directory to your code location. To do this, you must first find your profile directory:</p>
<h3>Find your profile directory</h3>
<p>The profile directory is where you will find all the settings for your Firefox profiles, including extension information.</p>
<h4>Find profile directory on Windows</h4>
<p>In Windows 2000 and XP, open Explorer and go to <code>C:\Documents and Settings\[your user name]\Application Data\Mozilla\Firefox\Profiles</code> and in Vista, go to <code>C:\Users\[your user name]\AppData\Roaming</code>.</p>
<h4>Find profile directory on Mac</h4>
<p>Open the Terminal and type in <code><span class="lowercase"><acronym title="Compact Disk">CD</acronym></span> ~/Library/Application\ Support/Firefox/profiles/</code>. There you will find your Firefox profiles, and they will be named with letters and numbers, followed by a dot (.) and then your profile name, e.g. <code>12a3bc4d.dev</code>.</p>
<h4>Find profile directory on Linux</h4>
<p>Open a terminal and type in <code><span class="lowercase"><acronym title="Compact Disk">CD</acronym></span> ~/.mozilla/</code>. In that location, you will find all your Firefox profiles, and they will be named with letters and numbers, followed by a dot (.) and then your profile name, e.g. <code>12a3bc4d.dev</code>.</p>
<h3>Pointing to an extension</h3>
<p>In your development profile folder, you will find a folder named <code>extensions</code>. In it, you will have code for all your installed extensions. Instead of placing your code there, you can create a pointer file. Do that by creating a file with a unique name for you (this will have to be the same as you chose for your <code>em:id</code> value in your <code>install.rdf</code> file &#8211; more on that below).</p>
<p>In the case of our example, create a file named <code>linktargetfinder@robertnyman.com</code>, without any extension, and in it just point it to where you will have your code, e.g. <code>C:\extensions\</code> (Windows) or <code>~/Sites/linktargetfinder/</code> (Mac).</p>
<h2>Creating folder structure and files</h2>
<p>What is needed to have a good base for your extension development, is to create the structure of the extension code. Start by creating this hierarchy:</p>
<p><img src="http://blog.mozilla.com/addons/files/2009/01/extension-structure.png" alt="A picture of a hierarchy with four folders, named chrome, defaults, locale and skin. The chrome has a child folder named content, the defaults folder has a child named preferences and the locale folders has a child folder named en-US. The root also contains two files, chrome.manifest and install.rdf"></p>
<h3><span class="lowercase">i</span>nstall.rdf</h3>
<p>We begin with the intimidating code of <code>install.rdf</code>. This is where you will have all the meta information about your extension, which versions of Firefox it supports and other assorted information. Our <code>install.rdf</code> will look like this:</p>
<pre class="code"><code>&lt;?xml version="1.0"?&gt;

&lt;<acronym title="Resource Description Framework">RDF</acronym> xmlns="http://www.w3.org/1999/02/22-<acronym title="Resource Description Framework">RDF</acronym>-syntax-ns#"
     xmlns:em="http://www.mozilla.org/2004/em-<acronym title="Resource Description Framework">RDF</acronym>#"&gt;

	&lt;Description about="urn:mozilla:install-manifest"&gt;
		&lt;em:id&gt;linktargetfinder@robertnyman.com&lt;/em:id&gt;

		&lt;em:name&gt;Link Target Finder&lt;/em:name&gt;
		&lt;em:version&gt;1.0&lt;/em:version&gt;
		&lt;em:type&gt;2&lt;/em:type&gt;
		&lt;em:creator&gt;Robert Nyman&lt;/em:creator&gt;

		&lt;em:description&gt;Finds links that have a target attribute&lt;/em:description&gt;
		&lt;em:homepageURL&gt;http://www.robertnyman.com/&lt;/em:homepageURL&gt;
		&lt;em:optionsURL&gt;chrome://linktargetfinder/content/options.xul&lt;/em:optionsURL&gt;

		&lt;em:targetApplication&gt;

			&lt;Description&gt;
				&lt;em:id&gt;{ec8030f7-c20a-464f-9b0e-13a3a9e97384}&lt;/em:id&gt;
				&lt;em:minVersion&gt;2.0&lt;/em:minVersion&gt;
				&lt;em:maxVersion&gt;3.1b2&lt;/em:maxVersion&gt;

			&lt;/Description&gt;
		&lt;/em:targetApplication&gt;
	&lt;/Description&gt;
&lt;/RDF&gt;</code></pre>
<p>Scary, right? Well, even if your not used to <acronym title="Resource Description Framework">RDF</acronym> it&#8217;s not that bad at all. Like most code, there&#8217;s some mandatory information that you will never need to change, and then some of your own to sprinkle in. The interesting parts for us are:</p>
<h4>In the <code>Description</code> node</h4>
<dl>
<dt><code>em:id</code></dt>
<dd>This is where you add your unique developer id, of your own choosing. Note that this has to be the same as the pointer file you created above.</dd>
<dt><code>em:name</code></dt>
<dd>The name of your extension.</dd>
<dt><code>em:version</code></dt>
<dd>Current version of your extension.</dd>
<dt><code>em:type</code></dt>
<dd>The type declares that is an extension, as opposed to, for instance, a theme.</dd>
<dt><code>em:creator</code></dt>
<dd>Well, you!</dd>
<dt><code>em:description</code></dt>
<dd>Describes your extension functionality. Will be shown in the Tools &gt; Add-ons window.</dd>
<dt><code>em:homepageURL</code></dt>
<dd>The <acronym title="Uniform Resource Locator">URL</acronym> of your extension&#8217;s web site.</dd>
<dt><code>em:optionsURL</code></dt>
<dd>The <acronym title="Uniform Resource Locator">URL</acronym> to where you will have your file for editing options/preferences.</dd>
</dl>
<h4>In the <code>Description/em:targetApplication</code> node</h4>
<dl>
<dt><code>em:id</code></dt>
<dd>This value is the actual id of Firefox. Change this if you want to develop for Thunderbird or something else.</dd>
<dt><code>em:minVersion</code></dt>
<dd>The minimum version of Firefox required to run the extension. <a href="https://addons.mozilla.org/en-US/firefox/pages/appversions">Valid Application Versions</a>.</dd>
<dt><code>em:maxVersion</code></dt>
<dd>The maximum version of Firefox required to run the extension. <a href="https://addons.mozilla.org/en-US/firefox/pages/appversions">Valid Application Versions</a>.</dd>
</dl>
<p>Read about more options in <a href="https://developer.mozilla.org/en/Install_Manifests">Install Manifests</a>.</p>
<h3><span class="lowercase">c</span>hrome.manifest</h3>
<p>The chrome of Firefox is everything around the content window. i.e. web browser toolbar, menus, statusbar etc. The next file for our extension, which will probably feel a bit awkward to edit, is the <code>chrome.mainfest</code> file. This one, however, is in conjunction with <code>install.rdf</code> the key to how your extension will be added to Firefox, and how it will work. Our <code>chrome.manifest</code> file looks like this:</p>
<pre class="code"><code>content     linktargetfinder    chrome/content/
content     linktargetfinder    chrome/content/ contentaccessible=yes
overlay chrome://browser/content/browser.xul chrome://linktargetfinder/content/browser.xul

locale	linktargetfinder	en-US	locale/en-US/

skin	linktargetfinder	classic/1.0	skin/
style	chrome://global/content/customizeToolbar.xul	chrome://linktargetfinder/skin/skin.css</code></pre>
<p>So, what are all those options? Let&#8217;s go through them:</p>
<dl>
<dt><code>content     linktargetfinder    chrome/content/</code></dt>
<dd>The path to where your extension content files will be found.</dd>
<dt><code>content     linktargetfinder    chrome/content/ contentaccessible=yes</code></dt>
<dd>Same as the above, but when <code>contentaccessible=yes</code> is added, it allows Firefox 3 and later to access the extension&#8217;s files and show them in the web browser (like within a web page). Found this excellent help through <a href="http://adblockplus.org/blog/web-pages-accessing-chrome-is-forbidden">Web pages accessing chrome:// is forbidden</a>.</dd>
<dt><code>overlay chrome://browser/content/browser.xul chrome://linktargetfinder/content/browser.xul</code></dt>
<dd>The path to which file you will use to override web browser elements, and add items to the toolbar, menu and statusbar.</dd>
<dt><code>locale	linktargetfinder	en-US	locale/en-US/</code></dt>
<dd>Used for localization of content.</dd>
<dt><code>skin	linktargetfinder	classic/1.0	skin/</code></dt>
<dd>Skin reference.</dd>
<dt><code>style	chrome://global/content/customizeToolbar.xul	chrome://linktargetfinder/skin/skin.css</code></dt>
<dd>Style overlays for chrome pages.</dd>
</dl>
<p>More information can be found in <a href="https://developer.mozilla.org/en/Chrome_Manifest">Chrome Manifest</a>.</p>
<h3><span class="lowercase">c</span>hrome folder</h3>
<p>Ok, once the mandatory parts are out of the way, now things start to get interesting. This is also when we start to look at XUL, which stands for <acronym title="eXtensible Markup Language">XML</acronym> User Interface Language. It is developed by Mozilla to create interfaces in Firefox, Thunderbird etc.</p>
<p>First, within the <code>chrome/content</code> folder, create three files:</p>
<ul>
<li><code>browser.xul</code></li>
<li><code>options.xul</code></li>
<li><code>linkTargetFinder.js</code></li>
</ul>
<h4><code><span class="lowercase">b</span>rowser.xul</code></h4>
<p>This is the file we will use to override some of the default look of the web browser, i.e. add a button to the toolbar, an item to the Tools menu and a statusbar icon. Let&#8217;s look at the complete browser.xul file and then break it down:</p>
<pre class="code"><code>&lt;?xml version="1.0"?&gt;
&lt;?xml-stylesheet href="chrome://linktargetfinder/skin/skin.css" type="text/css"?&gt;
&lt;!DOCTYPE linktargetfinder SYSTEM "chrome://linktargetfinder/locale/translations.dtd"&gt;
&lt;overlay id="sample" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"&gt;

		&lt;script src="linkTargetFinder.js" /&gt;

		&lt;menupopup id="menu_ToolsPopup"&gt;
			&lt;menuitem label="&#038;runlinktargetfinder;" key="link-target-finder-run-key" oncommand="linkTargetFinder.run()"/&gt;
		&lt;/menupopup&gt;

		&lt;keyset&gt;

			&lt;key id="link-target-finder-run-key" modifiers="accel alt shift" key="L" oncommand="linkTargetFinder.run()"/&gt;
		&lt;/keyset&gt;

		&lt;statusbar id="status-bar"&gt;
			&lt;statusbarpanel id="link-target-finder-status-bar-icon" class="statusbarpanel-iconic" src="chrome://linktargetfinder/skin/status-bar.png" tooltiptext="&#038;runlinktargetfinder;" onclick="linkTargetFinder.run()" /&gt;
		&lt;/statusbar&gt;

		&lt;toolbarpalette id="BrowserToolbarPalette"&gt;
			&lt;toolbarbutton id="link-target-finder-toolbar-button" label="Link Target Finder" tooltiptext="&#038;runlinktargetfinder;" oncommand="linkTargetFinder.run()"/&gt;
		&lt;/toolbarpalette&gt;
&lt;/overlay&gt;</code></pre>
<p>First, there some general <acronym title="eXtensible Markup Language">XML</acronym> syntax, then you include your <acronym title="Cascading Style Sheets">CSS</acronym> code and set a DOCTYPE for localization. It&#8217;s followed by the <code>overlay</code> root element with its Ghostbuster-inspired namespace (developers are truly geeks <img src='http://www.robertnyman.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley'> ).</p>
<p>After that you&#8217;re free to write whatever XUL you want, and basically it&#8217;s like <acronym title="HyperText Markup Language">HTML</acronym> should&#8217;ve been. What I mean with that is that it is filled with basic interface options that can&#8217;t be found anywhere in <acronym title="HyperText Markup Language">HTML</acronym>. For a complete overview of what you can do, please read the <a href="https://developer.mozilla.org/en/XUL_Reference">XUL Reference</a>.</p>
<p>In our code here, we start with adding a menu option to the Tools menu in Firefox, and connect it to a keyboard shortcut:</p>
<pre class="code"><code>&lt;menupopup id="menu_ToolsPopup"&gt;

	&lt;menuitem label="&#038;runlinktargetfinder;" key="link-target-finder-run-key" oncommand="linkTargetFinder.run()"/&gt;
&lt;/menupopup&gt;

&lt;keyset&gt;
	&lt;key id="link-target-finder-run-key" modifiers="accel alt shift" key="L" oncommand="linkTargetFinder.run()"/&gt;
&lt;/keyset&gt;</code></pre>
<p>Followed by adding an icon to the Firefox statusbar:</p>
<pre class="code"><code>&lt;statusbar id="status-bar"&gt;

	&lt;statusbarpanel id="link-target-finder-status-bar-icon" class="statusbarpanel-iconic" src="chrome://linktargetfinder/skin/status-bar.png" tooltiptext="&#038;runlinktargetfinder;" onclick="linkTargetFinder.run()" /&gt;
&lt;/statusbar&gt;</code></pre>
<p>And at the end, we add a button to the Firefox toolbar:</p>
<pre class="code"><code>&lt;toolbarpalette id="BrowserToolbarPalette"&gt;
	&lt;toolbarbutton id="link-target-finder-toolbar-button" label="Link Target Finder" tooltiptext="&#038;runlinktargetfinder;" oncommand="linkTargetFinder.run()"/&gt;
&lt;/toolbarpalette&gt;</code></pre>
<p>Note that you need to go to View &gt; Toolbars &gt; Customize&#8230; to add your button to the visible toolbar.</p>
<p>In the above examples, you might have noticed the <code>&#038;runlinktargetfinder;</code> code. That is used for localizing text, and its translation can be found in the <code>locale</code> folder. More on that later.</p>
<p>Another thing to notice, which can be tricky at first, is that some ids and classes for XUL elements actually have meaning for its display, stemming from core Firefox code. Make sure to read the <a href="https://developer.mozilla.org/en/XUL_Reference">XUL Reference</a> thoroughly for the elements you&#8217;re using.</p>
<p>If you want to use regular <acronym title="HyperText Markup Language">HTML</acronym> elements instead of/together with XUL, you can include the <acronym title="eXtensible HyperText Markup Language - HTML reformulated as XML">XHTML</acronym> definition in your root element, and then include any <acronym title="HyperText Markup Language">HTML</acronym> element with the <code>html:</code> prefix. Like this:</p>
<pre class="code"><code>&lt;overlay id="sample" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" xmlns:<acronym title="HyperText Markup Language">HTML</acronym>="http://www.w3.org/1999/xhtml"&gt;

&lt;html:input type="submit" value="Send" /&gt;
</code></pre>
<h4><code><span class="lowercase">o</span>ptions.xul</code></h4>
<p>This file is used for the options/preferences dialog for your extension, and its path is pointed out in the <code>install.rdf</code> file in the <code>Description/em:optionsURL</code> node. The complete options file for our extension looks like this:</p>
<pre class="code"><code>&lt;?xml version="1.0"?&gt;
&lt;?xml-stylesheet href="chrome://global/skin/" type="text/css"?&gt;

&lt;prefwindow
     title="Link Target Finder Preferences"
     xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"&gt;

	&lt;prefpane label="Link Target Finder Preferences"&gt;
		&lt;preferences&gt;
			&lt;preference id="link-target-finder-autorun" name="extensions.linktargetfinder.autorun" type="bool"/&gt;

		&lt;/preferences&gt;

		&lt;groupbox&gt;
			&lt;caption label="Settings"/&gt;
			&lt;grid&gt;
				&lt;columns&gt;
					&lt;column flex="4"/&gt;

					&lt;column flex="1"/&gt;
				&lt;/columns&gt;
				&lt;rows&gt;
					&lt;row&gt;
						&lt;label control="autorun" value="Autorun"/&gt;
						&lt;checkbox id="autorun" preference="link-target-finder-autorun"/&gt;

					&lt;/row&gt;
				&lt;/rows&gt;
			&lt;/grid&gt;
		&lt;/groupbox&gt;	

	&lt;/prefpane&gt;

&lt;/prefwindow&gt;</code></pre>
<p>Again, some regular <acronym title="eXtensible Markup Language">XML</acronym> information and styling of the content. It then uses some XUL to layout the content of the preferences dialog. The interesting part here, though, is connecting the user input to the actual settings for the extension (those settings are to be found in the <code>prefs.js</code> file, mentioned in detail below).</p>
<p>To start with, you create a <code>preferences</code> group in the <code>options.xul</code> file with your desired preferences. Then, give each preference an id and connect it to the extension&#8217;s real preferences with the <code>name</code> attribute:</p>
<pre class="code"><code>&lt;preferences&gt;
	&lt;preference id="link-target-finder-autorun" name="extensions.linktargetfinder.autorun" type="bool"/&gt;
&lt;/preferences&gt;</code></pre>
<p>Then you create an element and add a <code>preference</code> attribute to it, pointing to the before-chosen <code>id</code>attribute for the preference in the <code>preferences</code> group. It will then automatically connect its value to that specific preference.</p>
<pre class="code"><code>&lt;checkbox id="autorun" preference="link-target-finder-autorun"/&gt;</code></pre>
<p>Note that you don&#8217;t need to add an OK button for the dialog &#8211; for instance, on Macs there won&#8217;t be one while it&#8217;s automatically added for Windows users. All about system compatibility, my friends.</p>
<h4><code><span class="lowercase">l</span>inkTargetFinder.js</code></h4>
<p>If you&#8217;re like me, this is where you will feel at home. Good ol&#8217; JavaScript code. <img src='http://www.robertnyman.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley'> </p>
<p>What&#8217;s nice here is that you can script any element in the XUL <em>and</em> any element in the <acronym title="HyperText Markup Language">HTML</acronym> content window as well. All you need to access the content window is to precede your document call with the <code>content</code> keyword, like this:</p>
<pre class="code"><code><strong>content</strong>.document.getElementsByTagName("a");</code></pre>
<p>Here&#8217;s the complete code of the <code>linkTargetFinder.js</code> file:</p>
<pre class="code"><code>var linkTargetFinder = function () {
	var prefManager = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);
	return {
		init : function () {
			gBrowser.addEventListener("load", function () {
				var autoRun = prefManager.getBoolPref("extensions.linktargetfinder.autorun");
				if (autoRun) {
					linkTargetFinder.run();
				}
			}, false);
		},

		run : function () {
			var head = content.document.getElementsByTagName("head")[0],
				style = content.document.getElementById("link-target-finder-style"),
				allLinks = content.document.getElementsByTagName("a"),
				foundLinks = 0;

			if (!style) {
				style = content.document.createElement("link");
				style.id = "link-target-finder-style";
				style.type = "text/css";
				style.rel = "stylesheet";
				style.href = "chrome://linktargetfinder/skin/skin.css";
				head.appendChild(style);
			}	

			for (var i=0, il=allLinks.length; i&lt;il; i++) {
				elm = allLinks[i];
				if (elm.getAttribute("target")) {
					elm.className += ((elm.className.length &gt; 0)? " " : "") + "link-target-finder-selected";
					foundLinks++;
				}
			}
			if (foundLinks === 0) {
				alert("No links found with a target attribute");
			}
			else {
				alert("Found " + foundLinks + " links with a target attribute");
			}
		}
	};
}();
window.addEventListener("load", linkTargetFinder.init, false);</code></pre>
<p>While it&#8217;s a fair bit of code, it is also very basic. When the window loads, it runs the <code>init</code> method of the <code>linkTargetFinder</code> object. If the preference <code>autorun</code> is set to true, it calls its <code>run</code>  method immediately. Otherwise, it will only be called when the toolbar button, menu item or statusbar icon is clicked. This happens through the <code>oncommand</code> attribute on the elements in the <code>browser.xul</code> file.</p>
<p>The code in the <code>run</code> method is pretty straight-forward. It adds a <acronym title="Cascading Style Sheets">CSS</acronym> file from the extensions chrome folder to the current document, finds all links in it, loops through them and checks if they have a <code>target</code> attribute, counts those, highlights them and alerts you with the number of hits.</p>
<p>As you can see, there&#8217;s a pointer in the code to something called <code>gBrowser</code>. That is how to get a reference to the current web browser, and you could also use <code>getBrowser()</code> as well. Note that this sort of code is only available from within the XUL context of the web browser. More information and options can be found in <a href="https://developer.mozilla.org/en/Code_snippets/Tabbed_browser">Tabbed Browser.</a></p>
<p>The only unusual part for a JavaScript is the variable <code>prefManager</code>, which connects to Firefox preference manager, and later gets the <code>autorun</code> preference with the help of this code:</p>
<pre class="code"><code>var autoRun = prefManager.getBoolPref("extensions.linktargetfinder.autorun");</code></pre>
<p>The three types of extension preferences are string, integer and boolean, and the six methods to work with them are:</p>
<ul>
<li><code>getBoolPref()</code></li>
<li><code>setBoolPref()</code></li>
<li><code>getCharPref()</code></li>
<li><code>setCharPref()</code></li>
<li><code>getIntPref()</code></li>
<li><code>setIntPref()</code></li>
</ul>
<h3><span class="lowercase">d</span>efaults folder</h3>
<p>Within the <code>defaults</code> folder, you create a <code>preferences</code> folder and in that one a file named <code>pref.js</code>. This is used for the preferences you want to use for your extension, and looks like this:</p>
<pre class="code"><code>pref("extensions.linktargetfinder.autorun", false);</code></pre>
<h3><span class="lowercase">l</span>ocale folder</h3>
<p>Used for localization. In our case here, we just have one child folder for <code>en-US</code> content, but it can be easily extended. That folder has a file named <code>translations.dtd</code>, which contains translations for entities used in XUL files. Our file looks like this:</p>
<pre class="code"><code>&lt;!ENTITY runlinktargetfinder "Run Link Target Finder"&gt;</code></pre>
<p>Remember <code>&#038;runlinktargetfinder;</code> in the <code>browser.xul</code> file? This is where it gets its translation.</p>
<h3><span class="lowercase">s</span>kin folder</h3>
<p>Now when we have all functionality in place, let&#8217;s make things a little more pretty (just a little, ok?). In our <code>skin</code> folder, we have three files: <code>skin.css</code>, <code>status-bar.png</code> and <code>toolbar-large.png</code>. The images are, naturally, used for the toolbar and statusbar respectively.</p>
<p>The <acronym title="Cascading Style Sheets">CSS</acronym> in <code>skin.css</code> is used for setting the image for the toolbar, the size and space for the statusbar icon and the highlight look of links with a <code>target</code> attribute. The code looks like this:</p>
<pre class="code"><code>#link-target-finder-toolbar-button {
	list-style-image: <acronym title="Uniform Resource Locator">URL</acronym>("chrome://linktargetfinder/skin/toolbar-large.png");
}

#link-target-finder-status-bar-icon {
	width: 83px;
	margin: 0 5px;
}

.link-target-finder-selected {
	outline: 2px solid red !important;
}</code></pre>
<h2>Packaging and installing</h2>
<p>Firefox extensions are delivered like XPI files, and those are basically just ZIP files with another extension. Therefore, when you&#8217;re finished with your extension, all you need to do is ZIP your files together and give it an XPI extension. Note: do <em>not</em> ZIP the containing folder for your extension, just its contents (<code>chrome</code> folder, <code>chrome.manifest</code> and <code>install.rdf</code> files etc).</p>
<p>Once you have your XPI file, you can just drag and drop it into Firefox, and it will automatically install.</p>
<h3>Packaging with Windows</h3>
<p>Select all the contents of your extension folder, right-click and choose <code>Send To &gt; Compressed (Zipped) Folder</code>. Rename it to <code>.xpi</code> instead of <code>.zip</code> and you&#8217;re done!</p>
<h3>Packaging with Mac</h3>
<p>Open the Terminal, navigate to your extension with the <code><span class="lowercase"><acronym title="Compact Disk">CD</acronym></span></code> command and then type in <code>zip -r LinkTargetFinder.xpi *</code>. Ta daa!</p>
<h3>Packaging with Linux</h3>
<p>Open a terminal, get to your extension folder, and type in <code>zip -r LinkTargetFinder.xpi *</code> All done!</p>
<h2>Distribution of your extension</h2>
<p>There are two options of distributing your extension. Either use <a href="http://addons.mozilla.org/">addons.mozilla.org</a> or host it yourself. If you do it yourself, you can specify an <code>updateURL</code> in your <code>install.rdf</code> file, but note that since Firefox 3 it has to be a secure location, e.g. through <acronym title="Secure Sockets Layer (a security protocol)">SSL</acronym> or similar.</p>
<p>Personally, I&#8217;d recommend addons.mozilla.org for greater reach, auto-update pushing and statistics. The downside of it, though, is that the review process can take quite some time for your extension to get an approval. Before that it can still be downloaded as an experimental add-on, but people need to have an addons.mozilla account and log in to do so.</p>
<p>To make sure it doesn&#8217;t take longer than necessary, I recommend reading <a href="http://blog.mozilla.com/addons/2009/01/14/successfully-getting-your-addon-reviewed/"><br />
Successfully Getting your Addon Reviewed</a>.</p>
<h2>Downloads</h2>
<p>All the code I&#8217;ve created here is available both as a ZIP file of everything, so you can start experimenting, change stuff and see what happens. It is also available as an XPI file, which you can install in your Firefox just to test the functionality (drag and drop it into Firefox).</p>
<ul>
<li><a href="http://www.robertnyman.com/extensions/LinkTargetFinder.zip">Download Link Target Finder code as a ZIP file</a>.</li>
<li><a href="http://www.robertnyman.com/extensions/LinkTargetFinder.xpi">Download Link Target Finder as an XPI file</a>.</li>
</ul>
<h2>Happy extension developing!</h2>
<p>I hope this has been a good, albeit long, introduction to Firefox extension development and that it has helped you to grasp concepts you hadn&#8217;t gotten full control over yet. Good luck, and don&#8217;t hesitate to ask if you have any questions!</p>
<p><a href="http://sharethis.com/item?&wp=2.8.6&amp;publisher=7e0eb025-1057-4238-a77c-a634ef8a9d63&amp;title=How+to+develop+a+Firefox+extension&amp;url=http%3A%2F%2Fblog.mozilla.com%2Faddons%2F2009%2F01%2F28%2Fhow-to-develop-a-firefox-extension%2F">ShareThis</a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.mozilla.com/addons/2009/01/28/how-to-develop-a-firefox-extension/feed/</wfw:commentRss>
		<slash:comments>36</slash:comments>
		</item>
		<item>
		<title>Firefox Extensions: Global Namespace Pollution</title>
		<link>http://blog.mozilla.com/addons/2009/01/16/firefox-extensions-global-namespace-pollution/</link>
		<comments>http://blog.mozilla.com/addons/2009/01/16/firefox-extensions-global-namespace-pollution/#comments</comments>
		<pubDate>Fri, 16 Jan 2009 16:13:29 +0000</pubDate>
		<dc:creator>rbango</dc:creator>
				<category><![CDATA[documentation]]></category>
		<category><![CDATA[general]]></category>
		<category><![CDATA[guest posts]]></category>
		<category><![CDATA[tutorials]]></category>

		<guid isPermaLink="false">http://blog.mozilla.com/addons/?p=258</guid>
		<description><![CDATA[Reposted with permission from Jan Odvarko (AKA Honza):
I have been recently asked by couple of developers how to properly design architecture of a Firefox extension. The first thing that immediately came to my mind at that point was a problem with global variables defined by extensions in ChromeWindow scope.
This problem can easily cause collisions among [...]<script type="text/javascript">SHARETHIS.addEntry({ title: "Firefox Extensions: Global Namespace Pollution", url: "http://blog.mozilla.com/addons/2009/01/16/firefox-extensions-global-namespace-pollution/" });</script>]]></description>
			<content:encoded><![CDATA[<p><em>Reposted with permission from <a href="http://www.softwareishard.com/blog/planet-mozilla/firefox-extensions-global-namespace-pollution/">Jan Odvarko (AKA Honza)</a>:</em></p>
<p>I have been recently asked by couple of developers how to properly design architecture of a Firefox extension. The first thing that immediately came to my mind at that point was a problem with global variables defined by extensions in <a href="http://www.xulplanet.com./references/objref/ChromeWindow.html">ChromeWindow</a> scope.</p>
<p>This problem can easily cause collisions among various extensions. Something that should be always avoided (and is also part of AMO <a href="http://www.cesaroliveira.net/tea/archives/51">review</a> process) since this kind of issues is very hard to find. Yes, global variables are still <a href="http://yuiblog.com./blog/2006/06/01/global-domination/">evil</a>, especially in OOP world.</p>
<p>I don’t want to describe how to develop a new extension from scratch. For this there is already bunch of <a href="https://developer.mozilla.org/en/Building_an_Extension">detailed</a> <a href="http://kb.mozillazine.org/Getting_started_with_extension_development">articles</a>. I am rather concentrating on effective tactics how to make Firefox extension architecture maintainable and well designed.</p>
<p>So, read more if you are interested…</p>
<p><span id="more-27"></span></p>
<h3>Namespace Architecture</h3>
<p>Defining global variables is a way how to risk collisions with other extensions. I think that creating just one global variable per extension that is unique enough (composed e.g. from the name of the extension, domain URL, etc.) is sufficient strategy how to avoid undesirable collisions.</p>
<p>The architecture for namespaces used in Firebug, is based (more or less) on well known <a href="http://yuiblog.com/blog/2007/06/12/module-pattern/">module pattern</a> (originally described by <a href="http://en.wikipedia.org./wiki/Douglas_Crockford">Douglas Crockford</a>). It’s really simple and transparent so, I hadn’t understand how it actually works for a long time. I believe other extension developers can utilize this approach as well.</p>
<p>The basic idea is to wrap content of every JS file into its own scope that is represented by a function so, there are no global objects. See following snippet.</p>
<div class="dean_ch" style="white-space: nowrap;"><span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></p>
<p><span class="co1">// TODO: entire JS code in this file is here</span><br />
<span class="br0">&#125;</span></div>
<p>This is what I am going to call a <em>namespace</em>.</p>
<p>The first question is how to ensure that the function is actually called and the code executed at the right time. The second question is how to share objects among more files (see <em>Sharing among namespaces</em> chapter below). Firebug solves this by registering every namespace and executing all when Firefox chrome UI is ready. See modified example.</p>
<div class="dean_ch" style="white-space: nowrap;">myExtension.<span class="me1">ns</span><span class="br0">&#40;</span><span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></p>
<p><span class="co1">// TODO: entire JS code in this file is here</span><br />
<span class="br0">&#125;</span><span class="br0">&#41;</span>;</div>
<p>The namespace (regular function) is passed as a parameter to <em>myExtension.ns</em> function. The <em>myExtension</em> object is the only global object that is defined by the extension. This is the singleton object that represents entire extension. Don’t worry if the name is long, there’ll be a shortcut for it (in real application it could be e.g. <em>comSoftwareIsHardMyExtension</em>).</p>
<p>The <em>ns</em> function is simple. Every function is pushed into an array.</p>
<div class="dean_ch" style="white-space: nowrap;"><span class="kw2">var</span> namespaces = <span class="br0">&#91;</span><span class="br0">&#93;</span>;</p>
<p><span class="kw1">this</span>.<span class="me1">ns</span> = <span class="kw2">function</span><span class="br0">&#40;</span>fn<span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="kw2">var</span> ns = <span class="br0">&#123;</span><span class="br0">&#125;</span>;</p>
<p>&nbsp; &nbsp; namespaces.<span class="me1">push</span><span class="br0">&#40;</span>fn, ns<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; <span class="kw1">return</span> ns;<br />
<span class="br0">&#125;</span>;</div>
<p>Actual execution of registered namespaces (functions) is only matter of calling <em>apply</em> on them.</p>
<div class="dean_ch" style="white-space: nowrap;"><span class="kw1">this</span>.<span class="me1">initialize</span> = <span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="kw1">for</span> <span class="br0">&#40;</span><span class="kw2">var</span> i=<span class="nu0">0</span>; i&lt;namespaces.<span class="me1">length</span>; i+=<span class="nu0">2</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> fn = namespaces<span class="br0">&#91;</span>i<span class="br0">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> ns = namespaces<span class="br0">&#91;</span>i<span class="nu0">+1</span><span class="br0">&#93;</span>;</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; fn.<span class="me1">apply</span><span class="br0">&#40;</span>ns<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span>;</div>
<p>Now, let’s put all together and see how the global extension (singleton) object is defined and initialized.</p>
<p>The following source code snippet represents a <em>browserOverlay.js</em> file that is included into an overlay (<em>browserOverlay.xul</em>)</p>
<div class="dean_ch" style="white-space: nowrap;"><span class="co1">// The only global object for this extension.</span><br />
<span class="kw2">var</span> myExtension = <span class="br0">&#123;</span><span class="br0">&#125;</span>;</p>
<p><span class="br0">&#40;</span><span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
<span class="co1">// Registration</span><br />
<span class="kw2">var</span> namespaces = <span class="br0">&#91;</span><span class="br0">&#93;</span>;</p>
<p><span class="kw1">this</span>.<span class="me1">ns</span> = <span class="kw2">function</span><span class="br0">&#40;</span>fn<span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="kw2">var</span> ns = <span class="br0">&#123;</span><span class="br0">&#125;</span>;<br />
&nbsp; &nbsp; namespaces.<span class="me1">push</span><span class="br0">&#40;</span>fn, ns<span class="br0">&#41;</span>;</p>
<p>&nbsp; &nbsp; <span class="kw1">return</span> ns;<br />
<span class="br0">&#125;</span>;<br />
<span class="co1">// Initialization</span><br />
<span class="kw1">this</span>.<span class="me1">initialize</span> = <span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></p>
<p>&nbsp; &nbsp; <span class="kw1">for</span> <span class="br0">&#40;</span><span class="kw2">var</span> i=<span class="nu0">0</span>; i&lt;namespaces.<span class="me1">length</span>; i+=<span class="nu0">2</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> fn = namespaces<span class="br0">&#91;</span>i<span class="br0">&#93;</span>;</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> ns = namespaces<span class="br0">&#91;</span>i<span class="nu0">+1</span><span class="br0">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; fn.<span class="me1">apply</span><span class="br0">&#40;</span>ns<span class="br0">&#41;</span>;</p>
<p>&nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p><span class="br0">&#125;</span>;<br />
<span class="co1">// Clean up</span><br />
<span class="kw1">this</span>.<span class="me1">shutdown</span> = <span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; window.<span class="me1">removeEventListener</span><span class="br0">&#40;</span><span class="st0">&quot;load&quot;</span>, myExtension.<span class="me1">initialize</span>, <span class="kw2">false</span><span class="br0">&#41;</span>;</p>
<p>&nbsp; &nbsp; window.<span class="me1">removeEventListener</span><span class="br0">&#40;</span><span class="st0">&quot;unload&quot;</span>, myExtension.<span class="me1">shutdown</span>, <span class="kw2">false</span><span class="br0">&#41;</span>;<br />
<span class="br0">&#125;</span>;<br />
<span class="co1">// Register handlers to maintain extension life cycle.</span><br />
window.<span class="me1">addEventListener</span><span class="br0">&#40;</span><span class="st0">&quot;load&quot;</span>, myExtension.<span class="me1">initialize</span>, <span class="kw2">false</span><span class="br0">&#41;</span>;</p>
<p>window.<span class="me1">addEventListener</span><span class="br0">&#40;</span><span class="st0">&quot;unload&quot;</span>, myExtension.<span class="me1">shutdown</span>, <span class="kw2">false</span><span class="br0">&#41;</span>;<br />
<span class="br0">&#125;</span><span class="br0">&#41;</span>.<span class="me1">apply</span><span class="br0">&#40;</span>myExtension<span class="br0">&#41;</span>;</div>
<p>As I mentioned above, there is just one global object <em>myExtension</em>.</p>
<p>To summarize, the object implements following methods:</p>
<ul>
<li><em>ns</em> &#8211; register a new namespace.</li>
<li><em>initialize</em> &#8211; initialize all namespaces.</li>
<li><em>shutdown</em> &#8211; clean up.</li>
</ul>
<p>And also, the code makes sure that <em>initialize</em> and <em>shutdown</em> methods are called at the right time. This is why event handlers are registered.</p>
<p>The <em>browserOverlay.xul</em> looks as follows now.</p>
<div class="dean_ch" style="white-space: nowrap;"><span class="sc3"><span class="re1">&lt;?xml</span> <span class="re0">version</span>=<span class="st0">&quot;1.0&quot;</span><span class="re2">?&gt;</span></span><br />
<span class="sc3"><span class="re1">&lt;overlay</span> <span class="re0">xmlns</span>=<span class="st0">&quot;http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul&quot;</span><span class="re2">&gt;</span></span></p>
<p>&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;script</span> <span class="re0">src</span>=<span class="st0">&quot;chrome://namespace/content/browserOverlay.js&quot;</span> <span class="re0">type</span>=<span class="st0">&quot;application/x-javascript&quot;</span><span class="re2">/&gt;</span></span><br />
&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;script</span> <span class="re0">src</span>=<span class="st0">&quot;chrome://namespace/content/Module1.js&quot;</span> <span class="re0">type</span>=<span class="st0">&quot;application/x-javascript&quot;</span><span class="re2">/&gt;</span></span></p>
<p>&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;script</span> <span class="re0">src</span>=<span class="st0">&quot;chrome://namespace/content/Module2.js&quot;</span> <span class="re0">type</span>=<span class="st0">&quot;application/x-javascript&quot;</span><span class="re2">/&gt;</span></span><br />
<span class="sc3"><span class="re1">&lt;/overlay<span class="re2">&gt;</span></span></span></div>
<p>And the <em>Module1.js</em> and <em>Module2.js</em> files are both the same.</p>
<div class="dean_ch" style="white-space: nowrap;">myExtension.<span class="me1">ns</span><span class="br0">&#40;</span><span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
<span class="co1">// TODO: entire JS code in this file is here</span><br />
<span class="br0">&#125;</span><span class="br0">&#41;</span>;</div>
<h3>Sharing among namespaces</h3>
<p>Now, when we have our script within a local scope(s), let’s answer the question how to share functionality and data among individual namespaces. The general idea is to use the one global object we have &#8211; <em>myExtension</em>.</p>
<p>First of all, see the following source code (<em>lib.js</em> file).</p>
<div class="dean_ch" style="white-space: nowrap;">myExtension.<span class="me1">LIB</span> = <span class="br0">&#123;</span></p>
<p>&nbsp; &nbsp; <span class="co1">// Shared APIs</span><br />
&nbsp; &nbsp; getCurrentURI: <span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> window.<span class="me1">location</span>.<span class="me1">href</span>;</p>
<p>&nbsp; &nbsp; <span class="br0">&#125;</span>,</p>
<p>&nbsp; &nbsp; <span class="co1">// Extension singleton shortcut</span><br />
&nbsp; &nbsp; theApp: myExtension,</p>
<p>&nbsp; &nbsp; <span class="co1">// XPCOM shortcuts</span><br />
&nbsp; &nbsp; Cc: Components.<span class="me1">classes</span>,</p>
<p>&nbsp; &nbsp; Ci: Components.<span class="me1">interfaces</span>,</p>
<p>&nbsp; &nbsp; <span class="co1">// Etc.</span><br />
<span class="br0">&#125;</span>;</div>
<p>You can see that a new LIB property is created within our global <em>myExtension</em> singleton. This objects represents a library of functions that should be shared among all modules in our extension. At this point, you can also get inspiration from <a href="http://en.wikipedia.org./wiki/Java_package">Java Packaging</a> and create whole tree of namespaces within the global singleton (just like e.g. <a href="http://developer.yahoo.com/yui/yahoo/">YUI</a> does)</p>
<p>The <em>lib.js</em> file is included in <em>browserOvelay.xul</em> (just after <em>browserOverlay.js</em>)</p>
<div class="dean_ch" style="white-space: nowrap;"><span class="sc3"><span class="re1">&lt;?xml</span> <span class="re0">version</span>=<span class="st0">&quot;1.0&quot;</span><span class="re2">?&gt;</span></span></p>
<p><span class="sc3"><span class="re1">&lt;overlay</span> <span class="re0">xmlns</span>=<span class="st0">&quot;http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul&quot;</span><span class="re2">&gt;</span></span><br />
&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;script</span> <span class="re0">src</span>=<span class="st0">&quot;chrome://myextension/content/browserOverlay.js&quot;</span> <span class="re0">type</span>=<span class="st0">&quot;application/x-javascript&quot;</span><span class="re2">/&gt;</span></span></p>
<p>&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;script</span> <span class="re0">src</span>=<span class="st0">&quot;chrome://myextension/content/lib.js&quot;</span> <span class="re0">type</span>=<span class="st0">&quot;application/x-javascript&quot;</span><span class="re2">/&gt;</span></span><br />
&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;script</span> <span class="re0">src</span>=<span class="st0">&quot;chrome://myextension/content/Module1.js&quot;</span> <span class="re0">type</span>=<span class="st0">&quot;application/x-javascript&quot;</span><span class="re2">/&gt;</span></span></p>
<p>&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;script</span> <span class="re0">src</span>=<span class="st0">&quot;chrome://myextension/content/Module2.js&quot;</span> <span class="re0">type</span>=<span class="st0">&quot;application/x-javascript&quot;</span><span class="re2">/&gt;</span></span><br />
<span class="sc3"><span class="re1">&lt;/overlay<span class="re2">&gt;</span></span></span></div>
<p>Let’s also improve our module script a bit.</p>
<div class="dean_ch" style="white-space: nowrap;">myExtension.<span class="me1">ns</span><span class="br0">&#40;</span><span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span> <span class="kw1">with</span> <span class="br0">&#40;</span>myExtension.<span class="me1">LIB</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
<span class="co1">// TODO: entire JS code in this file is here</span></p>
<p><span class="kw2">var</span> moduleVariable = <span class="st0">&quot;Accessible only from withing this module&quot;</span>;</p>
<p>dump<span class="br0">&#40;</span><span class="st0">&quot;myExtension.Module initialization &quot;</span> + getCurrentURI<span class="br0">&#40;</span><span class="br0">&#41;</span> + <span class="st0">&quot;<span class="es0">\n</span>&quot;</span><span class="br0">&#41;</span>;</p>
<p><span class="br0">&#125;</span><span class="br0">&#125;</span><span class="br0">&#41;</span>;</div>
<p>By utilizing <strong>with</strong> statement we can simply access all library functions as if they would be a global functions.</p>
<p>In case we want to access our singleton global object we can also utilize <em>theApp</em> shortcut (useful especially if the name is long) as follows:</p>
<div class="dean_ch" style="white-space: nowrap;">myExtension.<span class="me1">ns</span><span class="br0">&#40;</span><span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span> <span class="kw1">with</span> <span class="br0">&#40;</span>myExtension.<span class="me1">LIB</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
<span class="co1">// TODO: entire JS code in this file is here</span></p>
<p>theApp.<span class="me1">sharedValue</span> = <span class="st0">&quot;A new shared property&quot;</span>;</p>
<p><span class="br0">&#125;</span><span class="br0">&#125;</span><span class="br0">&#41;</span>;</div>
<p>Here is how the architecture look like from UML perspective.</p>
<p><img src="http://blog.mozilla.com/addons/files/2009/01/namespaces-300x225.png" alt="Namespaces within a Firefox extension." align="center" /></p>
<p>Download example extension <a href="http://www.softwareishard.com/downloads/examples/extensions/namespaces-20090115.xpi">here</a>.</p>
<p><a href="http://sharethis.com/item?&wp=2.8.6&amp;publisher=7e0eb025-1057-4238-a77c-a634ef8a9d63&amp;title=Firefox+Extensions%3A+Global+Namespace+Pollution&amp;url=http%3A%2F%2Fblog.mozilla.com%2Faddons%2F2009%2F01%2F16%2Ffirefox-extensions-global-namespace-pollution%2F">ShareThis</a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.mozilla.com/addons/2009/01/16/firefox-extensions-global-namespace-pollution/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
