edit add

Hack on FirefoxOS

Hack on FirefoxOS:

mobile, web-based and really open

LD 2012 - luca.greco@alcacoop.it

Who are you?
Why you're talking about FirefoxOS?

not an actual contributor

... but I started to hack on javascript
and Mozilla platform long time ago...

and I like to hack... so Let's hack on Mozilla FirefoxOS...

MOTIVATIONS

HTML5: fill the gap between desktop and web apps

A lot of people already use more web apps than desktop apps

... and now they are moving from desktop to mobile devices

Mobile Platforms lacks Standards (and sometimes they lacks Freedom too)

Cross Platform Mobile Development is a mess

Mozilla wants HTML5 to reach native mobile platforms features ASAP

PRIOR ART

Mozilla XULRunner

a Web Runtime for Desktop Apps from a long long time

Apache Cordova

(a.k.a. Phonegap) a Web Runtime for Mobile Apps

HP/Palm WebOS

web-based mobile OS

Google Chrome/Chromium OS

web-based desktop/laptop/netbook OS

Mozilla Mobile Activities

Firefox for Android

Native Firefox for Android Platform

FirefoxOS and WebAPI

A mobile OS based on Gecko and Linux, and bunch of new experimental APIs for native mobile apps (proposed as standards)

OpenWebApps

Decentralized Installable WebApps on Desktop (Firefox Desktop Nightly) and Mobile (Firefox for Android Nightly and FirefoxOS)

FirefoxOS - Architecture

OpenWebApps
Gaia
Gecko (+ new WebAPI)
Gonk

GONK

Low Level System (based on a Linux kernel and system utils used on Android)

GECKO

Mozilla Runtime (standard Web technologies from Desktop and Mobile Firefox and new WebAPIs)

GAIA

Base UI, System Utils and Apps (UI based on HTML+JS+CSS, uses new WebAPIs)

Boot2Gecko?

B2G is the internal project codename for FirefoxOS

FirefoxOS Developer Tools

FirefoxOS Emulator

QEMU ARM as in Android Emulator + generated firmware

B2G Desktop

FirefoxOS Simulator (Custom Gecko build + fake/mocked WebAPIs)

Run Gaia on Nighly

and use Firefox-included Web Developer Tools

Marionette

for automated testing and remote interactive development

Remote Debugger

included in FirefoxOS, B2G Desktop, Firefox Android and Desktop Nightly

Mozilla MXR

Mozilla Cross-Reference sources

FirefoxOS Emulator

Building and installing B2G

how to build qemu arm emulator and b2g firmware

Connect to Gonk (ADB)

adb shell
# ps 
            

Do you want Busybox?

download/build an arm binary busybox

# and uploads it to the emulator
adb shell mount -o remount,rw /system
adb push busybox /system/bin/
adb shell chmod 0755 /system/bin/busybox
            

Connect to Gecko

Setting Up Marionette for B2GMarionette for Interactive Python

$ adb forward tcp:2828 tcp:2828
$ python
>>> from marionette import Marionette
>>> marionette = Marionette('localhost', 2828)
>>> marionette.start_session()
u'session-b2g'
            

FirefoxOS Dev Tips Screencasts

some useful tips and tricks from an FirefoxOS developer

R2D2B2G

experimental addon, integrate/interact with B2G-desktop from Firefox.

FirefoxOS Simulator (B2G Desktop)

Get a Nightly or Build yourself

B2G-Desktop Nightly Build Build YourselfBuild Prerequisites

Install MozREPL Extension

Let's install a powerfull introspection javascript shell into B2G
MozREPL GIT Repo

$ cd b2g
$ mkdir extensions
$ cd extensions
$ git clone https://github.com/bard/mozrepl mozrepl@hyperstruct.net

# bump toolkit compatibility in install.rdf (max to 19.*)
            

Run B2G with MozREPL enabled

Let's start b2g desktop on an existent gaia profile with MozREPL enabled

