{"id":298,"date":"2005-12-20T11:10:04","date_gmt":"2005-12-20T17:10:04","guid":{"rendered":"http:\/\/www.mooreds.com\/wordpress\/?p=298"},"modified":"2005-12-20T11:10:04","modified_gmt":"2005-12-20T17:10:04","slug":"mozilla-xpcom-and-xpcshell","status":"publish","type":"post","link":"https:\/\/www.mooreds.com\/wordpress\/archives\/298","title":{"rendered":"Mozilla, XPCOM and xpcshell"},"content":{"rendered":"<p>Most people know about mozilla through Firefox, <a href='http:\/\/www.epinions.com\/content_4042760324'>their IE browser replacement<\/a>.  (Some geeks may remember the <a href='http:\/\/wp.netscape.com\/newsref\/pr\/newsrelease591.html'>Netscape source code release<\/a>.)  But mozilla is a lot more than just a browser&#8211;there&#8217;s an entire API set, <a href='http:\/\/www.mozilla.org\/projects\/xpcom\/'>XPCOM<\/a> and <a href='http:\/\/www.mozilla.org\/projects\/xul\/'>XUL<\/a>, that you can use to build applications.  (There are <a href='http:\/\/books.mozdev.org\/chapters\/index.html'>books<\/a> about doing so, but mozilla development seems to run ahead of them.)  I&#8217;m working on a project that needs some custom browser action, so looking at XPCOM seemed a wise idea.<\/p>\n<p>XPCOM components can be written in a variety of languages, but most of the articles out there <a href='http:\/\/www-128.ibm.com\/developerworks\/webservices\/library\/co-xpcom.html'>focus on C++<\/a>.  While I&#8217;ve had <a href='http:\/\/www.mooreds.com\/weblog\/archives\/000115.html'>doubts about scripting languages and large scale systems<\/a>, some others <a href='http:\/\/open-ils.org\/blog\/?p=15'>have had success heading down the javascript path<\/a>.  I have no desire to delve into C++ any more than I have to (I like <a href='http:\/\/www.joelonsoftware.com\/articles\/APIWar.html'>memory management<\/a>), so I&#8217;ll probably be writing some javascript components.  Unfortunately, because XPCOM allows javascript to talk to C++, I won&#8217;t be able to entirely <a href='http:\/\/www.mozilla.org\/scriptable\/avoiding-leaks.html'>avoid the issue of memory management<\/a>.<\/p>\n<p><a href='http:\/\/developer.mozilla.org\/en\/docs\/xpcshell'><code>xpcshell<\/code><\/a> is an application bundled with mozilla that allows me to interact with mozilla&#8217;s platform in a very flexible manner.  It&#8217;s more than just <a href='http:\/\/burstproject.org\/build\/doc\/shells.html'>another javascript shell<\/a> because it gives me a way to interact with the XPCOM API (<a href='http:\/\/kb.mozillazine.org\/Category:Example_code'>examples<\/a>).  To install <code>xpcshell<\/code> (on Windows) make sure you <a href='http:\/\/www.mozilla.org\/releases\/#1.7.12'>download and install the zip file<\/a>, not the Windows Installer.  (I tried doing the complete install and the custom install, and couldn&#8217;t figure out a way to get the <code>xpcshell<\/code> executable.)  <\/p>\n<p>One cool thing you can do with xpcshell is write command line javascript scripts.  Putting this:<\/p>\n<pre><code>var a = \"foobar\";\nprint(a);\na=a.substr(1,2);\nprint(a);<\/code><\/pre>\n<p>in a file named <code>test.js<\/code> gives this output:<\/p>\n<pre><code>$ cat test.js | .\/xpcshell.exe\nfoobar\noo\n<\/code><\/pre>\n<p>Of course, this code doesn&#8217;t do anything with XPCOM&#8211;for that, see aforementioned <a href='http:\/\/kb.mozillazine.org\/Category:Example_code'>examples<\/a>.  <\/p>\n<p>I did run into some library issues running the above code on linux&#8211;I needed to execute it in the directory where xpcshell was installed.  On windows that problem doesn&#8217;t seem to occur.<\/p>\n<p>A few other interesting links: <a href='http:\/\/www.webweavertech.com\/costin\/archives\/000385.html'>installing xpcshell for firefox<\/a>, <a href='http:\/\/www.allpeers.com\/blog\/creating-complex-firefox-extensions\/'>firefox extensions with the mozilla build system<\/a>, <a href='http:\/\/jslib.mozdev.org\/docs.html'>a javascript library easing XPCOM development<\/a>, and another <a href='http:\/\/www.xulplanet.com\/references\/xpcomref\/'>XPCOM reference<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Most people know about mozilla through Firefox, their IE browser replacement. (Some geeks may remember the Netscape source code release.) But mozilla is a lot more than just a browser&#8211;there&#8217;s [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-298","post","type-post","status-publish","format-standard","hentry","category-technology"],"_links":{"self":[{"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/posts\/298","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/comments?post=298"}],"version-history":[{"count":0,"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/posts\/298\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/media?parent=298"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/categories?post=298"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/tags?post=298"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}