pages tagged Mozillarohieb.namehttps://rohieb.name/blag/tag/Mozilla/rohieb.nameikiwiki2013-09-19T05:04:01ZXULRunner rocks!https://rohieb.name/blag/post/xulrunner-rocks-/rohieb
CC-BY-SA 3.0
2013-09-19T05:04:01Z2011-03-15T21:16:00Z
<p>For <a href="https://rohieb.name/projects/infopoint-html/">one of my projects</a>, I needed an
application to display a web page in full screen mode. At first, I used
Firefox with the <a href="http://web.archive.org/web/20120415204503/http://www.krickelkrackel.de/autohide/autohide.htm">AutoHide extension</a>, but this solution was more of
a hack and not easy to deploy to multiple machines — I worked with a
pre-configured user profile that was copied every time the application
started. Furthermore, after each update, Firefox would check for
compatibility of installed plugins and displayed a nasty dialog in the
meantime.</p>
<p>So I tried to move away from Firefox and do something on my own,
something slim which did just what I wanted, nothing more, and do it
good — according to the <a href="http://en.wikipedia.org/wiki/Unix_philosophy">UNIX philosophy</a>. But writing another
C/C++/Python/whatever application from scratch was not an option
(implementing an HTML renderer would be a pain, and I didn’t fancy
reading extensive manuals about WebKit, Gecko or any other rendering
engine).</p>
<p>After a while of thinking, which included thought fragments of
<a href="http://getsongbird.com/">Songbird</a> and <a href="http://conkeror.org/">Conkeror</a>, I decided to give <a href="https://developer.mozilla.org/en/XULRunner">XULrunner</a> a shot
(for those who do not know, XUL is the XML-based user interface language
used by the Mozilla applications and the Firefox and Thunderbird
extensions, and XULRunner is an interpreter and run-time environment for
XUL documents).</p>
<p>So after a while of hacking (there is a good <a href="https://developer.mozilla.org/en/Getting_started_with_XULRunner">tutorial on the Mozilla
Developer Network</a>), I ended up with a few lines of code:</p>
<div class="highlight-xml"><pre class="hl"><span class="hl kwa"><?xml</span> <span class="hl kwb">version</span>=<span class="hl str">"1.0"</span><span class="hl kwa">?></span>
<span class="hl kwa"><?xml-stylesheet</span> <span class="hl kwb">href</span>=<span class="hl str">"chrome://global/skin/"</span> <span class="hl kwb">type</span>=<span class="hl str">"text/css"</span><span class="hl kwa">?></span>
<span class="hl kwa"><?xml-stylesheet</span> <span class="hl kwb">href</span>=<span class="hl str">"main.css"</span> <span class="hl kwb">type</span>=<span class="hl str">"text/css"</span><span class="hl kwa">?></span>
<span class="hl kwa"><window</span>
<span class="hl kwb">xmlns</span>=<span class="hl str">"http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"</span>
<span class="hl kwb">id</span>=<span class="hl str">"viewer"</span> <span class="hl kwb">windowtype</span>=<span class="hl str">"viewer"</span> <span class="hl kwb">title</span>=<span class="hl str">"Infopoint HTML View"</span>
<span class="hl kwb">hidechrome</span>=<span class="hl str">"true"</span><span class="hl kwa">></span>
<span class="hl kwa"><hbox</span> <span class="hl kwb">flex</span>=<span class="hl str">"1"</span><span class="hl kwa">></span>
<span class="hl kwa"><iframe</span> <span class="hl kwb">id</span>=<span class="hl str">"contentview"</span> <span class="hl kwb">flex</span>=<span class="hl str">"1"</span>
<span class="hl kwb">src</span>=<span class="hl str">"chrome://infopointhtmlviewer/content/default.html"</span> <span class="hl kwa">/></span>
<span class="hl kwa"></hbox></span>
<span class="hl kwa"><script></span>
// load URI given on command line
var content = document.getElementById(<span class="hl str">"contentview"</span>);
var cmdLine = window.arguments[<span class="hl num">0</span>].QueryInterface(
Components.interfaces.nsICommandLine);
var uri = content.getAttribute(<span class="hl str">"src"</span>);
alert(<span class="hl str">"Default URL: "</span> + uri);
if(cmdLine.length <span class="hl kwa">></span> <span class="hl num">0</span>) {
uri = cmdLine.getArgument(<span class="hl num">0</span>);
}
if(content != null) {
content.setAttribute(<span class="hl str">"src"</span>, uri);
}
// resize to full screen
window.resizeTo(screen.width, screen.height);
<span class="hl kwa"></script></span>
<span class="hl kwa"></window></span>
</pre></div>
<p>The above code is in the public domain.</p>
<p>And that was basically everything. I was surprised that there was
nothing more to it.</p>
<p>You can get the source code of the full application <a href="https://github.com/rohieb/infopoint-html">on GitHub</a>.</p>