$ ./b2g -profile PATH_TO_GAIA_PROFILE -repl
$ rlwrap telnet 127.0.0.1 4242
...
Current working context: chrome://browser/content/shell.xul
Current input mode: syntax

repl> 
            

WebAPI

Web Content Installed Web App Privileged Web App Certified Web App
Regular web content A regular web app A "privileged" web app; more power = more responsibility A "certified" web app; device-critical applications

Hack on WebAPIs from inside

### RUN ACTIVITIES (as in "Android Intents")
activity1 = new MozActivity({name: "dial", data: 
  {number: "+39328", type: "webtelephony/number"}});

activity2 = new MozActivity({name: "new", data: 
  {number: "+39328", type: "websms/sms"}});
            

Hack on WebAPIs from inside

### INSPECT OBJECTS
repl.inspect(activity1);
...

### BACK TO HOME (workaround B2G Desktop bug)
document.getElementById("homescreen").reload();
            

Hack on WebAPIs from inside

repl> repl.inspect(navigator);
object.battery
object.geolocation
object.getDeviceStorage
object.registerContentHandler
object.registerProtocolHandler
repl> 
            

Hack on WebAPIs from inside

repl> repl.search(/^moz/,navigator);
mozSettings
mozApps
mozPower
mozNotification
mozIsLocallyAvailable
mozSms
mozConnection
mozCameras
mozSetMessageHandler
mozHasPendingMessage
mozTime
            

Hack on WebAPIs from inside

repl> repl.inspect(navigator.battery);
...
repl> res = navigator.mozApps.mgmt.getAll();
repl> repl.inspect(res.result[0])
...
            

Gaia

Build

Let's build Gaia profile from sources
Gaia Hacking - Build Notes

$ git clone git://github.com/mozilla-b2g/gaia.git gaia
...
$ cd gaia
$ make DEBUG=1 # to build a profile runnable on Firefox Nightly
...
            

$ make         # to build a profile runnable on B2G Desktop
...
$ make USE_LOCAL_XULRUNNER_SDK=1 # to use a local installed xulrunner sdk
...
Profile Ready: please run [b2g|firefox] -profile /tmp/gaia/profile
            

Run on Firefox Nightly

and use Responsive Design View

/path/to/firefox -profile ./profile -no-remote \
   http://clock.gaiamobile.org:8080
            

OpenWebApp

MarketPlace Developer Hub

Developer's Getting Started Guides on Mozilla MarketPlace Reference Implementation.

AppTemplates and Volo

html5boilerplate, Prebuilt manifest.webapp, marketplace js api, require.js, volo for automating local development and deployment

Our Gaia Chrono
Example App Sources

A simple installable webapp, created by us as example, using volo and Gaia UI Building Blocks. Installable on Firefox Desktop Nightly, Firefox for Android Nightly and FirefoxOS.

Run Gaia Chrono

Installable on Firefox Desktop Nightly, Firefox for Android Nightly and FirefoxOS.

App Manifest 1/2

{
  "name": "Chrono",
  "description": "Gaia Chronometer Example App",
  "launch_path": "/index.html",
  "developer": {
    "name": "Luca Greco <luca.greco@alcacoop.it>",
    "url": "https://github.com/rpl/gaia-chrono"
  },
  "installs_allowed_from": ["*"],
  ...
            

App Manifest 2/2

  "locales": {
    "en-US": {
      "name": "Chrono",
      "description": "Gaia Chronometer Example App"
    },
    ...
  },
  "default_locale": "en-US",
  "icons": {
    "120": "/icons/chrono-120.png",
    "60": "/icons/chrono-60.png"
  },
  "orientation": "portrait-primary"
}
            

Cache Manifest and Works Offline 1/2

CACHE MANIFEST
# ...
CACHE:
index.html
icons/chrono-60.png
...
            

Cache Manifest and Works Offline 2/2

# catch-all for anything else
NETWORK:
*
http://*
https://*
            

Questions?

CREDITS

Mozilla Foundation

get involved in the OpenWeb future

Alca Società Cooperativa

we love to code