SlideShare a Scribd company logo
Firefox Architecture Overview
June 23, 2011
Bird’s Eye View
XPCOM

Extensions
Browser

Places

SpiderMonkey

Necko

Content

Security

Gecko

NSPR

Firefox

Core

NSS
Component Object Model
•

•

XPCOM - The glue that binds all the pieces

•
•

Stable, supported bindings for C++ and JavaScript
Interfaces defined in dialect of IDL called XPIDL

Any part of the code can create & use XPCOM objects

•

Core provides objects to deal with: Files, Memory, Threads,
Data structures, Networking, etc.
User Interface
•
•
•

XUL is our cross platform UI toolkit
Elements are similar to HTML elements
UI of any Mozilla-based application can be modified
dynamically

•

With use of the DOM object model & common methods
2 ways to extend
Add-ons

Feature

Pro: Fast development time (changes
can be tested by browser restart)

Con: Longer development time
(requires recompile for every change)

Con: User has to explicitly install the
add-on to use feature

Pro: Can be rolled into the next
Firefox release (every 3 months)

Con: Cannot change functionality not Pro: Can change any aspect of the
exposed by XPCOM (eg. <video>)
browser by direct code modification
Example: Read a binary file
const Cc = Components.classes;
const Ci = Components.interfaces;
var ios = Cc["@mozilla.org/network/io-service;1"].
getService(Ci.nsIIOService);
var url = ios.newURI("file:///home/mozilla/test.png", null, null);
if (!url || !url.schemeIs("file")) throw "Expected a file URL.";
var pngFile = url.QueryInterface(Ci.nsIFileURL).file;
var istream = Cc["@mozilla.org/network/file-input-stream;1"].
createInstance(Ci.nsIFileInputStream);
istream.init(pngFile, -1, -1, false);
var bstream = Cc["@mozilla.org/binaryinputstream;1"].
createInstance(Ci.nsIBinaryInputStream);
bstream.setInputStream(istream);
var bytes = bstream.readBytes(bstream.available());
Example: Code path for video
Location

Interface

Purpose

nsIHTMLVideoElement : nsIHTMLMediaElement

<video> parsed on page, object created

/netwerk/base/src/nsBaseContentStream.cpp

nsIContentStream : nsIInputStream

src=’http://...’ parsed and network fetch requested

/content/media/webm/nsWebMDecoder.cpp

nsWebmDecoder : nsIBuiltinDecoder

MIME type detected to be WebM, decoder object created
and attached to network channel

non Mozilla API

vp8 decoding

nsVideoFrame : nsFrame

rendering object for <video> element

non Mozilla API

low level colorspace conversion & OS-gfx painting

/content/html/content/src/nsHTMLVideoElement.cpp

/media/libvpx/
/layout/generic/nsVideoFrame.cpp
/gfx/cairo/cairo/src/cairo-directfb-surface.c
Example: Inject a JS API
const Cu = Components.utils;
const Ci = Components.interfaces;
const Cc = Components.classes;
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://gre/modules/Services.jsm");
function MyAPI() {}
MyAPI.prototype = {
classID: Components.ID("{3d92fb7f-be77-475c-992a-5235615f9189}"),
QueryInterface: XPCOMUtils.generateQI([
Ci.nsIDOMGlobalPropertyInitializer,
Ci.nsIObserver]),
init: function MyAPI_init(aWindow) {
let self = this;
return {
log: self.log.bind(self)
};
},
log: function MyAPI_init(msg) {
console.log(msg); // Privileged method
}
};
var NSGetFactory = XPCOMUtils.generateNSGetFactory([MyAPI]);
JS-ctypes & restartless add-ons
•

libffi binding, allows dynamic loading and execution of binary
code from JavaScript
Components.utils.import("resource://gre/modules/ctypes.jsm");
var lib = ctypes.open("C:WINDOWSsystem32user32.dll");
var msgBox = lib.declare("MessageBoxW",
ctypes.winapi_abi,
ctypes.int32_t,
ctypes.int32_t,
ctypes.jschar.ptr,
ctypes.jschar.ptr,
ctypes.int32_t);
var MB_OK = 3;
var ret = msgBox(0, "Hello world", "title", MB_OK);
lib.close();
Adding functionality to Firefox is viable through both add-ons
and direct feature integration, to differing extents
Injecting a JS API to web pages, interfacing with binary code, streaming
data from the network and rendering video on a <canvas> element
is doable as an add-on
mxr.mozilla.org
developer.mozilla.org

Questions?

More Related Content

What's hot (20)

PPTX
Block and inline elements in HTML
Pradipta Poudel
 
PPTX
HTML5 and DHTML
patelpriyank01
 
PDF
HTMLを書くだけで誰でも簡単!A-FrameではじめるWeb AR/VR
Takashi Yoshinaga
 
