SlideShare a Scribd company logo
1 of 52
Download to read offline
IMPLEMENTING NEW WEBAPIS
   Gregor Wagner (gwagner@mozilla.com)
    Julian Viereck (jviereck@mozilla.com)
DISCALIMER

• No    API designing/standadization here

• Talk   about making the implementation happen!

• 55”   not enough to get you going

• Reach    out to us and do “hands-on” hacking
OUTLINE
• General   Introduction

• How    To Implement New API

  • JS

  • C++

• Make    your work land

• Q&A
GENERAL INTRODUCTION
GENERAL INTRODUCTION
• Build   on two previous presentations

  • JS: David Dahl’s “From Web Developer to Firefox
      Hacker” [1]

  • C++:    Bobby Holley’s “Hacking Gecko” [2]

  •   [1]: http://people.mozilla.com/~ddahl/pages/HackingFirefox/
      template.html

  •   [2]: http://people.mozilla.com/~bholley/hacking-gecko-
      fosdem2012/hacking-gecko.html
GENERAL INTRODUCTION
• Need   to build Firefox

• Run   build:

  • Linux/Windows:      objdir/dist/bin/firefox

  • OSX:
       objdir/dist/AppName.app/Contents/
   MacOS/firefox

  • options:     -ProfileManager, -no-remote
GENERAL INTRODUCTION
GENERAL INTRODUCTION
• Don’t   get lost in the details

• Ask   for an implementation outline

• There    is documentation, overview

• Über-Weapon:      Ask for help

  • IRC:   https://wiki.mozilla.org/IRC, #developers

  • Mailing list:
   https://lists.mozilla.org/listinfo, dev-webapi
FRIENDLY PEOPLE TO
    PING ON IRC
khuey (Kyle Huey)
ehsan (Ehsan Akhgari)
bholley (Bobby Holley)
jdm (Josh Matthews)
dholbert (Daniel Holbert)
Ms2ger (???)
GENERAL INTRODUCTION
• whenever    you do communication

 • try   to be precise

 • give   reasoning to your arguments

 • get
     only short answer - don’t take it wrong,
  people are really busy

 • dump     whatever you have (crashback/patch...)
GENERAL INTRODUCTION

• don’t   be afraid to ping people

• might    get hint to ping someone else

• tell   people you're new to hacking JS/Gecko

• look/ask    for bugs that do similar things you try
 to solve
HTTPS://MXR.MOZILLA.ORG/
FIREFOX OS WEBAPI

 Wifi     Browser          Battery
                  Telephony
 Settings                     Idle
                Power
Contacts                 Bluetooth
        Vibrator   Webapps
           many more to come....

    https://wiki.mozilla.org/WebAPI/
INTERFACE + IMPLEMENTATION
IT ALL STARTS WITH AN INTERFACE
         XPIDL VS. WEBIDL
XPIDL VS. WEBIDL

[scriptable, builtinclass,
                                                            interface EventTarget {
uuid(5a8294df-ffe4-48e5-803f-f57bebc29289)]
                                                             void addEventListener(DOMString type,
interface nsIDOMScreen : nsIDOMEventTarget
                                                                         EventListener? listener,
{                                                                        optional boolean capture = false,
  readonly attribute long top;                                           optional boolean? wantsUntrusted = null);
  readonly attribute DOMString mozOrientation;               void removeEventListener(DOMString type,
  [implicit_jscontext]                                                    EventListener? listener,
  attribute jsval      onmozorientationchange;                            optional boolean capture = false);
                                                             boolean dispatchEvent(Event event);
  boolean mozLockOrientation(in DOMString orientation);     };
  void mozUnlockOrientation();
};




          https://developer.mozilla.org/en-US/docs/XPIDL   https://developer.mozilla.org/en-US/docs/Mozilla/WebIDL_bindings
MAPPING JS VS C++

• Read    other APIs

• Interfaces   are defined in dom/interfaces

