52
IMPLEMENTING NEW WEBAPIS Gregor Wagner ([email protected] ) Julian Viereck ([email protected] )

Implementing new WebAPIs

  • View
    1.775

  • Download
    0

Embed Size (px)

DESCRIPTION

This session gives a rough overview how to implement new WebAPIs in JS and C++.

Citation preview

Page 1: Implementing new WebAPIs

IMPLEMENTING NEW WEBAPISGregor Wagner (gwagnermozillacom)

Julian Viereck (jviereckmozillacom)

DISCALIMER

bull No API designingstandadization here

bull Talk about making the implementation happen

bull 55rdquo not enough to get you going

bull Reach out to us and do ldquohands-onrdquo hacking

OUTLINEbull General Introduction

bull How To Implement New API

bull JS

bull C++

bull Make your work land

bull QampA

GENERAL INTRODUCTION

GENERAL INTRODUCTIONbull Build on two previous presentations

bull JS David Dahlrsquos ldquoFrom Web Developer to Firefox Hackerrdquo [1]

bull C++ Bobby Holleyrsquos ldquoHacking Geckordquo [2]

bull [1] httppeoplemozillacom~ddahlpagesHackingFirefoxtemplatehtml

bull [2] httppeoplemozillacom~bholleyhacking-gecko-fosdem2012hacking-geckohtml

GENERAL INTRODUCTION

bull Need to build Firefox

bull Run build

bull LinuxWindows objdirdistbinfirefox

bullOSX objdirdistAppNameappContentsMacOSfirefox

bulloptions -ProfileManager -no-remote

GENERAL INTRODUCTION

GENERAL INTRODUCTION

bull Donrsquot get lost in the details

bull Ask for an implementation outline

bull There is documentation overview

bull Uumlber-Weapon Ask for help

bull IRC httpswikimozillaorgIRC developers

bull Mailing list httpslistsmozillaorglistinfo 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

bull whenever you do communication

bull try to be precise

bull give reasoning to your arguments

bull get only short answer - donrsquot take it wrong people are really busy

bull dump whatever you have (crashbackpatch)

GENERAL INTRODUCTION

bull donrsquot be afraid to ping people

bull might get hint to ping someone else

bull tell people youre new to hacking JSGecko

bull lookask for bugs that do similar things you try to solve

HTTPSMXRMOZILLAORG

FIREFOX OS WEBAPI

Telephony

VibratorContacts

Settings

Battery

PowerIdle

Bluetooth

many more to come

Browser

Webapps

httpswikimozillaorgWebAPI

Wifi

INTERFACE + IMPLEMENTATION

IT ALL STARTS WITH AN INTERFACEXPIDL VS WEBIDL

XPIDL VS WEBIDL

interface EventTarget void addEventListener(DOMString type EventListener listener optional boolean capture = false optional boolean wantsUntrusted = null) void removeEventListener(DOMString type EventListener listener optional boolean capture = false) boolean dispatchEvent(Event event)

[scriptable builtinclass uuid(5a8294df-ffe4-48e5-803f-f57bebc29289)]interface nsIDOMScreen nsIDOMEventTarget readonly attribute long top readonly attribute DOMString mozOrientation [implicit_jscontext] attribute jsval onmozorientationchange

boolean mozLockOrientation(in DOMString orientation) void mozUnlockOrientation()

httpsdevelopermozillaorgen-USdocsMozillaWebIDL_bindingshttpsdevelopermozillaorgen-USdocsXPIDL

MAPPING JS VS C++

bull Read other APIs

bull Interfaces are defined in dominterfaces

bull Implementations mostly in dom content

bull c++ implementations use common inheritance

bull JS implementations use manifest file

TIME TO FILE A BUGBugzilla DOMDevice Interfaces

HOW TO IMPLEMENT JS

WHY IN JSbull Prototyping

bull Lower entry point

bull WebDevs know JS

bull Also better for understanding

INTERFACE EXAMPLE

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

httpsbugzillamozillaorgshow_bugcgiid=674720

For example dominterfaceshelloworldnsIHelloWorldidl

HELLOWORLDMANIFEST

component f5181640-89e8-11e1-b0c4-0800200c9444 HelloWorldjscontract mozillaorghelloWorld1 f5181640-89e8-11e1-b0c4-0800200c9444category JavaScript-navigator-property mozHelloWorld mozillaorghelloWorld1

For example domhelloworldHelloWorldmanifest

HELLOWORLDJS

Text

const Cc = Componentsclassesconst Ci = Componentsinterfacesconst Cu = Componentsutils

Cuimport(resourcegremodulesXPCOMUtilsjsm)

function HelloWorld()

HelloWorldprototype =

init function init(aWindow)

sayHello function sayHello(aName) dump(Hello + aName + n)

classID ComponentsID(d88af7e0-a45f-11e1-b3dd-0800200c9444) QueryInterface XPCOMUtilsgenerateQI([ComponentsinterfacesnsIDOMHelloWorld])

classInfo XPCOMUtilsgenerateCI(classID ComponentsID(d88af7e0-a45f-11e1-b3dd-0800200c9444) contractID mozillaorghelloWorld1 classDescription HelloWorld interfaces [ComponentsinterfacesnsIDOMHelloWorld CinsIDOMGlobalPropertyInitializer] flags CinsIClassInfoDOM_OBJECT)

const NSGetFactory = XPCOMUtilsgenerateNSGetFactory([HelloWorld])

For example domhelloworldHelloWorldjs

BOILERPLATE

bull Makefiles

bull Manifest

bull Packaging

bull Module Loading

bull Access Permission

EXPOSEDPROPS

let foo = new Foo()

Fooprototype = __exposedProps__ name rw

FIREFOX OS PROCESS MODELbull Parent - Child Processes

bull Only one parent

bull Browser is in parent content pages are children

bull Nested process structure not possible (yet)

bull Parent is trusted

bull Child can be compromised

bull Security critical code has to run in parent

SYSTEM MESSAGE MANAGERbull Use for child-parent communication

bull Child

bull Parent

childProcessMessageManagersendAsyncMessage(message-name foo 2)

var response = sendSyncMessage(message-name foo 1)

receiveMessage function(aMessage) switch (aMessagename) [] parentProcessMessageManagersendAsynMessage(ldquoreturn-message-namerdquo [])

DOMREQUESTS

var pending = navigatormozAppsinstall(manifestUrl)pendingonsuccess = function () Save the App object that is returned var appRecord = thisresult alert(Installation successful)pendingonerror = function () Display the name of the error alert(Install failed error + thiserrorname)

PERMISSIONS

HOW TO IMPLEMENT C++

MAPPING JSC++

bull IDL files rarr JS amp C++

bull JS ctxlineWidth C++ ctxGetLineWidth(float width)

bull Need to implement C++ class for interface

bull NS_IMETHODIMP returns NS_ltstatusgt

bull Expose object nsDOMClassInfocppnsDOMClassInfoClassesh

INTERFACES

Attribute

PrintStateCallback

canvasmozPrintCallback =

function(obj) var ctx = objcontext ctxfillRect(0 0 100 100) objdone()

INTERFACES[scriptable uuid(a7062fca-41c6-4520-b777-3bb30fd77273)]interface nsIDOMHTMLCanvasElement nsIDOMHTMLElement []

A Mozilla-only callback that is called during the printing process attribute nsIPrintCallback mozPrintCallback

Attrib

ute

Callb

ack

[scriptable function uuid(8d5fb8a0-7782-11e1-b0c4-0800200c9a66)]interface nsIPrintCallback nsISupports void render(in nsIDOMMozCanvasPrintState ctx)

[scriptable builtinclass uuid(8d5fb8a0-7782-11e1-b0c4-0800200c9a67)]interface nsIDOMMozCanvasPrintState nsISupports A canvas rendering context readonly attribute nsISupports context

To be called when rendering to the context is done void done()

PrintS

tate

Taken frombug 745025

class nsHTMLCanvasPrintState public nsIDOMMozCanvasPrintStatepublic 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() [] return NS_OK

[]

Taken frombug 745025