PPTX
How Browser Works?
Vova Voyevidka
 
PPTX
Sending Email
primeteacher32
 
PPTX
HTML Media
krupesh patel
 
PPT
CSS ppt
Sanmuga Nathan
 
PPTX
Java and OpenJDK: disecting the ecosystem
Rafael Winterhalter
 
DOCX
PHP HTML CSS Notes
Tushar Rajput
 
PPT
JavaScript Control Statements I
Reem Alattas
 
PPT
Common Gateway Interface
Piero Fraternali
 
PPTX
Angular 14.pptx
MohaNedGhawar
 
ODP
Web mining
Daminda Herath
 
PPT
Cascading Style Sheet
vijayta
 
DOC
Internet programming lab manual
inteldualcore
 
PDF
Lecture-1: Introduction to web engineering - course overview and grading scheme
Mubashir Ali
 
PPTX
Html5 tutorial for beginners
Singsys Pte Ltd
 
Block and inline elements in HTML
Pradipta Poudel
 
HTML5 and DHTML
patelpriyank01
 
HTMLを書くだけで誰でも簡単!A-FrameではじめるWeb AR/VR
Takashi Yoshinaga
 
How Browser Works?
Vova Voyevidka
 
Sending Email
primeteacher32
 
HTML Media
krupesh patel
 
Java and OpenJDK: disecting the ecosystem
Rafael Winterhalter
 
PHP HTML CSS Notes
Tushar Rajput
 
JavaScript Control Statements I
Reem Alattas
 
Common Gateway Interface
Piero Fraternali
 
Angular 14.pptx
MohaNedGhawar
 
Web mining
Daminda Herath
 
Cascading Style Sheet
vijayta
 
Internet programming lab manual
inteldualcore
 
Lecture-1: Introduction to web engineering - course overview and grading scheme
Mubashir Ali
 
Html5 tutorial for beginners
Singsys Pte Ltd
 

Similar to Firefox Architecture Overview (20)

PDF
GStreamer support in WebKit. What's new? (GStreamer Conference 2015)
Igalia
 
PDF
GStreamer support in WebKit. what’s new?
philn2
 
PDF
IoT-javascript-2019-fosdem
Phil www.rzr.online.fr
 
PDF
Initiation & hands-on Moovweb 5's new feature
BeMyApp
 
PPT
Presentation On Com Dcom
Bharat Kumar Katur
 
PPTX
20180518 QNAP Seminar - Introduction to React Native
Eric Deng
 
DOCX
Group project home management system
Sean Ahearne
 
PDF
Developing for Industrial IoT with Linux OS on DragonBoard™ 410c: Session 1
Qualcomm Developer Network
 
PDF
TDC2016POA | Trilha Cloud Computing - Source-to-image - How to transform any ...
tdc-globalcode
 
PPTX
Eclipse IDE Yocto Plugin
cudma
 
PPTX
Bringing Javascript to the Desktop with Electron
Nir Noy
 
PDF
Desktop apps with node webkit
Paul Jensen
 
PPTX
Windows Azure Media Services June 2013 update
Mingfei Yan
 
DOCX
Resume_Up
Parmeet Singh
 
PDF
Making your app soar without a container manifest
LibbySchulze
 
PPTX
Node js meetup
Ansuman Roy
 
PPTX
[GCP Summit 2018] Kubernetes with Nginx and Elasticsearch on GCP
용호 최
 
PDF
Polymer Web Framework - Swecha Boot Camp
Swecha | స్వేచ్ఛ
 
PPT
Firefox vs. chrome
Prabhath Suminda
 
PPTX
Android - Application Framework
Yong Heui Cho
 
GStreamer support in WebKit. What's new? (GStreamer Conference 2015)
Igalia
 
GStreamer support in WebKit. what’s new?
philn2
 
IoT-javascript-2019-fosdem
Phil www.rzr.online.fr
 
Initiation & hands-on Moovweb 5's new feature
BeMyApp
 
Presentation On Com Dcom
Bharat Kumar Katur
 
20180518 QNAP Seminar - Introduction to React Native
Eric Deng
 
Group project home management system
Sean Ahearne
 
Developing for Industrial IoT with Linux OS on DragonBoard™ 410c: Session 1
Qualcomm Developer Network
 
TDC2016POA | Trilha Cloud Computing - Source-to-image - How to transform any ...
tdc-globalcode
 
Eclipse IDE Yocto Plugin
cudma
 
Bringing Javascript to the Desktop with Electron
Nir Noy
 
Desktop apps with node webkit
Paul Jensen
 
Windows Azure Media Services June 2013 update
Mingfei Yan
 
Resume_Up
Parmeet Singh
 
Making your app soar without a container manifest
LibbySchulze
 
Node js meetup
Ansuman Roy
 
[GCP Summit 2018] Kubernetes with Nginx and Elasticsearch on GCP
용호 최
 
