88
From HTML5 to hardware @janjongboom Simonyi Conference, Budapest, April 15 Tuesday, April 15, 14

From HTML5 to Hardware - Simonyi Conference Budapest April 15

Embed Size (px)

DESCRIPTION

Internals of Firefox OS. Process isolation, difference between Gonk/Gecko/Gaia. Tracing a call to the SMS service from the UI back to the RIL.

Citation preview

Page 1: From HTML5 to Hardware - Simonyi Conference Budapest April 15

From HTML5 to hardware

@janjongboomSimonyi Conference, Budapest, April 15

Tuesday, April 15, 14

Page 2: From HTML5 to Hardware - Simonyi Conference Budapest April 15

@janjongboomTuesday, April 15, 14

I’m Jan, live in Amsterdam. Work for Telenor on Mozilla products. Firefox OS contributor & keyboard peer. I write code for Gaia and Gecko.

Page 3: From HTML5 to Hardware - Simonyi Conference Budapest April 15

@janjongboomTuesday, April 15, 14

I’m Jan, live in Amsterdam. Work for Telenor on Mozilla products. Firefox OS contributor & keyboard peer. I write code for Gaia and Gecko.

Page 4: From HTML5 to Hardware - Simonyi Conference Budapest April 15

@janjongboomTuesday, April 15, 14

I’m Jan, live in Amsterdam. Work for Telenor on Mozilla products. Firefox OS contributor & keyboard peer. I write code for Gaia and Gecko.

Page 5: From HTML5 to Hardware - Simonyi Conference Budapest April 15

Tuesday, April 15, 14

Internet is normal for western world, but big part of the world doesnt have it.

Click Only 2.5 billion people out of 7.

Page 6: From HTML5 to Hardware - Simonyi Conference Budapest April 15

4,500,000,000

Tuesday, April 15, 14

Internet is normal for western world, but big part of the world doesnt have it.

Click Only 2.5 billion people out of 7.

Page 7: From HTML5 to Hardware - Simonyi Conference Budapest April 15

The web has everythingInformation does not like to be locked down

Tuesday, April 15, 14

We want people to access the web, not the closed silo’s that Android / iOS are, because thats not where the information is

Page 8: From HTML5 to Hardware - Simonyi Conference Budapest April 15

Affordable device to access the internet

Tuesday, April 15, 14

So goal: affordable device that people can use to get on the internet

Page 9: From HTML5 to Hardware - Simonyi Conference Budapest April 15

Tuesday, April 15, 14

Meet Firefox OS

Page 10: From HTML5 to Hardware - Simonyi Conference Budapest April 15

19,000 HUF

Tuesday, April 15, 14

First generation came out last year. Goes for about 19000 HUF here in Hungary (65 eur)

Page 11: From HTML5 to Hardware - Simonyi Conference Budapest April 15

Tuesday, April 15, 14

Next generation is going to be lower. System requirements are four times as low as Android.

Page 12: From HTML5 to Hardware - Simonyi Conference Budapest April 15

Great performance on cheap hardware?

Tuesday, April 15, 14

So if we want to get great performance out of cheap hardware, how do we do it?

Page 13: From HTML5 to Hardware - Simonyi Conference Budapest April 15

Tuesday, April 15, 14

Traditional model: Application -> VM (f.e. Dalvik on Android; .NET on Windows Phone, JavaScript in V8)

Page 14: From HTML5 to Hardware - Simonyi Conference Budapest April 15

Dalvik .NET V8

Tuesday, April 15, 14

Traditional model: Application -> VM (f.e. Dalvik on Android; .NET on Windows Phone, JavaScript in V8)

Page 15: From HTML5 to Hardware - Simonyi Conference Budapest April 15

Dalvik .NET V8

Apps Apps Apps

Tuesday, April 15, 14

Traditional model: Application -> VM (f.e. Dalvik on Android; .NET on Windows Phone, JavaScript in V8)

Page 16: From HTML5 to Hardware - Simonyi Conference Budapest April 15

Most mobile OS’es

App

Tuesday, April 15, 14

VM on top of OS. Kernel is hardware dependent. But always two layers between App and Kernel.

Page 17: From HTML5 to Hardware - Simonyi Conference Budapest April 15

Most mobile OS’es

App VM

Tuesday, April 15, 14

