wishlist update
[www-rohieb-name.git] / blag / post / xulrunner-rocks-.mdwn
1 [[!meta title="XULRunner rocks!"]]
2 [[!meta date="2011-03-15 22:16"]]
3 [[!meta author="rohieb"]]
4 [[!meta license="CC-BY-SA 3.0"]]
5
6 For [[one of my projects|projects/infopoint-html]], I needed an
7 application to display a web page in full screen mode. At first, I used
8 Firefox with the [AutoHide extension][0], but this solution was more of
9 a hack and not easy to deploy to multiple machines — I worked with a
10 pre-configured user profile that was copied every time the application
11 started. Furthermore, after each update, Firefox would check for
12 compatibility of installed plugins and displayed a nasty dialog in the
13 meantime.
14
15 So I tried to move away from Firefox and do something on my own,
16 something slim which did just what I wanted, nothing more, and do it
17 good — according to the [UNIX philosophy][1]. But writing another
18 C/C++/Python/whatever application from scratch was not an option
19 (implementing an HTML renderer would be a pain, and I didn’t fancy
20 reading extensive manuals about WebKit, Gecko or any other rendering
21 engine).
22
23 After a while of thinking, which included thought fragments of
24 [Songbird][2] and [Conkeror][3], I decided to give [XULrunner][4] a shot
25 (for those who do not know, XUL is the XML-based user interface language
26 used by the Mozilla applications and the Firefox and Thunderbird
27 extensions, and XULRunner is an interpreter and run-time environment for
28 XUL documents).
29
30 So after a while of hacking (there is a good [tutorial on the Mozilla
31 Developer Network][5]), I ended up with a few lines of code:
32
33 [[!format xml """
34 <?xml version="1.0"?>
35 <?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
36 <?xml-stylesheet href="main.css" type="text/css"?>
37 <window
38 xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
39 id="viewer" windowtype="viewer" title="Infopoint HTML View"
40 hidechrome="true">
41
42 <hbox flex="1">
43 <iframe id="contentview" flex="1"
44 src="chrome://infopointhtmlviewer/content/default.html" />
45 </hbox>
46 <script>
47 // load URI given on command line
48 var content = document.getElementById("contentview");
49 var cmdLine = window.arguments[0].QueryInterface(
50 Components.interfaces.nsICommandLine);
51 var uri = content.getAttribute("src");
52 alert("Default URL: " + uri);
53 if(cmdLine.length > 0) {
54 uri = cmdLine.getArgument(0);
55 }
56
57 if(content != null) {
58 content.setAttribute("src", uri);
59 }
60
61 // resize to full screen
62 window.resizeTo(screen.width, screen.height);
63 </script>
64 </window>
65 """]]
66
67 The above code is in the public domain.
68
69 And that was basically everything. I was surprised that there was
70 nothing more to it.
71
72 You can get the source code of the full application [on GitHub][6].
73
74 [0]: http://web.archive.org/web/20120415204503/http://www.krickelkrackel.de/autohide/autohide.htm
75 [1]: http://en.wikipedia.org/wiki/Unix_philosophy
76 [2]: http://getsongbird.com/
77 [3]: http://conkeror.org/
78 [4]: https://developer.mozilla.org/en/XULRunner
79 [5]: https://developer.mozilla.org/en/Getting_started_with_XULRunner
80 [6]: https://github.com/rohieb/infopoint-html
81
82 [[!tag programming GitHub JavaScript Mozilla Mozilla_Firefox XUL
83 XULRunner]]
This page took 0.059347 seconds and 5 git commands to generate.