Polymer Web Framework - Swecha Boot Camp
Swecha | స్వేచ్ఛ
 
Firefox vs. chrome
Prabhath Suminda
 
Android - Application Framework
Yong Heui Cho
 
Ad

More from Anant Narayanan (20)

PDF
Enterprise Scale Knowledge Graphs
Anant Narayanan
 
PDF
Building an Intelligent Assistant
Anant Narayanan
 
PDF
WebRTC: A Practical Introduction
Anant Narayanan
 
PDF
Message Passing vs. Data Synchronization
Anant Narayanan
 
PDF
Firebase: Tales from the Trenches
Anant Narayanan
 
PDF
WebRTC: An Overview
Anant Narayanan
 
PDF
Error Handling in WebRTC
Anant Narayanan
 
PDF
WebRTC Demystified
Anant Narayanan
 
PDF
WebRTC: User Security & Privacy
Anant Narayanan
 
PDF
Next Generation Browser Add-Ons
Anant Narayanan
 
PDF
An Overview of Distributed Debugging
Anant Narayanan
 
PDF
A Brief Incursion into Botnet Detection
Anant Narayanan
 
PDF
Mozilla Weave: Integrating Services into the Browser
Anant Narayanan
 
PDF
about:labs
Anant Narayanan
 
PDF
Distributed File Systems: An Overview
Anant Narayanan
 
PDF
Innovating with Mozilla Labs
Anant Narayanan
 
PDF
Glendix: The Why and the How
Anant Narayanan
 
PDF
Mozilla Prism
Anant Narayanan
 
PDF
Making Gentoo Tick
Anant Narayanan
 
Enterprise Scale Knowledge Graphs
Anant Narayanan
 
Building an Intelligent Assistant
Anant Narayanan
 
WebRTC: A Practical Introduction
Anant Narayanan
 
Message Passing vs. Data Synchronization
Anant Narayanan
 
Firebase: Tales from the Trenches
Anant Narayanan
 
WebRTC: An Overview
Anant Narayanan
 
Error Handling in WebRTC
Anant Narayanan
 
WebRTC Demystified
Anant Narayanan
 
WebRTC: User Security & Privacy
Anant Narayanan
 
Next Generation Browser Add-Ons
Anant Narayanan
 
An Overview of Distributed Debugging
Anant Narayanan
 
A Brief Incursion into Botnet Detection
Anant Narayanan
 
Mozilla Weave: Integrating Services into the Browser
Anant Narayanan
 
about:labs
Anant Narayanan
 
Distributed File Systems: An Overview
Anant Narayanan
 
Innovating with Mozilla Labs
Anant Narayanan
 
Glendix: The Why and the How
Anant Narayanan
 
Mozilla Prism
Anant Narayanan
 
Making Gentoo Tick
Anant Narayanan
 
Ad

Recently uploaded (20)

PDF
Empowering Cloud Providers with Apache CloudStack and Stackbill
ShapeBlue
 
PDF
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
PDF
Windsurf Meetup Ottawa 2025-07-12 - Planning Mode at Reliza.pdf
Pavel Shukhman
 
PDF
Persuasive AI: risks and opportunities in the age of digital debate
Speck&Tech
 
PPTX
Darren Mills The Migration Modernization Balancing Act: Navigating Risks and...
AWS Chicago
 
PPTX
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
PDF
CloudStack GPU Integration - Rohit Yadav
ShapeBlue
 
PPTX
Extensions Framework (XaaS) - Enabling Orchestrate Anything
ShapeBlue
 
PDF
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
PDF
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
PPT
Interview paper part 3, It is based on Interview Prep
SoumyadeepGhosh39
 
PDF
TrustArc Webinar - Data Privacy Trends 2025: Mid-Year Insights & Program Stra...
TrustArc
 
PDF
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
PDF
Ampere Offers Energy-Efficient Future For AI And Cloud
ShapeBlue
 
PDF
Predicting the unpredictable: re-engineering recommendation algorithms for fr...
Speck&Tech
 
PDF
The Builder’s Playbook - 2025 State of AI Report.pdf
jeroen339954
 
PDF
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
PDF
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
PPTX
Top Managed Service Providers in Los Angeles
Captain IT
 
PDF
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
Empowering Cloud Providers with Apache CloudStack and Stackbill
ShapeBlue
 
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
Windsurf Meetup Ottawa 2025-07-12 - Planning Mode at Reliza.pdf
Pavel Shukhman
 
Persuasive AI: risks and opportunities in the age of digital debate
Speck&Tech
 
Darren Mills The Migration Modernization Balancing Act: Navigating Risks and...
AWS Chicago
 
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
CloudStack GPU Integration - Rohit Yadav
ShapeBlue
 