• Implementations      mostly in dom/*, content/*

• c++   implementations use common inheritance

• JS   implementations use manifest file
TIME TO FILE A BUG
Bugzilla: DOM:Device Interfaces
HOW TO IMPLEMENT JS
WHY IN JS?
• Prototyping

• Lower   entry point

• WebDevs    know JS

 • Also
      better for
  understanding!
INTERFACE EXAMPLE



For example dom/interfaces/helloworld/nsIHelloWorld.idl

[scriptable, uuid(da0f7040-388b-11e1-b86c-0800200c9444)]
interface nsIDOMHelloWorld : nsISupports
{
  void sayHello(in DOMString aName);
};




https://bugzilla.mozilla.org/show_bug.cgi?id=674720
HELLOWORLD.MANIFEST

For example dom/helloworld/HelloWorld.manifest


component {f5181640-89e8-11e1-b0c4-0800200c9444} HelloWorld.js
contract @mozilla.org/helloWorld;1 {f5181640-89e8-11e1-b0c4-0800200c9444}
category JavaScript-navigator-property mozHelloWorld @mozilla.org/helloWorld;1
HELLOWORLD.JS
For example dom/helloworld/HelloWorld.js
const Cc = Components.classes;
const Ci = Components.interfaces;
const Cu = Components.utils;

Cu.import("resource://gre/modules/XPCOMUtils.jsm");

function HelloWorld() {}

HelloWorld.prototype = {

  init: function init(aWindow) {},



                                                      Text
  sayHello: function sayHello(aName) {
    dump("Hello " + aName + "n");
  },

  classID : Components.ID("{d88af7e0-a45f-11e1-b3dd-0800200c9444}"),
  QueryInterface : XPCOMUtils.generateQI([Components.interfaces.nsIDOMHelloWorld]),

  classInfo : XPCOMUtils.generateCI({classID: Components.ID("{d88af7e0-a45f-11e1-b3dd-0800200c9444}"),
                                     contractID: "@mozilla.org/helloWorld;1",
                                     classDescription: "HelloWorld",
                                     interfaces: [Components.interfaces.nsIDOMHelloWorld,
Ci.nsIDOMGlobalPropertyInitializer],
                                     flags: Ci.nsIClassInfo.DOM_OBJECT})
}

const NSGetFactory = XPCOMUtils.generateNSGetFactory([HelloWorld]);
BOILERPLATE

• Makefiles

• Manifest

• Packaging

• Module   Loading

• Access   Permission
EXPOSEDPROPS


let foo = new Foo();

Foo.prototype = {
  __exposedProps__: {
                        name: 'rw'
    }
}
FIREFOX OS PROCESS MODEL
• Parent
       - Child            • Nested process
 Processes                 structure not possible
                           (yet)
• Only   one parent
                          • Parent   is trusted
• Browser is in parent,
 content pages are        • Child
                               can be
 children                  compromised

                          • Securitycritical code
                           has to run in parent
SYSTEM MESSAGE MANAGER
• Use   for child-parent
     communication

• Child:
childProcessMessageManager.sendAsyncMessage("message-name", {"foo": 2});
var response = sendSyncMessage("message-name", {"foo": 1});




  Parent:
•receiveMessage: function(aMessage) {
     switch (aMessage.name) {
       [...]
       parentProcessMessageManager.sendAsynMessage(“return-message-name”, [...])
     }
 }
DOMREQUESTS

var pending = navigator.mozApps.install(manifestUrl);
pending.onsuccess = function () {
  // Save the App object that is returned
  var appRecord = this.result;
  alert('Installation successful!')
};
pending.onerror = function () {
  // Display the name of the error
  alert('Install failed, error: ' + this.error.name);
};
PERMISSIONS
HOW TO IMPLEMENT C++
MAPPING JS/C++
• IDL   files → JS & C++

• JS: ctx.lineWidth
 C++: ctx::GetLineWidth(float *width)

• Need   to implement C++ class for interface

• NS_IMETHODIMP:      returns NS_<status>

• Expose
      object:
 nsDOMClassInfo.cpp/nsDOMClassInfoClasses.h
INTERFACES
                     Attribute

           canvas.mozPrintCallback =

Callback    function(obj) {              PrintState
              var ctx = obj.context;
              ctx.fillRect(0, 0, 100, 100);
              obj.done();
            };
INTERFACES                                                               Taken from
                                                                        bug #745025

       te    [scriptable, uuid(a7062fca-41c6-4520-b777-3bb30fd77273)]
             interface nsIDOMHTMLCanvasElement : nsIDOMHTMLElement
     bu

             {
  tri


               [...]
At




               // A Mozilla-only callback that is called during the printing process.
               attribute nsIPrintCallback mozPrintCallback;
             };
       k
     ac




             [scriptable, function, uuid(8d5fb8a0-7782-11e1-b0c4-0800200c9a66)]
  llb




             interface nsIPrintCallback : nsISupports
Ca




             {
               void render(in nsIDOMMozCanvasPrintState ctx);
             };
        te
      ta




             [scriptable, builtinclass, uuid(8d5fb8a0-7782-11e1-b0c4-0800200c9a67)]
    tS




             interface nsIDOMMozCanvasPrintState : nsISupports
  in




             {
Pr




               // A canvas rendering context.
               readonly attribute nsISupports context;

               // To be called when rendering to the context is done.
               void done();
             };
class nsHTMLCanvasPrintState : public nsIDOMMozCanvasPrintState
{
public:
  nsHTMLCanvasPrintState(nsHTMLCanvasElement* aCanvas,
                         nsICanvasRenderingContextInternal* aContext,
                         nsITimerCallback* aCallback)
    : mIsDone(false), mPendingNotify(false), mCanvas(aCanvas),
      mContext(aContext), mCallback(aCallback)
  {
  }

    NS_IMETHOD GetContext(nsISupports** aContext)
    {
      NS_ADDREF(*aContext = mContext);
      return NS_OK;
    }

    NS_IMETHOD Done()
    {
      [...]                                                    Taken from
      return NS_OK;
    }
                                                              bug #745025


    [...]
}
MEMORY MANAGEMENT
• C++   doesn’t have a garbage collector :(

• In   Gecko: Reference counting & cycle collector

• Reference    counting:

  • nsCOMPtr     (for interfaces), nsREFPtr

   • use   getter_AddRefs

   • NS_IF_ADDREF     & NS_IF_RELEASE
MEMORY MANAGEMENT


• Reference   counting doesn’t work always

• Make   use of Gecko’s cycle collector

• Better   cycle then maybe leak
DEBUGGING

• Make     sure to have a debug build

• Enable    logging (example)

• Watch    for assertion in logs

• Insert   printfs

• There    is documentation how to use debugger
OVERVIEW OF SOME TREES


• Frame   Tree:     Frames on page

• Content   Tree:   Content going with frames

• View   Tree:      Connecting views
MAKE YOUR WORK LAND
TESTS TESTS TESTS
DIFFERENT TYPE OF TESTS
• Reftests

• Crashtests

• XPCShell     Tests

• Mochitests

• JS   tests

• Compiled     code tests :-(

• Marionette     tests
MOCHITEST

•/path/to/objdir $ TEST_PATH=dom/
 contacts/tests make mochitest-plain

•/path/to/objdir $ TEST_PATH=dom/
                 Text
 contacts/tests/test_contacts.html
 make mochitest-plain
TIME FOR REVIEW
• Makesure the patch is   • Whenuploading a new
formatted according to    version:
the guidelines:
                           • address
                                  *all* review
 •8   lines of context      comments

 • correctcommitter        • obsolete   the old
  info (name + email)       patch

 • correct
        checking           • run   tests again
  message
REVIEW
• Make     sure your patch is clean

• Patch    should be green on try-push

• WIP:    State what’s working/what not/what’s next

• Review    might take some time (~1 week?)

• If   longer, ping person, switch review person

• Except    r-, don’t worry!
Q&A
THINGS TO HACK ON


• Implement   vw/vh/vmin/vmax

• "dirname"   DOM attribute on form controls

• Implement   FileSaver

More Related Content

What's hot

Node.js - async for the rest of us.
Node.js - async for the rest of us.Node.js - async for the rest of us.
Node.js - async for the rest of us.Mike Brevoort
 
Node.js Explained
Node.js ExplainedNode.js Explained
Node.js ExplainedJeff Kunkle
 
Node js实践
Node js实践Node js实践
Node js实践jay li
 
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...Domenic Denicola
 
Building a real life application in node js
Building a real life application in node jsBuilding a real life application in node js
Building a real life application in node jsfakedarren
 
Writing robust Node.js applications
Writing robust Node.js applicationsWriting robust Node.js applications
Writing robust Node.js applicationsTom Croucher
 
Intro to Node.js (v1)
Intro to Node.js (v1)Intro to Node.js (v1)
Intro to Node.js (v1)Chris Cowan
 
node.js - Eventful JavaScript on the Server
node.js - Eventful JavaScript on the Servernode.js - Eventful JavaScript on the Server
node.js - Eventful JavaScript on the ServerDavid Ruiz
 
node.js: Javascript's in your backend
node.js: Javascript's in your backendnode.js: Javascript's in your backend
node.js: Javascript's in your backendDavid Padbury
 
연구자 및 교육자를 위한 계산 및 분석 플랫폼 설계 - PyCon KR 2015
연구자 및 교육자를 위한 계산 및 분석 플랫폼 설계 - PyCon KR 2015연구자 및 교육자를 위한 계산 및 분석 플랫폼 설계 - PyCon KR 2015
연구자 및 교육자를 위한 계산 및 분석 플랫폼 설계 - PyCon KR 2015Jeongkyu Shin
 
Supercharging reflective libraries with InvokeDynamic
Supercharging reflective libraries with InvokeDynamicSupercharging reflective libraries with InvokeDynamic
Supercharging reflective libraries with InvokeDynamicIan Robertson
 
Introduction to Nodejs
Introduction to NodejsIntroduction to Nodejs
Introduction to NodejsGabriele Lana
 
How to Write Node.js Module
How to Write Node.js ModuleHow to Write Node.js Module
How to Write Node.js ModuleFred Chien
 
Non-blocking I/O, Event loops and node.js
Non-blocking I/O, Event loops and node.jsNon-blocking I/O, Event loops and node.js
Non-blocking I/O, Event loops and node.jsMarcus Frödin
 
soft-shake.ch - Hands on Node.js
soft-shake.ch - Hands on Node.jssoft-shake.ch - Hands on Node.js
soft-shake.ch - Hands on Node.jssoft-shake.ch
 

What's hot (20)

Node.js - async for the rest of us.
Node.js - async for the rest of us.Node.js - async for the rest of us.
Node.js - async for the rest of us.
 
Node.js Explained
Node.js ExplainedNode.js Explained
Node.js Explained
 
Node js实践
Node js实践Node js实践
Node js实践
 
Introduction Node.js
Introduction Node.jsIntroduction Node.js
Introduction Node.js
 
Nodejs in Production
Nodejs in ProductionNodejs in Production
Nodejs in Production
 
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
 
Building a real life application in node js
Building a real life application in node jsBuilding a real life application in node js
Building a real life application in node js
 
Writing robust Node.js applications
Writing robust Node.js applicationsWriting robust Node.js applications
Writing robust Node.js applications
 
Intro to Node.js (v1)
Intro to Node.js (v1)Intro to Node.js (v1)
Intro to Node.js (v1)
 
node.js - Eventful JavaScript on the Server
node.js - Eventful JavaScript on the Servernode.js - Eventful JavaScript on the Server
node.js - Eventful JavaScript on the Server
 
Node.js
Node.jsNode.js
Node.js
 
NodeJS
NodeJSNodeJS
NodeJS
 
node.js: Javascript's in your backend
node.js: Javascript's in your backendnode.js: Javascript's in your backend
node.js: Javascript's in your backend
 
연구자 및 교육자를 위한 계산 및 분석 플랫폼 설계 - PyCon KR 2015
연구자 및 교육자를 위한 계산 및 분석 플랫폼 설계 - PyCon KR 2015연구자 및 교육자를 위한 계산 및 분석 플랫폼 설계 - PyCon KR 2015
연구자 및 교육자를 위한 계산 및 분석 플랫폼 설계 - PyCon KR 2015
 
Supercharging reflective libraries with InvokeDynamic
Supercharging reflective libraries with InvokeDynamicSupercharging reflective libraries with InvokeDynamic
Supercharging reflective libraries with InvokeDynamic
 
NodeJS
NodeJSNodeJS
NodeJS
 
Introduction to Nodejs
Introduction to NodejsIntroduction to Nodejs
Introduction to Nodejs
 
How to Write Node.js Module
How to Write Node.js ModuleHow to Write Node.js Module
How to Write Node.js Module
 
Non-blocking I/O, Event loops and node.js
Non-blocking I/O, Event loops and node.jsNon-blocking I/O, Event loops and node.js
Non-blocking I/O, Event loops and node.js
 
soft-shake.ch - Hands on Node.js
soft-shake.ch - Hands on Node.jssoft-shake.ch - Hands on Node.js
soft-shake.ch - Hands on Node.js
 

Similar to Implementing New Web

HTML5 for the Silverlight Guy
HTML5 for the Silverlight GuyHTML5 for the Silverlight Guy
HTML5 for the Silverlight GuyDavid Padbury
 
Porting legacy apps to Griffon
Porting legacy apps to GriffonPorting legacy apps to Griffon
Porting legacy apps to GriffonJames Williams
 
Intro To Node.js
Intro To Node.jsIntro To Node.js
Intro To Node.jsChris Cowan
 
Playing With Fire - An Introduction to Node.js
Playing With Fire - An Introduction to Node.jsPlaying With Fire - An Introduction to Node.js
Playing With Fire - An Introduction to Node.jsMike Hagedorn
 
JVM Mechanics: When Does the JVM JIT & Deoptimize?
JVM Mechanics: When Does the JVM JIT & Deoptimize?JVM Mechanics: When Does the JVM JIT & Deoptimize?
JVM Mechanics: When Does the JVM JIT & Deoptimize?Doug Hawkins
 
Advanced iOS Build Mechanics, Sebastien Pouliot
Advanced iOS Build Mechanics, Sebastien PouliotAdvanced iOS Build Mechanics, Sebastien Pouliot
Advanced iOS Build Mechanics, Sebastien PouliotXamarin
 
Meetup Performance
Meetup PerformanceMeetup Performance
Meetup PerformanceGreg Whalin
 
Silicon Valley JUG: JVM Mechanics
Silicon Valley JUG: JVM MechanicsSilicon Valley JUG: JVM Mechanics
Silicon Valley JUG: JVM MechanicsAzul Systems, Inc.
 
Original slides from Ryan Dahl's NodeJs intro talk
Original slides from Ryan Dahl's NodeJs intro talkOriginal slides from Ryan Dahl's NodeJs intro talk
Original slides from Ryan Dahl's NodeJs intro talkAarti Parikh
 
Import golang; struct microservice
Import golang; struct microserviceImport golang; struct microservice
Import golang; struct microserviceGiulio De Donato
 
Why Every Tester Should Learn Ruby
Why Every Tester Should Learn RubyWhy Every Tester Should Learn Ruby
Why Every Tester Should Learn RubyRaimonds Simanovskis
 
Practical JavaScript Programming - Session 8/8
Practical JavaScript Programming - Session 8/8Practical JavaScript Programming - Session 8/8
Practical JavaScript Programming - Session 8/8Wilson Su
 
LISA Qooxdoo Tutorial Handouts
LISA Qooxdoo Tutorial HandoutsLISA Qooxdoo Tutorial Handouts
LISA Qooxdoo Tutorial HandoutsTobias Oetiker
 
Mobile webapplication development
Mobile webapplication developmentMobile webapplication development
Mobile webapplication developmentGanesh Gembali
 
Introduction to REST API with Node.js
Introduction to REST API with Node.jsIntroduction to REST API with Node.js
Introduction to REST API with Node.jsYoann Gotthilf
 
MFF UK - Advanced iOS Topics
MFF UK - Advanced iOS TopicsMFF UK - Advanced iOS Topics
MFF UK - Advanced iOS TopicsPetr Dvorak
 

Similar to Implementing New Web (20)

HTML5 for the Silverlight Guy
HTML5 for the Silverlight GuyHTML5 for the Silverlight Guy
HTML5 for the Silverlight Guy
 
Porting legacy apps to Griffon
Porting legacy apps to GriffonPorting legacy apps to Griffon
Porting legacy apps to Griffon
 
Intro To Node.js
Intro To Node.jsIntro To Node.js
Intro To Node.js
 
Playing With Fire - An Introduction to Node.js
Playing With Fire - An Introduction to Node.jsPlaying With Fire - An Introduction to Node.js
Playing With Fire - An Introduction to Node.js
 
Node azure
Node azureNode azure
Node azure
 
JVM Mechanics: When Does the JVM JIT & Deoptimize?
JVM Mechanics: When Does the JVM JIT & Deoptimize?JVM Mechanics: When Does the JVM JIT & Deoptimize?
JVM Mechanics: When Does the JVM JIT & Deoptimize?
 
Advanced iOS Build Mechanics, Sebastien Pouliot
Advanced iOS Build Mechanics, Sebastien PouliotAdvanced iOS Build Mechanics, Sebastien Pouliot
Advanced iOS Build Mechanics, Sebastien Pouliot
 
Meetup Performance
Meetup PerformanceMeetup Performance
Meetup Performance
 
Meetup Performance
Meetup PerformanceMeetup Performance
Meetup Performance
 
Silicon Valley JUG: JVM Mechanics
Silicon Valley JUG: JVM MechanicsSilicon Valley JUG: JVM Mechanics
Silicon Valley JUG: JVM Mechanics
 
Original slides from Ryan Dahl's NodeJs intro talk
Original slides from Ryan Dahl's NodeJs intro talkOriginal slides from Ryan Dahl's NodeJs intro talk
Original slides from Ryan Dahl's NodeJs intro talk
 
Import golang; struct microservice
Import golang; struct microserviceImport golang; struct microservice
Import golang; struct microservice
 
Why Every Tester Should Learn Ruby
Why Every Tester Should Learn RubyWhy Every Tester Should Learn Ruby
Why Every Tester Should Learn Ruby
 
NodeJS for Beginner
NodeJS for BeginnerNodeJS for Beginner
NodeJS for Beginner
 
Practical JavaScript Programming - Session 8/8
Practical JavaScript Programming - Session 8/8Practical JavaScript Programming - Session 8/8
Practical JavaScript Programming - Session 8/8
 
LISA Qooxdoo Tutorial Handouts
LISA Qooxdoo Tutorial HandoutsLISA Qooxdoo Tutorial Handouts
LISA Qooxdoo Tutorial Handouts
 
Mobile webapplication development
Mobile webapplication developmentMobile webapplication development
Mobile webapplication development
 
Introduction to REST API with Node.js
Introduction to REST API with Node.jsIntroduction to REST API with Node.js
Introduction to REST API with Node.js
 
MFF UK - Advanced iOS Topics
MFF UK - Advanced iOS TopicsMFF UK - Advanced iOS Topics
MFF UK - Advanced iOS Topics
 
Brad Wood - CommandBox CLI
Brad Wood - CommandBox CLI Brad Wood - CommandBox CLI
Brad Wood - CommandBox CLI
 

More from Julian Viereck

Learning To Hop Using Guided Policy Search / ETH Zurich Computer Science Mast...
Learning To Hop Using Guided Policy Search / ETH Zurich Computer Science Mast...Learning To Hop Using Guided Policy Search / ETH Zurich Computer Science Mast...
Learning To Hop Using Guided Policy Search / ETH Zurich Computer Science Mast...Julian Viereck
 
Implementing new WebAPIs
Implementing new WebAPIsImplementing new WebAPIs
Implementing new WebAPIsJulian Viereck
 
PDF.JS at SwissJeese 2012
PDF.JS at SwissJeese 2012PDF.JS at SwissJeese 2012
PDF.JS at SwissJeese 2012Julian Viereck
 

More from Julian Viereck (6)

Learning To Hop Using Guided Policy Search / ETH Zurich Computer Science Mast...
Learning To Hop Using Guided Policy Search / ETH Zurich Computer Science Mast...Learning To Hop Using Guided Policy Search / ETH Zurich Computer Science Mast...
Learning To Hop Using Guided Policy Search / ETH Zurich Computer Science Mast...
 
Implementing new WebAPIs
Implementing new WebAPIsImplementing new WebAPIs
Implementing new WebAPIs
 
PDF.JS at SwissJeese 2012
PDF.JS at SwissJeese 2012PDF.JS at SwissJeese 2012
PDF.JS at SwissJeese 2012
 
2011 11-mozcamp
2011 11-mozcamp2011 11-mozcamp
2011 11-mozcamp
 
2011 09-pdfjs
2011 09-pdfjs2011 09-pdfjs
2011 09-pdfjs
 
2011 05-jszurich
2011 05-jszurich2011 05-jszurich
2011 05-jszurich
 

Recently uploaded

DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 

Recently uploaded (20)

DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 

Implementing New Web

  • 1. IMPLEMENTING NEW WEBAPIS Gregor Wagner (gwagner@mozilla.com) Julian Viereck (jviereck@mozilla.com)
  • 2. DISCALIMER • No API designing/standadization here • Talk about making the implementation happen! • 55” not enough to get you going • Reach out to us and do “hands-on” hacking
  • 3. OUTLINE • General Introduction • How To Implement New API • JS • C++ • Make your work land • Q&A
  • 5. GENERAL INTRODUCTION • Build on two previous presentations • JS: David Dahl’s “From Web Developer to Firefox Hacker” [1] • C++: Bobby Holley’s “Hacking Gecko” [2] • [1]: http://people.mozilla.com/~ddahl/pages/HackingFirefox/ template.html • [2]: http://people.mozilla.com/~bholley/hacking-gecko- fosdem2012/hacking-gecko.html
  • 6. GENERAL INTRODUCTION • Need to build Firefox • Run build: • Linux/Windows: objdir/dist/bin/firefox • OSX: objdir/dist/AppName.app/Contents/ MacOS/firefox • options: -ProfileManager, -no-remote
  • 8. GENERAL INTRODUCTION • Don’t get lost in the details • Ask for an implementation outline • There is documentation, overview • Über-Weapon: Ask for help • IRC: https://wiki.mozilla.org/IRC, #developers • Mailing list: https://lists.mozilla.org/listinfo, dev-webapi
  • 9. FRIENDLY PEOPLE TO PING ON IRC
  • 16. GENERAL INTRODUCTION • whenever you do communication • try to be precise • give reasoning to your arguments • get only short answer - don’t take it wrong, people are really busy • dump whatever you have (crashback/patch...)
  • 17. GENERAL INTRODUCTION • don’t be afraid to ping people • might get hint to ping someone else • tell people you're new to hacking JS/Gecko • look/ask for bugs that do similar things you try to solve
  • 19. FIREFOX OS WEBAPI Wifi Browser Battery Telephony Settings Idle Power Contacts Bluetooth Vibrator Webapps many more to come.... https://wiki.mozilla.org/WebAPI/
  • 21. IT ALL STARTS WITH AN INTERFACE XPIDL VS. WEBIDL
  • 22. XPIDL VS. WEBIDL [scriptable, builtinclass, interface EventTarget { uuid(5a8294df-ffe4-48e5-803f-f57bebc29289)] void addEventListener(DOMString type, interface nsIDOMScreen : nsIDOMEventTarget EventListener? listener, { optional boolean capture = false, readonly attribute long top; optional boolean? wantsUntrusted = null); readonly attribute DOMString mozOrientation; void removeEventListener(DOMString type, [implicit_jscontext] EventListener? listener, attribute jsval onmozorientationchange; optional boolean capture = false); boolean dispatchEvent(Event event); boolean mozLockOrientation(in DOMString orientation); }; void mozUnlockOrientation(); }; https://developer.mozilla.org/en-US/docs/XPIDL https://developer.mozilla.org/en-US/docs/Mozilla/WebIDL_bindings
  • 23. MAPPING JS VS C++ • Read other APIs • Interfaces are defined in dom/interfaces • Implementations mostly in dom/*, content/* • c++ implementations use common inheritance • JS implementations use manifest file
  • 24. TIME TO FILE A BUG Bugzilla: DOM:Device Interfaces
  • 26. WHY IN JS? • Prototyping • Lower entry point • WebDevs know JS • Also better for understanding!
  • 27. INTERFACE EXAMPLE For example dom/interfaces/helloworld/nsIHelloWorld.idl [scriptable, uuid(da0f7040-388b-11e1-b86c-0800200c9444)] interface nsIDOMHelloWorld : nsISupports { void sayHello(in DOMString aName); }; https://bugzilla.mozilla.org/show_bug.cgi?id=674720
  • 28. HELLOWORLD.MANIFEST For example dom/helloworld/HelloWorld.manifest component {f5181640-89e8-11e1-b0c4-0800200c9444} HelloWorld.js contract @mozilla.org/helloWorld;1 {f5181640-89e8-11e1-b0c4-0800200c9444} category JavaScript-navigator-property mozHelloWorld @mozilla.org/helloWorld;1
  • 29. HELLOWORLD.JS For example dom/helloworld/HelloWorld.js const Cc = Components.classes; const Ci = Components.interfaces; const Cu = Components.utils; Cu.import("resource://gre/modules/XPCOMUtils.jsm"); function HelloWorld() {} HelloWorld.prototype = { init: function init(aWindow) {}, Text sayHello: function sayHello(aName) { dump("Hello " + aName + "n"); }, classID : Components.ID("{d88af7e0-a45f-11e1-b3dd-0800200c9444}"), QueryInterface : XPCOMUtils.generateQI([Components.interfaces.nsIDOMHelloWorld]), classInfo : XPCOMUtils.generateCI({classID: Components.ID("{d88af7e0-a45f-11e1-b3dd-0800200c9444}"), contractID: "@mozilla.org/helloWorld;1", classDescription: "HelloWorld", interfaces: [Components.interfaces.nsIDOMHelloWorld, Ci.nsIDOMGlobalPropertyInitializer], flags: Ci.nsIClassInfo.DOM_OBJECT}) } const NSGetFactory = XPCOMUtils.generateNSGetFactory([HelloWorld]);
  • 30. BOILERPLATE • Makefiles • Manifest • Packaging • Module Loading • Access Permission
  • 31. EXPOSEDPROPS let foo = new Foo(); Foo.prototype = { __exposedProps__: { name: 'rw' } }
  • 32. FIREFOX OS PROCESS MODEL • Parent - Child • Nested process Processes structure not possible (yet) • Only one parent • Parent is trusted • Browser is in parent, content pages are • Child can be children compromised • Securitycritical code has to run in parent
  • 33. SYSTEM MESSAGE MANAGER • Use for child-parent communication • Child: childProcessMessageManager.sendAsyncMessage("message-name", {"foo": 2}); var response = sendSyncMessage("message-name", {"foo": 1}); Parent: •receiveMessage: function(aMessage) { switch (aMessage.name) { [...] parentProcessMessageManager.sendAsynMessage(“return-message-name”, [...]) } }
  • 34. DOMREQUESTS var pending = navigator.mozApps.install(manifestUrl); pending.onsuccess = function () {   // Save the App object that is returned   var appRecord = this.result;   alert('Installation successful!') }; pending.onerror = function () {   // Display the name of the error   alert('Install failed, error: ' + this.error.name); };
  • 37. MAPPING JS/C++ • IDL files → JS & C++ • JS: ctx.lineWidth C++: ctx::GetLineWidth(float *width) • Need to implement C++ class for interface • NS_IMETHODIMP: returns NS_<status> • Expose object: nsDOMClassInfo.cpp/nsDOMClassInfoClasses.h
  • 38. INTERFACES Attribute canvas.mozPrintCallback = Callback function(obj) { PrintState var ctx = obj.context; ctx.fillRect(0, 0, 100, 100); obj.done(); };
  • 39. INTERFACES Taken from bug #745025 te [scriptable, uuid(a7062fca-41c6-4520-b777-3bb30fd77273)] interface nsIDOMHTMLCanvasElement : nsIDOMHTMLElement bu { tri [...] At // A Mozilla-only callback that is called during the printing process. attribute nsIPrintCallback mozPrintCallback; }; k ac [scriptable, function, uuid(8d5fb8a0-7782-11e1-b0c4-0800200c9a66)] llb interface nsIPrintCallback : nsISupports Ca { void render(in nsIDOMMozCanvasPrintState ctx); }; te ta [scriptable, builtinclass, uuid(8d5fb8a0-7782-11e1-b0c4-0800200c9a67)] tS interface nsIDOMMozCanvasPrintState : nsISupports in { Pr // A canvas rendering context. readonly attribute nsISupports context; // To be called when rendering to the context is done. void done(); };
  • 40. class nsHTMLCanvasPrintState : public nsIDOMMozCanvasPrintState { public: nsHTMLCanvasPrintState(nsHTMLCanvasElement* aCanvas, nsICanvasRenderingContextInternal* aContext, nsITimerCallback* aCallback) : mIsDone(false), mPendingNotify(false), mCanvas(aCanvas), mContext(aContext), mCallback(aCallback) { } NS_IMETHOD GetContext(nsISupports** aContext) { NS_ADDREF(*aContext = mContext); return NS_OK; } NS_IMETHOD Done() { [...] Taken from return NS_OK; } bug #745025 [...] }
  • 41. MEMORY MANAGEMENT • C++ doesn’t have a garbage collector :( • In Gecko: Reference counting & cycle collector • Reference counting: • nsCOMPtr (for interfaces), nsREFPtr • use getter_AddRefs • NS_IF_ADDREF & NS_IF_RELEASE
  • 42. MEMORY MANAGEMENT • Reference counting doesn’t work always • Make use of Gecko’s cycle collector • Better cycle then maybe leak
  • 43. DEBUGGING • Make sure to have a debug build • Enable logging (example) • Watch for assertion in logs • Insert printfs • There is documentation how to use debugger
  • 44. OVERVIEW OF SOME TREES • Frame Tree: Frames on page • Content Tree: Content going with frames • View Tree: Connecting views
  • 47. DIFFERENT TYPE OF TESTS • Reftests • Crashtests • XPCShell Tests • Mochitests • JS tests • Compiled code tests :-( • Marionette tests
  • 48. MOCHITEST •/path/to/objdir $ TEST_PATH=dom/ contacts/tests make mochitest-plain •/path/to/objdir $ TEST_PATH=dom/ Text contacts/tests/test_contacts.html make mochitest-plain
  • 49. TIME FOR REVIEW • Makesure the patch is • Whenuploading a new formatted according to version: the guidelines: • address *all* review •8 lines of context comments • correctcommitter • obsolete the old info (name + email) patch • correct checking • run tests again message
  • 50. REVIEW • Make sure your patch is clean • Patch should be green on try-push • WIP: State what’s working/what not/what’s next • Review might take some time (~1 week?) • If longer, ping person, switch review person • Except r-, don’t worry!
  • 51. Q&A
  • 52. THINGS TO HACK ON • Implement vw/vh/vmin/vmax • "dirname" DOM attribute on form controls • Implement FileSaver