Home Programming Learning Firefox OS Application Development

Learning Firefox OS Application Development

By Tanay Pant
books-svg-icon Book
eBook $25.99 $17.99
Print $32.99 $18.99
Subscription $15.99 $10 p/m for three months
$10 p/m for first 3 months. $15.99 p/m after that. Cancel Anytime!
What do you get with a Packt Subscription?
This book & 7000+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook + Subscription?
Download this book in EPUB and PDF formats, plus a monthly download credit
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook?
Download this book in EPUB and PDF formats
Access this title in our online reader
DRM FREE - Read whenever, wherever and however you want
Online reader with customised display settings for better reading experience
What do you get with video?
Download this video in MP4 format
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with video?
Stream this video
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with Audiobook?
Download a zip folder consisting of audio files (in MP3 Format) along with supplementary PDF
What do you get with Exam Trainer?
Flashcards, Mock exams, Exam Tips, Practice Questions
Access these resources with our interactive certification platform
Mobile compatible-Practice whenever, wherever, however you want
BUY NOW $10 p/m for first 3 months. $15.99 p/m after that. Cancel Anytime!
eBook $25.99 $17.99
Print $32.99 $18.99
Subscription $15.99 $10 p/m for three months
What do you get with a Packt Subscription?
This book & 7000+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook + Subscription?
Download this book in EPUB and PDF formats, plus a monthly download credit
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook?
Download this book in EPUB and PDF formats
Access this title in our online reader
DRM FREE - Read whenever, wherever and however you want
Online reader with customised display settings for better reading experience
What do you get with video?
Download this video in MP4 format
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with video?
Stream this video
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with Audiobook?
Download a zip folder consisting of audio files (in MP3 Format) along with supplementary PDF
What do you get with Exam Trainer?
Flashcards, Mock exams, Exam Tips, Practice Questions
Access these resources with our interactive certification platform
Mobile compatible-Practice whenever, wherever, however you want
  1. Free Chapter
    Introduction to Firefox OS
About this book
With broad compatibility, the latest in web technologies, and powerful development tools, Firefox is a great choice for both web developers and end users. Firefox OS’s promotion of HTML5 as a first class citizen opens up the walled gardens of mobile application development for web developers. It is because of this initiative that no special SDKs are required to develop for Firefox OS. This book will help you excel in the art of developing applications for Firefox OS. It sequentially covers knowledge building, skills acquisition, and practical applications. Starting with an introduction to Firefox OS, usage of WebIDE, and then the application structure, this book introduces applications of increasing complexity with each chapter. An application that measures your tapping speed, a geolocation tagging application, and a photo editing and sharing application are the three applications that will be built from scratch. You will learn about topics such as the difference between various types of Firefox OS applications, application manifest files, offline apps, and designing principles for applications. You will also learn to test and submit the applications to the marketplace and finally maintain the repository of the Firefox OS application. By the end, you will be able to develop beautifully designed, fully-fledged, and rigorously tested Firefox OS applications and also share them at the Firefox OS Marketplace.
Publication date:
October 2015
Publisher
Packt
Pages
166
ISBN
9781783989409

 

Chapter 1. Introduction to Firefox OS

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

 

Introducing 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:

 

The need to develop applications for 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


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

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.

Gonk – the kernel

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 – the engine

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 – the interface

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.

Firefox OS applications

Next are the third-party applications that are made by great developers like you and are running on Gaia. These applications run on top of Gaia and can be downloaded from the Firefox Marketplace. You will learn how to make these applications shortly after you study some essentials of Firefox OS.

 

The working of components under Firefox OS's hood – an example


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.

 

HTML5 and open web applications


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.

 

The security model of Firefox OS


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.

 

Devices running Firefox OS available in the market


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/.

 

Summary


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.

About the Author
  • Tanay Pant

    Tanay Pant is a developer, white hat, and writer who has a passion for web development. He contributes code to Mozilla Webmaker and is the chief architect of Stock Wolf (www.stockwolf.net), a global virtual stock trading platform that aims to impart practical education about stocks and markets. He is also a representative of Mozilla, and you can find his name listed under the credits (https://www.mozilla.org/credits/) of the Firefox web browser. You can also find articles written by him on web development at SitePoint and TutsPlus. Tanay acts as a security consultant and enjoys helping corporations fix vulnerabilities in their products.

    Browse publications by this author