CloudServices/ServiceWorker
Overview
Providing Cloud Services for Firefox OS may require adding some code on the client side that interacts with our servers.
The two first projects at Cloud Services that added such code on the Firefox OS platform are https://wiki.mozilla.org/WebAPI/SimplePush and https://wiki.mozilla.org/Identity/Firefox-Accounts
We're expecting that more projects will do the same in the future, and this wiki page describes the biggest problems that were encountered and how we can make this integration work faster & easier for every one.
Firefox OS Integration
Adding features in Firefox OS can be done at several levels:
- by creating an open web app at one of the 3 permission level: normal, privileged and certified
- by extending Firefox OS at a lower level : Gecko, Gaia
The first solution offers a lot of advantages:
- updates are very easy
- applications can interact with most of the system using Web API https://wiki.mozilla.org/WebAPI
- we're coding in pure HTML5/Javascript
There are some pitfalls however:
- limited control when the application is in the background, which is the case for headless features
- security restrictions. For example we can't load another app's UI
- some restrictions in what can be done in sandboxed child processes (XXX elaborate)
The other option --extending the system at lower level-- has a few advantages:
- there are no restrictions whatsoever in what can be done
- the code is part of the B2G process, and is not treated like web apps. For example, it can be running in the background without fearing oomkiller
But the pitfalls are quite big:
- the feature becomes part of B2G and must follow its release lifecycle, and fast iterations become impossible: once it's part of the system it's there forever. What if we need to push a security patch asap for Firefox Account ?
- developing in the core is very hard for people outside the FFOS team because it's a moving target. It involves a lot of boiler plate code and knowledge, and is not about coding the web anymore (xpcom anyone? JSM?)
Proposal: Service Workers
We propose to add a new kind of worker in Firefox OS: Service Workers.
Service Workers are Web Workers that run in their own scope but with full chrome privileges -- like allow IDB, XHR etc
Services Workers can be defined in any web application, and are managed by a specialized component in Gecko: the Services Manager.
The Services Manager is responsible for the registration and lifecycle of Services Workers
XXX
Description
XXX