In this chapter, you will improve your understanding of Firefox OS by learning about its terminology, architecture, abstraction layers, as well as the security model. We will discuss the reasons why it makes sense to develop or port applications to Firefox OS. We will also take a look at the Firefox OS devices currently available in the global market. We will go through the following topics in detail:
Getting to know about Firefox OS
Why you should develop applications for Firefox OS
Technical details of Firefox OS
The security model of the OS
Devices on the market that run Firefox OS
Mozilla and Telefónica started a joint project in 2011 under the code name Boot to Gecko—a new mobile operating system built on top of a web technology. Mozilla publicly demonstrated the open source Firefox OS in February 2012. The reason to roll out this platform was to provide developers with an alternative operating system that respects the user's privacy and security so that new smartphone users have a choice in buying. Firefox OS devices are a great choice for users who wish to make a transition from feature phones to smartphones, or for those who have concerns about the privacy settings. Mozilla is best known for developing open source software, such as Firefox Web Browser, and it answers to its users rather than answering to its stakeholders. The aim of Firefox OS is to run on devices that have limited hardware capabilities while still providing users with a unique and smooth experience.
Let's now take a look at a screenshot of a device that uses Firefox OS:

Firefox OS is one of the emerging platforms in the market, with devices having been released in a large number of countries. Developing applications for Firefox OS is very easy, especially for web developers, as Firefox OS treats HTML5 applications as first-class citizens, and hence there isn't any requirement to learn about using any unique platform-specific SDK.
The greatest thing about developing applications for Firefox OS is that the apps that you construct can run on a host of other devices that run Firefox as well, the goal being to make the Firefox OS apps to run in any web browser. For example, if the application that you build is responsive, then you will also be able to install and run it on a computer/laptop that runs Firefox. Isn't that great? Firefox is available for Windows, OS X, Linux, and Android, and very soon it will be available for iOS as well! This will allow you to distribute your applications to a wide number of people using different platforms. Also, unlike platforms such as iOS, you are not forced to publish your applications via the official marketplace; you can host your applications by yourself as well.
Mozilla has a huge community of developers and users, who are always willing to help others on platforms such as GitHub and IRC (https://wiki.mozilla.org/IRC). Firefox OS also has a great marketplace, which has grown over the years and offers great applications. Even the user interface of Firefox OS, which is known as Gaia, is built with the help of three components, namely HTML5, JavaScript, and CSS3. This makes developing applications for this platform easy for people who have experience in web development.
You can also port the applications that you build for Firefox OS to native applications for other platforms with the use of software such as PhoneGap, since Firefox OS applications are essentially web applications.
The architecture of Firefox OS is a bit different from other mobile operating systems. There are three levels of abstraction in Firefox OS: Gonk, Gecko, and Gaia.
Mobile hardware refers to the various components present in a mobile, such as the battery, sensors, camera, GPS, Bluetooth, and other things, that are crucial for the interaction of the operating system with the device and environment. The interaction of these various components with the operating system is what makes the experience of smartphones unique compared to the previous generation of phones, called feature phones.

Firefox OS's kernel is built in the Android Open Source Project, which itself is a Linux kernel, and is the lowest level in the abstraction structure of the operating system. Gonk acts as the interface between the underlying hardware and Gecko. It deals with all the complex tasks of abstracting the hardware such that the components of the mobile device such as Bluetooth, camera, and sensors can be accessed via Gecko. Thus, Gonk is responsible for exposing the features of the chipset to be used via the WebAPIs to Gecko.
Gecko is the web engine that connects components such as HTML and JavaScript to the underlying low-level layer of Gecko. Gecko is the same HTML parsing and rendering engine that is used in the Firefox web browser. However, a certain web renderer of Gecko is used for this project just as different variants of Gecko are used for Firefox, Windows, Android, and OS X. Gecko is responsible for handling details such as providing access to the hardware via secure APIs. It consists of a robust security framework and it also handles the update management, along with various other core services. It is basically an application runtime layer.
Gaia is the user interface part of Firefox OS. It is what we actually see in the OS. The app launcher and all the default applications such as camera, dialer, and settings are part of Gaia, and are completely built using HTML, CSS and JavaScript. This is the final layer of Firefox OS. Gaia exposes the WebAPIs for developers to interact with Gecko and the underlying hardware. As Firefox OS is completely open source and available online on GitHub (Gaia) and Mercurial (Gecko and Gonk), it gives full access to the user so that they can tweak the default look and feel of Firefox OS to suit their personal or organizational needs.
Let's take the example of the camera application of Firefox OS. Let's think of a high-level view of what happens when we take a picture in Firefox OS's ecosystem. We open the Camera application, which is a part of Gaia. Gaia makes use of the Camera API, which is implemented in Gecko to run the application, as Gecko is the rendering engine for the operating system. Gecko then passes the requests to Gonk, which interfaces with the hardware. Gonk sends a low-level request to the chip that activates the camera and actually takes a picture.
Note
Note that the flow of control here goes from the highest layer in the abstraction layer to the lowest layer of the OS, and then finally to the mobile hardware.
All these types of access to the hardware are provided to the developer via the WebAPIs, so you don't actually have to think of or concern yourself with what lies under the hood. It feels great to drive a car, but having abstract knowledge of what actually lies under the hood can always prove to be useful.

In the preceding illustration, the purple line from Command to Action denotes the flow of control from the highest to the lowest abstraction level, and finally to the hardware.
Open web applications are those web applications that make use of open standard technologies, such as HTML5, CSS, JavaScript, and so on. These applications differ from native applications based on the fact that open web applications run on a web browser and hence can be accessed from a wide range of devices. These applications can be installed, access device hardware via the WebAPIs, and be run offline by making use of technologies such as AppCache and IndexedDB. However, these applications should be designed in such a way that they are cross-platform; if a device does not have all the hardware capabilities, then there will be a graceful degradation of the features of the application. Open web applications do not make use of proprietary technologies.
Let's take the example of Stack Edit (a web application), which is an online text editor that parses the markdown text and is very popular among authors. It is an example of an open web application. When loaded for the first time, it stores all its static data in the form of AppCache. All subsequent files that you store with the help of the in-browser text editor will be stored in the browser itself with IndexedDB. The application does not require a working Internet connection on subsequent runs.
In Firefox OS, each application runs in an iframe with superpowers; hence, apps that run on Gecko run on a separate process that is a child process of the B2G system process. Due to this, a malicious application cannot disturb Gaia or other applications. Access to the underlying hardware is available only via the WebAPIs, which themselves are divided into different levels of permissions: Hosted (Web), Privileged, and Certified.
Each Firefox OS application has a manifest file that contains the details of the application. The developer has to declare the permissions for the use of the WebAPIs in the manifest file. Every application that runs in Firefox OS runs in a sandboxed environment. This means that the data generated by the application is sandboxed as well, and hence the data of one application cannot be accessed by another application. The following illustration will help you grasp the preceding discussion of application sandboxing:

Even permissions from different websites are sandboxed on Firefox OS. For example, if an application uses OAuth to authenticate its users, then another app which uses a similar OAuth mechanism will ask for the login credentials again, even when you have used the login credentials in one application. This is because both applications are running in different sandboxes separately from one another, and the cookies of one application cannot be accessed by another application.
Don't worry if the concepts of the manifest file and the permissions levels are not clear yet; we will cover these topics in depth in Chapter 3, Getting Your Hands Dirty: Firefox OS Apps. Right now, you can just think of them as features that contribute to the application security in Firefox OS.
Firefox OS pays great attention to the user's data security as well. There is a setting called Do Not Track that helps to protect a user's privacy when browsing the Internet. The apps run in a sandboxed mode as described earlier, and once a user uninstalls an application, all the data associated with the application, such as cookies, AppCache, Local Storage, and IndexedDB, is also permanently deleted.
A large number of devices that run Firefox OS are now available for purchase from many operators and carriers in over 30 countries. Alcatel One Touch Fire, LG Fireweb, ZTE Open, Huawei Y300II, Alcatel One Touch Fire C, ZTE Open C, ZTE Open II, Alcatel One Touch Fire E, Intex Cloud FX, Spice Fire MI FX1, Symphony Gofox F15, Alcatel One Touch Fire C 2G, Zen 105 Fire, Cherry Mobile Ace, Fx0, Orange Klif, and Spice Fire One MI FX2 are examples of such devices. The following image shows the newly launched Fx0 smartphone:

In 2015, Panasonic launched Panasonic CX700, which is a television that runs on Firefox OS. Isn't that amazing? Now, the applications that you develop can also run on televisions.

Note
For complete details of the specifications and availability of the various devices that run Firefox OS, you can visit the Mozilla Firefox OS devices website at https://www.mozilla.org/en-US/firefox/os/devices/.
In this chapter, you learned what Firefox OS is, why a developer should consider developing applications for Firefox OS, and the architecture and technical know-how of Firefox OS. We also took a look at the security model of the operating system, what open web applications are, and the devices available in the market that run Firefox OS. We looked at the devices on which our own applications will run in the future.
In the next chapter, we will study WebIDE, using which we will be able to run the Firefox OS simulator on our machines, as well as install and manage Firefox OS applications. We will go through the features of WebIDE and you will learn how to perform daily tasks on the operating system, such as uninstalling and browsing other runtime applications.