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

PPTX
.NETラボ2021年9月 Blazorのカスタム認証を通じてDIの便利さを学ぶ
PDF
A story of the passive aggressive sysadmin of AEM
PDF
I Love APIs 2015: Microservices at Amazon
PDF
【Unite 2017 Tokyo】Unityを使ったNintendo Switch™ローンチタイトル制作~スーパーボンバーマンRの事例~
PPT
프레임레이트 향상을 위한 공간분할 및 오브젝트 컬링 기법
PPT
[1216 박민근] 게임회사취업및이직에관한조언
PDF
게임 디자이너와 게임 서버
PDF
猿でもわかる Helm
.NETラボ2021年9月 Blazorのカスタム認証を通じてDIの便利さを学ぶ
A story of the passive aggressive sysadmin of AEM
I Love APIs 2015: Microservices at Amazon
【Unite 2017 Tokyo】Unityを使ったNintendo Switch™ローンチタイトル制作~スーパーボンバーマンRの事例~
프레임레이트 향상을 위한 공간분할 및 오브젝트 컬링 기법
[1216 박민근] 게임회사취업및이직에관한조언
게임 디자이너와 게임 서버
猿でもわかる Helm

What's hot (20)

PPTX
REST Service Authetication with TLS & JWTs
PPTX
Zuul @ Netflix SpringOne Platform
PPTX
Game Architecture with Scriptable Objects
PDF
3種類のTEE比較(Intel SGX, ARM TrustZone, RISC-V Keystone)
PPTX
OpenStack Architecture and Use Cases
PDF
TypeScript - An Introduction
PDF
[GTMF2019] Python / BlueprintによるUnreal Engineの自動化
PDF
LogbackからLog4j 2への移行によるアプリケーションのスループット改善 ( JJUG CCC 2021 Fall )
PDF
Introduction to docker and docker compose
PDF
Velero search &amp; practice 20210609
PDF
Visual Studio를 이용한 어셈블리어 학습 part 1
PDF
「黒騎士と白の魔王」gRPCによるHTTP/2 - API, Streamingの実践
PDF
왕초보를 위한 도커 사용법
PPTX
Keycloak入門-OpenID ConnectによるAPIセキュリティ
PPTX
UE4に初めて触ってから半年で同人ゲームを作るまで
PPTX
Docker: From Zero to Hero
PDF
FIDO2 Specifications Overview
PDF
Android Chromium Rendering Pipeline
PDF
【Unite Tokyo 2019】運用中超大規模タイトルにおけるUnityアップデート課題の解決手法と事例
REST Service Authetication with TLS & JWTs
Zuul @ Netflix SpringOne Platform
Game Architecture with Scriptable Objects
3種類のTEE比較(Intel SGX, ARM TrustZone, RISC-V Keystone)
OpenStack Architecture and Use Cases
TypeScript - An Introduction
[GTMF2019] Python / BlueprintによるUnreal Engineの自動化
LogbackからLog4j 2への移行によるアプリケーションのスループット改善 ( JJUG CCC 2021 Fall )
Introduction to docker and docker compose
Velero search &amp; practice 20210609
Visual Studio를 이용한 어셈블리어 학습 part 1
「黒騎士と白の魔王」gRPCによるHTTP/2 - API, Streamingの実践
왕초보를 위한 도커 사용법
Keycloak入門-OpenID ConnectによるAPIセキュリティ
UE4に初めて触ってから半年で同人ゲームを作るまで
Docker: From Zero to Hero
FIDO2 Specifications Overview
Android Chromium Rendering Pipeline
【Unite Tokyo 2019】運用中超大規模タイトルにおけるUnityアップデート課題の解決手法と事例
Ad

Similar to Firefox Architecture Overview (20)

PDF
GStreamer support in WebKit. What's new? (GStreamer Conference 2015)
PDF
GStreamer support in WebKit. what’s new?
PDF
IoT-javascript-2019-fosdem
PDF
Initiation & hands-on Moovweb 5's new feature
PPT
Presentation On Com Dcom
PPTX
20180518 QNAP Seminar - Introduction to React Native
DOCX
Group project home management system
PDF
Developing for Industrial IoT with Linux OS on DragonBoard™ 410c: Session 1
PDF
TDC2016POA | Trilha Cloud Computing - Source-to-image - How to transform any ...
PPTX
Eclipse IDE Yocto Plugin
PPTX
Bringing Javascript to the Desktop with Electron
PDF
Desktop apps with node webkit
PPTX
Windows Azure Media Services June 2013 update
DOCX
Resume_Up
PDF
Making your app soar without a container manifest
PPTX
Node js meetup
PPTX
[GCP Summit 2018] Kubernetes with Nginx and Elasticsearch on GCP
PDF
Polymer Web Framework - Swecha Boot Camp
PPT
Firefox vs. chrome
PPTX
Android - Application Framework
GStreamer support in WebKit. What's new? (GStreamer Conference 2015)
GStreamer support in WebKit. what’s new?
IoT-javascript-2019-fosdem
Initiation & hands-on Moovweb 5's new feature
Presentation On Com Dcom
20180518 QNAP Seminar - Introduction to React Native
Group project home management system
Developing for Industrial IoT with Linux OS on DragonBoard™ 410c: Session 1
TDC2016POA | Trilha Cloud Computing - Source-to-image - How to transform any ...
Eclipse IDE Yocto Plugin
Bringing Javascript to the Desktop with Electron
Desktop apps with node webkit
Windows Azure Media Services June 2013 update
Resume_Up
Making your app soar without a container manifest
Node js meetup
[GCP Summit 2018] Kubernetes with Nginx and Elasticsearch on GCP
Polymer Web Framework - Swecha Boot Camp
Firefox vs. chrome
Android - Application Framework
Ad

More from Anant Narayanan (20)

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

Recently uploaded (20)

PPTX
MYSQL Presentation for SQL database connectivity
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
solutions_manual_-_materials___processing_in_manufacturing__demargo_.pdf
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
NewMind AI Monthly Chronicles - July 2025
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PPTX
breach-and-attack-simulation-cybersecurity-india-chennai-defenderrabbit-2025....
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PPTX
Cloud computing and distributed systems.
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
GDG Cloud Iasi [PUBLIC] Florian Blaga - Unveiling the Evolution of Cybersecur...
MYSQL Presentation for SQL database connectivity
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
solutions_manual_-_materials___processing_in_manufacturing__demargo_.pdf
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
Reach Out and Touch Someone: Haptics and Empathic Computing
Per capita expenditure prediction using model stacking based on satellite ima...
Unlocking AI with Model Context Protocol (MCP)
NewMind AI Weekly Chronicles - August'25 Week I
NewMind AI Monthly Chronicles - July 2025
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
Advanced methodologies resolving dimensionality complications for autism neur...
breach-and-attack-simulation-cybersecurity-india-chennai-defenderrabbit-2025....
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Cloud computing and distributed systems.
Spectral efficient network and resource selection model in 5G networks
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
GDG Cloud Iasi [PUBLIC] Florian Blaga - Unveiling the Evolution of Cybersecur...

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?