VM on top of OS. Kernel is hardware dependent. But always two layers between App and Kernel.

Page 18: From HTML5 to Hardware - Simonyi Conference Budapest April 15

Most mobile OS’es

App VM OS

Tuesday, April 15, 14

VM on top of OS. Kernel is hardware dependent. But always two layers between App and Kernel.

Page 19: From HTML5 to Hardware - Simonyi Conference Budapest April 15

Most mobile OS’es

App VM OS Kernel

Tuesday, April 15, 14

VM on top of OS. Kernel is hardware dependent. But always two layers between App and Kernel.

Page 20: From HTML5 to Hardware - Simonyi Conference Budapest April 15

Most mobile OS’es

App VM OS Kernel Hardware

Tuesday, April 15, 14

VM on top of OS. Kernel is hardware dependent. But always two layers between App and Kernel.

Page 21: From HTML5 to Hardware - Simonyi Conference Budapest April 15

Firefox OS

App

JS VM

Browser

Kernel Hardware

Tuesday, April 15, 14

Firefox OS only has one intermediate layer. The browser. Everything has to go through there. No exceptions like proprietary APIs (ok, well a few)

Page 22: From HTML5 to Hardware - Simonyi Conference Budapest April 15

One application runtimeBrowser runs directly on top of the kernel

Tuesday, April 15, 14

So browser directly on top of the kernel. No overhead.

Page 23: From HTML5 to Hardware - Simonyi Conference Budapest April 15

Everything runs in browserSMS, Payments, Marketplace

Tuesday, April 15, 14

System itself can’t take shortcuts. Everything is browser. Also system apps.

Page 24: From HTML5 to Hardware - Simonyi Conference Budapest April 15

Small Kernel

• Small Linux kernel

• Based on Android Open Source Project

• Contains Hardware Abstraction Layer

• Porting target

• Boot straight into Gecko

Tuesday, April 15, 14

All runs on top of a very small kernel. Based on Android OSP. Contains HAL and boots straight into Gecko. Gecko is browser engine.

Page 25: From HTML5 to Hardware - Simonyi Conference Budapest April 15

WindowsTuesday, April 15, 14

Makes it easier and light weight. Windows: 998 lines of calls to Win32 API on clipboard code.

Page 26: From HTML5 to Hardware - Simonyi Conference Budapest April 15

Firefox OSTuesday, April 15, 14

Firefox OS: 200 lines, just have a var that holds the clipboard. Other stuff is IPC.

Page 27: From HTML5 to Hardware - Simonyi Conference Budapest April 15

Application runtime

Tuesday, April 15, 14

Application runtime is done through iframes. Every application is iframe.

Page 28: From HTML5 to Hardware - Simonyi Conference Budapest April 15

Window Manager

• Boot into HTML app (system)• System is the window manager• Applications are loaded in iframe• iframes can be ran out of process

Tuesday, April 15, 14

The window manager is called the system app. It creates the iframes on demand. There is automatic process isolation in place. For example Here maps.

Page 29: From HTML5 to Hardware - Simonyi Conference Budapest April 15

remote=true

Tuesday, April 15, 14

It’s an iframe that points to a special URL that maps to a location on disk. But it has remote=true.

Page 30: From HTML5 to Hardware - Simonyi Conference Budapest April 15

Tuesday, April 15, 14

Automatic process isolation, and automatic user isolation. Security ftw.

Page 31: From HTML5 to Hardware - Simonyi Conference Budapest April 15

Tuesday, April 15, 14

Automatic process isolation, and automatic user isolation. Security ftw.

Page 32: From HTML5 to Hardware - Simonyi Conference Budapest April 15

Tracing down a SMS messageFrom HTML to the RIL

Tuesday, April 15, 14

All cool, but now let’s talk about some actual code. How does it look like if you make a call from HTML to the RIL.

Page 33: From HTML5 to Hardware - Simonyi Conference Budapest April 15

I NEED AN ADULT!Tuesday, April 15, 14

No clue what the RIL is? I’ll walk you through it.

Page 34: From HTML5 to Hardware - Simonyi Conference Budapest April 15

Tuesday, April 15, 14

We’ll walk over what happens if you click Send, up until the moment it reaches the cell tower.

Page 35: From HTML5 to Hardware - Simonyi Conference Budapest April 15

Gaia

Gecko

Gonk

User Interface