Extensions Framework (XaaS) - Enabling Orchestrate Anything
ShapeBlue
 
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
Interview paper part 3, It is based on Interview Prep
SoumyadeepGhosh39
 
TrustArc Webinar - Data Privacy Trends 2025: Mid-Year Insights & Program Stra...
TrustArc
 
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
Ampere Offers Energy-Efficient Future For AI And Cloud
ShapeBlue
 
Predicting the unpredictable: re-engineering recommendation algorithms for fr...
Speck&Tech
 
The Builder’s Playbook - 2025 State of AI Report.pdf
jeroen339954
 
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
Top Managed Service Providers in Los Angeles
Captain IT
 
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 

Firefox Architecture Overview

  • 3. Component Object Model • • XPCOM - The glue that binds all the pieces • • Stable, supported bindings for C++ and JavaScript Interfaces defined in dialect of IDL called XPIDL Any part of the code can create & use XPCOM objects • Core provides objects to deal with: Files, Memory, Threads, Data structures, Networking, etc.
  • 4. User Interface • • • XUL is our cross platform UI toolkit Elements are similar to HTML elements UI of any Mozilla-based application can be modified dynamically • With use of the DOM object model & common methods
  • 5. 2 ways to extend Add-ons Feature Pro: Fast development time (changes can be tested by browser restart) Con: Longer development time (requires recompile for every change) Con: User has to explicitly install the add-on to use feature Pro: Can be rolled into the next Firefox release (every 3 months) Con: Cannot change functionality not Pro: Can change any aspect of the exposed by XPCOM (eg. <video>) browser by direct code modification
  • 6. Example: Read a binary file const Cc = Components.classes; const Ci = Components.interfaces; var ios = Cc["@mozilla.org/network/io-service;1"]. getService(Ci.nsIIOService); var url = ios.newURI("file:///home/mozilla/test.png", null, null); if (!url || !url.schemeIs("file")) throw "Expected a file URL."; var pngFile = url.QueryInterface(Ci.nsIFileURL).file; var istream = Cc["@mozilla.org/network/file-input-stream;1"]. createInstance(Ci.nsIFileInputStream); istream.init(pngFile, -1, -1, false); var bstream = Cc["@mozilla.org/binaryinputstream;1"]. createInstance(Ci.nsIBinaryInputStream); bstream.setInputStream(istream); var bytes = bstream.readBytes(bstream.available());
  • 7. Example: Code path for video Location Interface Purpose nsIHTMLVideoElement : nsIHTMLMediaElement <video> parsed on page, object created /netwerk/base/src/nsBaseContentStream.cpp nsIContentStream : nsIInputStream src=’http://...’ parsed and network fetch requested /content/media/webm/nsWebMDecoder.cpp nsWebmDecoder : nsIBuiltinDecoder MIME type detected to be WebM, decoder object created and attached to network channel non Mozilla API vp8 decoding nsVideoFrame : nsFrame rendering object for <video> element non Mozilla API low level colorspace conversion & OS-gfx painting /content/html/content/src/nsHTMLVideoElement.cpp /media/libvpx/ /layout/generic/nsVideoFrame.cpp /gfx/cairo/cairo/src/cairo-directfb-surface.c
  • 8. Example: Inject a JS API const Cu = Components.utils; const Ci = Components.interfaces; const Cc = Components.classes; Cu.import("resource://gre/modules/XPCOMUtils.jsm"); Cu.import("resource://gre/modules/Services.jsm"); function MyAPI() {} MyAPI.prototype = { classID: Components.ID("{3d92fb7f-be77-475c-992a-5235615f9189}"), QueryInterface: XPCOMUtils.generateQI([ Ci.nsIDOMGlobalPropertyInitializer, Ci.nsIObserver]), init: function MyAPI_init(aWindow) { let self = this; return { log: self.log.bind(self) }; }, log: function MyAPI_init(msg) { console.log(msg); // Privileged method } }; var NSGetFactory = XPCOMUtils.generateNSGetFactory([MyAPI]);
  • 9. JS-ctypes & restartless add-ons • libffi binding, allows dynamic loading and execution of binary code from JavaScript Components.utils.import("resource://gre/modules/ctypes.jsm"); var lib = ctypes.open("C:WINDOWSsystem32user32.dll"); var msgBox = lib.declare("MessageBoxW", ctypes.winapi_abi, ctypes.int32_t, ctypes.int32_t, ctypes.jschar.ptr, ctypes.jschar.ptr, ctypes.int32_t); var MB_OK = 3; var ret = msgBox(0, "Hello world", "title", MB_OK); lib.close();
  • 10. Adding functionality to Firefox is viable through both add-ons and direct feature integration, to differing extents Injecting a JS API to web pages, interfacing with binary code, streaming data from the network and rendering video on a <canvas> element is doable as an add-on mxr.mozilla.org developer.mozilla.org Questions?