Chapter 3 - Gaia under the hood
3.1 Booting path
Before looks Gaia from above, we can take some time to know how we go to Gaia when we power-on a device.
Gaia is booting from Gecko. On Firefox OS device, the Gecko is booting from linux kernel. The Architecture overview in Mozilla Developer Network (MDN) described the bootstrapping process of how FirefoxOS is booting to Gecko.

System bootup flow
3.1.1 Bootloader process
Bootloader bring up the Firefox OS device, checking basic hardwares are functional, then Linux Kernel will take the responsibility to bring up devices and run essential processes.
3.1.2 Linux Kernel process
The Linux Kernel used for Firefox OS is based on Android Open Source Project (AOSP). You can reference Android boot process to understand howto bring the device up to kernal.
kernel will execute processes defined in init.rc and the successor init.b2g.rc to boot essential process such as b2g (FirefoxOS basic process, containing Gecko), rild (telephony related process that might proprietary by different chipsets).
Then we already boot to Gecko (the b2g process).
3.1.3 In b2g process (Gecko)
The b2g process runs libxul, which reference to b2g/chrome/app/b2g.js to get default preference.
From the perference it will open the described html file called b2g/chrome/content/shell.html,
which is compiled within the omni.ja file.
The shell.html includes b2g/chrome/content/shell.js file, which will trigger the Gaia system app.

FirefoxOS structure
3.2 Search Gecko code
To search code in gecko, you could use http://dxr.mozilla.org. It’s more fancy and provide good jump and reference features, but with limited repositories. Or you could try the traditional http://mxr.mozilla.org, which contains more Mozilla projects.
3.3 Gecko files that related to Gaia
Following folders contains files that related to gaia
b2g/
b2g folder contains mainly FirefoxOS related functions.
b2g/chrome/content
Contain Javascript files run above system app
b2g/chrome/content/shell.html
The entry point, the first html to load Gaia system app.
in shell.html, Gecko include settings.js and shell.js
1 <script type="application/javascript;version=1.8"
2 src="chrome://browser/content/settings.js"> </script>
3 <script type="application/javascript;version=1.8"
4 src="chrome://browser/content/shell.js"> </script>
settings.js are system default setting parameters.
b2g/chrome/content/shell.js
shell.js is the first script to load Gaia system app.
shell.js import all required modules, register key listeners,
defined
sendCustomEvent and sendChromeEvent to communicate with Gaia, and
provide webapp install helper. indexedDB quota, RemoteDebugger, keyboard
helper, screenshot. But the most important thing is shell.js launch
the Gaia system app, then hand over the overall system related
management work to Gaia system app.
1 let systemAppFrame =
2 document.createElementNS('http://www.w3.org/1999/xhtml', 'html:iframe');
3 ....
4 container.appendChild(systemAppFrame);
b2g/chrome/app/b2g.js
predefined references, like about:config in browser, same as gaia pref.js Can change this values in settings. Can be overwrite with Gaia’s user.js in Gaia build script.
mozilla/central/dom/{API}
API implementation after b2g will locate in dom/. Older API will locate in dom/base, ex navigator.cpp
mozilla/central/dom/apps
.jsm will be loaded. .js API implementation ex: webapp.js install, getSelf…
mozilla/central/dom/apps/src/
PermissionsTable.jsm All permissions are defined in PermissionsTable.jsm
mozilla/central/dom/webidl
language to define web api. search MDN WebIDL_bindings for supported attributes.
mozilla/central/hal/gonk
hardware related gonk port layer.
3.4 Generated files
module/libpref/src/init/all.js
contain all configs
/system/b2g/omni.ja the omni.js
contains the pack of styles, resources in device.
3.5 Contribute gecko related bug
Though this books is focus on gaia. You could refer How to submit a patch if you have a chance to patch gecko code.
Before that, you also require to become a mozilla committer.
3.6 Reference
- FirefoxOS and its use of linux http://www.slideshare.net/aimeemaree/firefoxos-and-its-use-of-linux-a-deep-dive-into-gonk-architecture