Browser engine

Kernel

Tuesday, April 15, 14

FFOS consists of three layers. Gaia, Gecko, Gonk

Page 36: From HTML5 to Hardware - Simonyi Conference Budapest April 15

Gaia• Frontend• github.com/mozilla-b2g/gaia• All system applications• HTML/CSS/JS• SMS app code under /apps/sms

(that easy!)

Tuesday, April 15, 14

Gaia, open source frontend. Not limited to only run on Gecko (but at the moment it is).

Page 37: From HTML5 to Hardware - Simonyi Conference Budapest April 15

index.html

Tuesday, April 15, 14

SMS app index.html has the button

Page 38: From HTML5 to Hardware - Simonyi Conference Budapest April 15

thread_ui.js

Tuesday, April 15, 14

Button has click handler that goes to MessageManager. There is also a callback involved.

Page 39: From HTML5 to Hardware - Simonyi Conference Budapest April 15

thread_ui.js

Tuesday, April 15, 14

Button has click handler that goes to MessageManager. There is also a callback involved.

Page 40: From HTML5 to Hardware - Simonyi Conference Budapest April 15

thread_ui.js

Tuesday, April 15, 14

Button has click handler that goes to MessageManager. There is also a callback involved.

Page 41: From HTML5 to Hardware - Simonyi Conference Budapest April 15

thread_ui.js

Tuesday, April 15, 14

Button has click handler that goes to MessageManager. There is also a callback involved.

Page 42: From HTML5 to Hardware - Simonyi Conference Budapest April 15

thread_ui.js

Tuesday, April 15, 14

Button has click handler that goes to MessageManager. There is also a callback involved.

Page 43: From HTML5 to Hardware - Simonyi Conference Budapest April 15

message_manager.js

Tuesday, April 15, 14

MessageManager makes a call to Gecko (under navigator object). Returns a DOMRequest. Like a promise.

Page 44: From HTML5 to Hardware - Simonyi Conference Budapest April 15

message_manager.jsGecko!

Tuesday, April 15, 14

MessageManager makes a call to Gecko (under navigator object). Returns a DOMRequest. Like a promise.

Page 45: From HTML5 to Hardware - Simonyi Conference Budapest April 15

message_manager.jsGecko!

Tuesday, April 15, 14

MessageManager makes a call to Gecko (under navigator object). Returns a DOMRequest. Like a promise.

Page 46: From HTML5 to Hardware - Simonyi Conference Budapest April 15

We need to go deeper!Tuesday, April 15, 14

So let’s go into Gecko.

Page 47: From HTML5 to Hardware - Simonyi Conference Budapest April 15

Gecko

• Browser engine• Same as Firefox for Desktop / Android / etc.• Runs directly on kernel (B2G)

Tuesday, April 15, 14

Browser engine

Page 48: From HTML5 to Hardware - Simonyi Conference Budapest April 15

nsIDOMMobileMessageManager.idl(yeah, that’s long)

Tuesday, April 15, 14

Gecko has IDL files. These are shared by browser vendors so eveyrone implements the same API. Can be implemented in C++ or JSM (variant of JS)

Page 49: From HTML5 to Hardware - Simonyi Conference Budapest April 15

nsIDOMMobileMessageManager.idl(yeah, that’s long)

addEventListener

Tuesday, April 15, 14

Gecko has IDL files. These are shared by browser vendors so eveyrone implements the same API. Can be implemented in C++ or JSM (variant of JS)

Page 50: From HTML5 to Hardware - Simonyi Conference Budapest April 15

nsIDOMMobileMessageManager.idl(yeah, that’s long)

Tuesday, April 15, 14

Gecko has IDL files. These are shared by browser vendors so eveyrone implements the same API. Can be implemented in C++ or JSM (variant of JS)

Page 51: From HTML5 to Hardware - Simonyi Conference Budapest April 15

MobileMessageManager.cppCould also be .jsm

Tuesday, April 15, 14

Inheritance chain. This is written in CPP.

Page 52: From HTML5 to Hardware - Simonyi Conference Budapest April 15

MobileMessageManager.cppCould also be .jsm

Tuesday, April 15, 14

Inheritance chain. This is written in CPP.

Page 53: From HTML5 to Hardware - Simonyi Conference Budapest April 15

MobileMessageManager.cpp

Tuesday, April 15, 14