MEMORY MANAGEMENTbull C++ doesnrsquot have a garbage collector (

bull In Gecko Reference counting amp cycle collector

bull Reference counting

bull nsCOMPtr (for interfaces) nsREFPtr

bull use getter_AddRefs

bull NS_IF_ADDREF amp NS_IF_RELEASE

MEMORY MANAGEMENT

bull Reference counting doesnrsquot work always

bull Make use of Geckorsquos cycle collector

bull Better cycle then maybe leak

DEBUGGING

bull Make sure to have a debug build

bull Enable logging (example)

bull Watch for assertion in logs

bull Insert printfs

bull There is documentation how to use debugger

OVERVIEW OF SOME TREES

bull Frame Tree Frames on page

bull Content Tree Content going with frames

bull View Tree Connecting views

MAKE YOUR WORK LAND

TESTS TESTS TESTS

bull Reftests

bull Crashtests

bull XPCShell Tests

bull Mochitests

bull JS tests

bull Compiled code tests -(

bull Marionette tests

DIFFERENT TYPE OF TESTS

MOCHITEST

Text

bullpathtoobjdir $ TEST_PATH=domcontactstests make mochitest-plain

bullpathtoobjdir $ TEST_PATH=domcontactsteststest_contactshtml make mochitest-plain

TIME FOR REVIEWbull Make sure the patch is formatted according to the guidelines

bull 8 lines of context

bull correct committer info (name + email)

bull correct checking message

bull When uploading a new version

bull address all review comments

bull obsolete the old patch

bull run tests again

REVIEWbull Make sure your patch is clean

bull Patch should be green on try-push

bull WIP State whatrsquos workingwhat notwhatrsquos next

bull Review might take some time (~1 week)

bull If longer ping person switch review person

bull Except r- donrsquot worry

Q amp A

THINGS TO HACK ON

bull Implement vwvhvminvmax

bull dirname DOM attribute on form controls

bull Implement FileSaver

Page 2: Implementing new WebAPIs

DISCALIMER

bull No API designingstandadization here

bull Talk about making the implementation happen

bull 55rdquo not enough to get you going

bull Reach out to us and do ldquohands-onrdquo hacking

OUTLINEbull General Introduction

bull How To Implement New API

bull JS

bull C++

bull Make your work land

bull QampA

GENERAL INTRODUCTION

GENERAL INTRODUCTIONbull Build on two previous presentations

bull JS David Dahlrsquos ldquoFrom Web Developer to Firefox Hackerrdquo [1]

bull C++ Bobby Holleyrsquos ldquoHacking Geckordquo [2]

bull [1] httppeoplemozillacom~ddahlpagesHackingFirefoxtemplatehtml

bull [2] httppeoplemozillacom~bholleyhacking-gecko-fosdem2012hacking-geckohtml

GENERAL INTRODUCTION

bull Need to build Firefox

bull Run build

bull LinuxWindows objdirdistbinfirefox

bullOSX objdirdistAppNameappContentsMacOSfirefox

bulloptions -ProfileManager -no-remote

GENERAL INTRODUCTION

GENERAL INTRODUCTION

bull Donrsquot get lost in the details

bull Ask for an implementation outline

bull There is documentation overview

bull Uumlber-Weapon Ask for help

bull IRC httpswikimozillaorgIRC developers

bull Mailing list httpslistsmozillaorglistinfo 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

bull whenever you do communication

bull try to be precise

bull give reasoning to your arguments

bull get only short answer - donrsquot take it wrong people are really busy

bull dump whatever you have (crashbackpatch)

GENERAL INTRODUCTION

bull donrsquot be afraid to ping people

bull might get hint to ping someone else

bull tell people youre new to hacking JSGecko

bull lookask for bugs that do similar things you try to solve

HTTPSMXRMOZILLAORG

FIREFOX OS WEBAPI

Telephony

VibratorContacts

Settings

Battery

PowerIdle

Bluetooth

many more to come

Browser

Webapps

httpswikimozillaorgWebAPI

Wifi

INTERFACE + IMPLEMENTATION

IT ALL STARTS WITH AN INTERFACEXPIDL VS WEBIDL

XPIDL VS WEBIDL

interface EventTarget void addEventListener(DOMString type EventListener listener optional boolean capture = false optional boolean wantsUntrusted = null) void removeEventListener(DOMString type EventListener listener optional boolean capture = false) boolean dispatchEvent(Event event)

[scriptable builtinclass uuid(5a8294df-ffe4-48e5-803f-f57bebc29289)]interface nsIDOMScreen nsIDOMEventTarget readonly attribute long top readonly attribute DOMString mozOrientation [implicit_jscontext] attribute jsval onmozorientationchange

boolean mozLockOrientation(in DOMString orientation) void mozUnlockOrientation()

httpsdevelopermozillaorgen-USdocsMozillaWebIDL_bindingshttpsdevelopermozillaorgen-USdocsXPIDL

MAPPING JS VS C++

bull Read other APIs

bull Interfaces are defined in dominterfaces

bull Implementations mostly in dom content

bull c++ implementations use common inheritance

bull JS implementations use manifest file

TIME TO FILE A BUGBugzilla DOMDevice Interfaces

HOW TO IMPLEMENT JS

WHY IN JSbull Prototyping

bull Lower entry point

bull WebDevs know JS

bull Also better for understanding

INTERFACE EXAMPLE

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

httpsbugzillamozillaorgshow_bugcgiid=674720

For example dominterfaceshelloworldnsIHelloWorldidl

HELLOWORLDMANIFEST

component f5181640-89e8-11e1-b0c4-0800200c9444 HelloWorldjscontract mozillaorghelloWorld1 f5181640-89e8-11e1-b0c4-0800200c9444category JavaScript-navigator-property mozHelloWorld mozillaorghelloWorld1

For example domhelloworldHelloWorldmanifest

HELLOWORLDJS

Text

const Cc = Componentsclassesconst Ci = Componentsinterfacesconst Cu = Componentsutils

Cuimport(resourcegremodulesXPCOMUtilsjsm)

function HelloWorld()

HelloWorldprototype =

init function init(aWindow)

sayHello function sayHello(aName) dump(Hello + aName + n)

classID ComponentsID(d88af7e0-a45f-11e1-b3dd-0800200c9444) QueryInterface XPCOMUtilsgenerateQI([ComponentsinterfacesnsIDOMHelloWorld])

classInfo XPCOMUtilsgenerateCI(classID ComponentsID(d88af7e0-a45f-11e1-b3dd-0800200c9444) contractID mozillaorghelloWorld1 classDescription HelloWorld interfaces [ComponentsinterfacesnsIDOMHelloWorld CinsIDOMGlobalPropertyInitializer] flags CinsIClassInfoDOM_OBJECT)

const NSGetFactory = XPCOMUtilsgenerateNSGetFactory([HelloWorld])

For example domhelloworldHelloWorldjs

BOILERPLATE

bull Makefiles

bull Manifest

bull Packaging

bull Module Loading

bull Access Permission

EXPOSEDPROPS

let foo = new Foo()

Fooprototype = __exposedProps__ name rw

FIREFOX OS PROCESS MODELbull Parent - Child Processes

bull Only one parent

bull Browser is in parent content pages are children

bull Nested process structure not possible (yet)

bull Parent is trusted

bull Child can be compromised

bull Security critical code has to run in parent

SYSTEM MESSAGE MANAGERbull Use for child-parent communication

bull Child

bull Parent

childProcessMessageManagersendAsyncMessage(message-name foo 2)

var response = sendSyncMessage(message-name foo 1)

receiveMessage function(aMessage) switch (aMessagename) [] parentProcessMessageManagersendAsynMessage(ldquoreturn-message-namerdquo [])

DOMREQUESTS

var pending = navigatormozAppsinstall(manifestUrl)pendingonsuccess = function () Save the App object that is returned var appRecord = thisresult alert(Installation successful)pendingonerror = function () Display the name of the error alert(Install failed error + thiserrorname)

PERMISSIONS

HOW TO IMPLEMENT C++

MAPPING JSC++

bull IDL files rarr JS amp C++

bull JS ctxlineWidth C++ ctxGetLineWidth(float width)

bull Need to implement C++ class for interface

bull NS_IMETHODIMP returns NS_ltstatusgt

bull Expose object nsDOMClassInfocppnsDOMClassInfoClassesh

INTERFACES

Attribute

PrintStateCallback

canvasmozPrintCallback =

function(obj) var ctx = objcontext ctxfillRect(0 0 100 100) objdone()

INTERFACES[scriptable uuid(a7062fca-41c6-4520-b777-3bb30fd77273)]interface nsIDOMHTMLCanvasElement nsIDOMHTMLElement []

A Mozilla-only callback that is called during the printing process attribute nsIPrintCallback mozPrintCallback

Attrib

ute

Callb

ack

[scriptable function uuid(8d5fb8a0-7782-11e1-b0c4-0800200c9a66)]interface nsIPrintCallback nsISupports void render(in nsIDOMMozCanvasPrintState ctx)

[scriptable builtinclass uuid(8d5fb8a0-7782-11e1-b0c4-0800200c9a67)]interface nsIDOMMozCanvasPrintState nsISupports A canvas rendering context readonly attribute nsISupports context

To be called when rendering to the context is done void done()

PrintS

tate

Taken frombug 745025

class nsHTMLCanvasPrintState public nsIDOMMozCanvasPrintStatepublic 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() [] return NS_OK

[]

Taken frombug 745025

MEMORY MANAGEMENTbull C++ doesnrsquot have a garbage collector (

bull In Gecko Reference counting amp cycle collector

bull Reference counting

bull nsCOMPtr (for interfaces) nsREFPtr

bull use getter_AddRefs

bull NS_IF_ADDREF amp NS_IF_RELEASE

MEMORY MANAGEMENT

bull Reference counting doesnrsquot work always

bull Make use of Geckorsquos cycle collector

bull Better cycle then maybe leak

DEBUGGING

bull Make sure to have a debug build

bull Enable logging (example)

bull Watch for assertion in logs

bull Insert printfs

bull There is documentation how to use debugger

OVERVIEW OF SOME TREES

bull Frame Tree Frames on page

bull Content Tree Content going with frames

bull View Tree Connecting views

MAKE YOUR WORK LAND

TESTS TESTS TESTS

bull Reftests

bull Crashtests

bull XPCShell Tests

bull Mochitests

bull JS tests

bull Compiled code tests -(

bull Marionette tests

DIFFERENT TYPE OF TESTS

MOCHITEST

Text

bullpathtoobjdir $ TEST_PATH=domcontactstests make mochitest-plain

bullpathtoobjdir $ TEST_PATH=domcontactsteststest_contactshtml make mochitest-plain

TIME FOR REVIEWbull Make sure the patch is formatted according to the guidelines

bull 8 lines of context

bull correct committer info (name + email)

bull correct checking message

bull When uploading a new version

bull address all review comments

bull obsolete the old patch

bull run tests again

REVIEWbull Make sure your patch is clean

bull Patch should be green on try-push

bull WIP State whatrsquos workingwhat notwhatrsquos next

bull Review might take some time (~1 week)

bull If longer ping person switch review person

bull Except r- donrsquot worry

Q amp A

THINGS TO HACK ON

bull Implement vwvhvminvmax

bull dirname DOM attribute on form controls

bull Implement FileSaver

Page 3: Implementing new WebAPIs

OUTLINEbull General Introduction

bull How To Implement New API

bull JS

bull C++

bull Make your work land

bull QampA

GENERAL INTRODUCTION

GENERAL INTRODUCTIONbull Build on two previous presentations

bull JS David Dahlrsquos ldquoFrom Web Developer to Firefox Hackerrdquo [1]

bull C++ Bobby Holleyrsquos ldquoHacking Geckordquo [2]

bull [1] httppeoplemozillacom~ddahlpagesHackingFirefoxtemplatehtml

bull [2] httppeoplemozillacom~bholleyhacking-gecko-fosdem2012hacking-geckohtml

GENERAL INTRODUCTION

bull Need to build Firefox

bull Run build

bull LinuxWindows objdirdistbinfirefox

bullOSX objdirdistAppNameappContentsMacOSfirefox

bulloptions -ProfileManager -no-remote

GENERAL INTRODUCTION

GENERAL INTRODUCTION

bull Donrsquot get lost in the details

bull Ask for an implementation outline

bull There is documentation overview

bull Uumlber-Weapon Ask for help

bull IRC httpswikimozillaorgIRC developers

bull Mailing list httpslistsmozillaorglistinfo 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

bull whenever you do communication

bull try to be precise

bull give reasoning to your arguments

bull get only short answer - donrsquot take it wrong people are really busy

bull dump whatever you have (crashbackpatch)

GENERAL INTRODUCTION

bull donrsquot be afraid to ping people

bull might get hint to ping someone else

bull tell people youre new to hacking JSGecko

bull lookask for bugs that do similar things you try to solve

HTTPSMXRMOZILLAORG

FIREFOX OS WEBAPI

Telephony

VibratorContacts

Settings

Battery

PowerIdle

Bluetooth

many more to come

Browser

Webapps

httpswikimozillaorgWebAPI

Wifi

INTERFACE + IMPLEMENTATION

IT ALL STARTS WITH AN INTERFACEXPIDL VS WEBIDL

XPIDL VS WEBIDL

interface EventTarget void addEventListener(DOMString type EventListener listener optional boolean capture = false optional boolean wantsUntrusted = null) void removeEventListener(DOMString type EventListener listener optional boolean capture = false) boolean dispatchEvent(Event event)

[scriptable builtinclass uuid(5a8294df-ffe4-48e5-803f-f57bebc29289)]interface nsIDOMScreen nsIDOMEventTarget readonly attribute long top readonly attribute DOMString mozOrientation [implicit_jscontext] attribute jsval onmozorientationchange

boolean mozLockOrientation(in DOMString orientation) void mozUnlockOrientation()

httpsdevelopermozillaorgen-USdocsMozillaWebIDL_bindingshttpsdevelopermozillaorgen-USdocsXPIDL

MAPPING JS VS C++

bull Read other APIs

bull Interfaces are defined in dominterfaces

bull Implementations mostly in dom content

bull c++ implementations use common inheritance

bull JS implementations use manifest file

TIME TO FILE A BUGBugzilla DOMDevice Interfaces

HOW TO IMPLEMENT JS

WHY IN JSbull Prototyping

bull Lower entry point

bull WebDevs know JS

bull Also better for understanding

INTERFACE EXAMPLE

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

httpsbugzillamozillaorgshow_bugcgiid=674720

For example dominterfaceshelloworldnsIHelloWorldidl

HELLOWORLDMANIFEST

component f5181640-89e8-11e1-b0c4-0800200c9444 HelloWorldjscontract mozillaorghelloWorld1 f5181640-89e8-11e1-b0c4-0800200c9444category JavaScript-navigator-property mozHelloWorld mozillaorghelloWorld1

For example domhelloworldHelloWorldmanifest

HELLOWORLDJS

Text

const Cc = Componentsclassesconst Ci = Componentsinterfacesconst Cu = Componentsutils

Cuimport(resourcegremodulesXPCOMUtilsjsm)

function HelloWorld()

HelloWorldprototype =

init function init(aWindow)

sayHello function sayHello(aName) dump(Hello + aName + n)

classID ComponentsID(d88af7e0-a45f-11e1-b3dd-0800200c9444) QueryInterface XPCOMUtilsgenerateQI([ComponentsinterfacesnsIDOMHelloWorld])

classInfo XPCOMUtilsgenerateCI(classID ComponentsID(d88af7e0-a45f-11e1-b3dd-0800200c9444) contractID mozillaorghelloWorld1 classDescription HelloWorld interfaces [ComponentsinterfacesnsIDOMHelloWorld CinsIDOMGlobalPropertyInitializer] flags CinsIClassInfoDOM_OBJECT)

const NSGetFactory = XPCOMUtilsgenerateNSGetFactory([HelloWorld])

For example domhelloworldHelloWorldjs

BOILERPLATE

bull Makefiles

bull Manifest

bull Packaging

bull Module Loading

bull Access Permission

EXPOSEDPROPS

let foo = new Foo()

Fooprototype = __exposedProps__ name rw

FIREFOX OS PROCESS MODELbull Parent - Child Processes

bull Only one parent

bull Browser is in parent content pages are children

bull Nested process structure not possible (yet)

bull Parent is trusted

bull Child can be compromised

bull Security critical code has to run in parent

SYSTEM MESSAGE MANAGERbull Use for child-parent communication

bull Child

bull Parent

childProcessMessageManagersendAsyncMessage(message-name foo 2)

var response = sendSyncMessage(message-name foo 1)

receiveMessage function(aMessage) switch (aMessagename) [] parentProcessMessageManagersendAsynMessage(ldquoreturn-message-namerdquo [])

DOMREQUESTS

var pending = navigatormozAppsinstall(manifestUrl)pendingonsuccess = function () Save the App object that is returned var appRecord = thisresult alert(Installation successful)pendingonerror = function () Display the name of the error alert(Install failed error + thiserrorname)

PERMISSIONS

HOW TO IMPLEMENT C++

MAPPING JSC++

bull IDL files rarr JS amp C++

bull JS ctxlineWidth C++ ctxGetLineWidth(float width)

bull Need to implement C++ class for interface

bull NS_IMETHODIMP returns NS_ltstatusgt

bull Expose object nsDOMClassInfocppnsDOMClassInfoClassesh

INTERFACES

Attribute

PrintStateCallback

canvasmozPrintCallback =

function(obj) var ctx = objcontext ctxfillRect(0 0 100 100) objdone()

INTERFACES[scriptable uuid(a7062fca-41c6-4520-b777-3bb30fd77273)]interface nsIDOMHTMLCanvasElement nsIDOMHTMLElement []

A Mozilla-only callback that is called during the printing process attribute nsIPrintCallback mozPrintCallback

Attrib

ute

Callb

ack

[scriptable function uuid(8d5fb8a0-7782-11e1-b0c4-0800200c9a66)]interface nsIPrintCallback nsISupports void render(in nsIDOMMozCanvasPrintState ctx)

[scriptable builtinclass uuid(8d5fb8a0-7782-11e1-b0c4-0800200c9a67)]interface nsIDOMMozCanvasPrintState nsISupports A canvas rendering context readonly attribute nsISupports context

To be called when rendering to the context is done void done()

PrintS

tate

Taken frombug 745025

class nsHTMLCanvasPrintState public nsIDOMMozCanvasPrintStatepublic 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() [] return NS_OK

[]

Taken frombug 745025

MEMORY MANAGEMENTbull C++ doesnrsquot have a garbage collector (

bull In Gecko Reference counting amp cycle collector

bull Reference counting

bull nsCOMPtr (for interfaces) nsREFPtr

bull use getter_AddRefs

bull NS_IF_ADDREF amp NS_IF_RELEASE

MEMORY MANAGEMENT

bull Reference counting doesnrsquot work always

bull Make use of Geckorsquos cycle collector

bull Better cycle then maybe leak

DEBUGGING

bull Make sure to have a debug build

bull Enable logging (example)

bull Watch for assertion in logs

bull Insert printfs

bull There is documentation how to use debugger

OVERVIEW OF SOME TREES

bull Frame Tree Frames on page

bull Content Tree Content going with frames

bull View Tree Connecting views

MAKE YOUR WORK LAND

TESTS TESTS TESTS

bull Reftests

bull Crashtests

bull XPCShell Tests

bull Mochitests

bull JS tests

bull Compiled code tests -(

bull Marionette tests

DIFFERENT TYPE OF TESTS

MOCHITEST

Text

bullpathtoobjdir $ TEST_PATH=domcontactstests make mochitest-plain

bullpathtoobjdir $ TEST_PATH=domcontactsteststest_contactshtml make mochitest-plain

TIME FOR REVIEWbull Make sure the patch is formatted according to the guidelines

bull 8 lines of context

bull correct committer info (name + email)

bull correct checking message

bull When uploading a new version

bull address all review comments

bull obsolete the old patch

bull run tests again

REVIEWbull Make sure your patch is clean

bull Patch should be green on try-push

bull WIP State whatrsquos workingwhat notwhatrsquos next

bull Review might take some time (~1 week)

bull If longer ping person switch review person

bull Except r- donrsquot worry

Q amp A

THINGS TO HACK ON

bull Implement vwvhvminvmax

bull dirname DOM attribute on form controls

bull Implement FileSaver

Page 4: Implementing new WebAPIs

GENERAL INTRODUCTION

GENERAL INTRODUCTIONbull Build on two previous presentations

bull JS David Dahlrsquos ldquoFrom Web Developer to Firefox Hackerrdquo [1]

bull C++ Bobby Holleyrsquos ldquoHacking Geckordquo [2]

bull [1] httppeoplemozillacom~ddahlpagesHackingFirefoxtemplatehtml

bull [2] httppeoplemozillacom~bholleyhacking-gecko-fosdem2012hacking-geckohtml

GENERAL INTRODUCTION

bull Need to build Firefox

bull Run build

bull LinuxWindows objdirdistbinfirefox

bullOSX objdirdistAppNameappContentsMacOSfirefox

bulloptions -ProfileManager -no-remote

GENERAL INTRODUCTION

GENERAL INTRODUCTION

bull Donrsquot get lost in the details

bull Ask for an implementation outline

bull There is documentation overview

bull Uumlber-Weapon Ask for help

bull IRC httpswikimozillaorgIRC developers

bull Mailing list httpslistsmozillaorglistinfo 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

bull whenever you do communication

bull try to be precise

bull give reasoning to your arguments

bull get only short answer - donrsquot take it wrong people are really busy

bull dump whatever you have (crashbackpatch)

GENERAL INTRODUCTION

bull donrsquot be afraid to ping people

bull might get hint to ping someone else

bull tell people youre new to hacking JSGecko

bull lookask for bugs that do similar things you try to solve

HTTPSMXRMOZILLAORG

FIREFOX OS WEBAPI

Telephony

VibratorContacts

Settings

Battery

PowerIdle

Bluetooth

many more to come

Browser

Webapps

httpswikimozillaorgWebAPI

Wifi

INTERFACE + IMPLEMENTATION

IT ALL STARTS WITH AN INTERFACEXPIDL VS WEBIDL

XPIDL VS WEBIDL

interface EventTarget void addEventListener(DOMString type EventListener listener optional boolean capture = false optional boolean wantsUntrusted = null) void removeEventListener(DOMString type EventListener listener optional boolean capture = false) boolean dispatchEvent(Event event)

[scriptable builtinclass uuid(5a8294df-ffe4-48e5-803f-f57bebc29289)]interface nsIDOMScreen nsIDOMEventTarget readonly attribute long top readonly attribute DOMString mozOrientation [implicit_jscontext] attribute jsval onmozorientationchange

boolean mozLockOrientation(in DOMString orientation) void mozUnlockOrientation()

httpsdevelopermozillaorgen-USdocsMozillaWebIDL_bindingshttpsdevelopermozillaorgen-USdocsXPIDL

MAPPING JS VS C++

bull Read other APIs

bull Interfaces are defined in dominterfaces

bull Implementations mostly in dom content

bull c++ implementations use common inheritance

bull JS implementations use manifest file

TIME TO FILE A BUGBugzilla DOMDevice Interfaces

HOW TO IMPLEMENT JS

WHY IN JSbull Prototyping

bull Lower entry point

bull WebDevs know JS

bull Also better for understanding

INTERFACE EXAMPLE

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

httpsbugzillamozillaorgshow_bugcgiid=674720

For example dominterfaceshelloworldnsIHelloWorldidl

HELLOWORLDMANIFEST

component f5181640-89e8-11e1-b0c4-0800200c9444 HelloWorldjscontract mozillaorghelloWorld1 f5181640-89e8-11e1-b0c4-0800200c9444category JavaScript-navigator-property mozHelloWorld mozillaorghelloWorld1

For example domhelloworldHelloWorldmanifest

HELLOWORLDJS

Text

const Cc = Componentsclassesconst Ci = Componentsinterfacesconst Cu = Componentsutils

Cuimport(resourcegremodulesXPCOMUtilsjsm)

function HelloWorld()

HelloWorldprototype =

init function init(aWindow)

sayHello function sayHello(aName) dump(Hello + aName + n)

classID ComponentsID(d88af7e0-a45f-11e1-b3dd-0800200c9444) QueryInterface XPCOMUtilsgenerateQI([ComponentsinterfacesnsIDOMHelloWorld])

classInfo XPCOMUtilsgenerateCI(classID ComponentsID(d88af7e0-a45f-11e1-b3dd-0800200c9444) contractID mozillaorghelloWorld1 classDescription HelloWorld interfaces [ComponentsinterfacesnsIDOMHelloWorld CinsIDOMGlobalPropertyInitializer] flags CinsIClassInfoDOM_OBJECT)

const NSGetFactory = XPCOMUtilsgenerateNSGetFactory([HelloWorld])

For example domhelloworldHelloWorldjs

BOILERPLATE

bull Makefiles

bull Manifest

bull Packaging

bull Module Loading

bull Access Permission

EXPOSEDPROPS

let foo = new Foo()

Fooprototype = __exposedProps__ name rw

FIREFOX OS PROCESS MODELbull Parent - Child Processes

bull Only one parent

bull Browser is in parent content pages are children

bull Nested process structure not possible (yet)

bull Parent is trusted

bull Child can be compromised

bull Security critical code has to run in parent

SYSTEM MESSAGE MANAGERbull Use for child-parent communication

bull Child

bull Parent

childProcessMessageManagersendAsyncMessage(message-name foo 2)

var response = sendSyncMessage(message-name foo 1)

receiveMessage function(aMessage) switch (aMessagename) [] parentProcessMessageManagersendAsynMessage(ldquoreturn-message-namerdquo [])

DOMREQUESTS

var pending = navigatormozAppsinstall(manifestUrl)pendingonsuccess = function () Save the App object that is returned var appRecord = thisresult alert(Installation successful)pendingonerror = function () Display the name of the error alert(Install failed error + thiserrorname)

PERMISSIONS

HOW TO IMPLEMENT C++

MAPPING JSC++

bull IDL files rarr JS amp C++

bull JS ctxlineWidth C++ ctxGetLineWidth(float width)

bull Need to implement C++ class for interface

bull NS_IMETHODIMP returns NS_ltstatusgt

bull Expose object nsDOMClassInfocppnsDOMClassInfoClassesh

INTERFACES

Attribute

PrintStateCallback

canvasmozPrintCallback =

function(obj) var ctx = objcontext ctxfillRect(0 0 100 100) objdone()

INTERFACES[scriptable uuid(a7062fca-41c6-4520-b777-3bb30fd77273)]interface nsIDOMHTMLCanvasElement nsIDOMHTMLElement []

A Mozilla-only callback that is called during the printing process attribute nsIPrintCallback mozPrintCallback

Attrib

ute

Callb

ack

[scriptable function uuid(8d5fb8a0-7782-11e1-b0c4-0800200c9a66)]interface nsIPrintCallback nsISupports void render(in nsIDOMMozCanvasPrintState ctx)

[scriptable builtinclass uuid(8d5fb8a0-7782-11e1-b0c4-0800200c9a67)]interface nsIDOMMozCanvasPrintState nsISupports A canvas rendering context readonly attribute nsISupports context

To be called when rendering to the context is done void done()

PrintS

tate

Taken frombug 745025

class nsHTMLCanvasPrintState public nsIDOMMozCanvasPrintStatepublic 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() [] return NS_OK

[]

Taken frombug 745025

MEMORY MANAGEMENTbull C++ doesnrsquot have a garbage collector (

bull In Gecko Reference counting amp cycle collector

bull Reference counting

bull nsCOMPtr (for interfaces) nsREFPtr

bull use getter_AddRefs

bull NS_IF_ADDREF amp NS_IF_RELEASE

MEMORY MANAGEMENT

bull Reference counting doesnrsquot work always

bull Make use of Geckorsquos cycle collector

bull Better cycle then maybe leak

DEBUGGING

bull Make sure to have a debug build

bull Enable logging (example)

bull Watch for assertion in logs

bull Insert printfs

bull There is documentation how to use debugger

OVERVIEW OF SOME TREES

bull Frame Tree Frames on page

bull Content Tree Content going with frames

bull View Tree Connecting views

MAKE YOUR WORK LAND

TESTS TESTS TESTS

bull Reftests

bull Crashtests

bull XPCShell Tests

bull Mochitests

bull JS tests

bull Compiled code tests -(

bull Marionette tests

DIFFERENT TYPE OF TESTS

MOCHITEST

Text

bullpathtoobjdir $ TEST_PATH=domcontactstests make mochitest-plain

bullpathtoobjdir $ TEST_PATH=domcontactsteststest_contactshtml make mochitest-plain

TIME FOR REVIEWbull Make sure the patch is formatted according to the guidelines

bull 8 lines of context

bull correct committer info (name + email)

bull correct checking message

bull When uploading a new version

bull address all review comments

bull obsolete the old patch

bull run tests again

REVIEWbull Make sure your patch is clean

bull Patch should be green on try-push

bull WIP State whatrsquos workingwhat notwhatrsquos next

bull Review might take some time (~1 week)

bull If longer ping person switch review person

bull Except r- donrsquot worry

Q amp A

THINGS TO HACK ON

bull Implement vwvhvminvmax

bull dirname DOM attribute on form controls

bull Implement FileSaver

Page 5: Implementing new WebAPIs

GENERAL INTRODUCTIONbull Build on two previous presentations

bull JS David Dahlrsquos ldquoFrom Web Developer to Firefox Hackerrdquo [1]

bull C++ Bobby Holleyrsquos ldquoHacking Geckordquo [2]

bull [1] httppeoplemozillacom~ddahlpagesHackingFirefoxtemplatehtml

bull [2] httppeoplemozillacom~bholleyhacking-gecko-fosdem2012hacking-geckohtml

GENERAL INTRODUCTION

bull Need to build Firefox

bull Run build

bull LinuxWindows objdirdistbinfirefox

bullOSX objdirdistAppNameappContentsMacOSfirefox

bulloptions -ProfileManager -no-remote

GENERAL INTRODUCTION

GENERAL INTRODUCTION

bull Donrsquot get lost in the details

bull Ask for an implementation outline

bull There is documentation overview

bull Uumlber-Weapon Ask for help

bull IRC httpswikimozillaorgIRC developers

bull Mailing list httpslistsmozillaorglistinfo 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

bull whenever you do communication

bull try to be precise

bull give reasoning to your arguments

bull get only short answer - donrsquot take it wrong people are really busy

bull dump whatever you have (crashbackpatch)

GENERAL INTRODUCTION

bull donrsquot be afraid to ping people

bull might get hint to ping someone else

bull tell people youre new to hacking JSGecko

bull lookask for bugs that do similar things you try to solve

HTTPSMXRMOZILLAORG

FIREFOX OS WEBAPI

Telephony

VibratorContacts

Settings

Battery

PowerIdle

Bluetooth

many more to come

Browser

Webapps

httpswikimozillaorgWebAPI

Wifi

INTERFACE + IMPLEMENTATION

IT ALL STARTS WITH AN INTERFACEXPIDL VS WEBIDL

XPIDL VS WEBIDL

interface EventTarget void addEventListener(DOMString type EventListener listener optional boolean capture = false optional boolean wantsUntrusted = null) void removeEventListener(DOMString type EventListener listener optional boolean capture = false) boolean dispatchEvent(Event event)

[scriptable builtinclass uuid(5a8294df-ffe4-48e5-803f-f57bebc29289)]interface nsIDOMScreen nsIDOMEventTarget readonly attribute long top readonly attribute DOMString mozOrientation [implicit_jscontext] attribute jsval onmozorientationchange

boolean mozLockOrientation(in DOMString orientation) void mozUnlockOrientation()

httpsdevelopermozillaorgen-USdocsMozillaWebIDL_bindingshttpsdevelopermozillaorgen-USdocsXPIDL

MAPPING JS VS C++

bull Read other APIs

bull Interfaces are defined in dominterfaces

bull Implementations mostly in dom content

bull c++ implementations use common inheritance

bull JS implementations use manifest file

TIME TO FILE A BUGBugzilla DOMDevice Interfaces

HOW TO IMPLEMENT JS

WHY IN JSbull Prototyping

bull Lower entry point

bull WebDevs know JS

bull Also better for understanding

INTERFACE EXAMPLE

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

httpsbugzillamozillaorgshow_bugcgiid=674720

For example dominterfaceshelloworldnsIHelloWorldidl

HELLOWORLDMANIFEST

component f5181640-89e8-11e1-b0c4-0800200c9444 HelloWorldjscontract mozillaorghelloWorld1 f5181640-89e8-11e1-b0c4-0800200c9444category JavaScript-navigator-property mozHelloWorld mozillaorghelloWorld1

For example domhelloworldHelloWorldmanifest

HELLOWORLDJS

Text

const Cc = Componentsclassesconst Ci = Componentsinterfacesconst Cu = Componentsutils

Cuimport(resourcegremodulesXPCOMUtilsjsm)

function HelloWorld()

HelloWorldprototype =

init function init(aWindow)

sayHello function sayHello(aName) dump(Hello + aName + n)

classID ComponentsID(d88af7e0-a45f-11e1-b3dd-0800200c9444) QueryInterface XPCOMUtilsgenerateQI([ComponentsinterfacesnsIDOMHelloWorld])

classInfo XPCOMUtilsgenerateCI(classID ComponentsID(d88af7e0-a45f-11e1-b3dd-0800200c9444) contractID mozillaorghelloWorld1 classDescription HelloWorld interfaces [ComponentsinterfacesnsIDOMHelloWorld CinsIDOMGlobalPropertyInitializer] flags CinsIClassInfoDOM_OBJECT)

const NSGetFactory = XPCOMUtilsgenerateNSGetFactory([HelloWorld])

For example domhelloworldHelloWorldjs

BOILERPLATE

bull Makefiles

bull Manifest

bull Packaging

bull Module Loading

bull Access Permission

EXPOSEDPROPS

let foo = new Foo()

Fooprototype = __exposedProps__ name rw

FIREFOX OS PROCESS MODELbull Parent - Child Processes

bull Only one parent

bull Browser is in parent content pages are children

bull Nested process structure not possible (yet)

bull Parent is trusted

bull Child can be compromised

bull Security critical code has to run in parent

SYSTEM MESSAGE MANAGERbull Use for child-parent communication

bull Child

bull Parent

childProcessMessageManagersendAsyncMessage(message-name foo 2)

var response = sendSyncMessage(message-name foo 1)

receiveMessage function(aMessage) switch (aMessagename) [] parentProcessMessageManagersendAsynMessage(ldquoreturn-message-namerdquo [])

DOMREQUESTS

var pending = navigatormozAppsinstall(manifestUrl)pendingonsuccess = function () Save the App object that is returned var appRecord = thisresult alert(Installation successful)pendingonerror = function () Display the name of the error alert(Install failed error + thiserrorname)

PERMISSIONS

HOW TO IMPLEMENT C++

MAPPING JSC++

bull IDL files rarr JS amp C++

bull JS ctxlineWidth C++ ctxGetLineWidth(float width)

bull Need to implement C++ class for interface

bull NS_IMETHODIMP returns NS_ltstatusgt

bull Expose object nsDOMClassInfocppnsDOMClassInfoClassesh

INTERFACES

Attribute

PrintStateCallback

canvasmozPrintCallback =

function(obj) var ctx = objcontext ctxfillRect(0 0 100 100) objdone()

INTERFACES[scriptable uuid(a7062fca-41c6-4520-b777-3bb30fd77273)]interface nsIDOMHTMLCanvasElement nsIDOMHTMLElement []

A Mozilla-only callback that is called during the printing process attribute nsIPrintCallback mozPrintCallback

Attrib

ute

Callb

ack

[scriptable function uuid(8d5fb8a0-7782-11e1-b0c4-0800200c9a66)]interface nsIPrintCallback nsISupports void render(in nsIDOMMozCanvasPrintState ctx)

[scriptable builtinclass uuid(8d5fb8a0-7782-11e1-b0c4-0800200c9a67)]interface nsIDOMMozCanvasPrintState nsISupports A canvas rendering context readonly attribute nsISupports context

To be called when rendering to the context is done void done()

PrintS

tate

Taken frombug 745025

class nsHTMLCanvasPrintState public nsIDOMMozCanvasPrintStatepublic 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() [] return NS_OK

[]

Taken frombug 745025

MEMORY MANAGEMENTbull C++ doesnrsquot have a garbage collector (

bull In Gecko Reference counting amp cycle collector

bull Reference counting

bull nsCOMPtr (for interfaces) nsREFPtr

bull use getter_AddRefs

bull NS_IF_ADDREF amp NS_IF_RELEASE

MEMORY MANAGEMENT

bull Reference counting doesnrsquot work always

bull Make use of Geckorsquos cycle collector

bull Better cycle then maybe leak

DEBUGGING

bull Make sure to have a debug build

bull Enable logging (example)

bull Watch for assertion in logs

bull Insert printfs

bull There is documentation how to use debugger

OVERVIEW OF SOME TREES

bull Frame Tree Frames on page

bull Content Tree Content going with frames

bull View Tree Connecting views

MAKE YOUR WORK LAND

TESTS TESTS TESTS

bull Reftests

bull Crashtests

bull XPCShell Tests

bull Mochitests

bull JS tests

bull Compiled code tests -(

bull Marionette tests

DIFFERENT TYPE OF TESTS

MOCHITEST

Text

bullpathtoobjdir $ TEST_PATH=domcontactstests make mochitest-plain

bullpathtoobjdir $ TEST_PATH=domcontactsteststest_contactshtml make mochitest-plain

TIME FOR REVIEWbull Make sure the patch is formatted according to the guidelines

bull 8 lines of context

bull correct committer info (name + email)

bull correct checking message

bull When uploading a new version

bull address all review comments

bull obsolete the old patch

bull run tests again

REVIEWbull Make sure your patch is clean

bull Patch should be green on try-push

bull WIP State whatrsquos workingwhat notwhatrsquos next

bull Review might take some time (~1 week)

bull If longer ping person switch review person

bull Except r- donrsquot worry

Q amp A

THINGS TO HACK ON

bull Implement vwvhvminvmax

bull dirname DOM attribute on form controls

bull Implement FileSaver

Page 6: Implementing new WebAPIs

GENERAL INTRODUCTION

bull Need to build Firefox

bull Run build

bull LinuxWindows objdirdistbinfirefox

bullOSX objdirdistAppNameappContentsMacOSfirefox

bulloptions -ProfileManager -no-remote

GENERAL INTRODUCTION

GENERAL INTRODUCTION

bull Donrsquot get lost in the details

bull Ask for an implementation outline

bull There is documentation overview

bull Uumlber-Weapon Ask for help

bull IRC httpswikimozillaorgIRC developers

bull Mailing list httpslistsmozillaorglistinfo 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

bull whenever you do communication

bull try to be precise

bull give reasoning to your arguments

bull get only short answer - donrsquot take it wrong people are really busy

bull dump whatever you have (crashbackpatch)

GENERAL INTRODUCTION

bull donrsquot be afraid to ping people

bull might get hint to ping someone else

bull tell people youre new to hacking JSGecko

bull lookask for bugs that do similar things you try to solve

HTTPSMXRMOZILLAORG

FIREFOX OS WEBAPI

Telephony

VibratorContacts

Settings

Battery

PowerIdle

Bluetooth

many more to come

Browser

Webapps

httpswikimozillaorgWebAPI

Wifi

INTERFACE + IMPLEMENTATION

IT ALL STARTS WITH AN INTERFACEXPIDL VS WEBIDL

XPIDL VS WEBIDL

interface EventTarget void addEventListener(DOMString type EventListener listener optional boolean capture = false optional boolean wantsUntrusted = null) void removeEventListener(DOMString type EventListener listener optional boolean capture = false) boolean dispatchEvent(Event event)

[scriptable builtinclass uuid(5a8294df-ffe4-48e5-803f-f57bebc29289)]interface nsIDOMScreen nsIDOMEventTarget readonly attribute long top readonly attribute DOMString mozOrientation [implicit_jscontext] attribute jsval onmozorientationchange

boolean mozLockOrientation(in DOMString orientation) void mozUnlockOrientation()

httpsdevelopermozillaorgen-USdocsMozillaWebIDL_bindingshttpsdevelopermozillaorgen-USdocsXPIDL

MAPPING JS VS C++

bull Read other APIs

bull Interfaces are defined in dominterfaces

bull Implementations mostly in dom content

bull c++ implementations use common inheritance

bull JS implementations use manifest file

TIME TO FILE A BUGBugzilla DOMDevice Interfaces

HOW TO IMPLEMENT JS

WHY IN JSbull Prototyping

bull Lower entry point

bull WebDevs know JS

bull Also better for understanding

INTERFACE EXAMPLE

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

httpsbugzillamozillaorgshow_bugcgiid=674720

For example dominterfaceshelloworldnsIHelloWorldidl

HELLOWORLDMANIFEST

component f5181640-89e8-11e1-b0c4-0800200c9444 HelloWorldjscontract mozillaorghelloWorld1 f5181640-89e8-11e1-b0c4-0800200c9444category JavaScript-navigator-property mozHelloWorld mozillaorghelloWorld1

For example domhelloworldHelloWorldmanifest

HELLOWORLDJS

Text

const Cc = Componentsclassesconst Ci = Componentsinterfacesconst Cu = Componentsutils

Cuimport(resourcegremodulesXPCOMUtilsjsm)

function HelloWorld()

HelloWorldprototype =

init function init(aWindow)

sayHello function sayHello(aName) dump(Hello + aName + n)

classID ComponentsID(d88af7e0-a45f-11e1-b3dd-0800200c9444) QueryInterface XPCOMUtilsgenerateQI([ComponentsinterfacesnsIDOMHelloWorld])

classInfo XPCOMUtilsgenerateCI(classID ComponentsID(d88af7e0-a45f-11e1-b3dd-0800200c9444) contractID mozillaorghelloWorld1 classDescription HelloWorld interfaces [ComponentsinterfacesnsIDOMHelloWorld CinsIDOMGlobalPropertyInitializer] flags CinsIClassInfoDOM_OBJECT)

const NSGetFactory = XPCOMUtilsgenerateNSGetFactory([HelloWorld])

For example domhelloworldHelloWorldjs

BOILERPLATE

bull Makefiles

bull Manifest

bull Packaging

bull Module Loading

bull Access Permission

EXPOSEDPROPS

let foo = new Foo()

Fooprototype = __exposedProps__ name rw

FIREFOX OS PROCESS MODELbull Parent - Child Processes

bull Only one parent

bull Browser is in parent content pages are children

bull Nested process structure not possible (yet)

bull Parent is trusted

bull Child can be compromised

bull Security critical code has to run in parent

SYSTEM MESSAGE MANAGERbull Use for child-parent communication

bull Child

bull Parent

childProcessMessageManagersendAsyncMessage(message-name foo 2)

var response = sendSyncMessage(message-name foo 1)

receiveMessage function(aMessage) switch (aMessagename) [] parentProcessMessageManagersendAsynMessage(ldquoreturn-message-namerdquo [])

DOMREQUESTS

var pending = navigatormozAppsinstall(manifestUrl)pendingonsuccess = function () Save the App object that is returned var appRecord = thisresult alert(Installation successful)pendingonerror = function () Display the name of the error alert(Install failed error + thiserrorname)

PERMISSIONS

HOW TO IMPLEMENT C++

MAPPING JSC++

bull IDL files rarr JS amp C++

bull JS ctxlineWidth C++ ctxGetLineWidth(float width)

bull Need to implement C++ class for interface

bull NS_IMETHODIMP returns NS_ltstatusgt

bull Expose object nsDOMClassInfocppnsDOMClassInfoClassesh

INTERFACES

Attribute

PrintStateCallback

canvasmozPrintCallback =

function(obj) var ctx = objcontext ctxfillRect(0 0 100 100) objdone()

INTERFACES[scriptable uuid(a7062fca-41c6-4520-b777-3bb30fd77273)]interface nsIDOMHTMLCanvasElement nsIDOMHTMLElement []

A Mozilla-only callback that is called during the printing process attribute nsIPrintCallback mozPrintCallback

Attrib

ute

Callb

ack

[scriptable function uuid(8d5fb8a0-7782-11e1-b0c4-0800200c9a66)]interface nsIPrintCallback nsISupports void render(in nsIDOMMozCanvasPrintState ctx)

[scriptable builtinclass uuid(8d5fb8a0-7782-11e1-b0c4-0800200c9a67)]interface nsIDOMMozCanvasPrintState nsISupports A canvas rendering context readonly attribute nsISupports context

To be called when rendering to the context is done void done()

PrintS

tate

Taken frombug 745025

class nsHTMLCanvasPrintState public nsIDOMMozCanvasPrintStatepublic 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() [] return NS_OK

[]

Taken frombug 745025

MEMORY MANAGEMENTbull C++ doesnrsquot have a garbage collector (

bull In Gecko Reference counting amp cycle collector

bull Reference counting

bull nsCOMPtr (for interfaces) nsREFPtr

bull use getter_AddRefs

bull NS_IF_ADDREF amp NS_IF_RELEASE

MEMORY MANAGEMENT

bull Reference counting doesnrsquot work always

bull Make use of Geckorsquos cycle collector

bull Better cycle then maybe leak

DEBUGGING

bull Make sure to have a debug build

bull Enable logging (example)

bull Watch for assertion in logs

bull Insert printfs

bull There is documentation how to use debugger

OVERVIEW OF SOME TREES

bull Frame Tree Frames on page

bull Content Tree Content going with frames

bull View Tree Connecting views

MAKE YOUR WORK LAND

TESTS TESTS TESTS

bull Reftests

bull Crashtests

bull XPCShell Tests

bull Mochitests

bull JS tests

bull Compiled code tests -(

bull Marionette tests

DIFFERENT TYPE OF TESTS

MOCHITEST

Text

bullpathtoobjdir $ TEST_PATH=domcontactstests make mochitest-plain

bullpathtoobjdir $ TEST_PATH=domcontactsteststest_contactshtml make mochitest-plain

TIME FOR REVIEWbull Make sure the patch is formatted according to the guidelines

bull 8 lines of context

bull correct committer info (name + email)

bull correct checking message

bull When uploading a new version

bull address all review comments

bull obsolete the old patch

bull run tests again

REVIEWbull Make sure your patch is clean

bull Patch should be green on try-push

bull WIP State whatrsquos workingwhat notwhatrsquos next

bull Review might take some time (~1 week)

bull If longer ping person switch review person

bull Except r- donrsquot worry

Q amp A

THINGS TO HACK ON

bull Implement vwvhvminvmax

bull dirname DOM attribute on form controls

bull Implement FileSaver

Page 7: Implementing new WebAPIs

GENERAL INTRODUCTION

GENERAL INTRODUCTION

bull Donrsquot get lost in the details

bull Ask for an implementation outline

bull There is documentation overview

bull Uumlber-Weapon Ask for help

bull IRC httpswikimozillaorgIRC developers

bull Mailing list httpslistsmozillaorglistinfo 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

bull whenever you do communication

bull try to be precise

bull give reasoning to your arguments

bull get only short answer - donrsquot take it wrong people are really busy

bull dump whatever you have (crashbackpatch)

GENERAL INTRODUCTION

bull donrsquot be afraid to ping people

bull might get hint to ping someone else

bull tell people youre new to hacking JSGecko

bull lookask for bugs that do similar things you try to solve

HTTPSMXRMOZILLAORG

FIREFOX OS WEBAPI

Telephony

VibratorContacts

Settings

Battery

PowerIdle

Bluetooth

many more to come

Browser

Webapps

httpswikimozillaorgWebAPI

Wifi

INTERFACE + IMPLEMENTATION

IT ALL STARTS WITH AN INTERFACEXPIDL VS WEBIDL

XPIDL VS WEBIDL

interface EventTarget void addEventListener(DOMString type EventListener listener optional boolean capture = false optional boolean wantsUntrusted = null) void removeEventListener(DOMString type EventListener listener optional boolean capture = false) boolean dispatchEvent(Event event)

[scriptable builtinclass uuid(5a8294df-ffe4-48e5-803f-f57bebc29289)]interface nsIDOMScreen nsIDOMEventTarget readonly attribute long top readonly attribute DOMString mozOrientation [implicit_jscontext] attribute jsval onmozorientationchange

boolean mozLockOrientation(in DOMString orientation) void mozUnlockOrientation()

httpsdevelopermozillaorgen-USdocsMozillaWebIDL_bindingshttpsdevelopermozillaorgen-USdocsXPIDL

MAPPING JS VS C++

bull Read other APIs

bull Interfaces are defined in dominterfaces

bull Implementations mostly in dom content

bull c++ implementations use common inheritance

bull JS implementations use manifest file

TIME TO FILE A BUGBugzilla DOMDevice Interfaces

HOW TO IMPLEMENT JS

WHY IN JSbull Prototyping

bull Lower entry point

bull WebDevs know JS

bull Also better for understanding

INTERFACE EXAMPLE

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

httpsbugzillamozillaorgshow_bugcgiid=674720

For example dominterfaceshelloworldnsIHelloWorldidl

HELLOWORLDMANIFEST

component f5181640-89e8-11e1-b0c4-0800200c9444 HelloWorldjscontract mozillaorghelloWorld1 f5181640-89e8-11e1-b0c4-0800200c9444category JavaScript-navigator-property mozHelloWorld mozillaorghelloWorld1

For example domhelloworldHelloWorldmanifest

HELLOWORLDJS

Text

const Cc = Componentsclassesconst Ci = Componentsinterfacesconst Cu = Componentsutils

Cuimport(resourcegremodulesXPCOMUtilsjsm)

function HelloWorld()

HelloWorldprototype =

init function init(aWindow)

sayHello function sayHello(aName) dump(Hello + aName + n)

classID ComponentsID(d88af7e0-a45f-11e1-b3dd-0800200c9444) QueryInterface XPCOMUtilsgenerateQI([ComponentsinterfacesnsIDOMHelloWorld])

classInfo XPCOMUtilsgenerateCI(classID ComponentsID(d88af7e0-a45f-11e1-b3dd-0800200c9444) contractID mozillaorghelloWorld1 classDescription HelloWorld interfaces [ComponentsinterfacesnsIDOMHelloWorld CinsIDOMGlobalPropertyInitializer] flags CinsIClassInfoDOM_OBJECT)

const NSGetFactory = XPCOMUtilsgenerateNSGetFactory([HelloWorld])

For example domhelloworldHelloWorldjs

BOILERPLATE

bull Makefiles

bull Manifest

bull Packaging

bull Module Loading

bull Access Permission

EXPOSEDPROPS

let foo = new Foo()

Fooprototype = __exposedProps__ name rw

FIREFOX OS PROCESS MODELbull Parent - Child Processes

bull Only one parent

bull Browser is in parent content pages are children

bull Nested process structure not possible (yet)

bull Parent is trusted

bull Child can be compromised

bull Security critical code has to run in parent

SYSTEM MESSAGE MANAGERbull Use for child-parent communication

bull Child

bull Parent

childProcessMessageManagersendAsyncMessage(message-name foo 2)

var response = sendSyncMessage(message-name foo 1)

receiveMessage function(aMessage) switch (aMessagename) [] parentProcessMessageManagersendAsynMessage(ldquoreturn-message-namerdquo [])

DOMREQUESTS

var pending = navigatormozAppsinstall(manifestUrl)pendingonsuccess = function () Save the App object that is returned var appRecord = thisresult alert(Installation successful)pendingonerror = function () Display the name of the error alert(Install failed error + thiserrorname)

PERMISSIONS

HOW TO IMPLEMENT C++

MAPPING JSC++

bull IDL files rarr JS amp C++

bull JS ctxlineWidth C++ ctxGetLineWidth(float width)

bull Need to implement C++ class for interface

bull NS_IMETHODIMP returns NS_ltstatusgt

bull Expose object nsDOMClassInfocppnsDOMClassInfoClassesh

INTERFACES

Attribute

PrintStateCallback

canvasmozPrintCallback =

function(obj) var ctx = objcontext ctxfillRect(0 0 100 100) objdone()

INTERFACES[scriptable uuid(a7062fca-41c6-4520-b777-3bb30fd77273)]interface nsIDOMHTMLCanvasElement nsIDOMHTMLElement []

A Mozilla-only callback that is called during the printing process attribute nsIPrintCallback mozPrintCallback

Attrib

ute

Callb

ack

[scriptable function uuid(8d5fb8a0-7782-11e1-b0c4-0800200c9a66)]interface nsIPrintCallback nsISupports void render(in nsIDOMMozCanvasPrintState ctx)

[scriptable builtinclass uuid(8d5fb8a0-7782-11e1-b0c4-0800200c9a67)]interface nsIDOMMozCanvasPrintState nsISupports A canvas rendering context readonly attribute nsISupports context

To be called when rendering to the context is done void done()

PrintS

tate

Taken frombug 745025

class nsHTMLCanvasPrintState public nsIDOMMozCanvasPrintStatepublic 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() [] return NS_OK

[]

Taken frombug 745025

MEMORY MANAGEMENTbull C++ doesnrsquot have a garbage collector (

bull In Gecko Reference counting amp cycle collector

bull Reference counting

bull nsCOMPtr (for interfaces) nsREFPtr

bull use getter_AddRefs

bull NS_IF_ADDREF amp NS_IF_RELEASE

MEMORY MANAGEMENT

bull Reference counting doesnrsquot work always

bull Make use of Geckorsquos cycle collector

bull Better cycle then maybe leak

DEBUGGING

bull Make sure to have a debug build

bull Enable logging (example)

bull Watch for assertion in logs

bull Insert printfs

bull There is documentation how to use debugger

OVERVIEW OF SOME TREES

bull Frame Tree Frames on page

bull Content Tree Content going with frames

bull View Tree Connecting views

MAKE YOUR WORK LAND

TESTS TESTS TESTS

bull Reftests

bull Crashtests

bull XPCShell Tests

bull Mochitests

bull JS tests

bull Compiled code tests -(

bull Marionette tests

DIFFERENT TYPE OF TESTS

MOCHITEST

Text

bullpathtoobjdir $ TEST_PATH=domcontactstests make mochitest-plain

bullpathtoobjdir $ TEST_PATH=domcontactsteststest_contactshtml make mochitest-plain

TIME FOR REVIEWbull Make sure the patch is formatted according to the guidelines

bull 8 lines of context

bull correct committer info (name + email)

bull correct checking message

bull When uploading a new version

bull address all review comments

bull obsolete the old patch

bull run tests again

REVIEWbull Make sure your patch is clean

bull Patch should be green on try-push

bull WIP State whatrsquos workingwhat notwhatrsquos next

bull Review might take some time (~1 week)

bull If longer ping person switch review person

bull Except r- donrsquot worry

Q amp A

THINGS TO HACK ON

bull Implement vwvhvminvmax

bull dirname DOM attribute on form controls

bull Implement FileSaver

Page 8: Implementing new WebAPIs

GENERAL INTRODUCTION

bull Donrsquot get lost in the details

bull Ask for an implementation outline

bull There is documentation overview

bull Uumlber-Weapon Ask for help

bull IRC httpswikimozillaorgIRC developers

bull Mailing list httpslistsmozillaorglistinfo 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

bull whenever you do communication

bull try to be precise

bull give reasoning to your arguments

bull get only short answer - donrsquot take it wrong people are really busy

bull dump whatever you have (crashbackpatch)

GENERAL INTRODUCTION

bull donrsquot be afraid to ping people

bull might get hint to ping someone else

bull tell people youre new to hacking JSGecko

bull lookask for bugs that do similar things you try to solve

HTTPSMXRMOZILLAORG

FIREFOX OS WEBAPI

Telephony

VibratorContacts

Settings

Battery

PowerIdle

Bluetooth

many more to come

Browser

Webapps

httpswikimozillaorgWebAPI

Wifi

INTERFACE + IMPLEMENTATION

IT ALL STARTS WITH AN INTERFACEXPIDL VS WEBIDL

XPIDL VS WEBIDL

interface EventTarget void addEventListener(DOMString type EventListener listener optional boolean capture = false optional boolean wantsUntrusted = null) void removeEventListener(DOMString type EventListener listener optional boolean capture = false) boolean dispatchEvent(Event event)

[scriptable builtinclass uuid(5a8294df-ffe4-48e5-803f-f57bebc29289)]interface nsIDOMScreen nsIDOMEventTarget readonly attribute long top readonly attribute DOMString mozOrientation [implicit_jscontext] attribute jsval onmozorientationchange

boolean mozLockOrientation(in DOMString orientation) void mozUnlockOrientation()

httpsdevelopermozillaorgen-USdocsMozillaWebIDL_bindingshttpsdevelopermozillaorgen-USdocsXPIDL

MAPPING JS VS C++

bull Read other APIs

bull Interfaces are defined in dominterfaces

bull Implementations mostly in dom content

bull c++ implementations use common inheritance

bull JS implementations use manifest file

TIME TO FILE A BUGBugzilla DOMDevice Interfaces

HOW TO IMPLEMENT JS

WHY IN JSbull Prototyping

bull Lower entry point

bull WebDevs know JS

bull Also better for understanding

INTERFACE EXAMPLE

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

httpsbugzillamozillaorgshow_bugcgiid=674720

For example dominterfaceshelloworldnsIHelloWorldidl

HELLOWORLDMANIFEST

component f5181640-89e8-11e1-b0c4-0800200c9444 HelloWorldjscontract mozillaorghelloWorld1 f5181640-89e8-11e1-b0c4-0800200c9444category JavaScript-navigator-property mozHelloWorld mozillaorghelloWorld1

For example domhelloworldHelloWorldmanifest

HELLOWORLDJS

Text

const Cc = Componentsclassesconst Ci = Componentsinterfacesconst Cu = Componentsutils

Cuimport(resourcegremodulesXPCOMUtilsjsm)

function HelloWorld()

HelloWorldprototype =

init function init(aWindow)

sayHello function sayHello(aName) dump(Hello + aName + n)

classID ComponentsID(d88af7e0-a45f-11e1-b3dd-0800200c9444) QueryInterface XPCOMUtilsgenerateQI([ComponentsinterfacesnsIDOMHelloWorld])

classInfo XPCOMUtilsgenerateCI(classID ComponentsID(d88af7e0-a45f-11e1-b3dd-0800200c9444) contractID mozillaorghelloWorld1 classDescription HelloWorld interfaces [ComponentsinterfacesnsIDOMHelloWorld CinsIDOMGlobalPropertyInitializer] flags CinsIClassInfoDOM_OBJECT)

const NSGetFactory = XPCOMUtilsgenerateNSGetFactory([HelloWorld])

For example domhelloworldHelloWorldjs

BOILERPLATE

bull Makefiles

bull Manifest

bull Packaging

bull Module Loading

bull Access Permission

EXPOSEDPROPS

let foo = new Foo()

Fooprototype = __exposedProps__ name rw

FIREFOX OS PROCESS MODELbull Parent - Child Processes

bull Only one parent

bull Browser is in parent content pages are children

bull Nested process structure not possible (yet)

bull Parent is trusted

bull Child can be compromised

bull Security critical code has to run in parent

SYSTEM MESSAGE MANAGERbull Use for child-parent communication

bull Child

bull Parent

childProcessMessageManagersendAsyncMessage(message-name foo 2)

var response = sendSyncMessage(message-name foo 1)

receiveMessage function(aMessage) switch (aMessagename) [] parentProcessMessageManagersendAsynMessage(ldquoreturn-message-namerdquo [])

DOMREQUESTS

var pending = navigatormozAppsinstall(manifestUrl)pendingonsuccess = function () Save the App object that is returned var appRecord = thisresult alert(Installation successful)pendingonerror = function () Display the name of the error alert(Install failed error + thiserrorname)

PERMISSIONS

HOW TO IMPLEMENT C++

MAPPING JSC++

bull IDL files rarr JS amp C++

bull JS ctxlineWidth C++ ctxGetLineWidth(float width)

bull Need to implement C++ class for interface

bull NS_IMETHODIMP returns NS_ltstatusgt

bull Expose object nsDOMClassInfocppnsDOMClassInfoClassesh

INTERFACES

Attribute

PrintStateCallback

canvasmozPrintCallback =

function(obj) var ctx = objcontext ctxfillRect(0 0 100 100) objdone()

INTERFACES[scriptable uuid(a7062fca-41c6-4520-b777-3bb30fd77273)]interface nsIDOMHTMLCanvasElement nsIDOMHTMLElement []

A Mozilla-only callback that is called during the printing process attribute nsIPrintCallback mozPrintCallback

Attrib

ute

Callb

ack

[scriptable function uuid(8d5fb8a0-7782-11e1-b0c4-0800200c9a66)]interface nsIPrintCallback nsISupports void render(in nsIDOMMozCanvasPrintState ctx)

[scriptable builtinclass uuid(8d5fb8a0-7782-11e1-b0c4-0800200c9a67)]interface nsIDOMMozCanvasPrintState nsISupports A canvas rendering context readonly attribute nsISupports context

To be called when rendering to the context is done void done()

PrintS

tate

Taken frombug 745025

class nsHTMLCanvasPrintState public nsIDOMMozCanvasPrintStatepublic 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() [] return NS_OK

[]

Taken frombug 745025

MEMORY MANAGEMENTbull C++ doesnrsquot have a garbage collector (

bull In Gecko Reference counting amp cycle collector

bull Reference counting

bull nsCOMPtr (for interfaces) nsREFPtr

bull use getter_AddRefs

bull NS_IF_ADDREF amp NS_IF_RELEASE

MEMORY MANAGEMENT

bull Reference counting doesnrsquot work always

bull Make use of Geckorsquos cycle collector

bull Better cycle then maybe leak

DEBUGGING

bull Make sure to have a debug build

bull Enable logging (example)

bull Watch for assertion in logs

bull Insert printfs

bull There is documentation how to use debugger

OVERVIEW OF SOME TREES

bull Frame Tree Frames on page

bull Content Tree Content going with frames

bull View Tree Connecting views

MAKE YOUR WORK LAND

TESTS TESTS TESTS

bull Reftests

bull Crashtests

bull XPCShell Tests

bull Mochitests

bull JS tests

bull Compiled code tests -(

bull Marionette tests

DIFFERENT TYPE OF TESTS

MOCHITEST

Text

bullpathtoobjdir $ TEST_PATH=domcontactstests make mochitest-plain

bullpathtoobjdir $ TEST_PATH=domcontactsteststest_contactshtml make mochitest-plain

TIME FOR REVIEWbull Make sure the patch is formatted according to the guidelines

bull 8 lines of context

bull correct committer info (name + email)

bull correct checking message

bull When uploading a new version

bull address all review comments

bull obsolete the old patch

bull run tests again

REVIEWbull Make sure your patch is clean

bull Patch should be green on try-push

bull WIP State whatrsquos workingwhat notwhatrsquos next

bull Review might take some time (~1 week)

bull If longer ping person switch review person

bull Except r- donrsquot worry

Q amp A

THINGS TO HACK ON

bull Implement vwvhvminvmax

bull dirname DOM attribute on form controls

bull Implement FileSaver

Page 9: Implementing new WebAPIs

FRIENDLY PEOPLE TO PING ON IRC

khuey (Kyle Huey)

ehsan (Ehsan Akhgari)

bholley (Bobby Holley)

jdm (Josh Matthews)

dholbert (Daniel Holbert)

Ms2ger ()

GENERAL INTRODUCTION

bull whenever you do communication

bull try to be precise

bull give reasoning to your arguments

bull get only short answer - donrsquot take it wrong people are really busy

bull dump whatever you have (crashbackpatch)

GENERAL INTRODUCTION

bull donrsquot be afraid to ping people

bull might get hint to ping someone else

bull tell people youre new to hacking JSGecko

bull lookask for bugs that do similar things you try to solve

HTTPSMXRMOZILLAORG

FIREFOX OS WEBAPI

Telephony

VibratorContacts

Settings

Battery

PowerIdle

Bluetooth

many more to come

Browser

Webapps

httpswikimozillaorgWebAPI

Wifi

INTERFACE + IMPLEMENTATION

IT ALL STARTS WITH AN INTERFACEXPIDL VS WEBIDL

XPIDL VS WEBIDL

interface EventTarget void addEventListener(DOMString type EventListener listener optional boolean capture = false optional boolean wantsUntrusted = null) void removeEventListener(DOMString type EventListener listener optional boolean capture = false) boolean dispatchEvent(Event event)

[scriptable builtinclass uuid(5a8294df-ffe4-48e5-803f-f57bebc29289)]interface nsIDOMScreen nsIDOMEventTarget readonly attribute long top readonly attribute DOMString mozOrientation [implicit_jscontext] attribute jsval onmozorientationchange

boolean mozLockOrientation(in DOMString orientation) void mozUnlockOrientation()

httpsdevelopermozillaorgen-USdocsMozillaWebIDL_bindingshttpsdevelopermozillaorgen-USdocsXPIDL

MAPPING JS VS C++

bull Read other APIs

bull Interfaces are defined in dominterfaces

bull Implementations mostly in dom content

bull c++ implementations use common inheritance

bull JS implementations use manifest file

TIME TO FILE A BUGBugzilla DOMDevice Interfaces

HOW TO IMPLEMENT JS

WHY IN JSbull Prototyping

bull Lower entry point

bull WebDevs know JS

bull Also better for understanding

INTERFACE EXAMPLE

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

httpsbugzillamozillaorgshow_bugcgiid=674720

For example dominterfaceshelloworldnsIHelloWorldidl

HELLOWORLDMANIFEST

component f5181640-89e8-11e1-b0c4-0800200c9444 HelloWorldjscontract mozillaorghelloWorld1 f5181640-89e8-11e1-b0c4-0800200c9444category JavaScript-navigator-property mozHelloWorld mozillaorghelloWorld1

For example domhelloworldHelloWorldmanifest

HELLOWORLDJS

Text

const Cc = Componentsclassesconst Ci = Componentsinterfacesconst Cu = Componentsutils

Cuimport(resourcegremodulesXPCOMUtilsjsm)

function HelloWorld()

HelloWorldprototype =

init function init(aWindow)

sayHello function sayHello(aName) dump(Hello + aName + n)

classID ComponentsID(d88af7e0-a45f-11e1-b3dd-0800200c9444) QueryInterface XPCOMUtilsgenerateQI([ComponentsinterfacesnsIDOMHelloWorld])

classInfo XPCOMUtilsgenerateCI(classID ComponentsID(d88af7e0-a45f-11e1-b3dd-0800200c9444) contractID mozillaorghelloWorld1 classDescription HelloWorld interfaces [ComponentsinterfacesnsIDOMHelloWorld CinsIDOMGlobalPropertyInitializer] flags CinsIClassInfoDOM_OBJECT)

const NSGetFactory = XPCOMUtilsgenerateNSGetFactory([HelloWorld])

For example domhelloworldHelloWorldjs

BOILERPLATE

bull Makefiles

bull Manifest

bull Packaging

bull Module Loading

bull Access Permission

EXPOSEDPROPS

let foo = new Foo()

Fooprototype = __exposedProps__ name rw

FIREFOX OS PROCESS MODELbull Parent - Child Processes

bull Only one parent

bull Browser is in parent content pages are children

bull Nested process structure not possible (yet)

bull Parent is trusted

bull Child can be compromised

bull Security critical code has to run in parent

SYSTEM MESSAGE MANAGERbull Use for child-parent communication

bull Child

bull Parent

childProcessMessageManagersendAsyncMessage(message-name foo 2)

var response = sendSyncMessage(message-name foo 1)

receiveMessage function(aMessage) switch (aMessagename) [] parentProcessMessageManagersendAsynMessage(ldquoreturn-message-namerdquo [])

DOMREQUESTS

var pending = navigatormozAppsinstall(manifestUrl)pendingonsuccess = function () Save the App object that is returned var appRecord = thisresult alert(Installation successful)pendingonerror = function () Display the name of the error alert(Install failed error + thiserrorname)

PERMISSIONS

HOW TO IMPLEMENT C++

MAPPING JSC++

bull IDL files rarr JS amp C++

bull JS ctxlineWidth C++ ctxGetLineWidth(float width)

bull Need to implement C++ class for interface

bull NS_IMETHODIMP returns NS_ltstatusgt

bull Expose object nsDOMClassInfocppnsDOMClassInfoClassesh

INTERFACES

Attribute

PrintStateCallback

canvasmozPrintCallback =

function(obj) var ctx = objcontext ctxfillRect(0 0 100 100) objdone()

INTERFACES[scriptable uuid(a7062fca-41c6-4520-b777-3bb30fd77273)]interface nsIDOMHTMLCanvasElement nsIDOMHTMLElement []

A Mozilla-only callback that is called during the printing process attribute nsIPrintCallback mozPrintCallback

Attrib

ute

Callb

ack

[scriptable function uuid(8d5fb8a0-7782-11e1-b0c4-0800200c9a66)]interface nsIPrintCallback nsISupports void render(in nsIDOMMozCanvasPrintState ctx)

[scriptable builtinclass uuid(8d5fb8a0-7782-11e1-b0c4-0800200c9a67)]interface nsIDOMMozCanvasPrintState nsISupports A canvas rendering context readonly attribute nsISupports context

To be called when rendering to the context is done void done()

PrintS

tate

Taken frombug 745025

class nsHTMLCanvasPrintState public nsIDOMMozCanvasPrintStatepublic 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() [] return NS_OK

[]

Taken frombug 745025

MEMORY MANAGEMENTbull C++ doesnrsquot have a garbage collector (

bull In Gecko Reference counting amp cycle collector

bull Reference counting

bull nsCOMPtr (for interfaces) nsREFPtr

bull use getter_AddRefs

bull NS_IF_ADDREF amp NS_IF_RELEASE

MEMORY MANAGEMENT

bull Reference counting doesnrsquot work always

bull Make use of Geckorsquos cycle collector

bull Better cycle then maybe leak

DEBUGGING

bull Make sure to have a debug build

bull Enable logging (example)

bull Watch for assertion in logs

bull Insert printfs

bull There is documentation how to use debugger

OVERVIEW OF SOME TREES

bull Frame Tree Frames on page

bull Content Tree Content going with frames

bull View Tree Connecting views

MAKE YOUR WORK LAND

TESTS TESTS TESTS

bull Reftests

bull Crashtests

bull XPCShell Tests

bull Mochitests

bull JS tests

bull Compiled code tests -(

bull Marionette tests

DIFFERENT TYPE OF TESTS

MOCHITEST

Text

bullpathtoobjdir $ TEST_PATH=domcontactstests make mochitest-plain

bullpathtoobjdir $ TEST_PATH=domcontactsteststest_contactshtml make mochitest-plain

TIME FOR REVIEWbull Make sure the patch is formatted according to the guidelines

bull 8 lines of context

bull correct committer info (name + email)

bull correct checking message

bull When uploading a new version

bull address all review comments

bull obsolete the old patch

bull run tests again

REVIEWbull Make sure your patch is clean

bull Patch should be green on try-push

bull WIP State whatrsquos workingwhat notwhatrsquos next

bull Review might take some time (~1 week)

bull If longer ping person switch review person

bull Except r- donrsquot worry

Q amp A

THINGS TO HACK ON

bull Implement vwvhvminvmax

bull dirname DOM attribute on form controls

bull Implement FileSaver

Page 10: Implementing new WebAPIs

khuey (Kyle Huey)

ehsan (Ehsan Akhgari)

bholley (Bobby Holley)

jdm (Josh Matthews)

dholbert (Daniel Holbert)

Ms2ger ()

GENERAL INTRODUCTION

bull whenever you do communication

bull try to be precise

bull give reasoning to your arguments

bull get only short answer - donrsquot take it wrong people are really busy

bull dump whatever you have (crashbackpatch)

GENERAL INTRODUCTION

bull donrsquot be afraid to ping people

bull might get hint to ping someone else

bull tell people youre new to hacking JSGecko

bull lookask for bugs that do similar things you try to solve

HTTPSMXRMOZILLAORG

FIREFOX OS WEBAPI

Telephony

VibratorContacts

Settings

Battery

PowerIdle

Bluetooth

many more to come

Browser

Webapps

httpswikimozillaorgWebAPI

Wifi

INTERFACE + IMPLEMENTATION

IT ALL STARTS WITH AN INTERFACEXPIDL VS WEBIDL

XPIDL VS WEBIDL

interface EventTarget void addEventListener(DOMString type EventListener listener optional boolean capture = false optional boolean wantsUntrusted = null) void removeEventListener(DOMString type EventListener listener optional boolean capture = false) boolean dispatchEvent(Event event)

[scriptable builtinclass uuid(5a8294df-ffe4-48e5-803f-f57bebc29289)]interface nsIDOMScreen nsIDOMEventTarget readonly attribute long top readonly attribute DOMString mozOrientation [implicit_jscontext] attribute jsval onmozorientationchange

boolean mozLockOrientation(in DOMString orientation) void mozUnlockOrientation()

httpsdevelopermozillaorgen-USdocsMozillaWebIDL_bindingshttpsdevelopermozillaorgen-USdocsXPIDL

MAPPING JS VS C++

bull Read other APIs

bull Interfaces are defined in dominterfaces

bull Implementations mostly in dom content

bull c++ implementations use common inheritance

bull JS implementations use manifest file

TIME TO FILE A BUGBugzilla DOMDevice Interfaces

HOW TO IMPLEMENT JS

WHY IN JSbull Prototyping

bull Lower entry point

bull WebDevs know JS

bull Also better for understanding

INTERFACE EXAMPLE

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

httpsbugzillamozillaorgshow_bugcgiid=674720

For example dominterfaceshelloworldnsIHelloWorldidl

HELLOWORLDMANIFEST

component f5181640-89e8-11e1-b0c4-0800200c9444 HelloWorldjscontract mozillaorghelloWorld1 f5181640-89e8-11e1-b0c4-0800200c9444category JavaScript-navigator-property mozHelloWorld mozillaorghelloWorld1

For example domhelloworldHelloWorldmanifest

HELLOWORLDJS

Text

const Cc = Componentsclassesconst Ci = Componentsinterfacesconst Cu = Componentsutils

Cuimport(resourcegremodulesXPCOMUtilsjsm)

function HelloWorld()

HelloWorldprototype =

init function init(aWindow)

sayHello function sayHello(aName) dump(Hello + aName + n)

classID ComponentsID(d88af7e0-a45f-11e1-b3dd-0800200c9444) QueryInterface XPCOMUtilsgenerateQI([ComponentsinterfacesnsIDOMHelloWorld])

classInfo XPCOMUtilsgenerateCI(classID ComponentsID(d88af7e0-a45f-11e1-b3dd-0800200c9444) contractID mozillaorghelloWorld1 classDescription HelloWorld interfaces [ComponentsinterfacesnsIDOMHelloWorld CinsIDOMGlobalPropertyInitializer] flags CinsIClassInfoDOM_OBJECT)

const NSGetFactory = XPCOMUtilsgenerateNSGetFactory([HelloWorld])

For example domhelloworldHelloWorldjs

BOILERPLATE

bull Makefiles

bull Manifest

bull Packaging

bull Module Loading

bull Access Permission

EXPOSEDPROPS

let foo = new Foo()

Fooprototype = __exposedProps__ name rw

FIREFOX OS PROCESS MODELbull Parent - Child Processes

bull Only one parent

bull Browser is in parent content pages are children

bull Nested process structure not possible (yet)

bull Parent is trusted

bull Child can be compromised

bull Security critical code has to run in parent

SYSTEM MESSAGE MANAGERbull Use for child-parent communication

bull Child

bull Parent

childProcessMessageManagersendAsyncMessage(message-name foo 2)

var response = sendSyncMessage(message-name foo 1)

receiveMessage function(aMessage) switch (aMessagename) [] parentProcessMessageManagersendAsynMessage(ldquoreturn-message-namerdquo [])

DOMREQUESTS

var pending = navigatormozAppsinstall(manifestUrl)pendingonsuccess = function () Save the App object that is returned var appRecord = thisresult alert(Installation successful)pendingonerror = function () Display the name of the error alert(Install failed error + thiserrorname)

PERMISSIONS

HOW TO IMPLEMENT C++

MAPPING JSC++

bull IDL files rarr JS amp C++

bull JS ctxlineWidth C++ ctxGetLineWidth(float width)

bull Need to implement C++ class for interface

bull NS_IMETHODIMP returns NS_ltstatusgt

bull Expose object nsDOMClassInfocppnsDOMClassInfoClassesh

INTERFACES

Attribute

PrintStateCallback

canvasmozPrintCallback =

function(obj) var ctx = objcontext ctxfillRect(0 0 100 100) objdone()

INTERFACES[scriptable uuid(a7062fca-41c6-4520-b777-3bb30fd77273)]interface nsIDOMHTMLCanvasElement nsIDOMHTMLElement []

A Mozilla-only callback that is called during the printing process attribute nsIPrintCallback mozPrintCallback

Attrib

ute

Callb

ack

[scriptable function uuid(8d5fb8a0-7782-11e1-b0c4-0800200c9a66)]interface nsIPrintCallback nsISupports void render(in nsIDOMMozCanvasPrintState ctx)

[scriptable builtinclass uuid(8d5fb8a0-7782-11e1-b0c4-0800200c9a67)]interface nsIDOMMozCanvasPrintState nsISupports A canvas rendering context readonly attribute nsISupports context

To be called when rendering to the context is done void done()

PrintS

tate

Taken frombug 745025

class nsHTMLCanvasPrintState public nsIDOMMozCanvasPrintStatepublic 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() [] return NS_OK

[]

Taken frombug 745025

MEMORY MANAGEMENTbull C++ doesnrsquot have a garbage collector (

bull In Gecko Reference counting amp cycle collector

bull Reference counting

bull nsCOMPtr (for interfaces) nsREFPtr

bull use getter_AddRefs

bull NS_IF_ADDREF amp NS_IF_RELEASE

MEMORY MANAGEMENT

bull Reference counting doesnrsquot work always

bull Make use of Geckorsquos cycle collector

bull Better cycle then maybe leak

DEBUGGING

bull Make sure to have a debug build

bull Enable logging (example)

bull Watch for assertion in logs

bull Insert printfs

bull There is documentation how to use debugger

OVERVIEW OF SOME TREES

bull Frame Tree Frames on page

bull Content Tree Content going with frames

bull View Tree Connecting views

MAKE YOUR WORK LAND

TESTS TESTS TESTS

bull Reftests

bull Crashtests

bull XPCShell Tests

bull Mochitests

bull JS tests

bull Compiled code tests -(

bull Marionette tests

DIFFERENT TYPE OF TESTS

MOCHITEST

Text

bullpathtoobjdir $ TEST_PATH=domcontactstests make mochitest-plain

bullpathtoobjdir $ TEST_PATH=domcontactsteststest_contactshtml make mochitest-plain

TIME FOR REVIEWbull Make sure the patch is formatted according to the guidelines

bull 8 lines of context

bull correct committer info (name + email)

bull correct checking message

bull When uploading a new version

bull address all review comments

bull obsolete the old patch

bull run tests again

REVIEWbull Make sure your patch is clean

bull Patch should be green on try-push

bull WIP State whatrsquos workingwhat notwhatrsquos next

bull Review might take some time (~1 week)

bull If longer ping person switch review person

bull Except r- donrsquot worry

Q amp A

THINGS TO HACK ON

bull Implement vwvhvminvmax

bull dirname DOM attribute on form controls

bull Implement FileSaver

Page 11: Implementing new WebAPIs

ehsan (Ehsan Akhgari)

bholley (Bobby Holley)

jdm (Josh Matthews)

dholbert (Daniel Holbert)

Ms2ger ()

GENERAL INTRODUCTION

bull whenever you do communication

bull try to be precise

bull give reasoning to your arguments

bull get only short answer - donrsquot take it wrong people are really busy

bull dump whatever you have (crashbackpatch)

GENERAL INTRODUCTION

bull donrsquot be afraid to ping people

bull might get hint to ping someone else

bull tell people youre new to hacking JSGecko

bull lookask for bugs that do similar things you try to solve

HTTPSMXRMOZILLAORG

FIREFOX OS WEBAPI

Telephony

VibratorContacts

Settings

Battery

PowerIdle

Bluetooth

many more to come

Browser

Webapps

httpswikimozillaorgWebAPI

Wifi

INTERFACE + IMPLEMENTATION

IT ALL STARTS WITH AN INTERFACEXPIDL VS WEBIDL

XPIDL VS WEBIDL

interface EventTarget void addEventListener(DOMString type EventListener listener optional boolean capture = false optional boolean wantsUntrusted = null) void removeEventListener(DOMString type EventListener listener optional boolean capture = false) boolean dispatchEvent(Event event)

[scriptable builtinclass uuid(5a8294df-ffe4-48e5-803f-f57bebc29289)]interface nsIDOMScreen nsIDOMEventTarget readonly attribute long top readonly attribute DOMString mozOrientation [implicit_jscontext] attribute jsval onmozorientationchange

boolean mozLockOrientation(in DOMString orientation) void mozUnlockOrientation()

httpsdevelopermozillaorgen-USdocsMozillaWebIDL_bindingshttpsdevelopermozillaorgen-USdocsXPIDL

MAPPING JS VS C++

bull Read other APIs

bull Interfaces are defined in dominterfaces

bull Implementations mostly in dom content

bull c++ implementations use common inheritance

bull JS implementations use manifest file

TIME TO FILE A BUGBugzilla DOMDevice Interfaces

HOW TO IMPLEMENT JS

WHY IN JSbull Prototyping

bull Lower entry point

bull WebDevs know JS

bull Also better for understanding

INTERFACE EXAMPLE

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

httpsbugzillamozillaorgshow_bugcgiid=674720

For example dominterfaceshelloworldnsIHelloWorldidl

HELLOWORLDMANIFEST

component f5181640-89e8-11e1-b0c4-0800200c9444 HelloWorldjscontract mozillaorghelloWorld1 f5181640-89e8-11e1-b0c4-0800200c9444category JavaScript-navigator-property mozHelloWorld mozillaorghelloWorld1

For example domhelloworldHelloWorldmanifest

HELLOWORLDJS

Text

const Cc = Componentsclassesconst Ci = Componentsinterfacesconst Cu = Componentsutils

Cuimport(resourcegremodulesXPCOMUtilsjsm)

function HelloWorld()

HelloWorldprototype =

init function init(aWindow)

sayHello function sayHello(aName) dump(Hello + aName + n)

classID ComponentsID(d88af7e0-a45f-11e1-b3dd-0800200c9444) QueryInterface XPCOMUtilsgenerateQI([ComponentsinterfacesnsIDOMHelloWorld])

classInfo XPCOMUtilsgenerateCI(classID ComponentsID(d88af7e0-a45f-11e1-b3dd-0800200c9444) contractID mozillaorghelloWorld1 classDescription HelloWorld interfaces [ComponentsinterfacesnsIDOMHelloWorld CinsIDOMGlobalPropertyInitializer] flags CinsIClassInfoDOM_OBJECT)

const NSGetFactory = XPCOMUtilsgenerateNSGetFactory([HelloWorld])

For example domhelloworldHelloWorldjs

BOILERPLATE

bull Makefiles

bull Manifest

bull Packaging

bull Module Loading

bull Access Permission

EXPOSEDPROPS

let foo = new Foo()

Fooprototype = __exposedProps__ name rw

FIREFOX OS PROCESS MODELbull Parent - Child Processes

bull Only one parent

bull Browser is in parent content pages are children

bull Nested process structure not possible (yet)

bull Parent is trusted

bull Child can be compromised

bull Security critical code has to run in parent

SYSTEM MESSAGE MANAGERbull Use for child-parent communication

bull Child

bull Parent

childProcessMessageManagersendAsyncMessage(message-name foo 2)

var response = sendSyncMessage(message-name foo 1)

receiveMessage function(aMessage) switch (aMessagename) [] parentProcessMessageManagersendAsynMessage(ldquoreturn-message-namerdquo [])

DOMREQUESTS

var pending = navigatormozAppsinstall(manifestUrl)pendingonsuccess = function () Save the App object that is returned var appRecord = thisresult alert(Installation successful)pendingonerror = function () Display the name of the error alert(Install failed error + thiserrorname)

PERMISSIONS

HOW TO IMPLEMENT C++

MAPPING JSC++

bull IDL files rarr JS amp C++

bull JS ctxlineWidth C++ ctxGetLineWidth(float width)

bull Need to implement C++ class for interface

bull NS_IMETHODIMP returns NS_ltstatusgt

bull Expose object nsDOMClassInfocppnsDOMClassInfoClassesh

INTERFACES

Attribute

PrintStateCallback

canvasmozPrintCallback =

function(obj) var ctx = objcontext ctxfillRect(0 0 100 100) objdone()

INTERFACES[scriptable uuid(a7062fca-41c6-4520-b777-3bb30fd77273)]interface nsIDOMHTMLCanvasElement nsIDOMHTMLElement []

A Mozilla-only callback that is called during the printing process attribute nsIPrintCallback mozPrintCallback

Attrib

ute

Callb

ack

[scriptable function uuid(8d5fb8a0-7782-11e1-b0c4-0800200c9a66)]interface nsIPrintCallback nsISupports void render(in nsIDOMMozCanvasPrintState ctx)

[scriptable builtinclass uuid(8d5fb8a0-7782-11e1-b0c4-0800200c9a67)]interface nsIDOMMozCanvasPrintState nsISupports A canvas rendering context readonly attribute nsISupports context

To be called when rendering to the context is done void done()

PrintS

tate

Taken frombug 745025

class nsHTMLCanvasPrintState public nsIDOMMozCanvasPrintStatepublic 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() [] return NS_OK

[]

Taken frombug 745025

MEMORY MANAGEMENTbull C++ doesnrsquot have a garbage collector (

bull In Gecko Reference counting amp cycle collector

bull Reference counting

bull nsCOMPtr (for interfaces) nsREFPtr

bull use getter_AddRefs

bull NS_IF_ADDREF amp NS_IF_RELEASE

MEMORY MANAGEMENT

bull Reference counting doesnrsquot work always

bull Make use of Geckorsquos cycle collector

bull Better cycle then maybe leak

DEBUGGING

bull Make sure to have a debug build

bull Enable logging (example)

bull Watch for assertion in logs

bull Insert printfs

bull There is documentation how to use debugger

OVERVIEW OF SOME TREES

bull Frame Tree Frames on page

bull Content Tree Content going with frames

bull View Tree Connecting views

MAKE YOUR WORK LAND

TESTS TESTS TESTS

bull Reftests

bull Crashtests

bull XPCShell Tests

bull Mochitests

bull JS tests

bull Compiled code tests -(

bull Marionette tests

DIFFERENT TYPE OF TESTS

MOCHITEST

Text

bullpathtoobjdir $ TEST_PATH=domcontactstests make mochitest-plain

bullpathtoobjdir $ TEST_PATH=domcontactsteststest_contactshtml make mochitest-plain

TIME FOR REVIEWbull Make sure the patch is formatted according to the guidelines

bull 8 lines of context

bull correct committer info (name + email)

bull correct checking message

bull When uploading a new version

bull address all review comments

bull obsolete the old patch

bull run tests again

REVIEWbull Make sure your patch is clean

bull Patch should be green on try-push

bull WIP State whatrsquos workingwhat notwhatrsquos next

bull Review might take some time (~1 week)

bull If longer ping person switch review person

bull Except r- donrsquot worry

Q amp A

THINGS TO HACK ON

bull Implement vwvhvminvmax

bull dirname DOM attribute on form controls

bull Implement FileSaver

Page 12: Implementing new WebAPIs

bholley (Bobby Holley)

jdm (Josh Matthews)

dholbert (Daniel Holbert)

Ms2ger ()

GENERAL INTRODUCTION

bull whenever you do communication

bull try to be precise

bull give reasoning to your arguments

bull get only short answer - donrsquot take it wrong people are really busy

bull dump whatever you have (crashbackpatch)

GENERAL INTRODUCTION

bull donrsquot be afraid to ping people

bull might get hint to ping someone else

bull tell people youre new to hacking JSGecko

bull lookask for bugs that do similar things you try to solve

HTTPSMXRMOZILLAORG

FIREFOX OS WEBAPI

Telephony

VibratorContacts

Settings

Battery

PowerIdle

Bluetooth

many more to come

Browser

Webapps

httpswikimozillaorgWebAPI

Wifi

INTERFACE + IMPLEMENTATION

IT ALL STARTS WITH AN INTERFACEXPIDL VS WEBIDL

XPIDL VS WEBIDL

interface EventTarget void addEventListener(DOMString type EventListener listener optional boolean capture = false optional boolean wantsUntrusted = null) void removeEventListener(DOMString type EventListener listener optional boolean capture = false) boolean dispatchEvent(Event event)

[scriptable builtinclass uuid(5a8294df-ffe4-48e5-803f-f57bebc29289)]interface nsIDOMScreen nsIDOMEventTarget readonly attribute long top readonly attribute DOMString mozOrientation [implicit_jscontext] attribute jsval onmozorientationchange

boolean mozLockOrientation(in DOMString orientation) void mozUnlockOrientation()

httpsdevelopermozillaorgen-USdocsMozillaWebIDL_bindingshttpsdevelopermozillaorgen-USdocsXPIDL

MAPPING JS VS C++

bull Read other APIs

bull Interfaces are defined in dominterfaces

bull Implementations mostly in dom content

bull c++ implementations use common inheritance

bull JS implementations use manifest file

TIME TO FILE A BUGBugzilla DOMDevice Interfaces

HOW TO IMPLEMENT JS

WHY IN JSbull Prototyping

bull Lower entry point

bull WebDevs know JS

bull Also better for understanding

INTERFACE EXAMPLE

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

httpsbugzillamozillaorgshow_bugcgiid=674720

For example dominterfaceshelloworldnsIHelloWorldidl

HELLOWORLDMANIFEST

component f5181640-89e8-11e1-b0c4-0800200c9444 HelloWorldjscontract mozillaorghelloWorld1 f5181640-89e8-11e1-b0c4-0800200c9444category JavaScript-navigator-property mozHelloWorld mozillaorghelloWorld1

For example domhelloworldHelloWorldmanifest

HELLOWORLDJS

Text

const Cc = Componentsclassesconst Ci = Componentsinterfacesconst Cu = Componentsutils

Cuimport(resourcegremodulesXPCOMUtilsjsm)

function HelloWorld()

HelloWorldprototype =

init function init(aWindow)

sayHello function sayHello(aName) dump(Hello + aName + n)

classID ComponentsID(d88af7e0-a45f-11e1-b3dd-0800200c9444) QueryInterface XPCOMUtilsgenerateQI([ComponentsinterfacesnsIDOMHelloWorld])

classInfo XPCOMUtilsgenerateCI(classID ComponentsID(d88af7e0-a45f-11e1-b3dd-0800200c9444) contractID mozillaorghelloWorld1 classDescription HelloWorld interfaces [ComponentsinterfacesnsIDOMHelloWorld CinsIDOMGlobalPropertyInitializer] flags CinsIClassInfoDOM_OBJECT)

const NSGetFactory = XPCOMUtilsgenerateNSGetFactory([HelloWorld])

For example domhelloworldHelloWorldjs

BOILERPLATE

bull Makefiles

bull Manifest

bull Packaging

bull Module Loading

bull Access Permission

EXPOSEDPROPS

let foo = new Foo()

Fooprototype = __exposedProps__ name rw

FIREFOX OS PROCESS MODELbull Parent - Child Processes

bull Only one parent

bull Browser is in parent content pages are children

bull Nested process structure not possible (yet)

bull Parent is trusted

bull Child can be compromised

bull Security critical code has to run in parent

SYSTEM MESSAGE MANAGERbull Use for child-parent communication

bull Child

bull Parent

childProcessMessageManagersendAsyncMessage(message-name foo 2)

var response = sendSyncMessage(message-name foo 1)

receiveMessage function(aMessage) switch (aMessagename) [] parentProcessMessageManagersendAsynMessage(ldquoreturn-message-namerdquo [])

DOMREQUESTS

var pending = navigatormozAppsinstall(manifestUrl)pendingonsuccess = function () Save the App object that is returned var appRecord = thisresult alert(Installation successful)pendingonerror = function () Display the name of the error alert(Install failed error + thiserrorname)

PERMISSIONS

HOW TO IMPLEMENT C++

MAPPING JSC++

bull IDL files rarr JS amp C++

bull JS ctxlineWidth C++ ctxGetLineWidth(float width)

bull Need to implement C++ class for interface

bull NS_IMETHODIMP returns NS_ltstatusgt

bull Expose object nsDOMClassInfocppnsDOMClassInfoClassesh

INTERFACES

Attribute

PrintStateCallback

canvasmozPrintCallback =

function(obj) var ctx = objcontext ctxfillRect(0 0 100 100) objdone()

INTERFACES[scriptable uuid(a7062fca-41c6-4520-b777-3bb30fd77273)]interface nsIDOMHTMLCanvasElement nsIDOMHTMLElement []

A Mozilla-only callback that is called during the printing process attribute nsIPrintCallback mozPrintCallback

Attrib

ute

Callb

ack

[scriptable function uuid(8d5fb8a0-7782-11e1-b0c4-0800200c9a66)]interface nsIPrintCallback nsISupports void render(in nsIDOMMozCanvasPrintState ctx)

[scriptable builtinclass uuid(8d5fb8a0-7782-11e1-b0c4-0800200c9a67)]interface nsIDOMMozCanvasPrintState nsISupports A canvas rendering context readonly attribute nsISupports context

To be called when rendering to the context is done void done()

PrintS

tate

Taken frombug 745025

class nsHTMLCanvasPrintState public nsIDOMMozCanvasPrintStatepublic 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() [] return NS_OK

[]

Taken frombug 745025

MEMORY MANAGEMENTbull C++ doesnrsquot have a garbage collector (

bull In Gecko Reference counting amp cycle collector

bull Reference counting

bull nsCOMPtr (for interfaces) nsREFPtr

bull use getter_AddRefs

bull NS_IF_ADDREF amp NS_IF_RELEASE

MEMORY MANAGEMENT

bull Reference counting doesnrsquot work always

bull Make use of Geckorsquos cycle collector

bull Better cycle then maybe leak

DEBUGGING

bull Make sure to have a debug build

bull Enable logging (example)

bull Watch for assertion in logs

bull Insert printfs

bull There is documentation how to use debugger

OVERVIEW OF SOME TREES

bull Frame Tree Frames on page

bull Content Tree Content going with frames

bull View Tree Connecting views

MAKE YOUR WORK LAND

TESTS TESTS TESTS

bull Reftests

bull Crashtests

bull XPCShell Tests

bull Mochitests

bull JS tests

bull Compiled code tests -(

bull Marionette tests

DIFFERENT TYPE OF TESTS

MOCHITEST

Text

bullpathtoobjdir $ TEST_PATH=domcontactstests make mochitest-plain

bullpathtoobjdir $ TEST_PATH=domcontactsteststest_contactshtml make mochitest-plain

TIME FOR REVIEWbull Make sure the patch is formatted according to the guidelines

bull 8 lines of context

bull correct committer info (name + email)

bull correct checking message

bull When uploading a new version

bull address all review comments

bull obsolete the old patch

bull run tests again

REVIEWbull Make sure your patch is clean

bull Patch should be green on try-push

bull WIP State whatrsquos workingwhat notwhatrsquos next

bull Review might take some time (~1 week)

bull If longer ping person switch review person

bull Except r- donrsquot worry

Q amp A

THINGS TO HACK ON

bull Implement vwvhvminvmax

bull dirname DOM attribute on form controls

bull Implement FileSaver

Page 13: Implementing new WebAPIs

jdm (Josh Matthews)

dholbert (Daniel Holbert)

Ms2ger ()

GENERAL INTRODUCTION

bull whenever you do communication

bull try to be precise

bull give reasoning to your arguments

bull get only short answer - donrsquot take it wrong people are really busy

bull dump whatever you have (crashbackpatch)

GENERAL INTRODUCTION

bull donrsquot be afraid to ping people

bull might get hint to ping someone else

bull tell people youre new to hacking JSGecko

bull lookask for bugs that do similar things you try to solve

HTTPSMXRMOZILLAORG

FIREFOX OS WEBAPI

Telephony

VibratorContacts

Settings

Battery

PowerIdle

Bluetooth

many more to come

Browser

Webapps

httpswikimozillaorgWebAPI

Wifi

INTERFACE + IMPLEMENTATION

IT ALL STARTS WITH AN INTERFACEXPIDL VS WEBIDL

XPIDL VS WEBIDL

interface EventTarget void addEventListener(DOMString type EventListener listener optional boolean capture = false optional boolean wantsUntrusted = null) void removeEventListener(DOMString type EventListener listener optional boolean capture = false) boolean dispatchEvent(Event event)

[scriptable builtinclass uuid(5a8294df-ffe4-48e5-803f-f57bebc29289)]interface nsIDOMScreen nsIDOMEventTarget readonly attribute long top readonly attribute DOMString mozOrientation [implicit_jscontext] attribute jsval onmozorientationchange

boolean mozLockOrientation(in DOMString orientation) void mozUnlockOrientation()

httpsdevelopermozillaorgen-USdocsMozillaWebIDL_bindingshttpsdevelopermozillaorgen-USdocsXPIDL

MAPPING JS VS C++

bull Read other APIs

bull Interfaces are defined in dominterfaces

bull Implementations mostly in dom content

bull c++ implementations use common inheritance

bull JS implementations use manifest file

TIME TO FILE A BUGBugzilla DOMDevice Interfaces

HOW TO IMPLEMENT JS

WHY IN JSbull Prototyping

bull Lower entry point

bull WebDevs know JS

bull Also better for understanding

INTERFACE EXAMPLE

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

httpsbugzillamozillaorgshow_bugcgiid=674720

For example dominterfaceshelloworldnsIHelloWorldidl

HELLOWORLDMANIFEST

component f5181640-89e8-11e1-b0c4-0800200c9444 HelloWorldjscontract mozillaorghelloWorld1 f5181640-89e8-11e1-b0c4-0800200c9444category JavaScript-navigator-property mozHelloWorld mozillaorghelloWorld1

For example domhelloworldHelloWorldmanifest

HELLOWORLDJS

Text

const Cc = Componentsclassesconst Ci = Componentsinterfacesconst Cu = Componentsutils

Cuimport(resourcegremodulesXPCOMUtilsjsm)

function HelloWorld()

HelloWorldprototype =

init function init(aWindow)

sayHello function sayHello(aName) dump(Hello + aName + n)

classID ComponentsID(d88af7e0-a45f-11e1-b3dd-0800200c9444) QueryInterface XPCOMUtilsgenerateQI([ComponentsinterfacesnsIDOMHelloWorld])

classInfo XPCOMUtilsgenerateCI(classID ComponentsID(d88af7e0-a45f-11e1-b3dd-0800200c9444) contractID mozillaorghelloWorld1 classDescription HelloWorld interfaces [ComponentsinterfacesnsIDOMHelloWorld CinsIDOMGlobalPropertyInitializer] flags CinsIClassInfoDOM_OBJECT)

const NSGetFactory = XPCOMUtilsgenerateNSGetFactory([HelloWorld])

For example domhelloworldHelloWorldjs

BOILERPLATE

bull Makefiles

bull Manifest

bull Packaging

bull Module Loading

bull Access Permission

EXPOSEDPROPS

let foo = new Foo()

Fooprototype = __exposedProps__ name rw

FIREFOX OS PROCESS MODELbull Parent - Child Processes

bull Only one parent

bull Browser is in parent content pages are children

bull Nested process structure not possible (yet)

bull Parent is trusted

bull Child can be compromised

bull Security critical code has to run in parent

SYSTEM MESSAGE MANAGERbull Use for child-parent communication

bull Child

bull Parent

childProcessMessageManagersendAsyncMessage(message-name foo 2)

var response = sendSyncMessage(message-name foo 1)

receiveMessage function(aMessage) switch (aMessagename) [] parentProcessMessageManagersendAsynMessage(ldquoreturn-message-namerdquo [])

DOMREQUESTS

var pending = navigatormozAppsinstall(manifestUrl)pendingonsuccess = function () Save the App object that is returned var appRecord = thisresult alert(Installation successful)pendingonerror = function () Display the name of the error alert(Install failed error + thiserrorname)

PERMISSIONS

HOW TO IMPLEMENT C++

MAPPING JSC++

bull IDL files rarr JS amp C++

bull JS ctxlineWidth C++ ctxGetLineWidth(float width)

bull Need to implement C++ class for interface

bull NS_IMETHODIMP returns NS_ltstatusgt

bull Expose object nsDOMClassInfocppnsDOMClassInfoClassesh

INTERFACES

Attribute

PrintStateCallback

canvasmozPrintCallback =

function(obj) var ctx = objcontext ctxfillRect(0 0 100 100) objdone()

INTERFACES[scriptable uuid(a7062fca-41c6-4520-b777-3bb30fd77273)]interface nsIDOMHTMLCanvasElement nsIDOMHTMLElement []

A Mozilla-only callback that is called during the printing process attribute nsIPrintCallback mozPrintCallback

Attrib

ute

Callb

ack

[scriptable function uuid(8d5fb8a0-7782-11e1-b0c4-0800200c9a66)]interface nsIPrintCallback nsISupports void render(in nsIDOMMozCanvasPrintState ctx)

[scriptable builtinclass uuid(8d5fb8a0-7782-11e1-b0c4-0800200c9a67)]interface nsIDOMMozCanvasPrintState nsISupports A canvas rendering context readonly attribute nsISupports context

To be called when rendering to the context is done void done()

PrintS

tate

Taken frombug 745025

class nsHTMLCanvasPrintState public nsIDOMMozCanvasPrintStatepublic 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() [] return NS_OK

[]

Taken frombug 745025

MEMORY MANAGEMENTbull C++ doesnrsquot have a garbage collector (

bull In Gecko Reference counting amp cycle collector

bull Reference counting

bull nsCOMPtr (for interfaces) nsREFPtr

bull use getter_AddRefs

bull NS_IF_ADDREF amp NS_IF_RELEASE

MEMORY MANAGEMENT

bull Reference counting doesnrsquot work always

bull Make use of Geckorsquos cycle collector

bull Better cycle then maybe leak

DEBUGGING

bull Make sure to have a debug build

bull Enable logging (example)

bull Watch for assertion in logs

bull Insert printfs

bull There is documentation how to use debugger

OVERVIEW OF SOME TREES

bull Frame Tree Frames on page

bull Content Tree Content going with frames

bull View Tree Connecting views

MAKE YOUR WORK LAND

TESTS TESTS TESTS

bull Reftests

bull Crashtests

bull XPCShell Tests

bull Mochitests

bull JS tests

bull Compiled code tests -(

bull Marionette tests

DIFFERENT TYPE OF TESTS

MOCHITEST

Text

bullpathtoobjdir $ TEST_PATH=domcontactstests make mochitest-plain

bullpathtoobjdir $ TEST_PATH=domcontactsteststest_contactshtml make mochitest-plain

TIME FOR REVIEWbull Make sure the patch is formatted according to the guidelines

bull 8 lines of context

bull correct committer info (name + email)

bull correct checking message

bull When uploading a new version

bull address all review comments

bull obsolete the old patch

bull run tests again

REVIEWbull Make sure your patch is clean

bull Patch should be green on try-push

bull WIP State whatrsquos workingwhat notwhatrsquos next

bull Review might take some time (~1 week)

bull If longer ping person switch review person

bull Except r- donrsquot worry

Q amp A

THINGS TO HACK ON

bull Implement vwvhvminvmax

bull dirname DOM attribute on form controls

bull Implement FileSaver

Page 14: Implementing new WebAPIs

dholbert (Daniel Holbert)

Ms2ger ()

GENERAL INTRODUCTION

bull whenever you do communication

bull try to be precise

bull give reasoning to your arguments

bull get only short answer - donrsquot take it wrong people are really busy

bull dump whatever you have (crashbackpatch)

GENERAL INTRODUCTION

bull donrsquot be afraid to ping people

bull might get hint to ping someone else

bull tell people youre new to hacking JSGecko

bull lookask for bugs that do similar things you try to solve

HTTPSMXRMOZILLAORG

FIREFOX OS WEBAPI

Telephony

VibratorContacts

Settings

Battery

PowerIdle

Bluetooth

many more to come

Browser

Webapps

httpswikimozillaorgWebAPI

Wifi

INTERFACE + IMPLEMENTATION

IT ALL STARTS WITH AN INTERFACEXPIDL VS WEBIDL

XPIDL VS WEBIDL

interface EventTarget void addEventListener(DOMString type EventListener listener optional boolean capture = false optional boolean wantsUntrusted = null) void removeEventListener(DOMString type EventListener listener optional boolean capture = false) boolean dispatchEvent(Event event)

[scriptable builtinclass uuid(5a8294df-ffe4-48e5-803f-f57bebc29289)]interface nsIDOMScreen nsIDOMEventTarget readonly attribute long top readonly attribute DOMString mozOrientation [implicit_jscontext] attribute jsval onmozorientationchange

boolean mozLockOrientation(in DOMString orientation) void mozUnlockOrientation()

httpsdevelopermozillaorgen-USdocsMozillaWebIDL_bindingshttpsdevelopermozillaorgen-USdocsXPIDL

MAPPING JS VS C++

bull Read other APIs

bull Interfaces are defined in dominterfaces

bull Implementations mostly in dom content

bull c++ implementations use common inheritance

bull JS implementations use manifest file

TIME TO FILE A BUGBugzilla DOMDevice Interfaces

HOW TO IMPLEMENT JS

WHY IN JSbull Prototyping

bull Lower entry point

bull WebDevs know JS

bull Also better for understanding

INTERFACE EXAMPLE

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

httpsbugzillamozillaorgshow_bugcgiid=674720

For example dominterfaceshelloworldnsIHelloWorldidl

HELLOWORLDMANIFEST

component f5181640-89e8-11e1-b0c4-0800200c9444 HelloWorldjscontract mozillaorghelloWorld1 f5181640-89e8-11e1-b0c4-0800200c9444category JavaScript-navigator-property mozHelloWorld mozillaorghelloWorld1

For example domhelloworldHelloWorldmanifest

HELLOWORLDJS

Text

const Cc = Componentsclassesconst Ci = Componentsinterfacesconst Cu = Componentsutils

Cuimport(resourcegremodulesXPCOMUtilsjsm)

function HelloWorld()

HelloWorldprototype =

init function init(aWindow)

sayHello function sayHello(aName) dump(Hello + aName + n)

classID ComponentsID(d88af7e0-a45f-11e1-b3dd-0800200c9444) QueryInterface XPCOMUtilsgenerateQI([ComponentsinterfacesnsIDOMHelloWorld])

classInfo XPCOMUtilsgenerateCI(classID ComponentsID(d88af7e0-a45f-11e1-b3dd-0800200c9444) contractID mozillaorghelloWorld1 classDescription HelloWorld interfaces [ComponentsinterfacesnsIDOMHelloWorld CinsIDOMGlobalPropertyInitializer] flags CinsIClassInfoDOM_OBJECT)

const NSGetFactory = XPCOMUtilsgenerateNSGetFactory([HelloWorld])

For example domhelloworldHelloWorldjs

BOILERPLATE

bull Makefiles

bull Manifest

bull Packaging

bull Module Loading

bull Access Permission

EXPOSEDPROPS

let foo = new Foo()

Fooprototype = __exposedProps__ name rw

FIREFOX OS PROCESS MODELbull Parent - Child Processes

bull Only one parent

bull Browser is in parent content pages are children

bull Nested process structure not possible (yet)

bull Parent is trusted

bull Child can be compromised

bull Security critical code has to run in parent

SYSTEM MESSAGE MANAGERbull Use for child-parent communication

bull Child

bull Parent

childProcessMessageManagersendAsyncMessage(message-name foo 2)

var response = sendSyncMessage(message-name foo 1)

receiveMessage function(aMessage) switch (aMessagename) [] parentProcessMessageManagersendAsynMessage(ldquoreturn-message-namerdquo [])

DOMREQUESTS

var pending = navigatormozAppsinstall(manifestUrl)pendingonsuccess = function () Save the App object that is returned var appRecord = thisresult alert(Installation successful)pendingonerror = function () Display the name of the error alert(Install failed error + thiserrorname)

PERMISSIONS

HOW TO IMPLEMENT C++

MAPPING JSC++

bull IDL files rarr JS amp C++

bull JS ctxlineWidth C++ ctxGetLineWidth(float width)

bull Need to implement C++ class for interface

bull NS_IMETHODIMP returns NS_ltstatusgt

bull Expose object nsDOMClassInfocppnsDOMClassInfoClassesh

INTERFACES

Attribute

PrintStateCallback

canvasmozPrintCallback =

function(obj) var ctx = objcontext ctxfillRect(0 0 100 100) objdone()

INTERFACES[scriptable uuid(a7062fca-41c6-4520-b777-3bb30fd77273)]interface nsIDOMHTMLCanvasElement nsIDOMHTMLElement []

A Mozilla-only callback that is called during the printing process attribute nsIPrintCallback mozPrintCallback

Attrib

ute

Callb

ack

[scriptable function uuid(8d5fb8a0-7782-11e1-b0c4-0800200c9a66)]interface nsIPrintCallback nsISupports void render(in nsIDOMMozCanvasPrintState ctx)

[scriptable builtinclass uuid(8d5fb8a0-7782-11e1-b0c4-0800200c9a67)]interface nsIDOMMozCanvasPrintState nsISupports A canvas rendering context readonly attribute nsISupports context

To be called when rendering to the context is done void done()

PrintS

tate

Taken frombug 745025

class nsHTMLCanvasPrintState public nsIDOMMozCanvasPrintStatepublic 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() [] return NS_OK

[]

Taken frombug 745025

MEMORY MANAGEMENTbull C++ doesnrsquot have a garbage collector (

bull In Gecko Reference counting amp cycle collector

bull Reference counting

bull nsCOMPtr (for interfaces) nsREFPtr

bull use getter_AddRefs

bull NS_IF_ADDREF amp NS_IF_RELEASE

MEMORY MANAGEMENT

bull Reference counting doesnrsquot work always

bull Make use of Geckorsquos cycle collector

bull Better cycle then maybe leak

DEBUGGING

bull Make sure to have a debug build

bull Enable logging (example)

bull Watch for assertion in logs

bull Insert printfs

bull There is documentation how to use debugger

OVERVIEW OF SOME TREES

bull Frame Tree Frames on page

bull Content Tree Content going with frames

bull View Tree Connecting views

MAKE YOUR WORK LAND

TESTS TESTS TESTS

bull Reftests

bull Crashtests

bull XPCShell Tests

bull Mochitests

bull JS tests

bull Compiled code tests -(

bull Marionette tests

DIFFERENT TYPE OF TESTS

MOCHITEST

Text

bullpathtoobjdir $ TEST_PATH=domcontactstests make mochitest-plain

bullpathtoobjdir $ TEST_PATH=domcontactsteststest_contactshtml make mochitest-plain

TIME FOR REVIEWbull Make sure the patch is formatted according to the guidelines

bull 8 lines of context

bull correct committer info (name + email)

bull correct checking message

bull When uploading a new version

bull address all review comments

bull obsolete the old patch

bull run tests again

REVIEWbull Make sure your patch is clean

bull Patch should be green on try-push

bull WIP State whatrsquos workingwhat notwhatrsquos next

bull Review might take some time (~1 week)

bull If longer ping person switch review person

bull Except r- donrsquot worry

Q amp A

THINGS TO HACK ON

bull Implement vwvhvminvmax

bull dirname DOM attribute on form controls

bull Implement FileSaver

Page 15: Implementing new WebAPIs

Ms2ger ()

GENERAL INTRODUCTION

bull whenever you do communication

bull try to be precise

bull give reasoning to your arguments

bull get only short answer - donrsquot take it wrong people are really busy

bull dump whatever you have (crashbackpatch)

GENERAL INTRODUCTION

bull donrsquot be afraid to ping people

bull might get hint to ping someone else

bull tell people youre new to hacking JSGecko

bull lookask for bugs that do similar things you try to solve

HTTPSMXRMOZILLAORG

FIREFOX OS WEBAPI

Telephony

VibratorContacts

Settings

Battery

PowerIdle

Bluetooth

many more to come

Browser

Webapps

httpswikimozillaorgWebAPI

Wifi

INTERFACE + IMPLEMENTATION

IT ALL STARTS WITH AN INTERFACEXPIDL VS WEBIDL

XPIDL VS WEBIDL

interface EventTarget void addEventListener(DOMString type EventListener listener optional boolean capture = false optional boolean wantsUntrusted = null) void removeEventListener(DOMString type EventListener listener optional boolean capture = false) boolean dispatchEvent(Event event)

[scriptable builtinclass uuid(5a8294df-ffe4-48e5-803f-f57bebc29289)]interface nsIDOMScreen nsIDOMEventTarget readonly attribute long top readonly attribute DOMString mozOrientation [implicit_jscontext] attribute jsval onmozorientationchange

boolean mozLockOrientation(in DOMString orientation) void mozUnlockOrientation()

httpsdevelopermozillaorgen-USdocsMozillaWebIDL_bindingshttpsdevelopermozillaorgen-USdocsXPIDL

MAPPING JS VS C++

bull Read other APIs

bull Interfaces are defined in dominterfaces

bull Implementations mostly in dom content

bull c++ implementations use common inheritance

bull JS implementations use manifest file

TIME TO FILE A BUGBugzilla DOMDevice Interfaces

HOW TO IMPLEMENT JS

WHY IN JSbull Prototyping

bull Lower entry point

bull WebDevs know JS

bull Also better for understanding

INTERFACE EXAMPLE

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

httpsbugzillamozillaorgshow_bugcgiid=674720

For example dominterfaceshelloworldnsIHelloWorldidl

HELLOWORLDMANIFEST

component f5181640-89e8-11e1-b0c4-0800200c9444 HelloWorldjscontract mozillaorghelloWorld1 f5181640-89e8-11e1-b0c4-0800200c9444category JavaScript-navigator-property mozHelloWorld mozillaorghelloWorld1

For example domhelloworldHelloWorldmanifest

HELLOWORLDJS

Text

const Cc = Componentsclassesconst Ci = Componentsinterfacesconst Cu = Componentsutils

Cuimport(resourcegremodulesXPCOMUtilsjsm)

function HelloWorld()

HelloWorldprototype =

init function init(aWindow)

sayHello function sayHello(aName) dump(Hello + aName + n)

classID ComponentsID(d88af7e0-a45f-11e1-b3dd-0800200c9444) QueryInterface XPCOMUtilsgenerateQI([ComponentsinterfacesnsIDOMHelloWorld])

classInfo XPCOMUtilsgenerateCI(classID ComponentsID(d88af7e0-a45f-11e1-b3dd-0800200c9444) contractID mozillaorghelloWorld1 classDescription HelloWorld interfaces [ComponentsinterfacesnsIDOMHelloWorld CinsIDOMGlobalPropertyInitializer] flags CinsIClassInfoDOM_OBJECT)

const NSGetFactory = XPCOMUtilsgenerateNSGetFactory([HelloWorld])

For example domhelloworldHelloWorldjs

BOILERPLATE

bull Makefiles

bull Manifest

bull Packaging

bull Module Loading

bull Access Permission

EXPOSEDPROPS

let foo = new Foo()

Fooprototype = __exposedProps__ name rw

FIREFOX OS PROCESS MODELbull Parent - Child Processes

bull Only one parent

bull Browser is in parent content pages are children

bull Nested process structure not possible (yet)

bull Parent is trusted

bull Child can be compromised

bull Security critical code has to run in parent

SYSTEM MESSAGE MANAGERbull Use for child-parent communication

bull Child

bull Parent

childProcessMessageManagersendAsyncMessage(message-name foo 2)

var response = sendSyncMessage(message-name foo 1)

receiveMessage function(aMessage) switch (aMessagename) [] parentProcessMessageManagersendAsynMessage(ldquoreturn-message-namerdquo [])

DOMREQUESTS

var pending = navigatormozAppsinstall(manifestUrl)pendingonsuccess = function () Save the App object that is returned var appRecord = thisresult alert(Installation successful)pendingonerror = function () Display the name of the error alert(Install failed error + thiserrorname)

PERMISSIONS

HOW TO IMPLEMENT C++

MAPPING JSC++

bull IDL files rarr JS amp C++

bull JS ctxlineWidth C++ ctxGetLineWidth(float width)

bull Need to implement C++ class for interface

bull NS_IMETHODIMP returns NS_ltstatusgt

bull Expose object nsDOMClassInfocppnsDOMClassInfoClassesh

INTERFACES

Attribute

PrintStateCallback

canvasmozPrintCallback =

function(obj) var ctx = objcontext ctxfillRect(0 0 100 100) objdone()

INTERFACES[scriptable uuid(a7062fca-41c6-4520-b777-3bb30fd77273)]interface nsIDOMHTMLCanvasElement nsIDOMHTMLElement []

A Mozilla-only callback that is called during the printing process attribute nsIPrintCallback mozPrintCallback

Attrib

ute

Callb

ack

[scriptable function uuid(8d5fb8a0-7782-11e1-b0c4-0800200c9a66)]interface nsIPrintCallback nsISupports void render(in nsIDOMMozCanvasPrintState ctx)

[scriptable builtinclass uuid(8d5fb8a0-7782-11e1-b0c4-0800200c9a67)]interface nsIDOMMozCanvasPrintState nsISupports A canvas rendering context readonly attribute nsISupports context

To be called when rendering to the context is done void done()

PrintS

tate

Taken frombug 745025

class nsHTMLCanvasPrintState public nsIDOMMozCanvasPrintStatepublic 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() [] return NS_OK

[]

Taken frombug 745025

MEMORY MANAGEMENTbull C++ doesnrsquot have a garbage collector (

bull In Gecko Reference counting amp cycle collector

bull Reference counting

bull nsCOMPtr (for interfaces) nsREFPtr

bull use getter_AddRefs

bull NS_IF_ADDREF amp NS_IF_RELEASE

MEMORY MANAGEMENT

bull Reference counting doesnrsquot work always

bull Make use of Geckorsquos cycle collector

bull Better cycle then maybe leak

DEBUGGING

bull Make sure to have a debug build

bull Enable logging (example)

bull Watch for assertion in logs

bull Insert printfs

bull There is documentation how to use debugger

OVERVIEW OF SOME TREES

bull Frame Tree Frames on page

bull Content Tree Content going with frames

bull View Tree Connecting views

MAKE YOUR WORK LAND

TESTS TESTS TESTS

bull Reftests

bull Crashtests

bull XPCShell Tests

bull Mochitests

bull JS tests

bull Compiled code tests -(

bull Marionette tests

DIFFERENT TYPE OF TESTS

MOCHITEST

Text

bullpathtoobjdir $ TEST_PATH=domcontactstests make mochitest-plain

bullpathtoobjdir $ TEST_PATH=domcontactsteststest_contactshtml make mochitest-plain

TIME FOR REVIEWbull Make sure the patch is formatted according to the guidelines

bull 8 lines of context

bull correct committer info (name + email)

bull correct checking message

bull When uploading a new version

bull address all review comments

bull obsolete the old patch

bull run tests again

REVIEWbull Make sure your patch is clean

bull Patch should be green on try-push

bull WIP State whatrsquos workingwhat notwhatrsquos next

bull Review might take some time (~1 week)

bull If longer ping person switch review person

bull Except r- donrsquot worry

Q amp A

THINGS TO HACK ON

bull Implement vwvhvminvmax

bull dirname DOM attribute on form controls

bull Implement FileSaver

Page 16: Implementing new WebAPIs

GENERAL INTRODUCTION

bull whenever you do communication

bull try to be precise

bull give reasoning to your arguments

bull get only short answer - donrsquot take it wrong people are really busy

bull dump whatever you have (crashbackpatch)

GENERAL INTRODUCTION

bull donrsquot be afraid to ping people

bull might get hint to ping someone else

bull tell people youre new to hacking JSGecko

bull lookask for bugs that do similar things you try to solve

HTTPSMXRMOZILLAORG

FIREFOX OS WEBAPI

Telephony

VibratorContacts

Settings

Battery

PowerIdle

Bluetooth

many more to come

Browser

Webapps

httpswikimozillaorgWebAPI

Wifi

INTERFACE + IMPLEMENTATION

IT ALL STARTS WITH AN INTERFACEXPIDL VS WEBIDL

XPIDL VS WEBIDL

interface EventTarget void addEventListener(DOMString type EventListener listener optional boolean capture = false optional boolean wantsUntrusted = null) void removeEventListener(DOMString type EventListener listener optional boolean capture = false) boolean dispatchEvent(Event event)

[scriptable builtinclass uuid(5a8294df-ffe4-48e5-803f-f57bebc29289)]interface nsIDOMScreen nsIDOMEventTarget readonly attribute long top readonly attribute DOMString mozOrientation [implicit_jscontext] attribute jsval onmozorientationchange

boolean mozLockOrientation(in DOMString orientation) void mozUnlockOrientation()

httpsdevelopermozillaorgen-USdocsMozillaWebIDL_bindingshttpsdevelopermozillaorgen-USdocsXPIDL

MAPPING JS VS C++

bull Read other APIs

bull Interfaces are defined in dominterfaces

bull Implementations mostly in dom content

bull c++ implementations use common inheritance

bull JS implementations use manifest file

TIME TO FILE A BUGBugzilla DOMDevice Interfaces

HOW TO IMPLEMENT JS

WHY IN JSbull Prototyping

bull Lower entry point

bull WebDevs know JS

bull Also better for understanding

INTERFACE EXAMPLE

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

httpsbugzillamozillaorgshow_bugcgiid=674720

For example dominterfaceshelloworldnsIHelloWorldidl

HELLOWORLDMANIFEST

component f5181640-89e8-11e1-b0c4-0800200c9444 HelloWorldjscontract mozillaorghelloWorld1 f5181640-89e8-11e1-b0c4-0800200c9444category JavaScript-navigator-property mozHelloWorld mozillaorghelloWorld1

For example domhelloworldHelloWorldmanifest

HELLOWORLDJS

Text

const Cc = Componentsclassesconst Ci = Componentsinterfacesconst Cu = Componentsutils

Cuimport(resourcegremodulesXPCOMUtilsjsm)

function HelloWorld()

HelloWorldprototype =

init function init(aWindow)

sayHello function sayHello(aName) dump(Hello + aName + n)

classID ComponentsID(d88af7e0-a45f-11e1-b3dd-0800200c9444) QueryInterface XPCOMUtilsgenerateQI([ComponentsinterfacesnsIDOMHelloWorld])

classInfo XPCOMUtilsgenerateCI(classID ComponentsID(d88af7e0-a45f-11e1-b3dd-0800200c9444) contractID mozillaorghelloWorld1 classDescription HelloWorld interfaces [ComponentsinterfacesnsIDOMHelloWorld CinsIDOMGlobalPropertyInitializer] flags CinsIClassInfoDOM_OBJECT)

const NSGetFactory = XPCOMUtilsgenerateNSGetFactory([HelloWorld])

For example domhelloworldHelloWorldjs

BOILERPLATE

bull Makefiles

bull Manifest

bull Packaging

bull Module Loading

bull Access Permission

EXPOSEDPROPS

let foo = new Foo()

Fooprototype = __exposedProps__ name rw

FIREFOX OS PROCESS MODELbull Parent - Child Processes

bull Only one parent

bull Browser is in parent content pages are children

bull Nested process structure not possible (yet)

bull Parent is trusted

bull Child can be compromised

bull Security critical code has to run in parent

SYSTEM MESSAGE MANAGERbull Use for child-parent communication

bull Child

bull Parent

childProcessMessageManagersendAsyncMessage(message-name foo 2)

var response = sendSyncMessage(message-name foo 1)

receiveMessage function(aMessage) switch (aMessagename) [] parentProcessMessageManagersendAsynMessage(ldquoreturn-message-namerdquo [])

DOMREQUESTS

var pending = navigatormozAppsinstall(manifestUrl)pendingonsuccess = function () Save the App object that is returned var appRecord = thisresult alert(Installation successful)pendingonerror = function () Display the name of the error alert(Install failed error + thiserrorname)

PERMISSIONS

HOW TO IMPLEMENT C++

MAPPING JSC++

bull IDL files rarr JS amp C++

bull JS ctxlineWidth C++ ctxGetLineWidth(float width)

bull Need to implement C++ class for interface

bull NS_IMETHODIMP returns NS_ltstatusgt

bull Expose object nsDOMClassInfocppnsDOMClassInfoClassesh

INTERFACES

Attribute

PrintStateCallback

canvasmozPrintCallback =

function(obj) var ctx = objcontext ctxfillRect(0 0 100 100) objdone()

INTERFACES[scriptable uuid(a7062fca-41c6-4520-b777-3bb30fd77273)]interface nsIDOMHTMLCanvasElement nsIDOMHTMLElement []

A Mozilla-only callback that is called during the printing process attribute nsIPrintCallback mozPrintCallback

Attrib

ute

Callb

ack

[scriptable function uuid(8d5fb8a0-7782-11e1-b0c4-0800200c9a66)]interface nsIPrintCallback nsISupports void render(in nsIDOMMozCanvasPrintState ctx)

[scriptable builtinclass uuid(8d5fb8a0-7782-11e1-b0c4-0800200c9a67)]interface nsIDOMMozCanvasPrintState nsISupports A canvas rendering context readonly attribute nsISupports context

To be called when rendering to the context is done void done()

PrintS

tate

Taken frombug 745025

class nsHTMLCanvasPrintState public nsIDOMMozCanvasPrintStatepublic 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() [] return NS_OK

[]

Taken frombug 745025

MEMORY MANAGEMENTbull C++ doesnrsquot have a garbage collector (

bull In Gecko Reference counting amp cycle collector

bull Reference counting

bull nsCOMPtr (for interfaces) nsREFPtr

bull use getter_AddRefs

bull NS_IF_ADDREF amp NS_IF_RELEASE

MEMORY MANAGEMENT

bull Reference counting doesnrsquot work always

bull Make use of Geckorsquos cycle collector

bull Better cycle then maybe leak

DEBUGGING

bull Make sure to have a debug build

bull Enable logging (example)

bull Watch for assertion in logs

bull Insert printfs

bull There is documentation how to use debugger

OVERVIEW OF SOME TREES

bull Frame Tree Frames on page

bull Content Tree Content going with frames

bull View Tree Connecting views

MAKE YOUR WORK LAND

TESTS TESTS TESTS

bull Reftests

bull Crashtests

bull XPCShell Tests

bull Mochitests

bull JS tests

bull Compiled code tests -(

bull Marionette tests

DIFFERENT TYPE OF TESTS

MOCHITEST

Text

bullpathtoobjdir $ TEST_PATH=domcontactstests make mochitest-plain

bullpathtoobjdir $ TEST_PATH=domcontactsteststest_contactshtml make mochitest-plain

TIME FOR REVIEWbull Make sure the patch is formatted according to the guidelines

bull 8 lines of context

bull correct committer info (name + email)

bull correct checking message

bull When uploading a new version

bull address all review comments

bull obsolete the old patch

bull run tests again

REVIEWbull Make sure your patch is clean

bull Patch should be green on try-push

bull WIP State whatrsquos workingwhat notwhatrsquos next

bull Review might take some time (~1 week)

bull If longer ping person switch review person

bull Except r- donrsquot worry

Q amp A

THINGS TO HACK ON

bull Implement vwvhvminvmax

bull dirname DOM attribute on form controls

bull Implement FileSaver

Page 17: Implementing new WebAPIs

GENERAL INTRODUCTION

bull donrsquot be afraid to ping people

bull might get hint to ping someone else

bull tell people youre new to hacking JSGecko

bull lookask for bugs that do similar things you try to solve

HTTPSMXRMOZILLAORG

FIREFOX OS WEBAPI

Telephony

VibratorContacts

Settings

Battery

PowerIdle

Bluetooth

many more to come

Browser

Webapps

httpswikimozillaorgWebAPI

Wifi

INTERFACE + IMPLEMENTATION

IT ALL STARTS WITH AN INTERFACEXPIDL VS WEBIDL

XPIDL VS WEBIDL

interface EventTarget void addEventListener(DOMString type EventListener listener optional boolean capture = false optional boolean wantsUntrusted = null) void removeEventListener(DOMString type EventListener listener optional boolean capture = false) boolean dispatchEvent(Event event)

[scriptable builtinclass uuid(5a8294df-ffe4-48e5-803f-f57bebc29289)]interface nsIDOMScreen nsIDOMEventTarget readonly attribute long top readonly attribute DOMString mozOrientation [implicit_jscontext] attribute jsval onmozorientationchange

boolean mozLockOrientation(in DOMString orientation) void mozUnlockOrientation()

httpsdevelopermozillaorgen-USdocsMozillaWebIDL_bindingshttpsdevelopermozillaorgen-USdocsXPIDL

MAPPING JS VS C++

bull Read other APIs

bull Interfaces are defined in dominterfaces

bull Implementations mostly in dom content

bull c++ implementations use common inheritance

bull JS implementations use manifest file

TIME TO FILE A BUGBugzilla DOMDevice Interfaces

HOW TO IMPLEMENT JS

WHY IN JSbull Prototyping

bull Lower entry point

bull WebDevs know JS

bull Also better for understanding

INTERFACE EXAMPLE

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

httpsbugzillamozillaorgshow_bugcgiid=674720

For example dominterfaceshelloworldnsIHelloWorldidl

HELLOWORLDMANIFEST

component f5181640-89e8-11e1-b0c4-0800200c9444 HelloWorldjscontract mozillaorghelloWorld1 f5181640-89e8-11e1-b0c4-0800200c9444category JavaScript-navigator-property mozHelloWorld mozillaorghelloWorld1

For example domhelloworldHelloWorldmanifest

HELLOWORLDJS

Text

const Cc = Componentsclassesconst Ci = Componentsinterfacesconst Cu = Componentsutils

Cuimport(resourcegremodulesXPCOMUtilsjsm)

function HelloWorld()

HelloWorldprototype =

init function init(aWindow)

sayHello function sayHello(aName) dump(Hello + aName + n)

classID ComponentsID(d88af7e0-a45f-11e1-b3dd-0800200c9444) QueryInterface XPCOMUtilsgenerateQI([ComponentsinterfacesnsIDOMHelloWorld])

classInfo XPCOMUtilsgenerateCI(classID ComponentsID(d88af7e0-a45f-11e1-b3dd-0800200c9444) contractID mozillaorghelloWorld1 classDescription HelloWorld interfaces [ComponentsinterfacesnsIDOMHelloWorld CinsIDOMGlobalPropertyInitializer] flags CinsIClassInfoDOM_OBJECT)

const NSGetFactory = XPCOMUtilsgenerateNSGetFactory([HelloWorld])

For example domhelloworldHelloWorldjs

BOILERPLATE

bull Makefiles

bull Manifest

bull Packaging

bull Module Loading

bull Access Permission

EXPOSEDPROPS

let foo = new Foo()

Fooprototype = __exposedProps__ name rw

FIREFOX OS PROCESS MODELbull Parent - Child Processes

bull Only one parent

bull Browser is in parent content pages are children

bull Nested process structure not possible (yet)

bull Parent is trusted

bull Child can be compromised

bull Security critical code has to run in parent

SYSTEM MESSAGE MANAGERbull Use for child-parent communication

bull Child

bull Parent

childProcessMessageManagersendAsyncMessage(message-name foo 2)

var response = sendSyncMessage(message-name foo 1)

receiveMessage function(aMessage) switch (aMessagename) [] parentProcessMessageManagersendAsynMessage(ldquoreturn-message-namerdquo [])

DOMREQUESTS

var pending = navigatormozAppsinstall(manifestUrl)pendingonsuccess = function () Save the App object that is returned var appRecord = thisresult alert(Installation successful)pendingonerror = function () Display the name of the error alert(Install failed error + thiserrorname)

PERMISSIONS

HOW TO IMPLEMENT C++

MAPPING JSC++

bull IDL files rarr JS amp C++

bull JS ctxlineWidth C++ ctxGetLineWidth(float width)

bull Need to implement C++ class for interface

bull NS_IMETHODIMP returns NS_ltstatusgt

bull Expose object nsDOMClassInfocppnsDOMClassInfoClassesh

INTERFACES

Attribute

PrintStateCallback

canvasmozPrintCallback =

function(obj) var ctx = objcontext ctxfillRect(0 0 100 100) objdone()

INTERFACES[scriptable uuid(a7062fca-41c6-4520-b777-3bb30fd77273)]interface nsIDOMHTMLCanvasElement nsIDOMHTMLElement []

A Mozilla-only callback that is called during the printing process attribute nsIPrintCallback mozPrintCallback

Attrib

ute

Callb

ack

[scriptable function uuid(8d5fb8a0-7782-11e1-b0c4-0800200c9a66)]interface nsIPrintCallback nsISupports void render(in nsIDOMMozCanvasPrintState ctx)

[scriptable builtinclass uuid(8d5fb8a0-7782-11e1-b0c4-0800200c9a67)]interface nsIDOMMozCanvasPrintState nsISupports A canvas rendering context readonly attribute nsISupports context

To be called when rendering to the context is done void done()

PrintS

tate

Taken frombug 745025

class nsHTMLCanvasPrintState public nsIDOMMozCanvasPrintStatepublic 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() [] return NS_OK

[]

Taken frombug 745025

MEMORY MANAGEMENTbull C++ doesnrsquot have a garbage collector (

bull In Gecko Reference counting amp cycle collector

bull Reference counting

bull nsCOMPtr (for interfaces) nsREFPtr

bull use getter_AddRefs

bull NS_IF_ADDREF amp NS_IF_RELEASE

MEMORY MANAGEMENT

bull Reference counting doesnrsquot work always

bull Make use of Geckorsquos cycle collector

bull Better cycle then maybe leak

DEBUGGING

bull Make sure to have a debug build

bull Enable logging (example)

bull Watch for assertion in logs

bull Insert printfs

bull There is documentation how to use debugger

OVERVIEW OF SOME TREES

bull Frame Tree Frames on page

bull Content Tree Content going with frames

bull View Tree Connecting views

MAKE YOUR WORK LAND

TESTS TESTS TESTS

bull Reftests

bull Crashtests

bull XPCShell Tests

bull Mochitests

bull JS tests

bull Compiled code tests -(

bull Marionette tests

DIFFERENT TYPE OF TESTS

MOCHITEST

Text

bullpathtoobjdir $ TEST_PATH=domcontactstests make mochitest-plain

bullpathtoobjdir $ TEST_PATH=domcontactsteststest_contactshtml make mochitest-plain

TIME FOR REVIEWbull Make sure the patch is formatted according to the guidelines

bull 8 lines of context

bull correct committer info (name + email)

bull correct checking message

bull When uploading a new version

bull address all review comments

bull obsolete the old patch

bull run tests again

REVIEWbull Make sure your patch is clean

bull Patch should be green on try-push

bull WIP State whatrsquos workingwhat notwhatrsquos next

bull Review might take some time (~1 week)

bull If longer ping person switch review person

bull Except r- donrsquot worry

Q amp A

THINGS TO HACK ON

bull Implement vwvhvminvmax

bull dirname DOM attribute on form controls

bull Implement FileSaver

Page 18: Implementing new WebAPIs

HTTPSMXRMOZILLAORG

FIREFOX OS WEBAPI

Telephony

VibratorContacts

Settings

Battery

PowerIdle

Bluetooth

many more to come

Browser

Webapps

httpswikimozillaorgWebAPI

Wifi

INTERFACE + IMPLEMENTATION

IT ALL STARTS WITH AN INTERFACEXPIDL VS WEBIDL

XPIDL VS WEBIDL

interface EventTarget void addEventListener(DOMString type EventListener listener optional boolean capture = false optional boolean wantsUntrusted = null) void removeEventListener(DOMString type EventListener listener optional boolean capture = false) boolean dispatchEvent(Event event)

[scriptable builtinclass uuid(5a8294df-ffe4-48e5-803f-f57bebc29289)]interface nsIDOMScreen nsIDOMEventTarget readonly attribute long top readonly attribute DOMString mozOrientation [implicit_jscontext] attribute jsval onmozorientationchange

boolean mozLockOrientation(in DOMString orientation) void mozUnlockOrientation()

httpsdevelopermozillaorgen-USdocsMozillaWebIDL_bindingshttpsdevelopermozillaorgen-USdocsXPIDL

MAPPING JS VS C++

bull Read other APIs

bull Interfaces are defined in dominterfaces

bull Implementations mostly in dom content

bull c++ implementations use common inheritance

bull JS implementations use manifest file

TIME TO FILE A BUGBugzilla DOMDevice Interfaces

HOW TO IMPLEMENT JS

WHY IN JSbull Prototyping

bull Lower entry point

bull WebDevs know JS

bull Also better for understanding

INTERFACE EXAMPLE

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

httpsbugzillamozillaorgshow_bugcgiid=674720

For example dominterfaceshelloworldnsIHelloWorldidl

HELLOWORLDMANIFEST

component f5181640-89e8-11e1-b0c4-0800200c9444 HelloWorldjscontract mozillaorghelloWorld1 f5181640-89e8-11e1-b0c4-0800200c9444category JavaScript-navigator-property mozHelloWorld mozillaorghelloWorld1

For example domhelloworldHelloWorldmanifest

HELLOWORLDJS

Text

const Cc = Componentsclassesconst Ci = Componentsinterfacesconst Cu = Componentsutils

Cuimport(resourcegremodulesXPCOMUtilsjsm)

function HelloWorld()

HelloWorldprototype =

init function init(aWindow)

sayHello function sayHello(aName) dump(Hello + aName + n)

classID ComponentsID(d88af7e0-a45f-11e1-b3dd-0800200c9444) QueryInterface XPCOMUtilsgenerateQI([ComponentsinterfacesnsIDOMHelloWorld])

classInfo XPCOMUtilsgenerateCI(classID ComponentsID(d88af7e0-a45f-11e1-b3dd-0800200c9444) contractID mozillaorghelloWorld1 classDescription HelloWorld interfaces [ComponentsinterfacesnsIDOMHelloWorld CinsIDOMGlobalPropertyInitializer] flags CinsIClassInfoDOM_OBJECT)

const NSGetFactory = XPCOMUtilsgenerateNSGetFactory([HelloWorld])

For example domhelloworldHelloWorldjs

BOILERPLATE

bull Makefiles

bull Manifest

bull Packaging

bull Module Loading

bull Access Permission

EXPOSEDPROPS

let foo = new Foo()

Fooprototype = __exposedProps__ name rw

FIREFOX OS PROCESS MODELbull Parent - Child Processes

bull Only one parent

bull Browser is in parent content pages are children

bull Nested process structure not possible (yet)

bull Parent is trusted

bull Child can be compromised

bull Security critical code has to run in parent

SYSTEM MESSAGE MANAGERbull Use for child-parent communication

bull Child

bull Parent

childProcessMessageManagersendAsyncMessage(message-name foo 2)

var response = sendSyncMessage(message-name foo 1)

receiveMessage function(aMessage) switch (aMessagename) [] parentProcessMessageManagersendAsynMessage(ldquoreturn-message-namerdquo [])

DOMREQUESTS

var pending = navigatormozAppsinstall(manifestUrl)pendingonsuccess = function () Save the App object that is returned var appRecord = thisresult alert(Installation successful)pendingonerror = function () Display the name of the error alert(Install failed error + thiserrorname)

PERMISSIONS

HOW TO IMPLEMENT C++

MAPPING JSC++

bull IDL files rarr JS amp C++

bull JS ctxlineWidth C++ ctxGetLineWidth(float width)

bull Need to implement C++ class for interface

bull NS_IMETHODIMP returns NS_ltstatusgt

bull Expose object nsDOMClassInfocppnsDOMClassInfoClassesh

INTERFACES

Attribute

PrintStateCallback

canvasmozPrintCallback =

function(obj) var ctx = objcontext ctxfillRect(0 0 100 100) objdone()

INTERFACES[scriptable uuid(a7062fca-41c6-4520-b777-3bb30fd77273)]interface nsIDOMHTMLCanvasElement nsIDOMHTMLElement []

A Mozilla-only callback that is called during the printing process attribute nsIPrintCallback mozPrintCallback

Attrib

ute

Callb

ack

[scriptable function uuid(8d5fb8a0-7782-11e1-b0c4-0800200c9a66)]interface nsIPrintCallback nsISupports void render(in nsIDOMMozCanvasPrintState ctx)

[scriptable builtinclass uuid(8d5fb8a0-7782-11e1-b0c4-0800200c9a67)]interface nsIDOMMozCanvasPrintState nsISupports A canvas rendering context readonly attribute nsISupports context

To be called when rendering to the context is done void done()

PrintS

tate

Taken frombug 745025

class nsHTMLCanvasPrintState public nsIDOMMozCanvasPrintStatepublic 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() [] return NS_OK

[]

Taken frombug 745025

MEMORY MANAGEMENTbull C++ doesnrsquot have a garbage collector (

bull In Gecko Reference counting amp cycle collector

bull Reference counting

bull nsCOMPtr (for interfaces) nsREFPtr

bull use getter_AddRefs

bull NS_IF_ADDREF amp NS_IF_RELEASE

MEMORY MANAGEMENT

bull Reference counting doesnrsquot work always

bull Make use of Geckorsquos cycle collector

bull Better cycle then maybe leak

DEBUGGING

bull Make sure to have a debug build

bull Enable logging (example)

bull Watch for assertion in logs

bull Insert printfs

bull There is documentation how to use debugger

OVERVIEW OF SOME TREES

bull Frame Tree Frames on page

bull Content Tree Content going with frames

bull View Tree Connecting views

MAKE YOUR WORK LAND

TESTS TESTS TESTS

bull Reftests

bull Crashtests

bull XPCShell Tests

bull Mochitests

bull JS tests

bull Compiled code tests -(

bull Marionette tests

DIFFERENT TYPE OF TESTS

MOCHITEST

Text

bullpathtoobjdir $ TEST_PATH=domcontactstests make mochitest-plain

bullpathtoobjdir $ TEST_PATH=domcontactsteststest_contactshtml make mochitest-plain

TIME FOR REVIEWbull Make sure the patch is formatted according to the guidelines

bull 8 lines of context

bull correct committer info (name + email)

bull correct checking message

bull When uploading a new version

bull address all review comments

bull obsolete the old patch

bull run tests again

REVIEWbull Make sure your patch is clean

bull Patch should be green on try-push

bull WIP State whatrsquos workingwhat notwhatrsquos next

bull Review might take some time (~1 week)

bull If longer ping person switch review person

bull Except r- donrsquot worry

Q amp A

THINGS TO HACK ON

bull Implement vwvhvminvmax

bull dirname DOM attribute on form controls

bull Implement FileSaver

Page 19: Implementing new WebAPIs

FIREFOX OS WEBAPI

Telephony

VibratorContacts

Settings

Battery

PowerIdle

Bluetooth

many more to come

Browser

Webapps

httpswikimozillaorgWebAPI

Wifi

INTERFACE + IMPLEMENTATION

IT ALL STARTS WITH AN INTERFACEXPIDL VS WEBIDL

XPIDL VS WEBIDL

interface EventTarget void addEventListener(DOMString type EventListener listener optional boolean capture = false optional boolean wantsUntrusted = null) void removeEventListener(DOMString type EventListener listener optional boolean capture = false) boolean dispatchEvent(Event event)

[scriptable builtinclass uuid(5a8294df-ffe4-48e5-803f-f57bebc29289)]interface nsIDOMScreen nsIDOMEventTarget readonly attribute long top readonly attribute DOMString mozOrientation [implicit_jscontext] attribute jsval onmozorientationchange

boolean mozLockOrientation(in DOMString orientation) void mozUnlockOrientation()

httpsdevelopermozillaorgen-USdocsMozillaWebIDL_bindingshttpsdevelopermozillaorgen-USdocsXPIDL

MAPPING JS VS C++

bull Read other APIs

bull Interfaces are defined in dominterfaces

bull Implementations mostly in dom content

bull c++ implementations use common inheritance

bull JS implementations use manifest file

TIME TO FILE A BUGBugzilla DOMDevice Interfaces

HOW TO IMPLEMENT JS

WHY IN JSbull Prototyping

bull Lower entry point

bull WebDevs know JS

bull Also better for understanding

INTERFACE EXAMPLE

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

httpsbugzillamozillaorgshow_bugcgiid=674720

For example dominterfaceshelloworldnsIHelloWorldidl

HELLOWORLDMANIFEST

component f5181640-89e8-11e1-b0c4-0800200c9444 HelloWorldjscontract mozillaorghelloWorld1 f5181640-89e8-11e1-b0c4-0800200c9444category JavaScript-navigator-property mozHelloWorld mozillaorghelloWorld1

For example domhelloworldHelloWorldmanifest

HELLOWORLDJS

Text

const Cc = Componentsclassesconst Ci = Componentsinterfacesconst Cu = Componentsutils

Cuimport(resourcegremodulesXPCOMUtilsjsm)

function HelloWorld()

HelloWorldprototype =

init function init(aWindow)

sayHello function sayHello(aName) dump(Hello + aName + n)

classID ComponentsID(d88af7e0-a45f-11e1-b3dd-0800200c9444) QueryInterface XPCOMUtilsgenerateQI([ComponentsinterfacesnsIDOMHelloWorld])

classInfo XPCOMUtilsgenerateCI(classID ComponentsID(d88af7e0-a45f-11e1-b3dd-0800200c9444) contractID mozillaorghelloWorld1 classDescription HelloWorld interfaces [ComponentsinterfacesnsIDOMHelloWorld CinsIDOMGlobalPropertyInitializer] flags CinsIClassInfoDOM_OBJECT)

const NSGetFactory = XPCOMUtilsgenerateNSGetFactory([HelloWorld])

For example domhelloworldHelloWorldjs

BOILERPLATE

bull Makefiles

bull Manifest

bull Packaging

bull Module Loading

bull Access Permission

EXPOSEDPROPS

let foo = new Foo()

Fooprototype = __exposedProps__ name rw

FIREFOX OS PROCESS MODELbull Parent - Child Processes

bull Only one parent

bull Browser is in parent content pages are children

bull Nested process structure not possible (yet)

bull Parent is trusted

bull Child can be compromised

bull Security critical code has to run in parent

SYSTEM MESSAGE MANAGERbull Use for child-parent communication

bull Child

bull Parent

childProcessMessageManagersendAsyncMessage(message-name foo 2)

var response = sendSyncMessage(message-name foo 1)

receiveMessage function(aMessage) switch (aMessagename) [] parentProcessMessageManagersendAsynMessage(ldquoreturn-message-namerdquo [])

DOMREQUESTS

var pending = navigatormozAppsinstall(manifestUrl)pendingonsuccess = function () Save the App object that is returned var appRecord = thisresult alert(Installation successful)pendingonerror = function () Display the name of the error alert(Install failed error + thiserrorname)

PERMISSIONS

HOW TO IMPLEMENT C++

MAPPING JSC++

bull IDL files rarr JS amp C++

bull JS ctxlineWidth C++ ctxGetLineWidth(float width)

bull Need to implement C++ class for interface

bull NS_IMETHODIMP returns NS_ltstatusgt

bull Expose object nsDOMClassInfocppnsDOMClassInfoClassesh

INTERFACES

Attribute

PrintStateCallback

canvasmozPrintCallback =

function(obj) var ctx = objcontext ctxfillRect(0 0 100 100) objdone()

INTERFACES[scriptable uuid(a7062fca-41c6-4520-b777-3bb30fd77273)]interface nsIDOMHTMLCanvasElement nsIDOMHTMLElement []

A Mozilla-only callback that is called during the printing process attribute nsIPrintCallback mozPrintCallback

Attrib

ute

Callb

ack

[scriptable function uuid(8d5fb8a0-7782-11e1-b0c4-0800200c9a66)]interface nsIPrintCallback nsISupports void render(in nsIDOMMozCanvasPrintState ctx)

[scriptable builtinclass uuid(8d5fb8a0-7782-11e1-b0c4-0800200c9a67)]interface nsIDOMMozCanvasPrintState nsISupports A canvas rendering context readonly attribute nsISupports context

To be called when rendering to the context is done void done()

PrintS

tate

Taken frombug 745025

class nsHTMLCanvasPrintState public nsIDOMMozCanvasPrintStatepublic 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() [] return NS_OK

[]

Taken frombug 745025

MEMORY MANAGEMENTbull C++ doesnrsquot have a garbage collector (

bull In Gecko Reference counting amp cycle collector

bull Reference counting

bull nsCOMPtr (for interfaces) nsREFPtr

bull use getter_AddRefs

bull NS_IF_ADDREF amp NS_IF_RELEASE

MEMORY MANAGEMENT

bull Reference counting doesnrsquot work always

bull Make use of Geckorsquos cycle collector

bull Better cycle then maybe leak

DEBUGGING

bull Make sure to have a debug build

bull Enable logging (example)

bull Watch for assertion in logs

bull Insert printfs

bull There is documentation how to use debugger

OVERVIEW OF SOME TREES

bull Frame Tree Frames on page

bull Content Tree Content going with frames

bull View Tree Connecting views

MAKE YOUR WORK LAND

TESTS TESTS TESTS

bull Reftests

bull Crashtests

bull XPCShell Tests

bull Mochitests

bull JS tests

bull Compiled code tests -(

bull Marionette tests

DIFFERENT TYPE OF TESTS

MOCHITEST

Text

bullpathtoobjdir $ TEST_PATH=domcontactstests make mochitest-plain

bullpathtoobjdir $ TEST_PATH=domcontactsteststest_contactshtml make mochitest-plain

TIME FOR REVIEWbull Make sure the patch is formatted according to the guidelines

bull 8 lines of context

bull correct committer info (name + email)

bull correct checking message

bull When uploading a new version

bull address all review comments

bull obsolete the old patch

bull run tests again

REVIEWbull Make sure your patch is clean

bull Patch should be green on try-push

bull WIP State whatrsquos workingwhat notwhatrsquos next

bull Review might take some time (~1 week)

bull If longer ping person switch review person

bull Except r- donrsquot worry

Q amp A

THINGS TO HACK ON

bull Implement vwvhvminvmax

bull dirname DOM attribute on form controls

bull Implement FileSaver

Page 20: Implementing new WebAPIs

INTERFACE + IMPLEMENTATION

IT ALL STARTS WITH AN INTERFACEXPIDL VS WEBIDL

XPIDL VS WEBIDL

interface EventTarget void addEventListener(DOMString type EventListener listener optional boolean capture = false optional boolean wantsUntrusted = null) void removeEventListener(DOMString type EventListener listener optional boolean capture = false) boolean dispatchEvent(Event event)

[scriptable builtinclass uuid(5a8294df-ffe4-48e5-803f-f57bebc29289)]interface nsIDOMScreen nsIDOMEventTarget readonly attribute long top readonly attribute DOMString mozOrientation [implicit_jscontext] attribute jsval onmozorientationchange

boolean mozLockOrientation(in DOMString orientation) void mozUnlockOrientation()

httpsdevelopermozillaorgen-USdocsMozillaWebIDL_bindingshttpsdevelopermozillaorgen-USdocsXPIDL

MAPPING JS VS C++

bull Read other APIs

bull Interfaces are defined in dominterfaces

bull Implementations mostly in dom content

bull c++ implementations use common inheritance

bull JS implementations use manifest file

TIME TO FILE A BUGBugzilla DOMDevice Interfaces

HOW TO IMPLEMENT JS

WHY IN JSbull Prototyping

bull Lower entry point

bull WebDevs know JS

bull Also better for understanding

INTERFACE EXAMPLE

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

httpsbugzillamozillaorgshow_bugcgiid=674720

For example dominterfaceshelloworldnsIHelloWorldidl

HELLOWORLDMANIFEST

component f5181640-89e8-11e1-b0c4-0800200c9444 HelloWorldjscontract mozillaorghelloWorld1 f5181640-89e8-11e1-b0c4-0800200c9444category JavaScript-navigator-property mozHelloWorld mozillaorghelloWorld1

For example domhelloworldHelloWorldmanifest

HELLOWORLDJS

Text

const Cc = Componentsclassesconst Ci = Componentsinterfacesconst Cu = Componentsutils

Cuimport(resourcegremodulesXPCOMUtilsjsm)

function HelloWorld()

HelloWorldprototype =

init function init(aWindow)

sayHello function sayHello(aName) dump(Hello + aName + n)

classID ComponentsID(d88af7e0-a45f-11e1-b3dd-0800200c9444) QueryInterface XPCOMUtilsgenerateQI([ComponentsinterfacesnsIDOMHelloWorld])

classInfo XPCOMUtilsgenerateCI(classID ComponentsID(d88af7e0-a45f-11e1-b3dd-0800200c9444) contractID mozillaorghelloWorld1 classDescription HelloWorld interfaces [ComponentsinterfacesnsIDOMHelloWorld CinsIDOMGlobalPropertyInitializer] flags CinsIClassInfoDOM_OBJECT)

const NSGetFactory = XPCOMUtilsgenerateNSGetFactory([HelloWorld])

For example domhelloworldHelloWorldjs

BOILERPLATE

bull Makefiles

bull Manifest

bull Packaging

bull Module Loading

bull Access Permission

EXPOSEDPROPS

let foo = new Foo()

Fooprototype = __exposedProps__ name rw

FIREFOX OS PROCESS MODELbull Parent - Child Processes

bull Only one parent

bull Browser is in parent content pages are children

bull Nested process structure not possible (yet)

bull Parent is trusted

bull Child can be compromised

bull Security critical code has to run in parent

SYSTEM MESSAGE MANAGERbull Use for child-parent communication

bull Child

bull Parent

childProcessMessageManagersendAsyncMessage(message-name foo 2)

var response = sendSyncMessage(message-name foo 1)

receiveMessage function(aMessage) switch (aMessagename) [] parentProcessMessageManagersendAsynMessage(ldquoreturn-message-namerdquo [])

DOMREQUESTS

var pending = navigatormozAppsinstall(manifestUrl)pendingonsuccess = function () Save the App object that is returned var appRecord = thisresult alert(Installation successful)pendingonerror = function () Display the name of the error alert(Install failed error + thiserrorname)

PERMISSIONS

HOW TO IMPLEMENT C++

MAPPING JSC++

bull IDL files rarr JS amp C++

bull JS ctxlineWidth C++ ctxGetLineWidth(float width)

bull Need to implement C++ class for interface

bull NS_IMETHODIMP returns NS_ltstatusgt

bull Expose object nsDOMClassInfocppnsDOMClassInfoClassesh

INTERFACES

Attribute

PrintStateCallback

canvasmozPrintCallback =

function(obj) var ctx = objcontext ctxfillRect(0 0 100 100) objdone()

INTERFACES[scriptable uuid(a7062fca-41c6-4520-b777-3bb30fd77273)]interface nsIDOMHTMLCanvasElement nsIDOMHTMLElement []

A Mozilla-only callback that is called during the printing process attribute nsIPrintCallback mozPrintCallback

Attrib

ute

Callb

ack

[scriptable function uuid(8d5fb8a0-7782-11e1-b0c4-0800200c9a66)]interface nsIPrintCallback nsISupports void render(in nsIDOMMozCanvasPrintState ctx)

[scriptable builtinclass uuid(8d5fb8a0-7782-11e1-b0c4-0800200c9a67)]interface nsIDOMMozCanvasPrintState nsISupports A canvas rendering context readonly attribute nsISupports context

To be called when rendering to the context is done void done()

PrintS

tate

Taken frombug 745025

class nsHTMLCanvasPrintState public nsIDOMMozCanvasPrintStatepublic 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() [] return NS_OK

[]

Taken frombug 745025

MEMORY MANAGEMENTbull C++ doesnrsquot have a garbage collector (

bull In Gecko Reference counting amp cycle collector

bull Reference counting

bull nsCOMPtr (for interfaces) nsREFPtr

bull use getter_AddRefs

bull NS_IF_ADDREF amp NS_IF_RELEASE

MEMORY MANAGEMENT

bull Reference counting doesnrsquot work always

bull Make use of Geckorsquos cycle collector

bull Better cycle then maybe leak

DEBUGGING

bull Make sure to have a debug build

bull Enable logging (example)

bull Watch for assertion in logs

bull Insert printfs

bull There is documentation how to use debugger

OVERVIEW OF SOME TREES

bull Frame Tree Frames on page

bull Content Tree Content going with frames

bull View Tree Connecting views

MAKE YOUR WORK LAND

TESTS TESTS TESTS

bull Reftests

bull Crashtests

bull XPCShell Tests

bull Mochitests

bull JS tests

bull Compiled code tests -(

bull Marionette tests

DIFFERENT TYPE OF TESTS

MOCHITEST

Text

bullpathtoobjdir $ TEST_PATH=domcontactstests make mochitest-plain

bullpathtoobjdir $ TEST_PATH=domcontactsteststest_contactshtml make mochitest-plain

TIME FOR REVIEWbull Make sure the patch is formatted according to the guidelines

bull 8 lines of context

bull correct committer info (name + email)

bull correct checking message

bull When uploading a new version

bull address all review comments

bull obsolete the old patch

bull run tests again

REVIEWbull Make sure your patch is clean

bull Patch should be green on try-push

bull WIP State whatrsquos workingwhat notwhatrsquos next

bull Review might take some time (~1 week)

bull If longer ping person switch review person

bull Except r- donrsquot worry

Q amp A

THINGS TO HACK ON

bull Implement vwvhvminvmax

bull dirname DOM attribute on form controls

bull Implement FileSaver

Page 21: Implementing new WebAPIs

IT ALL STARTS WITH AN INTERFACEXPIDL VS WEBIDL

XPIDL VS WEBIDL

interface EventTarget void addEventListener(DOMString type EventListener listener optional boolean capture = false optional boolean wantsUntrusted = null) void removeEventListener(DOMString type EventListener listener optional boolean capture = false) boolean dispatchEvent(Event event)

[scriptable builtinclass uuid(5a8294df-ffe4-48e5-803f-f57bebc29289)]interface nsIDOMScreen nsIDOMEventTarget readonly attribute long top readonly attribute DOMString mozOrientation [implicit_jscontext] attribute jsval onmozorientationchange

boolean mozLockOrientation(in DOMString orientation) void mozUnlockOrientation()

httpsdevelopermozillaorgen-USdocsMozillaWebIDL_bindingshttpsdevelopermozillaorgen-USdocsXPIDL

MAPPING JS VS C++

bull Read other APIs

bull Interfaces are defined in dominterfaces

bull Implementations mostly in dom content

bull c++ implementations use common inheritance

bull JS implementations use manifest file

TIME TO FILE A BUGBugzilla DOMDevice Interfaces

HOW TO IMPLEMENT JS

WHY IN JSbull Prototyping

bull Lower entry point

bull WebDevs know JS

bull Also better for understanding

INTERFACE EXAMPLE

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

httpsbugzillamozillaorgshow_bugcgiid=674720

For example dominterfaceshelloworldnsIHelloWorldidl

HELLOWORLDMANIFEST

component f5181640-89e8-11e1-b0c4-0800200c9444 HelloWorldjscontract mozillaorghelloWorld1 f5181640-89e8-11e1-b0c4-0800200c9444category JavaScript-navigator-property mozHelloWorld mozillaorghelloWorld1

For example domhelloworldHelloWorldmanifest

HELLOWORLDJS

Text

const Cc = Componentsclassesconst Ci = Componentsinterfacesconst Cu = Componentsutils

Cuimport(resourcegremodulesXPCOMUtilsjsm)

function HelloWorld()

HelloWorldprototype =

init function init(aWindow)

sayHello function sayHello(aName) dump(Hello + aName + n)

classID ComponentsID(d88af7e0-a45f-11e1-b3dd-0800200c9444) QueryInterface XPCOMUtilsgenerateQI([ComponentsinterfacesnsIDOMHelloWorld])

classInfo XPCOMUtilsgenerateCI(classID ComponentsID(d88af7e0-a45f-11e1-b3dd-0800200c9444) contractID mozillaorghelloWorld1 classDescription HelloWorld interfaces [ComponentsinterfacesnsIDOMHelloWorld CinsIDOMGlobalPropertyInitializer] flags CinsIClassInfoDOM_OBJECT)

const NSGetFactory = XPCOMUtilsgenerateNSGetFactory([HelloWorld])

For example domhelloworldHelloWorldjs

BOILERPLATE

bull Makefiles

bull Manifest

bull Packaging

bull Module Loading

bull Access Permission

EXPOSEDPROPS

let foo = new Foo()

Fooprototype = __exposedProps__ name rw

FIREFOX OS PROCESS MODELbull Parent - Child Processes

bull Only one parent

bull Browser is in parent content pages are children

bull Nested process structure not possible (yet)

bull Parent is trusted

bull Child can be compromised

bull Security critical code has to run in parent

SYSTEM MESSAGE MANAGERbull Use for child-parent communication

bull Child

bull Parent

childProcessMessageManagersendAsyncMessage(message-name foo 2)

var response = sendSyncMessage(message-name foo 1)

receiveMessage function(aMessage) switch (aMessagename) [] parentProcessMessageManagersendAsynMessage(ldquoreturn-message-namerdquo [])

DOMREQUESTS

var pending = navigatormozAppsinstall(manifestUrl)pendingonsuccess = function () Save the App object that is returned var appRecord = thisresult alert(Installation successful)pendingonerror = function () Display the name of the error alert(Install failed error + thiserrorname)

PERMISSIONS

HOW TO IMPLEMENT C++

MAPPING JSC++

bull IDL files rarr JS amp C++

bull JS ctxlineWidth C++ ctxGetLineWidth(float width)

bull Need to implement C++ class for interface

bull NS_IMETHODIMP returns NS_ltstatusgt

bull Expose object nsDOMClassInfocppnsDOMClassInfoClassesh

INTERFACES

Attribute

PrintStateCallback

canvasmozPrintCallback =

function(obj) var ctx = objcontext ctxfillRect(0 0 100 100) objdone()

INTERFACES[scriptable uuid(a7062fca-41c6-4520-b777-3bb30fd77273)]interface nsIDOMHTMLCanvasElement nsIDOMHTMLElement []

A Mozilla-only callback that is called during the printing process attribute nsIPrintCallback mozPrintCallback

Attrib

ute

Callb

ack

[scriptable function uuid(8d5fb8a0-7782-11e1-b0c4-0800200c9a66)]interface nsIPrintCallback nsISupports void render(in nsIDOMMozCanvasPrintState ctx)

[scriptable builtinclass uuid(8d5fb8a0-7782-11e1-b0c4-0800200c9a67)]interface nsIDOMMozCanvasPrintState nsISupports A canvas rendering context readonly attribute nsISupports context

To be called when rendering to the context is done void done()

PrintS

tate

Taken frombug 745025

class nsHTMLCanvasPrintState public nsIDOMMozCanvasPrintStatepublic 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() [] return NS_OK

[]

Taken frombug 745025

MEMORY MANAGEMENTbull C++ doesnrsquot have a garbage collector (

bull In Gecko Reference counting amp cycle collector

bull Reference counting

bull nsCOMPtr (for interfaces) nsREFPtr

bull use getter_AddRefs

bull NS_IF_ADDREF amp NS_IF_RELEASE

MEMORY MANAGEMENT

bull Reference counting doesnrsquot work always

bull Make use of Geckorsquos cycle collector

bull Better cycle then maybe leak

DEBUGGING

bull Make sure to have a debug build

bull Enable logging (example)

bull Watch for assertion in logs

bull Insert printfs

bull There is documentation how to use debugger

OVERVIEW OF SOME TREES

bull Frame Tree Frames on page

bull Content Tree Content going with frames

bull View Tree Connecting views

MAKE YOUR WORK LAND

TESTS TESTS TESTS

bull Reftests

bull Crashtests

bull XPCShell Tests

bull Mochitests

bull JS tests

bull Compiled code tests -(

bull Marionette tests

DIFFERENT TYPE OF TESTS

MOCHITEST

Text

bullpathtoobjdir $ TEST_PATH=domcontactstests make mochitest-plain

bullpathtoobjdir $ TEST_PATH=domcontactsteststest_contactshtml make mochitest-plain

TIME FOR REVIEWbull Make sure the patch is formatted according to the guidelines

bull 8 lines of context

bull correct committer info (name + email)

bull correct checking message

bull When uploading a new version

bull address all review comments

bull obsolete the old patch

bull run tests again

REVIEWbull Make sure your patch is clean

bull Patch should be green on try-push

bull WIP State whatrsquos workingwhat notwhatrsquos next

bull Review might take some time (~1 week)

bull If longer ping person switch review person

bull Except r- donrsquot worry

Q amp A

THINGS TO HACK ON

bull Implement vwvhvminvmax

bull dirname DOM attribute on form controls

bull Implement FileSaver

Page 22: Implementing new WebAPIs

XPIDL VS WEBIDL

interface EventTarget void addEventListener(DOMString type EventListener listener optional boolean capture = false optional boolean wantsUntrusted = null) void removeEventListener(DOMString type EventListener listener optional boolean capture = false) boolean dispatchEvent(Event event)

[scriptable builtinclass uuid(5a8294df-ffe4-48e5-803f-f57bebc29289)]interface nsIDOMScreen nsIDOMEventTarget readonly attribute long top readonly attribute DOMString mozOrientation [implicit_jscontext] attribute jsval onmozorientationchange

boolean mozLockOrientation(in DOMString orientation) void mozUnlockOrientation()

httpsdevelopermozillaorgen-USdocsMozillaWebIDL_bindingshttpsdevelopermozillaorgen-USdocsXPIDL

MAPPING JS VS C++

bull Read other APIs

bull Interfaces are defined in dominterfaces

bull Implementations mostly in dom content

bull c++ implementations use common inheritance

bull JS implementations use manifest file

TIME TO FILE A BUGBugzilla DOMDevice Interfaces

HOW TO IMPLEMENT JS

WHY IN JSbull Prototyping

bull Lower entry point

bull WebDevs know JS

bull Also better for understanding

INTERFACE EXAMPLE

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

httpsbugzillamozillaorgshow_bugcgiid=674720

For example dominterfaceshelloworldnsIHelloWorldidl

HELLOWORLDMANIFEST

component f5181640-89e8-11e1-b0c4-0800200c9444 HelloWorldjscontract mozillaorghelloWorld1 f5181640-89e8-11e1-b0c4-0800200c9444category JavaScript-navigator-property mozHelloWorld mozillaorghelloWorld1

For example domhelloworldHelloWorldmanifest

HELLOWORLDJS

Text

const Cc = Componentsclassesconst Ci = Componentsinterfacesconst Cu = Componentsutils

Cuimport(resourcegremodulesXPCOMUtilsjsm)

function HelloWorld()

HelloWorldprototype =

init function init(aWindow)

sayHello function sayHello(aName) dump(Hello + aName + n)

classID ComponentsID(d88af7e0-a45f-11e1-b3dd-0800200c9444) QueryInterface XPCOMUtilsgenerateQI([ComponentsinterfacesnsIDOMHelloWorld])

classInfo XPCOMUtilsgenerateCI(classID ComponentsID(d88af7e0-a45f-11e1-b3dd-0800200c9444) contractID mozillaorghelloWorld1 classDescription HelloWorld interfaces [ComponentsinterfacesnsIDOMHelloWorld CinsIDOMGlobalPropertyInitializer] flags CinsIClassInfoDOM_OBJECT)

const NSGetFactory = XPCOMUtilsgenerateNSGetFactory([HelloWorld])

For example domhelloworldHelloWorldjs

BOILERPLATE

bull Makefiles

bull Manifest

bull Packaging

bull Module Loading

bull Access Permission

EXPOSEDPROPS

let foo = new Foo()

Fooprototype = __exposedProps__ name rw

FIREFOX OS PROCESS MODELbull Parent - Child Processes

bull Only one parent

bull Browser is in parent content pages are children

bull Nested process structure not possible (yet)

bull Parent is trusted

bull Child can be compromised

bull Security critical code has to run in parent

SYSTEM MESSAGE MANAGERbull Use for child-parent communication

bull Child

bull Parent

childProcessMessageManagersendAsyncMessage(message-name foo 2)

var response = sendSyncMessage(message-name foo 1)

receiveMessage function(aMessage) switch (aMessagename) [] parentProcessMessageManagersendAsynMessage(ldquoreturn-message-namerdquo [])

DOMREQUESTS

var pending = navigatormozAppsinstall(manifestUrl)pendingonsuccess = function () Save the App object that is returned var appRecord = thisresult alert(Installation successful)pendingonerror = function () Display the name of the error alert(Install failed error + thiserrorname)

PERMISSIONS

HOW TO IMPLEMENT C++

MAPPING JSC++

bull IDL files rarr JS amp C++

bull JS ctxlineWidth C++ ctxGetLineWidth(float width)

bull Need to implement C++ class for interface

bull NS_IMETHODIMP returns NS_ltstatusgt

bull Expose object nsDOMClassInfocppnsDOMClassInfoClassesh

INTERFACES

Attribute

PrintStateCallback

canvasmozPrintCallback =

function(obj) var ctx = objcontext ctxfillRect(0 0 100 100) objdone()

INTERFACES[scriptable uuid(a7062fca-41c6-4520-b777-3bb30fd77273)]interface nsIDOMHTMLCanvasElement nsIDOMHTMLElement []

A Mozilla-only callback that is called during the printing process attribute nsIPrintCallback mozPrintCallback

Attrib

ute

Callb

ack

[scriptable function uuid(8d5fb8a0-7782-11e1-b0c4-0800200c9a66)]interface nsIPrintCallback nsISupports void render(in nsIDOMMozCanvasPrintState ctx)

[scriptable builtinclass uuid(8d5fb8a0-7782-11e1-b0c4-0800200c9a67)]interface nsIDOMMozCanvasPrintState nsISupports A canvas rendering context readonly attribute nsISupports context

To be called when rendering to the context is done void done()

PrintS

tate

Taken frombug 745025

class nsHTMLCanvasPrintState public nsIDOMMozCanvasPrintStatepublic 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() [] return NS_OK

[]

Taken frombug 745025

MEMORY MANAGEMENTbull C++ doesnrsquot have a garbage collector (

bull In Gecko Reference counting amp cycle collector

bull Reference counting

bull nsCOMPtr (for interfaces) nsREFPtr

bull use getter_AddRefs

bull NS_IF_ADDREF amp NS_IF_RELEASE

MEMORY MANAGEMENT

bull Reference counting doesnrsquot work always

bull Make use of Geckorsquos cycle collector

bull Better cycle then maybe leak

DEBUGGING

bull Make sure to have a debug build

bull Enable logging (example)

bull Watch for assertion in logs

bull Insert printfs

bull There is documentation how to use debugger

OVERVIEW OF SOME TREES

bull Frame Tree Frames on page

bull Content Tree Content going with frames

bull View Tree Connecting views

MAKE YOUR WORK LAND

TESTS TESTS TESTS

bull Reftests

bull Crashtests

bull XPCShell Tests

bull Mochitests

bull JS tests

bull Compiled code tests -(

bull Marionette tests

DIFFERENT TYPE OF TESTS

MOCHITEST

Text

bullpathtoobjdir $ TEST_PATH=domcontactstests make mochitest-plain

bullpathtoobjdir $ TEST_PATH=domcontactsteststest_contactshtml make mochitest-plain

TIME FOR REVIEWbull Make sure the patch is formatted according to the guidelines

bull 8 lines of context

bull correct committer info (name + email)

bull correct checking message

bull When uploading a new version

bull address all review comments

bull obsolete the old patch

bull run tests again

REVIEWbull Make sure your patch is clean

bull Patch should be green on try-push

bull WIP State whatrsquos workingwhat notwhatrsquos next

bull Review might take some time (~1 week)

bull If longer ping person switch review person

bull Except r- donrsquot worry

Q amp A

THINGS TO HACK ON

bull Implement vwvhvminvmax

bull dirname DOM attribute on form controls

bull Implement FileSaver

Page 23: Implementing new WebAPIs

MAPPING JS VS C++

bull Read other APIs

bull Interfaces are defined in dominterfaces

bull Implementations mostly in dom content

bull c++ implementations use common inheritance

bull JS implementations use manifest file

TIME TO FILE A BUGBugzilla DOMDevice Interfaces

HOW TO IMPLEMENT JS

WHY IN JSbull Prototyping

bull Lower entry point

bull WebDevs know JS

bull Also better for understanding

INTERFACE EXAMPLE

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

httpsbugzillamozillaorgshow_bugcgiid=674720

For example dominterfaceshelloworldnsIHelloWorldidl

HELLOWORLDMANIFEST

component f5181640-89e8-11e1-b0c4-0800200c9444 HelloWorldjscontract mozillaorghelloWorld1 f5181640-89e8-11e1-b0c4-0800200c9444category JavaScript-navigator-property mozHelloWorld mozillaorghelloWorld1

For example domhelloworldHelloWorldmanifest

HELLOWORLDJS

Text

const Cc = Componentsclassesconst Ci = Componentsinterfacesconst Cu = Componentsutils

Cuimport(resourcegremodulesXPCOMUtilsjsm)

function HelloWorld()

HelloWorldprototype =

init function init(aWindow)

sayHello function sayHello(aName) dump(Hello + aName + n)

classID ComponentsID(d88af7e0-a45f-11e1-b3dd-0800200c9444) QueryInterface XPCOMUtilsgenerateQI([ComponentsinterfacesnsIDOMHelloWorld])

classInfo XPCOMUtilsgenerateCI(classID ComponentsID(d88af7e0-a45f-11e1-b3dd-0800200c9444) contractID mozillaorghelloWorld1 classDescription HelloWorld interfaces [ComponentsinterfacesnsIDOMHelloWorld CinsIDOMGlobalPropertyInitializer] flags CinsIClassInfoDOM_OBJECT)

const NSGetFactory = XPCOMUtilsgenerateNSGetFactory([HelloWorld])

For example domhelloworldHelloWorldjs

BOILERPLATE

bull Makefiles

bull Manifest

bull Packaging

bull Module Loading

bull Access Permission

EXPOSEDPROPS

let foo = new Foo()

Fooprototype = __exposedProps__ name rw

FIREFOX OS PROCESS MODELbull Parent - Child Processes

bull Only one parent

bull Browser is in parent content pages are children

bull Nested process structure not possible (yet)

bull Parent is trusted

bull Child can be compromised

bull Security critical code has to run in parent

SYSTEM MESSAGE MANAGERbull Use for child-parent communication

bull Child

bull Parent

childProcessMessageManagersendAsyncMessage(message-name foo 2)

var response = sendSyncMessage(message-name foo 1)

receiveMessage function(aMessage) switch (aMessagename) [] parentProcessMessageManagersendAsynMessage(ldquoreturn-message-namerdquo [])

DOMREQUESTS

var pending = navigatormozAppsinstall(manifestUrl)pendingonsuccess = function () Save the App object that is returned var appRecord = thisresult alert(Installation successful)pendingonerror = function () Display the name of the error alert(Install failed error + thiserrorname)

PERMISSIONS

HOW TO IMPLEMENT C++

MAPPING JSC++

bull IDL files rarr JS amp C++

bull JS ctxlineWidth C++ ctxGetLineWidth(float width)

bull Need to implement C++ class for interface

bull NS_IMETHODIMP returns NS_ltstatusgt

bull Expose object nsDOMClassInfocppnsDOMClassInfoClassesh

INTERFACES

Attribute

PrintStateCallback

canvasmozPrintCallback =

function(obj) var ctx = objcontext ctxfillRect(0 0 100 100) objdone()

INTERFACES[scriptable uuid(a7062fca-41c6-4520-b777-3bb30fd77273)]interface nsIDOMHTMLCanvasElement nsIDOMHTMLElement []

A Mozilla-only callback that is called during the printing process attribute nsIPrintCallback mozPrintCallback

Attrib

ute

Callb

ack

[scriptable function uuid(8d5fb8a0-7782-11e1-b0c4-0800200c9a66)]interface nsIPrintCallback nsISupports void render(in nsIDOMMozCanvasPrintState ctx)

[scriptable builtinclass uuid(8d5fb8a0-7782-11e1-b0c4-0800200c9a67)]interface nsIDOMMozCanvasPrintState nsISupports A canvas rendering context readonly attribute nsISupports context

To be called when rendering to the context is done void done()

PrintS

tate

Taken frombug 745025

class nsHTMLCanvasPrintState public nsIDOMMozCanvasPrintStatepublic 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() [] return NS_OK

[]

Taken frombug 745025

MEMORY MANAGEMENTbull C++ doesnrsquot have a garbage collector (

bull In Gecko Reference counting amp cycle collector

bull Reference counting

bull nsCOMPtr (for interfaces) nsREFPtr

bull use getter_AddRefs

bull NS_IF_ADDREF amp NS_IF_RELEASE

MEMORY MANAGEMENT

bull Reference counting doesnrsquot work always

bull Make use of Geckorsquos cycle collector

bull Better cycle then maybe leak

DEBUGGING

bull Make sure to have a debug build

bull Enable logging (example)

bull Watch for assertion in logs

bull Insert printfs

bull There is documentation how to use debugger

OVERVIEW OF SOME TREES

bull Frame Tree Frames on page

bull Content Tree Content going with frames

bull View Tree Connecting views

MAKE YOUR WORK LAND

TESTS TESTS TESTS

bull Reftests

bull Crashtests

bull XPCShell Tests

bull Mochitests

bull JS tests

bull Compiled code tests -(

bull Marionette tests

DIFFERENT TYPE OF TESTS

MOCHITEST

Text

bullpathtoobjdir $ TEST_PATH=domcontactstests make mochitest-plain

bullpathtoobjdir $ TEST_PATH=domcontactsteststest_contactshtml make mochitest-plain

TIME FOR REVIEWbull Make sure the patch is formatted according to the guidelines

bull 8 lines of context

bull correct committer info (name + email)

bull correct checking message

bull When uploading a new version

bull address all review comments

bull obsolete the old patch

bull run tests again

REVIEWbull Make sure your patch is clean

bull Patch should be green on try-push

bull WIP State whatrsquos workingwhat notwhatrsquos next

bull Review might take some time (~1 week)

bull If longer ping person switch review person

bull Except r- donrsquot worry

Q amp A

THINGS TO HACK ON

bull Implement vwvhvminvmax

bull dirname DOM attribute on form controls

bull Implement FileSaver

Page 24: Implementing new WebAPIs

TIME TO FILE A BUGBugzilla DOMDevice Interfaces

HOW TO IMPLEMENT JS

WHY IN JSbull Prototyping

bull Lower entry point

bull WebDevs know JS

bull Also better for understanding

INTERFACE EXAMPLE

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

httpsbugzillamozillaorgshow_bugcgiid=674720

For example dominterfaceshelloworldnsIHelloWorldidl

HELLOWORLDMANIFEST

component f5181640-89e8-11e1-b0c4-0800200c9444 HelloWorldjscontract mozillaorghelloWorld1 f5181640-89e8-11e1-b0c4-0800200c9444category JavaScript-navigator-property mozHelloWorld mozillaorghelloWorld1

For example domhelloworldHelloWorldmanifest

HELLOWORLDJS

Text

const Cc = Componentsclassesconst Ci = Componentsinterfacesconst Cu = Componentsutils

Cuimport(resourcegremodulesXPCOMUtilsjsm)

function HelloWorld()

HelloWorldprototype =

init function init(aWindow)

sayHello function sayHello(aName) dump(Hello + aName + n)

classID ComponentsID(d88af7e0-a45f-11e1-b3dd-0800200c9444) QueryInterface XPCOMUtilsgenerateQI([ComponentsinterfacesnsIDOMHelloWorld])

classInfo XPCOMUtilsgenerateCI(classID ComponentsID(d88af7e0-a45f-11e1-b3dd-0800200c9444) contractID mozillaorghelloWorld1 classDescription HelloWorld interfaces [ComponentsinterfacesnsIDOMHelloWorld CinsIDOMGlobalPropertyInitializer] flags CinsIClassInfoDOM_OBJECT)

const NSGetFactory = XPCOMUtilsgenerateNSGetFactory([HelloWorld])

For example domhelloworldHelloWorldjs

BOILERPLATE

bull Makefiles

bull Manifest

bull Packaging

bull Module Loading

bull Access Permission

EXPOSEDPROPS

let foo = new Foo()

Fooprototype = __exposedProps__ name rw

FIREFOX OS PROCESS MODELbull Parent - Child Processes

bull Only one parent

bull Browser is in parent content pages are children

bull Nested process structure not possible (yet)

bull Parent is trusted

bull Child can be compromised

bull Security critical code has to run in parent

SYSTEM MESSAGE MANAGERbull Use for child-parent communication

bull Child

bull Parent

childProcessMessageManagersendAsyncMessage(message-name foo 2)

var response = sendSyncMessage(message-name foo 1)

receiveMessage function(aMessage) switch (aMessagename) [] parentProcessMessageManagersendAsynMessage(ldquoreturn-message-namerdquo [])

DOMREQUESTS

var pending = navigatormozAppsinstall(manifestUrl)pendingonsuccess = function () Save the App object that is returned var appRecord = thisresult alert(Installation successful)pendingonerror = function () Display the name of the error alert(Install failed error + thiserrorname)

PERMISSIONS

HOW TO IMPLEMENT C++

MAPPING JSC++

bull IDL files rarr JS amp C++

bull JS ctxlineWidth C++ ctxGetLineWidth(float width)

bull Need to implement C++ class for interface

bull NS_IMETHODIMP returns NS_ltstatusgt

bull Expose object nsDOMClassInfocppnsDOMClassInfoClassesh

INTERFACES

Attribute

PrintStateCallback

canvasmozPrintCallback =

function(obj) var ctx = objcontext ctxfillRect(0 0 100 100) objdone()

INTERFACES[scriptable uuid(a7062fca-41c6-4520-b777-3bb30fd77273)]interface nsIDOMHTMLCanvasElement nsIDOMHTMLElement []

A Mozilla-only callback that is called during the printing process attribute nsIPrintCallback mozPrintCallback

Attrib

ute

Callb

ack

[scriptable function uuid(8d5fb8a0-7782-11e1-b0c4-0800200c9a66)]interface nsIPrintCallback nsISupports void render(in nsIDOMMozCanvasPrintState ctx)

[scriptable builtinclass uuid(8d5fb8a0-7782-11e1-b0c4-0800200c9a67)]interface nsIDOMMozCanvasPrintState nsISupports A canvas rendering context readonly attribute nsISupports context

To be called when rendering to the context is done void done()

PrintS

tate

Taken frombug 745025

class nsHTMLCanvasPrintState public nsIDOMMozCanvasPrintStatepublic 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() [] return NS_OK

[]

Taken frombug 745025

MEMORY MANAGEMENTbull C++ doesnrsquot have a garbage collector (

bull In Gecko Reference counting amp cycle collector

bull Reference counting

bull nsCOMPtr (for interfaces) nsREFPtr

bull use getter_AddRefs

bull NS_IF_ADDREF amp NS_IF_RELEASE

MEMORY MANAGEMENT

bull Reference counting doesnrsquot work always

bull Make use of Geckorsquos cycle collector

bull Better cycle then maybe leak

DEBUGGING

bull Make sure to have a debug build

bull Enable logging (example)

bull Watch for assertion in logs

bull Insert printfs

bull There is documentation how to use debugger

OVERVIEW OF SOME TREES

bull Frame Tree Frames on page

bull Content Tree Content going with frames

bull View Tree Connecting views

MAKE YOUR WORK LAND

TESTS TESTS TESTS

bull Reftests

bull Crashtests

bull XPCShell Tests

bull Mochitests

bull JS tests

bull Compiled code tests -(

bull Marionette tests

DIFFERENT TYPE OF TESTS

MOCHITEST

Text

bullpathtoobjdir $ TEST_PATH=domcontactstests make mochitest-plain

bullpathtoobjdir $ TEST_PATH=domcontactsteststest_contactshtml make mochitest-plain

TIME FOR REVIEWbull Make sure the patch is formatted according to the guidelines

bull 8 lines of context

bull correct committer info (name + email)

bull correct checking message

bull When uploading a new version

bull address all review comments

bull obsolete the old patch

bull run tests again

REVIEWbull Make sure your patch is clean

bull Patch should be green on try-push

bull WIP State whatrsquos workingwhat notwhatrsquos next

bull Review might take some time (~1 week)

bull If longer ping person switch review person

bull Except r- donrsquot worry

Q amp A

THINGS TO HACK ON

bull Implement vwvhvminvmax

bull dirname DOM attribute on form controls

bull Implement FileSaver

Page 25: Implementing new WebAPIs

HOW TO IMPLEMENT JS

WHY IN JSbull Prototyping

bull Lower entry point

bull WebDevs know JS

bull Also better for understanding

INTERFACE EXAMPLE

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

httpsbugzillamozillaorgshow_bugcgiid=674720

For example dominterfaceshelloworldnsIHelloWorldidl

HELLOWORLDMANIFEST

component f5181640-89e8-11e1-b0c4-0800200c9444 HelloWorldjscontract mozillaorghelloWorld1 f5181640-89e8-11e1-b0c4-0800200c9444category JavaScript-navigator-property mozHelloWorld mozillaorghelloWorld1

For example domhelloworldHelloWorldmanifest

HELLOWORLDJS

Text

const Cc = Componentsclassesconst Ci = Componentsinterfacesconst Cu = Componentsutils

Cuimport(resourcegremodulesXPCOMUtilsjsm)

function HelloWorld()

HelloWorldprototype =

init function init(aWindow)

sayHello function sayHello(aName) dump(Hello + aName + n)

classID ComponentsID(d88af7e0-a45f-11e1-b3dd-0800200c9444) QueryInterface XPCOMUtilsgenerateQI([ComponentsinterfacesnsIDOMHelloWorld])

classInfo XPCOMUtilsgenerateCI(classID ComponentsID(d88af7e0-a45f-11e1-b3dd-0800200c9444) contractID mozillaorghelloWorld1 classDescription HelloWorld interfaces [ComponentsinterfacesnsIDOMHelloWorld CinsIDOMGlobalPropertyInitializer] flags CinsIClassInfoDOM_OBJECT)

const NSGetFactory = XPCOMUtilsgenerateNSGetFactory([HelloWorld])

For example domhelloworldHelloWorldjs

BOILERPLATE

bull Makefiles

bull Manifest

bull Packaging

bull Module Loading

bull Access Permission

EXPOSEDPROPS

let foo = new Foo()

Fooprototype = __exposedProps__ name rw

FIREFOX OS PROCESS MODELbull Parent - Child Processes

bull Only one parent

bull Browser is in parent content pages are children

bull Nested process structure not possible (yet)

bull Parent is trusted

bull Child can be compromised

bull Security critical code has to run in parent

SYSTEM MESSAGE MANAGERbull Use for child-parent communication

bull Child

bull Parent

childProcessMessageManagersendAsyncMessage(message-name foo 2)

var response = sendSyncMessage(message-name foo 1)

receiveMessage function(aMessage) switch (aMessagename) [] parentProcessMessageManagersendAsynMessage(ldquoreturn-message-namerdquo [])

DOMREQUESTS

var pending = navigatormozAppsinstall(manifestUrl)pendingonsuccess = function () Save the App object that is returned var appRecord = thisresult alert(Installation successful)pendingonerror = function () Display the name of the error alert(Install failed error + thiserrorname)

PERMISSIONS

HOW TO IMPLEMENT C++

MAPPING JSC++

bull IDL files rarr JS amp C++

bull JS ctxlineWidth C++ ctxGetLineWidth(float width)

bull Need to implement C++ class for interface

bull NS_IMETHODIMP returns NS_ltstatusgt

bull Expose object nsDOMClassInfocppnsDOMClassInfoClassesh

INTERFACES

Attribute

PrintStateCallback

canvasmozPrintCallback =

function(obj) var ctx = objcontext ctxfillRect(0 0 100 100) objdone()

INTERFACES[scriptable uuid(a7062fca-41c6-4520-b777-3bb30fd77273)]interface nsIDOMHTMLCanvasElement nsIDOMHTMLElement []

A Mozilla-only callback that is called during the printing process attribute nsIPrintCallback mozPrintCallback

Attrib

ute

Callb

ack

[scriptable function uuid(8d5fb8a0-7782-11e1-b0c4-0800200c9a66)]interface nsIPrintCallback nsISupports void render(in nsIDOMMozCanvasPrintState ctx)

[scriptable builtinclass uuid(8d5fb8a0-7782-11e1-b0c4-0800200c9a67)]interface nsIDOMMozCanvasPrintState nsISupports A canvas rendering context readonly attribute nsISupports context

To be called when rendering to the context is done void done()

PrintS

tate

Taken frombug 745025

class nsHTMLCanvasPrintState public nsIDOMMozCanvasPrintStatepublic 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() [] return NS_OK

[]

Taken frombug 745025

MEMORY MANAGEMENTbull C++ doesnrsquot have a garbage collector (

bull In Gecko Reference counting amp cycle collector

bull Reference counting

bull nsCOMPtr (for interfaces) nsREFPtr

bull use getter_AddRefs

bull NS_IF_ADDREF amp NS_IF_RELEASE

MEMORY MANAGEMENT

bull Reference counting doesnrsquot work always

bull Make use of Geckorsquos cycle collector

bull Better cycle then maybe leak

DEBUGGING

bull Make sure to have a debug build

bull Enable logging (example)

bull Watch for assertion in logs

bull Insert printfs

bull There is documentation how to use debugger

OVERVIEW OF SOME TREES

bull Frame Tree Frames on page

bull Content Tree Content going with frames

bull View Tree Connecting views

MAKE YOUR WORK LAND

TESTS TESTS TESTS

bull Reftests

bull Crashtests

bull XPCShell Tests

bull Mochitests

bull JS tests

bull Compiled code tests -(

bull Marionette tests

DIFFERENT TYPE OF TESTS

MOCHITEST

Text

bullpathtoobjdir $ TEST_PATH=domcontactstests make mochitest-plain

bullpathtoobjdir $ TEST_PATH=domcontactsteststest_contactshtml make mochitest-plain

TIME FOR REVIEWbull Make sure the patch is formatted according to the guidelines

bull 8 lines of context

bull correct committer info (name + email)

bull correct checking message

bull When uploading a new version

bull address all review comments

bull obsolete the old patch

bull run tests again

REVIEWbull Make sure your patch is clean

bull Patch should be green on try-push

bull WIP State whatrsquos workingwhat notwhatrsquos next

bull Review might take some time (~1 week)

bull If longer ping person switch review person

bull Except r- donrsquot worry

Q amp A

THINGS TO HACK ON

bull Implement vwvhvminvmax

bull dirname DOM attribute on form controls

bull Implement FileSaver

Page 26: Implementing new WebAPIs

WHY IN JSbull Prototyping

bull Lower entry point

bull WebDevs know JS

bull Also better for understanding

INTERFACE EXAMPLE

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

httpsbugzillamozillaorgshow_bugcgiid=674720

For example dominterfaceshelloworldnsIHelloWorldidl

HELLOWORLDMANIFEST

component f5181640-89e8-11e1-b0c4-0800200c9444 HelloWorldjscontract mozillaorghelloWorld1 f5181640-89e8-11e1-b0c4-0800200c9444category JavaScript-navigator-property mozHelloWorld mozillaorghelloWorld1

For example domhelloworldHelloWorldmanifest

HELLOWORLDJS

Text

const Cc = Componentsclassesconst Ci = Componentsinterfacesconst Cu = Componentsutils

Cuimport(resourcegremodulesXPCOMUtilsjsm)

function HelloWorld()

HelloWorldprototype =

init function init(aWindow)

sayHello function sayHello(aName) dump(Hello + aName + n)

classID ComponentsID(d88af7e0-a45f-11e1-b3dd-0800200c9444) QueryInterface XPCOMUtilsgenerateQI([ComponentsinterfacesnsIDOMHelloWorld])

classInfo XPCOMUtilsgenerateCI(classID ComponentsID(d88af7e0-a45f-11e1-b3dd-0800200c9444) contractID mozillaorghelloWorld1 classDescription HelloWorld interfaces [ComponentsinterfacesnsIDOMHelloWorld CinsIDOMGlobalPropertyInitializer] flags CinsIClassInfoDOM_OBJECT)

const NSGetFactory = XPCOMUtilsgenerateNSGetFactory([HelloWorld])

For example domhelloworldHelloWorldjs

BOILERPLATE

bull Makefiles

bull Manifest

bull Packaging

bull Module Loading

bull Access Permission

EXPOSEDPROPS

let foo = new Foo()

Fooprototype = __exposedProps__ name rw

FIREFOX OS PROCESS MODELbull Parent - Child Processes

bull Only one parent

bull Browser is in parent content pages are children

bull Nested process structure not possible (yet)

bull Parent is trusted

bull Child can be compromised

bull Security critical code has to run in parent

SYSTEM MESSAGE MANAGERbull Use for child-parent communication

bull Child

bull Parent

childProcessMessageManagersendAsyncMessage(message-name foo 2)

var response = sendSyncMessage(message-name foo 1)

receiveMessage function(aMessage) switch (aMessagename) [] parentProcessMessageManagersendAsynMessage(ldquoreturn-message-namerdquo [])

DOMREQUESTS

var pending = navigatormozAppsinstall(manifestUrl)pendingonsuccess = function () Save the App object that is returned var appRecord = thisresult alert(Installation successful)pendingonerror = function () Display the name of the error alert(Install failed error + thiserrorname)

PERMISSIONS

HOW TO IMPLEMENT C++

MAPPING JSC++

bull IDL files rarr JS amp C++

bull JS ctxlineWidth C++ ctxGetLineWidth(float width)

bull Need to implement C++ class for interface

bull NS_IMETHODIMP returns NS_ltstatusgt

bull Expose object nsDOMClassInfocppnsDOMClassInfoClassesh

INTERFACES

Attribute

PrintStateCallback

canvasmozPrintCallback =

function(obj) var ctx = objcontext ctxfillRect(0 0 100 100) objdone()

INTERFACES[scriptable uuid(a7062fca-41c6-4520-b777-3bb30fd77273)]interface nsIDOMHTMLCanvasElement nsIDOMHTMLElement []

A Mozilla-only callback that is called during the printing process attribute nsIPrintCallback mozPrintCallback

Attrib

ute

Callb

ack

[scriptable function uuid(8d5fb8a0-7782-11e1-b0c4-0800200c9a66)]interface nsIPrintCallback nsISupports void render(in nsIDOMMozCanvasPrintState ctx)

[scriptable builtinclass uuid(8d5fb8a0-7782-11e1-b0c4-0800200c9a67)]interface nsIDOMMozCanvasPrintState nsISupports A canvas rendering context readonly attribute nsISupports context

To be called when rendering to the context is done void done()

PrintS

tate

Taken frombug 745025

class nsHTMLCanvasPrintState public nsIDOMMozCanvasPrintStatepublic 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() [] return NS_OK

[]

Taken frombug 745025

MEMORY MANAGEMENTbull C++ doesnrsquot have a garbage collector (

bull In Gecko Reference counting amp cycle collector

bull Reference counting

bull nsCOMPtr (for interfaces) nsREFPtr

bull use getter_AddRefs

bull NS_IF_ADDREF amp NS_IF_RELEASE

MEMORY MANAGEMENT

bull Reference counting doesnrsquot work always

bull Make use of Geckorsquos cycle collector

bull Better cycle then maybe leak

DEBUGGING

bull Make sure to have a debug build

bull Enable logging (example)

bull Watch for assertion in logs

bull Insert printfs

bull There is documentation how to use debugger

OVERVIEW OF SOME TREES

bull Frame Tree Frames on page

bull Content Tree Content going with frames

bull View Tree Connecting views

MAKE YOUR WORK LAND

TESTS TESTS TESTS

bull Reftests

bull Crashtests

bull XPCShell Tests

bull Mochitests

bull JS tests

bull Compiled code tests -(

bull Marionette tests

DIFFERENT TYPE OF TESTS

MOCHITEST

Text

bullpathtoobjdir $ TEST_PATH=domcontactstests make mochitest-plain

bullpathtoobjdir $ TEST_PATH=domcontactsteststest_contactshtml make mochitest-plain

TIME FOR REVIEWbull Make sure the patch is formatted according to the guidelines

bull 8 lines of context

bull correct committer info (name + email)

bull correct checking message

bull When uploading a new version

bull address all review comments

bull obsolete the old patch

bull run tests again

REVIEWbull Make sure your patch is clean

bull Patch should be green on try-push

bull WIP State whatrsquos workingwhat notwhatrsquos next

bull Review might take some time (~1 week)

bull If longer ping person switch review person

bull Except r- donrsquot worry

Q amp A

THINGS TO HACK ON

bull Implement vwvhvminvmax

bull dirname DOM attribute on form controls

bull Implement FileSaver

Page 27: Implementing new WebAPIs

INTERFACE EXAMPLE

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

httpsbugzillamozillaorgshow_bugcgiid=674720

For example dominterfaceshelloworldnsIHelloWorldidl

HELLOWORLDMANIFEST

component f5181640-89e8-11e1-b0c4-0800200c9444 HelloWorldjscontract mozillaorghelloWorld1 f5181640-89e8-11e1-b0c4-0800200c9444category JavaScript-navigator-property mozHelloWorld mozillaorghelloWorld1

For example domhelloworldHelloWorldmanifest

HELLOWORLDJS

Text

const Cc = Componentsclassesconst Ci = Componentsinterfacesconst Cu = Componentsutils

Cuimport(resourcegremodulesXPCOMUtilsjsm)

function HelloWorld()

HelloWorldprototype =

init function init(aWindow)

sayHello function sayHello(aName) dump(Hello + aName + n)

classID ComponentsID(d88af7e0-a45f-11e1-b3dd-0800200c9444) QueryInterface XPCOMUtilsgenerateQI([ComponentsinterfacesnsIDOMHelloWorld])

classInfo XPCOMUtilsgenerateCI(classID ComponentsID(d88af7e0-a45f-11e1-b3dd-0800200c9444) contractID mozillaorghelloWorld1 classDescription HelloWorld interfaces [ComponentsinterfacesnsIDOMHelloWorld CinsIDOMGlobalPropertyInitializer] flags CinsIClassInfoDOM_OBJECT)

const NSGetFactory = XPCOMUtilsgenerateNSGetFactory([HelloWorld])

For example domhelloworldHelloWorldjs

BOILERPLATE

bull Makefiles

bull Manifest

bull Packaging

bull Module Loading

bull Access Permission

EXPOSEDPROPS

let foo = new Foo()

Fooprototype = __exposedProps__ name rw

FIREFOX OS PROCESS MODELbull Parent - Child Processes

bull Only one parent

bull Browser is in parent content pages are children

bull Nested process structure not possible (yet)

bull Parent is trusted

bull Child can be compromised

bull Security critical code has to run in parent

SYSTEM MESSAGE MANAGERbull Use for child-parent communication

bull Child

bull Parent

childProcessMessageManagersendAsyncMessage(message-name foo 2)

var response = sendSyncMessage(message-name foo 1)

receiveMessage function(aMessage) switch (aMessagename) [] parentProcessMessageManagersendAsynMessage(ldquoreturn-message-namerdquo [])

DOMREQUESTS

var pending = navigatormozAppsinstall(manifestUrl)pendingonsuccess = function () Save the App object that is returned var appRecord = thisresult alert(Installation successful)pendingonerror = function () Display the name of the error alert(Install failed error + thiserrorname)

PERMISSIONS

HOW TO IMPLEMENT C++

MAPPING JSC++

bull IDL files rarr JS amp C++

bull JS ctxlineWidth C++ ctxGetLineWidth(float width)

bull Need to implement C++ class for interface

bull NS_IMETHODIMP returns NS_ltstatusgt

bull Expose object nsDOMClassInfocppnsDOMClassInfoClassesh

INTERFACES

Attribute

PrintStateCallback

canvasmozPrintCallback =

function(obj) var ctx = objcontext ctxfillRect(0 0 100 100) objdone()

INTERFACES[scriptable uuid(a7062fca-41c6-4520-b777-3bb30fd77273)]interface nsIDOMHTMLCanvasElement nsIDOMHTMLElement []

A Mozilla-only callback that is called during the printing process attribute nsIPrintCallback mozPrintCallback

Attrib

ute

Callb

ack

[scriptable function uuid(8d5fb8a0-7782-11e1-b0c4-0800200c9a66)]interface nsIPrintCallback nsISupports void render(in nsIDOMMozCanvasPrintState ctx)

[scriptable builtinclass uuid(8d5fb8a0-7782-11e1-b0c4-0800200c9a67)]interface nsIDOMMozCanvasPrintState nsISupports A canvas rendering context readonly attribute nsISupports context

To be called when rendering to the context is done void done()

PrintS

tate

Taken frombug 745025

class nsHTMLCanvasPrintState public nsIDOMMozCanvasPrintStatepublic 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() [] return NS_OK

[]

Taken frombug 745025

MEMORY MANAGEMENTbull C++ doesnrsquot have a garbage collector (

bull In Gecko Reference counting amp cycle collector

bull Reference counting

bull nsCOMPtr (for interfaces) nsREFPtr

bull use getter_AddRefs

bull NS_IF_ADDREF amp NS_IF_RELEASE

MEMORY MANAGEMENT

bull Reference counting doesnrsquot work always

bull Make use of Geckorsquos cycle collector

bull Better cycle then maybe leak

DEBUGGING

bull Make sure to have a debug build

bull Enable logging (example)

bull Watch for assertion in logs

bull Insert printfs

bull There is documentation how to use debugger

OVERVIEW OF SOME TREES

bull Frame Tree Frames on page

bull Content Tree Content going with frames

bull View Tree Connecting views

MAKE YOUR WORK LAND

TESTS TESTS TESTS

bull Reftests

bull Crashtests

bull XPCShell Tests

bull Mochitests

bull JS tests

bull Compiled code tests -(

bull Marionette tests

DIFFERENT TYPE OF TESTS

MOCHITEST

Text

bullpathtoobjdir $ TEST_PATH=domcontactstests make mochitest-plain

bullpathtoobjdir $ TEST_PATH=domcontactsteststest_contactshtml make mochitest-plain

TIME FOR REVIEWbull Make sure the patch is formatted according to the guidelines

bull 8 lines of context

bull correct committer info (name + email)

bull correct checking message

bull When uploading a new version

bull address all review comments

bull obsolete the old patch

bull run tests again

REVIEWbull Make sure your patch is clean

bull Patch should be green on try-push

bull WIP State whatrsquos workingwhat notwhatrsquos next

bull Review might take some time (~1 week)

bull If longer ping person switch review person

bull Except r- donrsquot worry

Q amp A

THINGS TO HACK ON

bull Implement vwvhvminvmax

bull dirname DOM attribute on form controls

bull Implement FileSaver

Page 28: Implementing new WebAPIs

HELLOWORLDMANIFEST

component f5181640-89e8-11e1-b0c4-0800200c9444 HelloWorldjscontract mozillaorghelloWorld1 f5181640-89e8-11e1-b0c4-0800200c9444category JavaScript-navigator-property mozHelloWorld mozillaorghelloWorld1

For example domhelloworldHelloWorldmanifest

HELLOWORLDJS

Text

const Cc = Componentsclassesconst Ci = Componentsinterfacesconst Cu = Componentsutils

Cuimport(resourcegremodulesXPCOMUtilsjsm)

function HelloWorld()

HelloWorldprototype =

init function init(aWindow)

sayHello function sayHello(aName) dump(Hello + aName + n)

classID ComponentsID(d88af7e0-a45f-11e1-b3dd-0800200c9444) QueryInterface XPCOMUtilsgenerateQI([ComponentsinterfacesnsIDOMHelloWorld])

classInfo XPCOMUtilsgenerateCI(classID ComponentsID(d88af7e0-a45f-11e1-b3dd-0800200c9444) contractID mozillaorghelloWorld1 classDescription HelloWorld interfaces [ComponentsinterfacesnsIDOMHelloWorld CinsIDOMGlobalPropertyInitializer] flags CinsIClassInfoDOM_OBJECT)

const NSGetFactory = XPCOMUtilsgenerateNSGetFactory([HelloWorld])

For example domhelloworldHelloWorldjs

BOILERPLATE

bull Makefiles

bull Manifest

bull Packaging

bull Module Loading

bull Access Permission

EXPOSEDPROPS

let foo = new Foo()

Fooprototype = __exposedProps__ name rw

FIREFOX OS PROCESS MODELbull Parent - Child Processes

bull Only one parent

bull Browser is in parent content pages are children

bull Nested process structure not possible (yet)

bull Parent is trusted

bull Child can be compromised

bull Security critical code has to run in parent

SYSTEM MESSAGE MANAGERbull Use for child-parent communication

bull Child

bull Parent

childProcessMessageManagersendAsyncMessage(message-name foo 2)

var response = sendSyncMessage(message-name foo 1)

receiveMessage function(aMessage) switch (aMessagename) [] parentProcessMessageManagersendAsynMessage(ldquoreturn-message-namerdquo [])

DOMREQUESTS

var pending = navigatormozAppsinstall(manifestUrl)pendingonsuccess = function () Save the App object that is returned var appRecord = thisresult alert(Installation successful)pendingonerror = function () Display the name of the error alert(Install failed error + thiserrorname)

PERMISSIONS

HOW TO IMPLEMENT C++

MAPPING JSC++

bull IDL files rarr JS amp C++

bull JS ctxlineWidth C++ ctxGetLineWidth(float width)

bull Need to implement C++ class for interface

bull NS_IMETHODIMP returns NS_ltstatusgt

bull Expose object nsDOMClassInfocppnsDOMClassInfoClassesh

INTERFACES

Attribute

PrintStateCallback

canvasmozPrintCallback =

function(obj) var ctx = objcontext ctxfillRect(0 0 100 100) objdone()

INTERFACES[scriptable uuid(a7062fca-41c6-4520-b777-3bb30fd77273)]interface nsIDOMHTMLCanvasElement nsIDOMHTMLElement []

A Mozilla-only callback that is called during the printing process attribute nsIPrintCallback mozPrintCallback

Attrib

ute

Callb

ack

[scriptable function uuid(8d5fb8a0-7782-11e1-b0c4-0800200c9a66)]interface nsIPrintCallback nsISupports void render(in nsIDOMMozCanvasPrintState ctx)

[scriptable builtinclass uuid(8d5fb8a0-7782-11e1-b0c4-0800200c9a67)]interface nsIDOMMozCanvasPrintState nsISupports A canvas rendering context readonly attribute nsISupports context

To be called when rendering to the context is done void done()

PrintS

tate

Taken frombug 745025

class nsHTMLCanvasPrintState public nsIDOMMozCanvasPrintStatepublic 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() [] return NS_OK

[]

Taken frombug 745025

MEMORY MANAGEMENTbull C++ doesnrsquot have a garbage collector (

bull In Gecko Reference counting amp cycle collector

bull Reference counting

bull nsCOMPtr (for interfaces) nsREFPtr

bull use getter_AddRefs

bull NS_IF_ADDREF amp NS_IF_RELEASE

MEMORY MANAGEMENT

bull Reference counting doesnrsquot work always

bull Make use of Geckorsquos cycle collector

bull Better cycle then maybe leak

DEBUGGING

bull Make sure to have a debug build

bull Enable logging (example)

bull Watch for assertion in logs

bull Insert printfs

bull There is documentation how to use debugger

OVERVIEW OF SOME TREES

bull Frame Tree Frames on page

bull Content Tree Content going with frames

bull View Tree Connecting views

MAKE YOUR WORK LAND

TESTS TESTS TESTS

bull Reftests

bull Crashtests

bull XPCShell Tests

bull Mochitests

bull JS tests

bull Compiled code tests -(

bull Marionette tests

DIFFERENT TYPE OF TESTS

MOCHITEST

Text

bullpathtoobjdir $ TEST_PATH=domcontactstests make mochitest-plain

bullpathtoobjdir $ TEST_PATH=domcontactsteststest_contactshtml make mochitest-plain

TIME FOR REVIEWbull Make sure the patch is formatted according to the guidelines

bull 8 lines of context

bull correct committer info (name + email)

bull correct checking message

bull When uploading a new version

bull address all review comments

bull obsolete the old patch

bull run tests again

REVIEWbull Make sure your patch is clean

bull Patch should be green on try-push

bull WIP State whatrsquos workingwhat notwhatrsquos next

bull Review might take some time (~1 week)

bull If longer ping person switch review person

bull Except r- donrsquot worry

Q amp A

THINGS TO HACK ON

bull Implement vwvhvminvmax

bull dirname DOM attribute on form controls

bull Implement FileSaver

Page 29: Implementing new WebAPIs

HELLOWORLDJS

Text

const Cc = Componentsclassesconst Ci = Componentsinterfacesconst Cu = Componentsutils

Cuimport(resourcegremodulesXPCOMUtilsjsm)

function HelloWorld()

HelloWorldprototype =

init function init(aWindow)

sayHello function sayHello(aName) dump(Hello + aName + n)

classID ComponentsID(d88af7e0-a45f-11e1-b3dd-0800200c9444) QueryInterface XPCOMUtilsgenerateQI([ComponentsinterfacesnsIDOMHelloWorld])

classInfo XPCOMUtilsgenerateCI(classID ComponentsID(d88af7e0-a45f-11e1-b3dd-0800200c9444) contractID mozillaorghelloWorld1 classDescription HelloWorld interfaces [ComponentsinterfacesnsIDOMHelloWorld CinsIDOMGlobalPropertyInitializer] flags CinsIClassInfoDOM_OBJECT)

const NSGetFactory = XPCOMUtilsgenerateNSGetFactory([HelloWorld])

For example domhelloworldHelloWorldjs

BOILERPLATE

bull Makefiles

bull Manifest

bull Packaging

bull Module Loading

bull Access Permission

EXPOSEDPROPS

let foo = new Foo()

Fooprototype = __exposedProps__ name rw

FIREFOX OS PROCESS MODELbull Parent - Child Processes

bull Only one parent

bull Browser is in parent content pages are children

bull Nested process structure not possible (yet)

bull Parent is trusted

bull Child can be compromised

bull Security critical code has to run in parent

SYSTEM MESSAGE MANAGERbull Use for child-parent communication

bull Child

bull Parent

childProcessMessageManagersendAsyncMessage(message-name foo 2)

var response = sendSyncMessage(message-name foo 1)

receiveMessage function(aMessage) switch (aMessagename) [] parentProcessMessageManagersendAsynMessage(ldquoreturn-message-namerdquo [])

DOMREQUESTS

var pending = navigatormozAppsinstall(manifestUrl)pendingonsuccess = function () Save the App object that is returned var appRecord = thisresult alert(Installation successful)pendingonerror = function () Display the name of the error alert(Install failed error + thiserrorname)

PERMISSIONS

HOW TO IMPLEMENT C++

MAPPING JSC++

bull IDL files rarr JS amp C++

bull JS ctxlineWidth C++ ctxGetLineWidth(float width)

bull Need to implement C++ class for interface

bull NS_IMETHODIMP returns NS_ltstatusgt

bull Expose object nsDOMClassInfocppnsDOMClassInfoClassesh

INTERFACES

Attribute

PrintStateCallback

canvasmozPrintCallback =

function(obj) var ctx = objcontext ctxfillRect(0 0 100 100) objdone()

INTERFACES[scriptable uuid(a7062fca-41c6-4520-b777-3bb30fd77273)]interface nsIDOMHTMLCanvasElement nsIDOMHTMLElement []

A Mozilla-only callback that is called during the printing process attribute nsIPrintCallback mozPrintCallback

Attrib

ute

Callb

ack

[scriptable function uuid(8d5fb8a0-7782-11e1-b0c4-0800200c9a66)]interface nsIPrintCallback nsISupports void render(in nsIDOMMozCanvasPrintState ctx)

[scriptable builtinclass uuid(8d5fb8a0-7782-11e1-b0c4-0800200c9a67)]interface nsIDOMMozCanvasPrintState nsISupports A canvas rendering context readonly attribute nsISupports context

To be called when rendering to the context is done void done()

PrintS

tate

Taken frombug 745025

class nsHTMLCanvasPrintState public nsIDOMMozCanvasPrintStatepublic 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() [] return NS_OK

[]

Taken frombug 745025

MEMORY MANAGEMENTbull C++ doesnrsquot have a garbage collector (

bull In Gecko Reference counting amp cycle collector

bull Reference counting

bull nsCOMPtr (for interfaces) nsREFPtr

bull use getter_AddRefs

bull NS_IF_ADDREF amp NS_IF_RELEASE

MEMORY MANAGEMENT

bull Reference counting doesnrsquot work always

bull Make use of Geckorsquos cycle collector

bull Better cycle then maybe leak

DEBUGGING

bull Make sure to have a debug build

bull Enable logging (example)

bull Watch for assertion in logs

bull Insert printfs

bull There is documentation how to use debugger

OVERVIEW OF SOME TREES

bull Frame Tree Frames on page

bull Content Tree Content going with frames

bull View Tree Connecting views

MAKE YOUR WORK LAND

TESTS TESTS TESTS

bull Reftests

bull Crashtests

bull XPCShell Tests

bull Mochitests

bull JS tests

bull Compiled code tests -(

bull Marionette tests

DIFFERENT TYPE OF TESTS

MOCHITEST

Text

bullpathtoobjdir $ TEST_PATH=domcontactstests make mochitest-plain

bullpathtoobjdir $ TEST_PATH=domcontactsteststest_contactshtml make mochitest-plain

TIME FOR REVIEWbull Make sure the patch is formatted according to the guidelines

bull 8 lines of context

bull correct committer info (name + email)

bull correct checking message

bull When uploading a new version

bull address all review comments

bull obsolete the old patch

bull run tests again

REVIEWbull Make sure your patch is clean

bull Patch should be green on try-push

bull WIP State whatrsquos workingwhat notwhatrsquos next

bull Review might take some time (~1 week)

bull If longer ping person switch review person

bull Except r- donrsquot worry

Q amp A

THINGS TO HACK ON

bull Implement vwvhvminvmax

bull dirname DOM attribute on form controls

bull Implement FileSaver

Page 30: Implementing new WebAPIs

BOILERPLATE

bull Makefiles

bull Manifest

bull Packaging

bull Module Loading

bull Access Permission

EXPOSEDPROPS

let foo = new Foo()

Fooprototype = __exposedProps__ name rw

FIREFOX OS PROCESS MODELbull Parent - Child Processes

bull Only one parent

bull Browser is in parent content pages are children

bull Nested process structure not possible (yet)

bull Parent is trusted

bull Child can be compromised

bull Security critical code has to run in parent

SYSTEM MESSAGE MANAGERbull Use for child-parent communication

bull Child

bull Parent

childProcessMessageManagersendAsyncMessage(message-name foo 2)

var response = sendSyncMessage(message-name foo 1)

receiveMessage function(aMessage) switch (aMessagename) [] parentProcessMessageManagersendAsynMessage(ldquoreturn-message-namerdquo [])

DOMREQUESTS

var pending = navigatormozAppsinstall(manifestUrl)pendingonsuccess = function () Save the App object that is returned var appRecord = thisresult alert(Installation successful)pendingonerror = function () Display the name of the error alert(Install failed error + thiserrorname)

PERMISSIONS

HOW TO IMPLEMENT C++

MAPPING JSC++

bull IDL files rarr JS amp C++

bull JS ctxlineWidth C++ ctxGetLineWidth(float width)

bull Need to implement C++ class for interface

bull NS_IMETHODIMP returns NS_ltstatusgt

bull Expose object nsDOMClassInfocppnsDOMClassInfoClassesh

INTERFACES

Attribute

PrintStateCallback

canvasmozPrintCallback =

function(obj) var ctx = objcontext ctxfillRect(0 0 100 100) objdone()

INTERFACES[scriptable uuid(a7062fca-41c6-4520-b777-3bb30fd77273)]interface nsIDOMHTMLCanvasElement nsIDOMHTMLElement []

A Mozilla-only callback that is called during the printing process attribute nsIPrintCallback mozPrintCallback

Attrib

ute

Callb

ack

[scriptable function uuid(8d5fb8a0-7782-11e1-b0c4-0800200c9a66)]interface nsIPrintCallback nsISupports void render(in nsIDOMMozCanvasPrintState ctx)

[scriptable builtinclass uuid(8d5fb8a0-7782-11e1-b0c4-0800200c9a67)]interface nsIDOMMozCanvasPrintState nsISupports A canvas rendering context readonly attribute nsISupports context

To be called when rendering to the context is done void done()

PrintS

tate

Taken frombug 745025

class nsHTMLCanvasPrintState public nsIDOMMozCanvasPrintStatepublic 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() [] return NS_OK

[]

Taken frombug 745025

MEMORY MANAGEMENTbull C++ doesnrsquot have a garbage collector (

bull In Gecko Reference counting amp cycle collector

bull Reference counting

bull nsCOMPtr (for interfaces) nsREFPtr

bull use getter_AddRefs

bull NS_IF_ADDREF amp NS_IF_RELEASE

MEMORY MANAGEMENT

bull Reference counting doesnrsquot work always

bull Make use of Geckorsquos cycle collector

bull Better cycle then maybe leak

DEBUGGING

bull Make sure to have a debug build

bull Enable logging (example)

bull Watch for assertion in logs

bull Insert printfs

bull There is documentation how to use debugger

OVERVIEW OF SOME TREES

bull Frame Tree Frames on page

bull Content Tree Content going with frames

bull View Tree Connecting views

MAKE YOUR WORK LAND

TESTS TESTS TESTS

bull Reftests

bull Crashtests

bull XPCShell Tests

bull Mochitests

bull JS tests

bull Compiled code tests -(

bull Marionette tests

DIFFERENT TYPE OF TESTS

MOCHITEST

Text

bullpathtoobjdir $ TEST_PATH=domcontactstests make mochitest-plain

bullpathtoobjdir $ TEST_PATH=domcontactsteststest_contactshtml make mochitest-plain

TIME FOR REVIEWbull Make sure the patch is formatted according to the guidelines

bull 8 lines of context

bull correct committer info (name + email)

bull correct checking message

bull When uploading a new version

bull address all review comments

bull obsolete the old patch

bull run tests again

REVIEWbull Make sure your patch is clean

bull Patch should be green on try-push

bull WIP State whatrsquos workingwhat notwhatrsquos next

bull Review might take some time (~1 week)

bull If longer ping person switch review person

bull Except r- donrsquot worry

Q amp A

THINGS TO HACK ON

bull Implement vwvhvminvmax

bull dirname DOM attribute on form controls

bull Implement FileSaver

Page 31: Implementing new WebAPIs

EXPOSEDPROPS

let foo = new Foo()

Fooprototype = __exposedProps__ name rw

FIREFOX OS PROCESS MODELbull Parent - Child Processes

bull Only one parent

bull Browser is in parent content pages are children

bull Nested process structure not possible (yet)

bull Parent is trusted

bull Child can be compromised

bull Security critical code has to run in parent

SYSTEM MESSAGE MANAGERbull Use for child-parent communication

bull Child

bull Parent

childProcessMessageManagersendAsyncMessage(message-name foo 2)

var response = sendSyncMessage(message-name foo 1)

receiveMessage function(aMessage) switch (aMessagename) [] parentProcessMessageManagersendAsynMessage(ldquoreturn-message-namerdquo [])

DOMREQUESTS

var pending = navigatormozAppsinstall(manifestUrl)pendingonsuccess = function () Save the App object that is returned var appRecord = thisresult alert(Installation successful)pendingonerror = function () Display the name of the error alert(Install failed error + thiserrorname)

PERMISSIONS

HOW TO IMPLEMENT C++

MAPPING JSC++

bull IDL files rarr JS amp C++

bull JS ctxlineWidth C++ ctxGetLineWidth(float width)

bull Need to implement C++ class for interface

bull NS_IMETHODIMP returns NS_ltstatusgt

bull Expose object nsDOMClassInfocppnsDOMClassInfoClassesh

INTERFACES

Attribute

PrintStateCallback

canvasmozPrintCallback =

function(obj) var ctx = objcontext ctxfillRect(0 0 100 100) objdone()

INTERFACES[scriptable uuid(a7062fca-41c6-4520-b777-3bb30fd77273)]interface nsIDOMHTMLCanvasElement nsIDOMHTMLElement []

A Mozilla-only callback that is called during the printing process attribute nsIPrintCallback mozPrintCallback

Attrib

ute

Callb

ack

[scriptable function uuid(8d5fb8a0-7782-11e1-b0c4-0800200c9a66)]interface nsIPrintCallback nsISupports void render(in nsIDOMMozCanvasPrintState ctx)

[scriptable builtinclass uuid(8d5fb8a0-7782-11e1-b0c4-0800200c9a67)]interface nsIDOMMozCanvasPrintState nsISupports A canvas rendering context readonly attribute nsISupports context

To be called when rendering to the context is done void done()

PrintS

tate

Taken frombug 745025

class nsHTMLCanvasPrintState public nsIDOMMozCanvasPrintStatepublic 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() [] return NS_OK

[]

Taken frombug 745025

MEMORY MANAGEMENTbull C++ doesnrsquot have a garbage collector (

bull In Gecko Reference counting amp cycle collector

bull Reference counting

bull nsCOMPtr (for interfaces) nsREFPtr

bull use getter_AddRefs

bull NS_IF_ADDREF amp NS_IF_RELEASE

MEMORY MANAGEMENT

bull Reference counting doesnrsquot work always

bull Make use of Geckorsquos cycle collector

bull Better cycle then maybe leak

DEBUGGING

bull Make sure to have a debug build

bull Enable logging (example)

bull Watch for assertion in logs

bull Insert printfs

bull There is documentation how to use debugger

OVERVIEW OF SOME TREES

bull Frame Tree Frames on page

bull Content Tree Content going with frames

bull View Tree Connecting views

MAKE YOUR WORK LAND

TESTS TESTS TESTS

bull Reftests

bull Crashtests

bull XPCShell Tests

bull Mochitests

bull JS tests

bull Compiled code tests -(

bull Marionette tests

DIFFERENT TYPE OF TESTS

MOCHITEST

Text

bullpathtoobjdir $ TEST_PATH=domcontactstests make mochitest-plain

bullpathtoobjdir $ TEST_PATH=domcontactsteststest_contactshtml make mochitest-plain

TIME FOR REVIEWbull Make sure the patch is formatted according to the guidelines

bull 8 lines of context

bull correct committer info (name + email)

bull correct checking message

bull When uploading a new version

bull address all review comments

bull obsolete the old patch

bull run tests again

REVIEWbull Make sure your patch is clean

bull Patch should be green on try-push

bull WIP State whatrsquos workingwhat notwhatrsquos next

bull Review might take some time (~1 week)

bull If longer ping person switch review person

bull Except r- donrsquot worry

Q amp A

THINGS TO HACK ON

bull Implement vwvhvminvmax

bull dirname DOM attribute on form controls

bull Implement FileSaver

Page 32: Implementing new WebAPIs

FIREFOX OS PROCESS MODELbull Parent - Child Processes

bull Only one parent

bull Browser is in parent content pages are children

bull Nested process structure not possible (yet)

bull Parent is trusted

bull Child can be compromised

bull Security critical code has to run in parent

SYSTEM MESSAGE MANAGERbull Use for child-parent communication

bull Child

bull Parent

childProcessMessageManagersendAsyncMessage(message-name foo 2)

var response = sendSyncMessage(message-name foo 1)

receiveMessage function(aMessage) switch (aMessagename) [] parentProcessMessageManagersendAsynMessage(ldquoreturn-message-namerdquo [])

DOMREQUESTS

var pending = navigatormozAppsinstall(manifestUrl)pendingonsuccess = function () Save the App object that is returned var appRecord = thisresult alert(Installation successful)pendingonerror = function () Display the name of the error alert(Install failed error + thiserrorname)

PERMISSIONS

HOW TO IMPLEMENT C++

MAPPING JSC++

bull IDL files rarr JS amp C++

bull JS ctxlineWidth C++ ctxGetLineWidth(float width)

bull Need to implement C++ class for interface

bull NS_IMETHODIMP returns NS_ltstatusgt

bull Expose object nsDOMClassInfocppnsDOMClassInfoClassesh

INTERFACES

Attribute

PrintStateCallback

canvasmozPrintCallback =

function(obj) var ctx = objcontext ctxfillRect(0 0 100 100) objdone()

INTERFACES[scriptable uuid(a7062fca-41c6-4520-b777-3bb30fd77273)]interface nsIDOMHTMLCanvasElement nsIDOMHTMLElement []

A Mozilla-only callback that is called during the printing process attribute nsIPrintCallback mozPrintCallback

Attrib

ute

Callb

ack

[scriptable function uuid(8d5fb8a0-7782-11e1-b0c4-0800200c9a66)]interface nsIPrintCallback nsISupports void render(in nsIDOMMozCanvasPrintState ctx)

[scriptable builtinclass uuid(8d5fb8a0-7782-11e1-b0c4-0800200c9a67)]interface nsIDOMMozCanvasPrintState nsISupports A canvas rendering context readonly attribute nsISupports context

To be called when rendering to the context is done void done()

PrintS

tate

Taken frombug 745025

class nsHTMLCanvasPrintState public nsIDOMMozCanvasPrintStatepublic 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() [] return NS_OK

[]

Taken frombug 745025

MEMORY MANAGEMENTbull C++ doesnrsquot have a garbage collector (

bull In Gecko Reference counting amp cycle collector

bull Reference counting

bull nsCOMPtr (for interfaces) nsREFPtr

bull use getter_AddRefs

bull NS_IF_ADDREF amp NS_IF_RELEASE

MEMORY MANAGEMENT

bull Reference counting doesnrsquot work always

bull Make use of Geckorsquos cycle collector

bull Better cycle then maybe leak

DEBUGGING

bull Make sure to have a debug build

bull Enable logging (example)

bull Watch for assertion in logs

bull Insert printfs

bull There is documentation how to use debugger

OVERVIEW OF SOME TREES

bull Frame Tree Frames on page

bull Content Tree Content going with frames

bull View Tree Connecting views

MAKE YOUR WORK LAND

TESTS TESTS TESTS

bull Reftests

bull Crashtests

bull XPCShell Tests

bull Mochitests

bull JS tests

bull Compiled code tests -(

bull Marionette tests

DIFFERENT TYPE OF TESTS

MOCHITEST

Text

bullpathtoobjdir $ TEST_PATH=domcontactstests make mochitest-plain

bullpathtoobjdir $ TEST_PATH=domcontactsteststest_contactshtml make mochitest-plain

TIME FOR REVIEWbull Make sure the patch is formatted according to the guidelines

bull 8 lines of context

bull correct committer info (name + email)

bull correct checking message

bull When uploading a new version

bull address all review comments

bull obsolete the old patch

bull run tests again

REVIEWbull Make sure your patch is clean

bull Patch should be green on try-push

bull WIP State whatrsquos workingwhat notwhatrsquos next

bull Review might take some time (~1 week)

bull If longer ping person switch review person

bull Except r- donrsquot worry

Q amp A

THINGS TO HACK ON

bull Implement vwvhvminvmax

bull dirname DOM attribute on form controls

bull Implement FileSaver

Page 33: Implementing new WebAPIs

SYSTEM MESSAGE MANAGERbull Use for child-parent communication

bull Child

bull Parent

childProcessMessageManagersendAsyncMessage(message-name foo 2)

var response = sendSyncMessage(message-name foo 1)

receiveMessage function(aMessage) switch (aMessagename) [] parentProcessMessageManagersendAsynMessage(ldquoreturn-message-namerdquo [])

DOMREQUESTS

var pending = navigatormozAppsinstall(manifestUrl)pendingonsuccess = function () Save the App object that is returned var appRecord = thisresult alert(Installation successful)pendingonerror = function () Display the name of the error alert(Install failed error + thiserrorname)

PERMISSIONS

HOW TO IMPLEMENT C++

MAPPING JSC++

bull IDL files rarr JS amp C++

bull JS ctxlineWidth C++ ctxGetLineWidth(float width)

bull Need to implement C++ class for interface

bull NS_IMETHODIMP returns NS_ltstatusgt

bull Expose object nsDOMClassInfocppnsDOMClassInfoClassesh

INTERFACES

Attribute

PrintStateCallback

canvasmozPrintCallback =

function(obj) var ctx = objcontext ctxfillRect(0 0 100 100) objdone()

INTERFACES[scriptable uuid(a7062fca-41c6-4520-b777-3bb30fd77273)]interface nsIDOMHTMLCanvasElement nsIDOMHTMLElement []

A Mozilla-only callback that is called during the printing process attribute nsIPrintCallback mozPrintCallback

Attrib

ute

Callb

ack

[scriptable function uuid(8d5fb8a0-7782-11e1-b0c4-0800200c9a66)]interface nsIPrintCallback nsISupports void render(in nsIDOMMozCanvasPrintState ctx)

[scriptable builtinclass uuid(8d5fb8a0-7782-11e1-b0c4-0800200c9a67)]interface nsIDOMMozCanvasPrintState nsISupports A canvas rendering context readonly attribute nsISupports context

To be called when rendering to the context is done void done()

PrintS

tate

Taken frombug 745025

class nsHTMLCanvasPrintState public nsIDOMMozCanvasPrintStatepublic 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() [] return NS_OK

[]

Taken frombug 745025

MEMORY MANAGEMENTbull C++ doesnrsquot have a garbage collector (

bull In Gecko Reference counting amp cycle collector

bull Reference counting

bull nsCOMPtr (for interfaces) nsREFPtr

bull use getter_AddRefs

bull NS_IF_ADDREF amp NS_IF_RELEASE

MEMORY MANAGEMENT

bull Reference counting doesnrsquot work always

bull Make use of Geckorsquos cycle collector

bull Better cycle then maybe leak

DEBUGGING

bull Make sure to have a debug build

bull Enable logging (example)

bull Watch for assertion in logs

bull Insert printfs

bull There is documentation how to use debugger

OVERVIEW OF SOME TREES

bull Frame Tree Frames on page

bull Content Tree Content going with frames

bull View Tree Connecting views

MAKE YOUR WORK LAND

TESTS TESTS TESTS

bull Reftests

bull Crashtests

bull XPCShell Tests

bull Mochitests

bull JS tests

bull Compiled code tests -(

bull Marionette tests

DIFFERENT TYPE OF TESTS

MOCHITEST

Text

bullpathtoobjdir $ TEST_PATH=domcontactstests make mochitest-plain

bullpathtoobjdir $ TEST_PATH=domcontactsteststest_contactshtml make mochitest-plain

TIME FOR REVIEWbull Make sure the patch is formatted according to the guidelines

bull 8 lines of context

bull correct committer info (name + email)

bull correct checking message

bull When uploading a new version

bull address all review comments

bull obsolete the old patch

bull run tests again

REVIEWbull Make sure your patch is clean

bull Patch should be green on try-push

bull WIP State whatrsquos workingwhat notwhatrsquos next

bull Review might take some time (~1 week)

bull If longer ping person switch review person

bull Except r- donrsquot worry

Q amp A

THINGS TO HACK ON

bull Implement vwvhvminvmax

bull dirname DOM attribute on form controls

bull Implement FileSaver

Page 34: Implementing new WebAPIs

DOMREQUESTS

var pending = navigatormozAppsinstall(manifestUrl)pendingonsuccess = function () Save the App object that is returned var appRecord = thisresult alert(Installation successful)pendingonerror = function () Display the name of the error alert(Install failed error + thiserrorname)

PERMISSIONS

HOW TO IMPLEMENT C++

MAPPING JSC++

bull IDL files rarr JS amp C++

bull JS ctxlineWidth C++ ctxGetLineWidth(float width)

bull Need to implement C++ class for interface

bull NS_IMETHODIMP returns NS_ltstatusgt

bull Expose object nsDOMClassInfocppnsDOMClassInfoClassesh

INTERFACES

Attribute

PrintStateCallback

canvasmozPrintCallback =

function(obj) var ctx = objcontext ctxfillRect(0 0 100 100) objdone()

INTERFACES[scriptable uuid(a7062fca-41c6-4520-b777-3bb30fd77273)]interface nsIDOMHTMLCanvasElement nsIDOMHTMLElement []

A Mozilla-only callback that is called during the printing process attribute nsIPrintCallback mozPrintCallback

Attrib

ute

Callb

ack

[scriptable function uuid(8d5fb8a0-7782-11e1-b0c4-0800200c9a66)]interface nsIPrintCallback nsISupports void render(in nsIDOMMozCanvasPrintState ctx)

[scriptable builtinclass uuid(8d5fb8a0-7782-11e1-b0c4-0800200c9a67)]interface nsIDOMMozCanvasPrintState nsISupports A canvas rendering context readonly attribute nsISupports context

To be called when rendering to the context is done void done()

PrintS

tate

Taken frombug 745025

class nsHTMLCanvasPrintState public nsIDOMMozCanvasPrintStatepublic 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() [] return NS_OK

[]

Taken frombug 745025

MEMORY MANAGEMENTbull C++ doesnrsquot have a garbage collector (

bull In Gecko Reference counting amp cycle collector

bull Reference counting

bull nsCOMPtr (for interfaces) nsREFPtr

bull use getter_AddRefs

bull NS_IF_ADDREF amp NS_IF_RELEASE

MEMORY MANAGEMENT

bull Reference counting doesnrsquot work always

bull Make use of Geckorsquos cycle collector

bull Better cycle then maybe leak

DEBUGGING

bull Make sure to have a debug build

bull Enable logging (example)

bull Watch for assertion in logs

bull Insert printfs

bull There is documentation how to use debugger

OVERVIEW OF SOME TREES

bull Frame Tree Frames on page

bull Content Tree Content going with frames

bull View Tree Connecting views

MAKE YOUR WORK LAND

TESTS TESTS TESTS

bull Reftests

bull Crashtests

bull XPCShell Tests

bull Mochitests

bull JS tests

bull Compiled code tests -(

bull Marionette tests

DIFFERENT TYPE OF TESTS

MOCHITEST

Text

bullpathtoobjdir $ TEST_PATH=domcontactstests make mochitest-plain

bullpathtoobjdir $ TEST_PATH=domcontactsteststest_contactshtml make mochitest-plain

TIME FOR REVIEWbull Make sure the patch is formatted according to the guidelines

bull 8 lines of context

bull correct committer info (name + email)

bull correct checking message

bull When uploading a new version

bull address all review comments

bull obsolete the old patch

bull run tests again

REVIEWbull Make sure your patch is clean

bull Patch should be green on try-push

bull WIP State whatrsquos workingwhat notwhatrsquos next

bull Review might take some time (~1 week)

bull If longer ping person switch review person

bull Except r- donrsquot worry

Q amp A

THINGS TO HACK ON

bull Implement vwvhvminvmax

bull dirname DOM attribute on form controls

bull Implement FileSaver

Page 35: Implementing new WebAPIs

PERMISSIONS

HOW TO IMPLEMENT C++

MAPPING JSC++

bull IDL files rarr JS amp C++

bull JS ctxlineWidth C++ ctxGetLineWidth(float width)

bull Need to implement C++ class for interface

bull NS_IMETHODIMP returns NS_ltstatusgt

bull Expose object nsDOMClassInfocppnsDOMClassInfoClassesh

INTERFACES

Attribute

PrintStateCallback

canvasmozPrintCallback =

function(obj) var ctx = objcontext ctxfillRect(0 0 100 100) objdone()

INTERFACES[scriptable uuid(a7062fca-41c6-4520-b777-3bb30fd77273)]interface nsIDOMHTMLCanvasElement nsIDOMHTMLElement []

A Mozilla-only callback that is called during the printing process attribute nsIPrintCallback mozPrintCallback

Attrib

ute

Callb

ack

[scriptable function uuid(8d5fb8a0-7782-11e1-b0c4-0800200c9a66)]interface nsIPrintCallback nsISupports void render(in nsIDOMMozCanvasPrintState ctx)

[scriptable builtinclass uuid(8d5fb8a0-7782-11e1-b0c4-0800200c9a67)]interface nsIDOMMozCanvasPrintState nsISupports A canvas rendering context readonly attribute nsISupports context

To be called when rendering to the context is done void done()

PrintS

tate

Taken frombug 745025

class nsHTMLCanvasPrintState public nsIDOMMozCanvasPrintStatepublic 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() [] return NS_OK

[]

Taken frombug 745025

MEMORY MANAGEMENTbull C++ doesnrsquot have a garbage collector (

bull In Gecko Reference counting amp cycle collector

bull Reference counting

bull nsCOMPtr (for interfaces) nsREFPtr

bull use getter_AddRefs

bull NS_IF_ADDREF amp NS_IF_RELEASE

MEMORY MANAGEMENT

bull Reference counting doesnrsquot work always

bull Make use of Geckorsquos cycle collector

bull Better cycle then maybe leak

DEBUGGING

bull Make sure to have a debug build

bull Enable logging (example)

bull Watch for assertion in logs

bull Insert printfs

bull There is documentation how to use debugger

OVERVIEW OF SOME TREES

bull Frame Tree Frames on page

bull Content Tree Content going with frames

bull View Tree Connecting views

MAKE YOUR WORK LAND

TESTS TESTS TESTS

bull Reftests

bull Crashtests

bull XPCShell Tests

bull Mochitests

bull JS tests

bull Compiled code tests -(

bull Marionette tests

DIFFERENT TYPE OF TESTS

MOCHITEST

Text

bullpathtoobjdir $ TEST_PATH=domcontactstests make mochitest-plain

bullpathtoobjdir $ TEST_PATH=domcontactsteststest_contactshtml make mochitest-plain

TIME FOR REVIEWbull Make sure the patch is formatted according to the guidelines

bull 8 lines of context

bull correct committer info (name + email)

bull correct checking message

bull When uploading a new version

bull address all review comments

bull obsolete the old patch

bull run tests again

REVIEWbull Make sure your patch is clean

bull Patch should be green on try-push

bull WIP State whatrsquos workingwhat notwhatrsquos next

bull Review might take some time (~1 week)

bull If longer ping person switch review person

bull Except r- donrsquot worry

Q amp A

THINGS TO HACK ON

bull Implement vwvhvminvmax

bull dirname DOM attribute on form controls

bull Implement FileSaver

Page 36: Implementing new WebAPIs

HOW TO IMPLEMENT C++

MAPPING JSC++

bull IDL files rarr JS amp C++

bull JS ctxlineWidth C++ ctxGetLineWidth(float width)

bull Need to implement C++ class for interface

bull NS_IMETHODIMP returns NS_ltstatusgt

bull Expose object nsDOMClassInfocppnsDOMClassInfoClassesh

INTERFACES

Attribute

PrintStateCallback

canvasmozPrintCallback =

function(obj) var ctx = objcontext ctxfillRect(0 0 100 100) objdone()

INTERFACES[scriptable uuid(a7062fca-41c6-4520-b777-3bb30fd77273)]interface nsIDOMHTMLCanvasElement nsIDOMHTMLElement []

A Mozilla-only callback that is called during the printing process attribute nsIPrintCallback mozPrintCallback

Attrib

ute

Callb

ack

[scriptable function uuid(8d5fb8a0-7782-11e1-b0c4-0800200c9a66)]interface nsIPrintCallback nsISupports void render(in nsIDOMMozCanvasPrintState ctx)

[scriptable builtinclass uuid(8d5fb8a0-7782-11e1-b0c4-0800200c9a67)]interface nsIDOMMozCanvasPrintState nsISupports A canvas rendering context readonly attribute nsISupports context

To be called when rendering to the context is done void done()

PrintS

tate

Taken frombug 745025

class nsHTMLCanvasPrintState public nsIDOMMozCanvasPrintStatepublic 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() [] return NS_OK

[]

Taken frombug 745025

MEMORY MANAGEMENTbull C++ doesnrsquot have a garbage collector (

bull In Gecko Reference counting amp cycle collector

bull Reference counting

bull nsCOMPtr (for interfaces) nsREFPtr

bull use getter_AddRefs

bull NS_IF_ADDREF amp NS_IF_RELEASE

MEMORY MANAGEMENT

bull Reference counting doesnrsquot work always

bull Make use of Geckorsquos cycle collector

bull Better cycle then maybe leak

DEBUGGING

bull Make sure to have a debug build

bull Enable logging (example)

bull Watch for assertion in logs

bull Insert printfs

bull There is documentation how to use debugger

OVERVIEW OF SOME TREES

bull Frame Tree Frames on page

bull Content Tree Content going with frames

bull View Tree Connecting views

MAKE YOUR WORK LAND

TESTS TESTS TESTS

bull Reftests

bull Crashtests

bull XPCShell Tests

bull Mochitests

bull JS tests

bull Compiled code tests -(

bull Marionette tests

DIFFERENT TYPE OF TESTS

MOCHITEST

Text

bullpathtoobjdir $ TEST_PATH=domcontactstests make mochitest-plain

bullpathtoobjdir $ TEST_PATH=domcontactsteststest_contactshtml make mochitest-plain

TIME FOR REVIEWbull Make sure the patch is formatted according to the guidelines

bull 8 lines of context

bull correct committer info (name + email)

bull correct checking message

bull When uploading a new version

bull address all review comments

bull obsolete the old patch

bull run tests again

REVIEWbull Make sure your patch is clean

bull Patch should be green on try-push

bull WIP State whatrsquos workingwhat notwhatrsquos next

bull Review might take some time (~1 week)

bull If longer ping person switch review person

bull Except r- donrsquot worry

Q amp A

THINGS TO HACK ON

bull Implement vwvhvminvmax

bull dirname DOM attribute on form controls

bull Implement FileSaver

Page 37: Implementing new WebAPIs

MAPPING JSC++

bull IDL files rarr JS amp C++

bull JS ctxlineWidth C++ ctxGetLineWidth(float width)

bull Need to implement C++ class for interface

bull NS_IMETHODIMP returns NS_ltstatusgt

bull Expose object nsDOMClassInfocppnsDOMClassInfoClassesh

INTERFACES

Attribute

PrintStateCallback

canvasmozPrintCallback =

function(obj) var ctx = objcontext ctxfillRect(0 0 100 100) objdone()

INTERFACES[scriptable uuid(a7062fca-41c6-4520-b777-3bb30fd77273)]interface nsIDOMHTMLCanvasElement nsIDOMHTMLElement []

A Mozilla-only callback that is called during the printing process attribute nsIPrintCallback mozPrintCallback

Attrib

ute

Callb

ack

[scriptable function uuid(8d5fb8a0-7782-11e1-b0c4-0800200c9a66)]interface nsIPrintCallback nsISupports void render(in nsIDOMMozCanvasPrintState ctx)

[scriptable builtinclass uuid(8d5fb8a0-7782-11e1-b0c4-0800200c9a67)]interface nsIDOMMozCanvasPrintState nsISupports A canvas rendering context readonly attribute nsISupports context

To be called when rendering to the context is done void done()

PrintS

tate

Taken frombug 745025

class nsHTMLCanvasPrintState public nsIDOMMozCanvasPrintStatepublic 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() [] return NS_OK

[]

Taken frombug 745025

MEMORY MANAGEMENTbull C++ doesnrsquot have a garbage collector (

bull In Gecko Reference counting amp cycle collector

bull Reference counting

bull nsCOMPtr (for interfaces) nsREFPtr

bull use getter_AddRefs

bull NS_IF_ADDREF amp NS_IF_RELEASE

MEMORY MANAGEMENT

bull Reference counting doesnrsquot work always

bull Make use of Geckorsquos cycle collector

bull Better cycle then maybe leak

DEBUGGING

bull Make sure to have a debug build

bull Enable logging (example)

bull Watch for assertion in logs

bull Insert printfs

bull There is documentation how to use debugger

OVERVIEW OF SOME TREES

bull Frame Tree Frames on page

bull Content Tree Content going with frames

bull View Tree Connecting views

MAKE YOUR WORK LAND

TESTS TESTS TESTS

bull Reftests

bull Crashtests

bull XPCShell Tests

bull Mochitests

bull JS tests

bull Compiled code tests -(

bull Marionette tests

DIFFERENT TYPE OF TESTS

MOCHITEST

Text

bullpathtoobjdir $ TEST_PATH=domcontactstests make mochitest-plain

bullpathtoobjdir $ TEST_PATH=domcontactsteststest_contactshtml make mochitest-plain

TIME FOR REVIEWbull Make sure the patch is formatted according to the guidelines

bull 8 lines of context

bull correct committer info (name + email)

bull correct checking message

bull When uploading a new version

bull address all review comments

bull obsolete the old patch

bull run tests again

REVIEWbull Make sure your patch is clean

bull Patch should be green on try-push

bull WIP State whatrsquos workingwhat notwhatrsquos next

bull Review might take some time (~1 week)

bull If longer ping person switch review person

bull Except r- donrsquot worry

Q amp A

THINGS TO HACK ON

bull Implement vwvhvminvmax

bull dirname DOM attribute on form controls

bull Implement FileSaver

Page 38: Implementing new WebAPIs

INTERFACES

Attribute

PrintStateCallback

canvasmozPrintCallback =

function(obj) var ctx = objcontext ctxfillRect(0 0 100 100) objdone()

INTERFACES[scriptable uuid(a7062fca-41c6-4520-b777-3bb30fd77273)]interface nsIDOMHTMLCanvasElement nsIDOMHTMLElement []

A Mozilla-only callback that is called during the printing process attribute nsIPrintCallback mozPrintCallback

Attrib

ute

Callb

ack

[scriptable function uuid(8d5fb8a0-7782-11e1-b0c4-0800200c9a66)]interface nsIPrintCallback nsISupports void render(in nsIDOMMozCanvasPrintState ctx)

[scriptable builtinclass uuid(8d5fb8a0-7782-11e1-b0c4-0800200c9a67)]interface nsIDOMMozCanvasPrintState nsISupports A canvas rendering context readonly attribute nsISupports context

To be called when rendering to the context is done void done()

PrintS

tate

Taken frombug 745025

class nsHTMLCanvasPrintState public nsIDOMMozCanvasPrintStatepublic 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() [] return NS_OK

[]

Taken frombug 745025

MEMORY MANAGEMENTbull C++ doesnrsquot have a garbage collector (

bull In Gecko Reference counting amp cycle collector

bull Reference counting

bull nsCOMPtr (for interfaces) nsREFPtr

bull use getter_AddRefs

bull NS_IF_ADDREF amp NS_IF_RELEASE

MEMORY MANAGEMENT

bull Reference counting doesnrsquot work always

bull Make use of Geckorsquos cycle collector

bull Better cycle then maybe leak

DEBUGGING

bull Make sure to have a debug build

bull Enable logging (example)

bull Watch for assertion in logs

bull Insert printfs

bull There is documentation how to use debugger

OVERVIEW OF SOME TREES

bull Frame Tree Frames on page

bull Content Tree Content going with frames

bull View Tree Connecting views

MAKE YOUR WORK LAND

TESTS TESTS TESTS

bull Reftests

bull Crashtests

bull XPCShell Tests

bull Mochitests

bull JS tests

bull Compiled code tests -(

bull Marionette tests

DIFFERENT TYPE OF TESTS

MOCHITEST

Text

bullpathtoobjdir $ TEST_PATH=domcontactstests make mochitest-plain

bullpathtoobjdir $ TEST_PATH=domcontactsteststest_contactshtml make mochitest-plain

TIME FOR REVIEWbull Make sure the patch is formatted according to the guidelines

bull 8 lines of context

bull correct committer info (name + email)

bull correct checking message

bull When uploading a new version

bull address all review comments

bull obsolete the old patch

bull run tests again

REVIEWbull Make sure your patch is clean

bull Patch should be green on try-push

bull WIP State whatrsquos workingwhat notwhatrsquos next

bull Review might take some time (~1 week)

bull If longer ping person switch review person

bull Except r- donrsquot worry

Q amp A

THINGS TO HACK ON

bull Implement vwvhvminvmax

bull dirname DOM attribute on form controls

bull Implement FileSaver

Page 39: Implementing new WebAPIs

INTERFACES[scriptable uuid(a7062fca-41c6-4520-b777-3bb30fd77273)]interface nsIDOMHTMLCanvasElement nsIDOMHTMLElement []

A Mozilla-only callback that is called during the printing process attribute nsIPrintCallback mozPrintCallback

Attrib

ute

Callb

ack

[scriptable function uuid(8d5fb8a0-7782-11e1-b0c4-0800200c9a66)]interface nsIPrintCallback nsISupports void render(in nsIDOMMozCanvasPrintState ctx)

[scriptable builtinclass uuid(8d5fb8a0-7782-11e1-b0c4-0800200c9a67)]interface nsIDOMMozCanvasPrintState nsISupports A canvas rendering context readonly attribute nsISupports context

To be called when rendering to the context is done void done()

PrintS

tate

Taken frombug 745025

class nsHTMLCanvasPrintState public nsIDOMMozCanvasPrintStatepublic 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() [] return NS_OK

[]

Taken frombug 745025

MEMORY MANAGEMENTbull C++ doesnrsquot have a garbage collector (

bull In Gecko Reference counting amp cycle collector

bull Reference counting

bull nsCOMPtr (for interfaces) nsREFPtr

bull use getter_AddRefs

bull NS_IF_ADDREF amp NS_IF_RELEASE

MEMORY MANAGEMENT

bull Reference counting doesnrsquot work always

bull Make use of Geckorsquos cycle collector

bull Better cycle then maybe leak

DEBUGGING

bull Make sure to have a debug build

bull Enable logging (example)

bull Watch for assertion in logs

bull Insert printfs

bull There is documentation how to use debugger

OVERVIEW OF SOME TREES

bull Frame Tree Frames on page

bull Content Tree Content going with frames

bull View Tree Connecting views

MAKE YOUR WORK LAND

TESTS TESTS TESTS

bull Reftests

bull Crashtests

bull XPCShell Tests

bull Mochitests

bull JS tests

bull Compiled code tests -(

bull Marionette tests

DIFFERENT TYPE OF TESTS

MOCHITEST

Text

bullpathtoobjdir $ TEST_PATH=domcontactstests make mochitest-plain

bullpathtoobjdir $ TEST_PATH=domcontactsteststest_contactshtml make mochitest-plain

TIME FOR REVIEWbull Make sure the patch is formatted according to the guidelines

bull 8 lines of context

bull correct committer info (name + email)

bull correct checking message

bull When uploading a new version

bull address all review comments

bull obsolete the old patch

bull run tests again

REVIEWbull Make sure your patch is clean

bull Patch should be green on try-push

bull WIP State whatrsquos workingwhat notwhatrsquos next

bull Review might take some time (~1 week)

bull If longer ping person switch review person

bull Except r- donrsquot worry

Q amp A

THINGS TO HACK ON

bull Implement vwvhvminvmax

bull dirname DOM attribute on form controls

bull Implement FileSaver

Page 40: Implementing new WebAPIs

class nsHTMLCanvasPrintState public nsIDOMMozCanvasPrintStatepublic 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() [] return NS_OK

[]

Taken frombug 745025

MEMORY MANAGEMENTbull C++ doesnrsquot have a garbage collector (

bull In Gecko Reference counting amp cycle collector

bull Reference counting

bull nsCOMPtr (for interfaces) nsREFPtr

bull use getter_AddRefs

bull NS_IF_ADDREF amp NS_IF_RELEASE

MEMORY MANAGEMENT

bull Reference counting doesnrsquot work always

bull Make use of Geckorsquos cycle collector

bull Better cycle then maybe leak

DEBUGGING

bull Make sure to have a debug build

bull Enable logging (example)

bull Watch for assertion in logs

bull Insert printfs

bull There is documentation how to use debugger

OVERVIEW OF SOME TREES

bull Frame Tree Frames on page

bull Content Tree Content going with frames

bull View Tree Connecting views

MAKE YOUR WORK LAND

TESTS TESTS TESTS

bull Reftests

bull Crashtests

bull XPCShell Tests

bull Mochitests

bull JS tests

bull Compiled code tests -(

bull Marionette tests

DIFFERENT TYPE OF TESTS

MOCHITEST

Text

bullpathtoobjdir $ TEST_PATH=domcontactstests make mochitest-plain

bullpathtoobjdir $ TEST_PATH=domcontactsteststest_contactshtml make mochitest-plain

TIME FOR REVIEWbull Make sure the patch is formatted according to the guidelines

bull 8 lines of context

bull correct committer info (name + email)

bull correct checking message

bull When uploading a new version

bull address all review comments

bull obsolete the old patch

bull run tests again

REVIEWbull Make sure your patch is clean

bull Patch should be green on try-push

bull WIP State whatrsquos workingwhat notwhatrsquos next

bull Review might take some time (~1 week)

bull If longer ping person switch review person

bull Except r- donrsquot worry

Q amp A

THINGS TO HACK ON

bull Implement vwvhvminvmax

bull dirname DOM attribute on form controls

bull Implement FileSaver

Page 41: Implementing new WebAPIs

MEMORY MANAGEMENTbull C++ doesnrsquot have a garbage collector (

bull In Gecko Reference counting amp cycle collector

bull Reference counting

bull nsCOMPtr (for interfaces) nsREFPtr

bull use getter_AddRefs

bull NS_IF_ADDREF amp NS_IF_RELEASE

MEMORY MANAGEMENT

bull Reference counting doesnrsquot work always

bull Make use of Geckorsquos cycle collector

bull Better cycle then maybe leak

DEBUGGING

bull Make sure to have a debug build

bull Enable logging (example)

bull Watch for assertion in logs

bull Insert printfs

bull There is documentation how to use debugger

OVERVIEW OF SOME TREES

bull Frame Tree Frames on page

bull Content Tree Content going with frames

bull View Tree Connecting views

MAKE YOUR WORK LAND

TESTS TESTS TESTS

bull Reftests

bull Crashtests

bull XPCShell Tests

bull Mochitests

bull JS tests

bull Compiled code tests -(

bull Marionette tests

DIFFERENT TYPE OF TESTS

MOCHITEST

Text

bullpathtoobjdir $ TEST_PATH=domcontactstests make mochitest-plain

bullpathtoobjdir $ TEST_PATH=domcontactsteststest_contactshtml make mochitest-plain

TIME FOR REVIEWbull Make sure the patch is formatted according to the guidelines

bull 8 lines of context

bull correct committer info (name + email)

bull correct checking message

bull When uploading a new version

bull address all review comments

bull obsolete the old patch

bull run tests again

REVIEWbull Make sure your patch is clean

bull Patch should be green on try-push

bull WIP State whatrsquos workingwhat notwhatrsquos next

bull Review might take some time (~1 week)

bull If longer ping person switch review person

bull Except r- donrsquot worry

Q amp A

THINGS TO HACK ON

bull Implement vwvhvminvmax

bull dirname DOM attribute on form controls

bull Implement FileSaver

Page 42: Implementing new WebAPIs

MEMORY MANAGEMENT

bull Reference counting doesnrsquot work always

bull Make use of Geckorsquos cycle collector

bull Better cycle then maybe leak

DEBUGGING

bull Make sure to have a debug build

bull Enable logging (example)

bull Watch for assertion in logs

bull Insert printfs

bull There is documentation how to use debugger

OVERVIEW OF SOME TREES

bull Frame Tree Frames on page

bull Content Tree Content going with frames

bull View Tree Connecting views

MAKE YOUR WORK LAND

TESTS TESTS TESTS

bull Reftests

bull Crashtests

bull XPCShell Tests

bull Mochitests

bull JS tests

bull Compiled code tests -(

bull Marionette tests

DIFFERENT TYPE OF TESTS

MOCHITEST

Text

bullpathtoobjdir $ TEST_PATH=domcontactstests make mochitest-plain

bullpathtoobjdir $ TEST_PATH=domcontactsteststest_contactshtml make mochitest-plain

TIME FOR REVIEWbull Make sure the patch is formatted according to the guidelines

bull 8 lines of context

bull correct committer info (name + email)

bull correct checking message

bull When uploading a new version

bull address all review comments

bull obsolete the old patch

bull run tests again

REVIEWbull Make sure your patch is clean

bull Patch should be green on try-push

bull WIP State whatrsquos workingwhat notwhatrsquos next

bull Review might take some time (~1 week)

bull If longer ping person switch review person

bull Except r- donrsquot worry

Q amp A

THINGS TO HACK ON

bull Implement vwvhvminvmax

bull dirname DOM attribute on form controls

bull Implement FileSaver

Page 43: Implementing new WebAPIs

DEBUGGING

bull Make sure to have a debug build

bull Enable logging (example)

bull Watch for assertion in logs

bull Insert printfs

bull There is documentation how to use debugger

OVERVIEW OF SOME TREES

bull Frame Tree Frames on page

bull Content Tree Content going with frames

bull View Tree Connecting views

MAKE YOUR WORK LAND

TESTS TESTS TESTS

bull Reftests

bull Crashtests

bull XPCShell Tests

bull Mochitests

bull JS tests

bull Compiled code tests -(

bull Marionette tests

DIFFERENT TYPE OF TESTS

MOCHITEST

Text

bullpathtoobjdir $ TEST_PATH=domcontactstests make mochitest-plain

bullpathtoobjdir $ TEST_PATH=domcontactsteststest_contactshtml make mochitest-plain

TIME FOR REVIEWbull Make sure the patch is formatted according to the guidelines

bull 8 lines of context

bull correct committer info (name + email)

bull correct checking message

bull When uploading a new version

bull address all review comments

bull obsolete the old patch

bull run tests again

REVIEWbull Make sure your patch is clean

bull Patch should be green on try-push

bull WIP State whatrsquos workingwhat notwhatrsquos next

bull Review might take some time (~1 week)

bull If longer ping person switch review person

bull Except r- donrsquot worry

Q amp A

THINGS TO HACK ON

bull Implement vwvhvminvmax

bull dirname DOM attribute on form controls

bull Implement FileSaver

Page 44: Implementing new WebAPIs

OVERVIEW OF SOME TREES

bull Frame Tree Frames on page

bull Content Tree Content going with frames

bull View Tree Connecting views

MAKE YOUR WORK LAND

TESTS TESTS TESTS

bull Reftests

bull Crashtests

bull XPCShell Tests

bull Mochitests

bull JS tests

bull Compiled code tests -(

bull Marionette tests

DIFFERENT TYPE OF TESTS

MOCHITEST

Text

bullpathtoobjdir $ TEST_PATH=domcontactstests make mochitest-plain

bullpathtoobjdir $ TEST_PATH=domcontactsteststest_contactshtml make mochitest-plain

TIME FOR REVIEWbull Make sure the patch is formatted according to the guidelines

bull 8 lines of context

bull correct committer info (name + email)

bull correct checking message

bull When uploading a new version

bull address all review comments

bull obsolete the old patch

bull run tests again

REVIEWbull Make sure your patch is clean

bull Patch should be green on try-push

bull WIP State whatrsquos workingwhat notwhatrsquos next

bull Review might take some time (~1 week)

bull If longer ping person switch review person

bull Except r- donrsquot worry

Q amp A

THINGS TO HACK ON

bull Implement vwvhvminvmax

bull dirname DOM attribute on form controls

bull Implement FileSaver

Page 45: Implementing new WebAPIs

MAKE YOUR WORK LAND

TESTS TESTS TESTS

bull Reftests

bull Crashtests

bull XPCShell Tests

bull Mochitests

bull JS tests

bull Compiled code tests -(

bull Marionette tests

DIFFERENT TYPE OF TESTS

MOCHITEST

Text

bullpathtoobjdir $ TEST_PATH=domcontactstests make mochitest-plain

bullpathtoobjdir $ TEST_PATH=domcontactsteststest_contactshtml make mochitest-plain

TIME FOR REVIEWbull Make sure the patch is formatted according to the guidelines

bull 8 lines of context

bull correct committer info (name + email)

bull correct checking message

bull When uploading a new version

bull address all review comments

bull obsolete the old patch

bull run tests again

REVIEWbull Make sure your patch is clean

bull Patch should be green on try-push

bull WIP State whatrsquos workingwhat notwhatrsquos next

bull Review might take some time (~1 week)

bull If longer ping person switch review person

bull Except r- donrsquot worry

Q amp A

THINGS TO HACK ON

bull Implement vwvhvminvmax

bull dirname DOM attribute on form controls

bull Implement FileSaver

Page 46: Implementing new WebAPIs

TESTS TESTS TESTS

bull Reftests

bull Crashtests

bull XPCShell Tests

bull Mochitests

bull JS tests

bull Compiled code tests -(

bull Marionette tests

DIFFERENT TYPE OF TESTS

MOCHITEST

Text

bullpathtoobjdir $ TEST_PATH=domcontactstests make mochitest-plain

bullpathtoobjdir $ TEST_PATH=domcontactsteststest_contactshtml make mochitest-plain

TIME FOR REVIEWbull Make sure the patch is formatted according to the guidelines

bull 8 lines of context

bull correct committer info (name + email)

bull correct checking message

bull When uploading a new version

bull address all review comments

bull obsolete the old patch

bull run tests again

REVIEWbull Make sure your patch is clean

bull Patch should be green on try-push

bull WIP State whatrsquos workingwhat notwhatrsquos next

bull Review might take some time (~1 week)

bull If longer ping person switch review person

bull Except r- donrsquot worry

Q amp A

THINGS TO HACK ON

bull Implement vwvhvminvmax

bull dirname DOM attribute on form controls

bull Implement FileSaver

Page 47: Implementing new WebAPIs

bull Reftests

bull Crashtests

bull XPCShell Tests

bull Mochitests

bull JS tests

bull Compiled code tests -(

bull Marionette tests

DIFFERENT TYPE OF TESTS

MOCHITEST

Text

bullpathtoobjdir $ TEST_PATH=domcontactstests make mochitest-plain

bullpathtoobjdir $ TEST_PATH=domcontactsteststest_contactshtml make mochitest-plain

TIME FOR REVIEWbull Make sure the patch is formatted according to the guidelines

bull 8 lines of context

bull correct committer info (name + email)

bull correct checking message

bull When uploading a new version

bull address all review comments

bull obsolete the old patch

bull run tests again

REVIEWbull Make sure your patch is clean

bull Patch should be green on try-push

bull WIP State whatrsquos workingwhat notwhatrsquos next

bull Review might take some time (~1 week)

bull If longer ping person switch review person

bull Except r- donrsquot worry

Q amp A

THINGS TO HACK ON

bull Implement vwvhvminvmax

bull dirname DOM attribute on form controls

bull Implement FileSaver

Page 48: Implementing new WebAPIs

MOCHITEST

Text

bullpathtoobjdir $ TEST_PATH=domcontactstests make mochitest-plain

bullpathtoobjdir $ TEST_PATH=domcontactsteststest_contactshtml make mochitest-plain

TIME FOR REVIEWbull Make sure the patch is formatted according to the guidelines

bull 8 lines of context

bull correct committer info (name + email)

bull correct checking message

bull When uploading a new version

bull address all review comments

bull obsolete the old patch

bull run tests again

REVIEWbull Make sure your patch is clean

bull Patch should be green on try-push

bull WIP State whatrsquos workingwhat notwhatrsquos next

bull Review might take some time (~1 week)

bull If longer ping person switch review person

bull Except r- donrsquot worry

Q amp A

THINGS TO HACK ON

bull Implement vwvhvminvmax

bull dirname DOM attribute on form controls

bull Implement FileSaver

Page 49: Implementing new WebAPIs

TIME FOR REVIEWbull Make sure the patch is formatted according to the guidelines

bull 8 lines of context

bull correct committer info (name + email)

bull correct checking message

bull When uploading a new version

bull address all review comments

bull obsolete the old patch

bull run tests again

REVIEWbull Make sure your patch is clean

bull Patch should be green on try-push

bull WIP State whatrsquos workingwhat notwhatrsquos next

bull Review might take some time (~1 week)

bull If longer ping person switch review person

bull Except r- donrsquot worry

Q amp A

THINGS TO HACK ON

bull Implement vwvhvminvmax

bull dirname DOM attribute on form controls

bull Implement FileSaver

Page 50: Implementing new WebAPIs

REVIEWbull Make sure your patch is clean

bull Patch should be green on try-push

bull WIP State whatrsquos workingwhat notwhatrsquos next

bull Review might take some time (~1 week)

bull If longer ping person switch review person

bull Except r- donrsquot worry

Q amp A

THINGS TO HACK ON

bull Implement vwvhvminvmax

bull dirname DOM attribute on form controls

bull Implement FileSaver

Page 51: Implementing new WebAPIs

Q amp A

THINGS TO HACK ON

bull Implement vwvhvminvmax

bull dirname DOM attribute on form controls

bull Implement FileSaver

Page 52: Implementing new WebAPIs

THINGS TO HACK ON

bull Implement vwvhvminvmax

bull dirname DOM attribute on form controls

bull Implement FileSaver