Your SlideShare is downloading. ×
0
FIREFOX OS  WebAPIs & Apps
@robertnyman
Using HTML5, CSS andJavaScript together with anumber of APIs to build appsand customize the UI.
https://addons.mozilla.org/firefox/addon/firefox-os-                    simulator/
Open Web Apps
Web apps are apps built using standard Web technologies. They             work in any modern Web browser.The Open Web apps...
https://developer.mozilla.org/docs/Apps/             Getting_Started
Steps to Take
Develop Web App using1.   HTML5, CSS, & Javascript2.   Create an app manifest file3.   Publish/install the app
1.Develop Web App usingHTML5, CSS & JavaScript
Reuse any existing web site/app or develop from scratch with open                          web standards.   Utilize HTML5 ...
2.Create an app manifest file
Create a file with a .webapp extension
{  "version": "1.0",  "name": "MozillaBall",  "description": "Exciting Open Web development action!",  "icons": {     "16"...
MANIFEST CHECKER   http://appmanifest.org/
Serve with Content-type/MIME type:application/x-web-app-manifest+json
Apache - in mime.types:application/x-web-app-manifest+json webappApache - in .htaccess:AddType application/x-web-app-manif...
IIS:In IIS Manager, right-click the localcomputer, and click Properties.Click the MIME Types button.Click New.In the Exten...
curl -I http://mozillalabs.com/manifest.webapp
3.Publish/install the app
Firefox Marketplace
https://marketplace.firefox.com/
https://marketplace.firefox.com/developers/
Installing/hosting the app
var request = navigator.mozApps.install(   "http://mozillalabs.com/MozillaBall.webapp",   {     user_id: "some_user"   });...
var request = navigator.mozApps.installPackage(   "http://mozillalabs.com/manifest.webapp");request.onsuccess = function()...
Packaged vs. Hosted Apps
A packaged app is an Open Web App that has all of its resources(HTML, CSS, JavaScript, app manifest, and so on) contained ...
Can be privileged apps with more API access than hosted appsSpecial protocol internal to the zip file: app://<uuid>Manifest...
https://developer.mozilla.org/docs/Apps/          For_Web_developers
WebAPIs
The Mozilla WebAPI team is pushing theenvelope of the web to include --- and in placesexceed --- the capabilities of compe...
https://wiki.mozilla.org/WebAPI
Security Levels
Granted by default                        Granted by authorized storeSafe web APIs that don’t expose privacy   Privacy and...
Web Content                        Certified Web AppRegular web content                Device-critical applicationsInstalle...
https://wiki.mozilla.org/WebAPI#Planned_for_initial_release_of_B2G_.          28aka_Basecamp.29
"permissions": {    "contacts": {        "description": "Required for autocompletion in the share screen",        "access"...
AlarmAPI                                      FMRadioBrowserAPI                                    geolocationContacts    ...
Vibration API (W3C)             Web ActivitiesScreen Orientation              Push Notifications APIGeolocation API        ...
BATTERY STATUSAPI
var battery = navigator.battery;if (battery) {        var batteryLevel = Math.round(battery.level * 100) + "%",           ...
NOTIFICATION
var notification = navigator.mozNotification;notification.createNotification(    "See this",    "This is a notification", ...
SCREENORIENTATION API
// Portrait mode:screen.mozLockOrientation("portrait");/*     Possible values:         "landscape"         "portrait"     ...
WEB ACTIVITIES
{    "activities": {        "share": {            "filters": {                type: ["image/png", "image/gif"],           ...
var activity = new MozActivity({    name: "view",    data: {        type: "image/png",        url: ...    }});activity.ons...
var register = navigator.mozRegisterActivityHandler({    name: "view",    disposition: "inline",    filters: {        type...
navigator.mozSetMessageHandler("activity", function (a) {    var img = getImageObject();    img.src = a.source.url;    // ...
VIBRATION API
// Vibrate for one secondnavigator.vibrate(1000);// Vibration pattern [vibrationTime, pause,…]navigator.vibrate([200, 100,...
WEB PAYMENTS
var pay = navigator.mozPay(paymentToken);pay.onsuccess = function (event) {    // Weee! Money!};
NETWORKINFORMATION API
var connection = window.navigator.mozConnection,    online = connection.bandwidth > 0,    metered = connection.metered;
ALARM API
var alarmId1,    request = navigator.mozAlarms.add(        new Date("May 15, 2012 16:20:00"),        "honorTimezone",     ...
var request = navigator.mozAlarms.getAll();request.onsuccess = function (event) {    console.log(JSON.stringify(event.targ...
navigator.mozAlarms.remove(alarmId1);
navigator.mozSetMessageHandler(    "alarm",    function (message) {        // Note: message has to be set in the manifest ...
{    "messages": ["alarm"]}
DEVICEPROXIMITY
window.addEventListener("deviceproximity", function (event) {    // Current device proximity, in centimeters    console.lo...
AMBIENT LIGHTEVENTS
window.addEventListener("devicelight", function (event) {    // The level of the ambient light in lux    console.log(event...
window.addEventListener("lightlevel", function (event) {    // Possible values: "normal", "bright", "dim"    console.log(e...
window.addEventListener("devicelight", function (event) {    // The lux values for "dim" typically begin below 50,    // a...
Device Storage APIBrowser APITCP Socket APIContacts APIsystemXHR                 PRIVILEGED APIS
DEVICE STORAGEAPI
var deviceStorage = navigator.getDeviceStorage("videos");
// "external", "shared", or "default".deviceStorage.type;// Add a file - returns DOMRequest with file namedeviceStorage.ad...
var storage = navigator.getDeviceStorage("videos"),    cursor = storage.enumerate();cursor.onerror = function() {   consol...
CONTACTS API
var contact = new mozContact();contact.init({name: "Tom"});var request = navigator.mozContacts.save(contact);request.onsuc...
WebTelephony                    WebBluetoothWebSMS                          Permissions APIIdle API                       ...
WEBTELEPHONY
// Telephony objectvar tel = navigator.mozTelephony;// Check if the phone is muted (read/write property)console.log(tel.mu...
// Place a callvar cal = tel.dial(“123456789”);
// Events for that callcall.onstatechange = function (event) {    /*        Possible values for state:        "dialing", "...
// Receiving a calltel.onincoming = function (event) {    var incomingCall = event.call;     // Get the number of the inco...
WEBSMS
// SMS objectvar sms = navigator.mozSMS;// Send a messagesms.send("123456789", "Hello world!");
// Recieve a messagesms.onreceived = function (event) {    // Read message    console.log(event.message);};
SETTINGS API
var settings = navigator.mozSettings;settings.getLock().set({"background": "pretty.png"});
Future APIs
Resource lock API         Spellcheck APIUDP Datagram Socket API   LogAPIPeer to Peer API          Keyboard/IME APIWebNFC  ...
Web Apps from Mozilla
Dialer               Alarm ClockContacts             CameraSettings             NotesSMS                  First Run Experi...
Getting help
irc://irc.mozilla.org/  #openwebapps
https://lists.mozilla.org/listinfo/dev-webapps
Trying things out
Robert Nymanrobertnyman.comrobert@mozilla.comMozilla   @robertnyman
Web APIs & Apps - Mozilla
Web APIs & Apps - Mozilla
Web APIs & Apps - Mozilla
Web APIs & Apps - Mozilla
Web APIs & Apps - Mozilla
Web APIs & Apps - Mozilla
Web APIs & Apps - Mozilla
Web APIs & Apps - Mozilla
Web APIs & Apps - Mozilla
Web APIs & Apps - Mozilla
Web APIs & Apps - Mozilla
Web APIs & Apps - Mozilla
Web APIs & Apps - Mozilla
Web APIs & Apps - Mozilla
Web APIs & Apps - Mozilla
Web APIs & Apps - Mozilla
Web APIs & Apps - Mozilla
Web APIs & Apps - Mozilla
Web APIs & Apps - Mozilla
Web APIs & Apps - Mozilla
Upcoming SlideShare
Loading in...5
×

Web APIs & Apps - Mozilla

4,256

Published on

Published in: Technology
0 Comments
12 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
4,256
On Slideshare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
93
Comments
0
Likes
12
Embeds 0
No embeds

No notes for slide

Transcript of "Web APIs & Apps - Mozilla"

  1. 1. FIREFOX OS WebAPIs & Apps
  2. 2. @robertnyman
  3. 3. Using HTML5, CSS andJavaScript together with anumber of APIs to build appsand customize the UI.
  4. 4. https://addons.mozilla.org/firefox/addon/firefox-os- simulator/
  5. 5. Open Web Apps
  6. 6. Web apps are apps built using standard Web technologies. They work in any modern Web browser.The Open Web apps project proposes some small additions to existing sites to turn them into apps. These apps run on desktop browsers and mobile devices.
  7. 7. https://developer.mozilla.org/docs/Apps/ Getting_Started
  8. 8. Steps to Take
  9. 9. Develop Web App using1. HTML5, CSS, & Javascript2. Create an app manifest file3. Publish/install the app
  10. 10. 1.Develop Web App usingHTML5, CSS & JavaScript
  11. 11. Reuse any existing web site/app or develop from scratch with open web standards. Utilize HTML5 features such as localStorage, offline manifest, IndexedDB and access Web APIs for more options. Responsive web design for adapting to varying resolutions and screen orientation.
  12. 12. 2.Create an app manifest file
  13. 13. Create a file with a .webapp extension
  14. 14. { "version": "1.0", "name": "MozillaBall", "description": "Exciting Open Web development action!", "icons": { "16": "/img/icon-16.png", "48": "/img/icon-48.png", "128": "/img/icon-128.png" }, "developer": { "name": "Mozilla Labs", "url": "http://mozillalabs.com" }, "installs_allowed_from": ["*"], "appcache_path": "/cache.manifest", "locales": { "es": { "description": "¡Acción abierta emocionante del desarrollo del Web!", "developer": { "url": "http://es.mozillalabs.com/" } }, "it": { "description": "Azione aperta emozionante di sviluppo difotoricettore!", "developer": { "url": "http://it.mozillalabs.com/" } } }, "default_locale": "en"}
  15. 15. MANIFEST CHECKER http://appmanifest.org/
  16. 16. Serve with Content-type/MIME type:application/x-web-app-manifest+json
  17. 17. Apache - in mime.types:application/x-web-app-manifest+json webappApache - in .htaccess:AddType application/x-web-app-manifest+json webappNGinx - in mime.types:types { text/html html htm shtml; text/css css; text/xml xml; application/x-web-app-manifest+jsonwebapp;}
  18. 18. IIS:In IIS Manager, right-click the localcomputer, and click Properties.Click the MIME Types button.Click New.In the Extension box, type the file nameextension.In the MIME type box, type a descriptionthat exactly matches the file type definedon the computer.Click OK.
  19. 19. curl -I http://mozillalabs.com/manifest.webapp
  20. 20. 3.Publish/install the app
  21. 21. Firefox Marketplace
  22. 22. https://marketplace.firefox.com/
  23. 23. https://marketplace.firefox.com/developers/
  24. 24. Installing/hosting the app
  25. 25. var request = navigator.mozApps.install( "http://mozillalabs.com/MozillaBall.webapp", { user_id: "some_user" });request.onsuccess = function() { // Success! Notification, launch page etc}request.onerror = function() { // Failed. this.error.name has details}
  26. 26. var request = navigator.mozApps.installPackage( "http://mozillalabs.com/manifest.webapp");request.onsuccess = function() { // Success!}request.onerror = function() { // Failed.}
  27. 27. Packaged vs. Hosted Apps
  28. 28. A packaged app is an Open Web App that has all of its resources(HTML, CSS, JavaScript, app manifest, and so on) contained in a zip file, instead of having its resources on a Web server.A packaged app is simply a zip file with the app manifest in its root directory. The manifest must be named manifest.webapp.
  29. 29. Can be privileged apps with more API access than hosted appsSpecial protocol internal to the zip file: app://<uuid>Manifest file must be named manifest.webappResources are accessed from the zip file, which is stored on the device where theapp is installedInstalled with a different mozApps API function: installPackage()Enforce a specific Content Security Policy for all application contentCan embed remote content in iframes, but that content will not have access toprivileged APIs nor will it have the default CSP applied to itHave an update process for getting new versions of the app to users. Hostedapps do not need this process.
  30. 30. https://developer.mozilla.org/docs/Apps/ For_Web_developers
  31. 31. WebAPIs
  32. 32. The Mozilla WebAPI team is pushing theenvelope of the web to include --- and in placesexceed --- the capabilities of competing stacks.
  33. 33. https://wiki.mozilla.org/WebAPI
  34. 34. Security Levels
  35. 35. Granted by default Granted by authorized storeSafe web APIs that don’t expose privacy Privacy and security sensitive APIs suchsensitive data. WebGL, fullscreen, as Contacts APIaudio, etc. Verified by signatureGranted by user Highly privileged APIs such as radiolocation, camera, file system access access (dialer)Granted when installedNo quota for localStorage, IndexedDB,offline cache
  36. 36. Web Content Certified Web AppRegular web content Device-critical applicationsInstalled Web AppA regular web appPrivileged Web AppMore access, more responsibility
  37. 37. https://wiki.mozilla.org/WebAPI#Planned_for_initial_release_of_B2G_. 28aka_Basecamp.29
  38. 38. "permissions": { "contacts": { "description": "Required for autocompletion in the share screen", "access": "readcreate" }, "alarms": { "description": "Required to schedule notifications" }}
  39. 39. AlarmAPI FMRadioBrowserAPI geolocationContacts systemXHRdevice-storage:music/device-storage:videos/ TCP Socket APIdevice-storage:pictures/device-storage:sdcard: wake-lock-screen Add, read, or modify files stored at a central location on the device. access property required: one of readonly, readwrite, readcreate, or createonly. NEED PERMISSION
  40. 40. Vibration API (W3C) Web ActivitiesScreen Orientation Push Notifications APIGeolocation API WebFM APIMouse Lock API (W3C) WebPaymentOpen WebApps IndexedDB (W3C)Network Information API (W3C) Ambient light sensorBattery Status API (W3C) Proximity sensorAlarm API Notification REGULAR APIS
  41. 41. BATTERY STATUSAPI
  42. 42. var battery = navigator.battery;if (battery) { var batteryLevel = Math.round(battery.level * 100) + "%", charging = (battery.charging)? "" : "not ", chargingTime = parseInt(battery.chargingTime / 60, 10, dischargingTime = parseInt(battery.dischargingTime / 60, 10); // Set events battery.addEventListener("levelchange", setStatus, false); battery.addEventListener("chargingchange", setStatus, false); battery.addEventListener("chargingtimechange", setStatus, false); battery.addEventListener("dischargingtimechange", setStatus, false);}
  43. 43. NOTIFICATION
  44. 44. var notification = navigator.mozNotification;notification.createNotification( "See this", "This is a notification", iconURL);
  45. 45. SCREENORIENTATION API
  46. 46. // Portrait mode:screen.mozLockOrientation("portrait");/* Possible values: "landscape" "portrait" "landscape-primary" "landscape-secondary" "portrait-primary" "portrait-secondary"*/
  47. 47. WEB ACTIVITIES
  48. 48. { "activities": { "share": { "filters": { type: ["image/png", "image/gif"], } "href": "sharing.html", "disposition": "window" } }}
  49. 49. var activity = new MozActivity({ name: "view", data: { type: "image/png", url: ... }});activity.onsuccess = function () { console.log("Showing the image!");};activity.onerror = function () { console.log("Cant view the image!");};
  50. 50. var register = navigator.mozRegisterActivityHandler({ name: "view", disposition: "inline", filters: { type: "image/png" }});register.onerror = function () { console.log("Failed to register activity");}
  51. 51. navigator.mozSetMessageHandler("activity", function (a) { var img = getImageObject(); img.src = a.source.url; // Call a.postResult() or a.postError() if // the activity should return a value});
  52. 52. VIBRATION API
  53. 53. // Vibrate for one secondnavigator.vibrate(1000);// Vibration pattern [vibrationTime, pause,…]navigator.vibrate([200, 100, 200, 100]);// Vibrate for 5 secondsnavigator.vibrate(5000);// Turn off vibrationnavigator.vibrate(0);
  54. 54. WEB PAYMENTS
  55. 55. var pay = navigator.mozPay(paymentToken);pay.onsuccess = function (event) { // Weee! Money!};
  56. 56. NETWORKINFORMATION API
  57. 57. var connection = window.navigator.mozConnection, online = connection.bandwidth > 0, metered = connection.metered;
  58. 58. ALARM API
  59. 59. var alarmId1, request = navigator.mozAlarms.add( new Date("May 15, 2012 16:20:00"), "honorTimezone", { mydata: "my event" } );request.onsuccess = function (event) { alarmId1 = event.target.result;};request.onerror = function (event) { console.log(event.target.error.name);};
  60. 60. var request = navigator.mozAlarms.getAll();request.onsuccess = function (event) { console.log(JSON.stringify(event.target.result));};request.onerror = function (event) { console.log(event.target.error.name);};
  61. 61. navigator.mozAlarms.remove(alarmId1);
  62. 62. navigator.mozSetMessageHandler( "alarm", function (message) { // Note: message has to be set in the manifest file console.log("Alarm fired: " + JSON.stringify(message)); });
  63. 63. { "messages": ["alarm"]}
  64. 64. DEVICEPROXIMITY
  65. 65. window.addEventListener("deviceproximity", function (event) { // Current device proximity, in centimeters console.log(event.value); // The maximum sensing distance the sensor is // able to report, in centimeters console.log(event.max); // The minimum sensing distance the sensor is // able to report, in centimeters console.log(event.min);});
  66. 66. AMBIENT LIGHTEVENTS
  67. 67. window.addEventListener("devicelight", function (event) { // The level of the ambient light in lux console.log(event.value);});
  68. 68. window.addEventListener("lightlevel", function (event) { // Possible values: "normal", "bright", "dim" console.log(event.value);});
  69. 69. window.addEventListener("devicelight", function (event) { // The lux values for "dim" typically begin below 50, // and the values for "bright" begin above 10000 console.log(event.value);});
  70. 70. Device Storage APIBrowser APITCP Socket APIContacts APIsystemXHR PRIVILEGED APIS
  71. 71. DEVICE STORAGEAPI
  72. 72. var deviceStorage = navigator.getDeviceStorage("videos");
  73. 73. // "external", "shared", or "default".deviceStorage.type;// Add a file - returns DOMRequest with file namedeviceStorage.add(blob);// Same as .add, with provided namedeviceStorage.addNamed(blob, name);// Returns DOMRequest/non-editable File objectdeviceStorage.get(name);// Returns editable FileHandle objectdeviceStorage.getEditable(name);// Returns DOMRequest with success or failuredeviceStorage.delete(name);// Enumerates filesdeviceStorage.enumerate([directory]);// Enumerates files as FileHandlesdeviceStorage.enumerateEditable([directory]);
  74. 74. var storage = navigator.getDeviceStorage("videos"), cursor = storage.enumerate();cursor.onerror = function() { console.error("Error in DeviceStorage.enumerate()", cursor.error.name);};cursor.onsuccess = function() { if (!cursor.result) return; var file = cursor.result; // If this isnt a video, skip it if (file.type.substring(0, 6) !== "video/") { cursor.continue(); return; } // If it isnt playable, skip it var testplayer = document.createElement("video"); if (!testplayer.canPlayType(file.type)) { cursor.continue(); return; }}
  75. 75. CONTACTS API
  76. 76. var contact = new mozContact();contact.init({name: "Tom"});var request = navigator.mozContacts.save(contact);request.onsuccess = function() { console.log("Success");};request.onerror = function() { console.log("Error")};
  77. 77. WebTelephony WebBluetoothWebSMS Permissions APIIdle API Network Stats APISettings API Camera APIPower Management API Time/Clock APIMobile Connection API Attention screenWiFi Information API Voicemail CERTIFIED APIS
  78. 78. WEBTELEPHONY
  79. 79. // Telephony objectvar tel = navigator.mozTelephony;// Check if the phone is muted (read/write property)console.log(tel.muted);// Check if the speaker is enabled (read/write property)console.log(tel.speakerEnabled);
  80. 80. // Place a callvar cal = tel.dial(“123456789”);
  81. 81. // Events for that callcall.onstatechange = function (event) { /* Possible values for state: "dialing", "ringing", "busy", "connecting", "connected", "disconnecting", "disconnected", "incoming" */ console.log(event.state);};// Above options as direct eventscall.onconnected = function () { // Call was connected};call.ondisconnected = function () { // Call was disconnected};
  82. 82. // Receiving a calltel.onincoming = function (event) { var incomingCall = event.call; // Get the number of the incoming call console.log(incomingCall.number); // Answer the call incomingCall.answer();};// Disconnect a callcall.hangUp();// Iterating over calls, and taking action depending on theirchanged statustel.oncallschanged = function (event) { tel.calls.forEach(function (call) { // Log the state of each call console.log(call.state); });};
  83. 83. WEBSMS
  84. 84. // SMS objectvar sms = navigator.mozSMS;// Send a messagesms.send("123456789", "Hello world!");
  85. 85. // Recieve a messagesms.onreceived = function (event) { // Read message console.log(event.message);};
  86. 86. SETTINGS API
  87. 87. var settings = navigator.mozSettings;settings.getLock().set({"background": "pretty.png"});
  88. 88. Future APIs
  89. 89. Resource lock API Spellcheck APIUDP Datagram Socket API LogAPIPeer to Peer API Keyboard/IME APIWebNFC WebRTCWebUSB FileHandle APIHTTP-cache API Sync APICalendar API
  90. 90. Web Apps from Mozilla
  91. 91. Dialer Alarm ClockContacts CameraSettings NotesSMS First Run ExperienceWeb browser NotificationsGallery Home ScreenVideo Player Mozilla MarketplaceMusic Player System UpdaterE-mail (POP, IMAP) Localization SupportCalendar
  92. 92. Getting help
  93. 93. irc://irc.mozilla.org/ #openwebapps
  94. 94. https://lists.mozilla.org/listinfo/dev-webapps
  95. 95. Trying things out
  96. 96. Robert Nymanrobertnyman.comrobert@mozilla.comMozilla @robertnyman
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×