JS values get boxed automatically. We create a new DOMRequest. See the gaia code.

Page 54: From HTML5 to Hardware - Simonyi Conference Budapest April 15

MobileMessageManager.cpp

Tuesday, April 15, 14

JS values get boxed automatically. We create a new DOMRequest. See the gaia code.

Page 55: From HTML5 to Hardware - Simonyi Conference Budapest April 15

MobileMessageManager.cpp

Tuesday, April 15, 14

JS values get boxed automatically. We create a new DOMRequest. See the gaia code.

Page 56: From HTML5 to Hardware - Simonyi Conference Budapest April 15

MobileMessageManager.cpp

Tuesday, April 15, 14

JS values get boxed automatically. We create a new DOMRequest. See the gaia code.

Page 57: From HTML5 to Hardware - Simonyi Conference Budapest April 15

MobileMessageManager.cpp

Tuesday, April 15, 14

Then in the same function we make a call to the SMS Service. This is platform specific. Android does different than FFOS.

Page 58: From HTML5 to Hardware - Simonyi Conference Budapest April 15

MobileMessageManager.cpp

Services are platform speci!c

Tuesday, April 15, 14

Then in the same function we make a call to the SMS Service. This is platform specific. Android does different than FFOS.

Page 59: From HTML5 to Hardware - Simonyi Conference Budapest April 15

moz.buildService injection at compile time

Tuesday, April 15, 14

This is the service injection in moz.build. Happens at compile time. In android we need Android SMS database access. FFOS we don’t.

Page 60: From HTML5 to Hardware - Simonyi Conference Budapest April 15

moz.buildService injection at compile time

Tuesday, April 15, 14

This is the service injection in moz.build. Happens at compile time. In android we need Android SMS database access. FFOS we don’t.

Page 61: From HTML5 to Hardware - Simonyi Conference Budapest April 15

Tuesday, April 15, 14

Time to go DEEPER

Page 62: From HTML5 to Hardware - Simonyi Conference Budapest April 15

Gonk

• Kernel• Hardware Abstraction• Think of the clipboard example• Android code calls back to Android• We can go straight to the RIL

Tuesday, April 15, 14

Gonk is the kernel. If you have platform dependent code it’s not in Gecko but in Gonk. Target for Gecko.

Page 63: From HTML5 to Hardware - Simonyi Conference Budapest April 15

SmsService.cpp

Tuesday, April 15, 14

Get the radio interface layer. It’s the API to the chipset in the phone. And send SMS.

Page 64: From HTML5 to Hardware - Simonyi Conference Budapest April 15

SmsService.cpp

Tuesday, April 15, 14

Get the radio interface layer. It’s the API to the chipset in the phone. And send SMS.

Page 65: From HTML5 to Hardware - Simonyi Conference Budapest April 15

SmsService.cpp

Tuesday, April 15, 14

Get the radio interface layer. It’s the API to the chipset in the phone. And send SMS.

Page 66: From HTML5 to Hardware - Simonyi Conference Budapest April 15

dom/system folder

Tuesday, April 15, 14

There are a bunch of platforms, they implement the services. In this case the RIL service is implemented by Gonk.

Page 67: From HTML5 to Hardware - Simonyi Conference Budapest April 15

nsIRadioInterfaceLayer.idl

Tuesday, April 15, 14

Also has IDL definitions.

Page 68: From HTML5 to Hardware - Simonyi Conference Budapest April 15

nsIRadioInterfaceLayer.idl

Tuesday, April 15, 14

Also has IDL definitions.

Page 69: From HTML5 to Hardware - Simonyi Conference Budapest April 15

nsIRadioInterfaceLayer.idl

Tuesday, April 15, 14

Also has IDL definitions.

Page 70: From HTML5 to Hardware - Simonyi Conference Budapest April 15

RadioInterfaceLayer.jsCould also be .cpp

Tuesday, April 15, 14

RIL code has been written in javascript in this case. It does stuff like normalizing phone numbers, because the chipset won’t do that for you

Page 71: From HTML5 to Hardware - Simonyi Conference Budapest April 15

RadioInterfaceLayer.jsCould also be .cpp

Tuesday, April 15, 14

RIL code has been written in javascript in this case. It does stuff like normalizing phone numbers, because the chipset won’t do that for you

Page 72: From HTML5 to Hardware - Simonyi Conference Budapest April 15

RadioInterfaceLayer.jsCould also be .cpp

Tuesday, April 15, 14

RIL code has been written in javascript in this case. It does stuff like normalizing phone numbers, because the chipset won’t do that for you

Page 73: From HTML5 to Hardware - Simonyi Conference Budapest April 15

RadioInterfaceLayer.js

Tuesday, April 15, 14

Now dispatch to a worker. JS single-threaded. Can’t wait for the response from hardware. Response codes are RIL data. Use these to feed back into the DOMRequest.

Page 74: From HTML5 to Hardware - Simonyi Conference Budapest April 15

RadioInterfaceLayer.js

Tuesday, April 15, 14

Now dispatch to a worker. JS single-threaded. Can’t wait for the response from hardware. Response codes are RIL data. Use these to feed back into the DOMRequest.

Page 75: From HTML5 to Hardware - Simonyi Conference Budapest April 15

RadioInterfaceLayer.js

Tuesday, April 15, 14

Now dispatch to a worker. JS single-threaded. Can’t wait for the response from hardware. Response codes are RIL data. Use these to feed back into the DOMRequest.

Page 76: From HTML5 to Hardware - Simonyi Conference Budapest April 15

Tuesday, April 15, 14

rilMessageToken is used to get the callbacks.

Page 77: From HTML5 to Hardware - Simonyi Conference Budapest April 15

Tuesday, April 15, 14

rilMessageToken is used to get the callbacks.

Page 78: From HTML5 to Hardware - Simonyi Conference Budapest April 15

Tuesday, April 15, 14

Something in between to shake up the audience.

Page 79: From HTML5 to Hardware - Simonyi Conference Budapest April 15

ril_worker.js

Tuesday, April 15, 14

Now ril_worker talks to the actual hardware. Pretty simple stuff. Some options.

Page 80: From HTML5 to Hardware - Simonyi Conference Budapest April 15

Mindig írni byte az én RIL!

Tuesday, April 15, 14

I always write bytes to the RIL. RIL doesn’t understand JS or CPP. Only understands bytes.

Page 81: From HTML5 to Hardware - Simonyi Conference Budapest April 15

ril_worker.js

Tuesday, April 15, 14

So now depending on protocol we talk, we dump bytes. SEND_SMS is 25, then some options. Send the parcel and now it’s on the actual RIL.

Page 82: From HTML5 to Hardware - Simonyi Conference Budapest April 15

ril_worker.js

Tuesday, April 15, 14

So now depending on protocol we talk, we dump bytes. SEND_SMS is 25, then some options. Send the parcel and now it’s on the actual RIL.

Page 83: From HTML5 to Hardware - Simonyi Conference Budapest April 15

ril_worker.js

Tuesday, April 15, 14

So now depending on protocol we talk, we dump bytes. SEND_SMS is 25, then some options. Send the parcel and now it’s on the actual RIL.

Page 84: From HTML5 to Hardware - Simonyi Conference Budapest April 15

ril_worker.js

Tuesday, April 15, 14

So now depending on protocol we talk, we dump bytes. SEND_SMS is 25, then some options. Send the parcel and now it’s on the actual RIL.

Page 85: From HTML5 to Hardware - Simonyi Conference Budapest April 15

Radio Interface Layer• Proprietary• Comes with chipset• Trade secret• Delivered to RIL? Done!• See how it looks like?

https://github.com/mozilla-b2g/b2g/

Tuesday, April 15, 14

And that’s where our job is done. RIL is proprietary and comes with chipset. RIL calls back with the token, we bubble it up back to Gecko and eventually Gaia, and show user the feedback. This happens in under a second. There is ref implementtion from Mozilla if you want to look at it.

Page 86: From HTML5 to Hardware - Simonyi Conference Budapest April 15

OMGAWESOMEPlay around? I have devices with me.

Tuesday, April 15, 14

OMG AWESOME SHIT. All open source. I have some devices, including the 25$ phone with me.

Page 87: From HTML5 to Hardware - Simonyi Conference Budapest April 15

Thank you!

slideshare.net/janjongboomTuesday, April 15, 14

Thanks!

Page 88: From HTML5 to Hardware - Simonyi Conference Budapest April 15

slideshare.net/janjongboom

Questions?

Tuesday, April 15, 14

Thanks!