SlideShare a Scribd company logo
1 of 28
Download to read offline
An Introduction to
XPConnect
Writing Extensions in Pure JavaScript

Anant Narayanan
Malaviya National Institute of Technology
FOSS.IN 2007
Why is Firefox
successful?
Apart from the fact that it is Open Source
EXTENSIONS
No other browser provides such a feature-rich extensible
development environment
Community
• There is a thriving community behind
extension development

• There are extensions to help you do every

imaginable task with web pages (Firefox) and
email (Thunderbird)

• Powered by the Mozilla platform
Contribution
• Writing extensions is one of the easiest and
most useful ways of contributing to Mozilla

• You just have to scratch your own itch, or

come up with an idea for your extension

• We’ll look into the technical aspect of
developing your extension in this
presentation
Overview
• XPCOM & why it is useful
• XPConnect & why it is useful
• How XPConnect packs punch into Javascript
• How you can develop your very own
extension in pure Javascript in a matter of
hours
(You need to know basic JavaScript)
XPCOM
• Cross Platform Component Object Model
• Provides a framework for writing crossplatform, modular software

• Provides the abstraction required to write
applications that will run on the Mozilla
platform across the variety of operating
systems that Mozilla supports
Components
• Core: Type System, Data Structures, Streams
• UI: Clipboard, Drag-and-Drop, XUL
• Application: Preferences, Profiles, WM
• Network: Channels, Protocol Handlers
• DOM, Mail and several others
• You can even create you own!
Interface Description
• Language neutral way to specify interfaces to
the XPCOM components

• The Interface Definition Language used by
Mozilla (IDL) is slightly different than the
conventional ones

• XPCOM initially meant to be used in C++
XPConnect
• Allows scriptability of XPCOM components
• Simple interoperation between XPCOM and
languages like Javascript, Perl and Python

• Allows transparent access and manipulation

of XPCOM objects via the XPIDL definitions
Javascript & XPConnect
• Javascript run in the Mozilla environment will
have access to all XPCOM components

• Caveat: Only those components that have

interfaces defined in XPIDL will be available

• Developing extensions is breeze, assuming
you already know Javascript

• JS is considerably easier than C++!
Development Tools
• Best way to work with Javascript is Firefox
• Plugins that you will find helpful:
• Console
• Extension Developer
• Firebug
• jsLib
• XPCOMViewer
2
Let’s Get Started
Skeleton of an
Extension
• Every extension is made up of a set of base
files and directory

• This hierarchy is zipped to create your .xpi
re-distributable extension
Visit the Wizard
• Don’t waste time in creating these base files
and directories

• Get your skeleton at
• http://ted.mielczarek.org/code/mozilla/
extensionwiz/

• Will generate a zip file containing the base
extension code
The Code
• All the JavaScript code goes into the
components/ directory

• Put all your other resources - HTML, Images
et. al. in content/

• This content will be available as
chrome://<name>/content/
Power Javascript
• Think of Javascript as a language
• All XPCOM components are available as
regular Javascript OBJECTS
The Lifecycle of an
XPConnect Object
• Every component is uniquely identified by a
Contract ID

• Usually something like:
•
•

@mozilla.org/network/simple-uri;1
@mozilla.org/consoleservice;1
Instantiating a
Component
• Usually, you will just call the getService

method on the component class passing an
interface along

• Components.classes[“@mozilla.org/
moz/jssubscript-loader;1].
getService(Components.interfaces.
mozIJSSubScriptLoader);
Code Snippets
Logging

function jsLog(msg, error) {
var consoleService = Components.classes
["@mozilla.org/consoleservice;1"].getService
(Components.interfaces.nsIConsoleService);
if (error) {
consoleService.logStringError(msg);
} else {
consoleService.logStringMessage(msg);
}
}
Loading other JS files
into a given Object
function jsImport(obj, fName) {
var loader = Components.classes
["@mozilla.org/moz/jssubscript-loader;
1"].getService
(Components.interfaces.mozIJSSubScriptLoader);
loader.loadSubScript
("file://"+__LOCATION__.parent.path+"/"+fName,
obj);
}
Some Theory
• Mozilla introduces the Components object
into the Global JS Namespace

• Components.classes
• Components.interfaces
• Components.results
• etc...
Preventing Clashes
• Since everything Javascript is in the global
namespace...

• ... you need to protect your code by
wrapping them suitably into objects

• Remember, multiple extensions may run on a
single Mozilla instance, and they all share the
namespace
Resources
• Use the XPCOMViewer for offline ready
documentation on the various scriptable
XPCOM components available to you

• eg: Ever felt the need for sockets in
Javascript?

@mozilla.org/network/sockettransport-service;1
Resources (Contd.)
• A lot of repetitive tasks and frequently used
components in Javascript are available as
friendly JS objects via jsLib

• Disadvantage: If your code uses jsLib, it

becomes a pre-requisite for your extension

• Mozilla normally doesn’t allow

dependencies between extensions, but it’s
Ok in this case
Resources (Contd.)
• Run XPConnect powered code in Firebug to
get instantaneous results (kind of like
working in the python interpreter)

• Firebug also will give you helpful error

messages when something goes wrong. Use
the Logger to segregate different types of
messages and view them in Console2
Resources (Contd.)
• Visit XULPlanet for comprehensive online
documentation on XPCOM scriptable
components:

• http://www.xulplanet.com/references/
xpcomref/

• Every serious JS programmer must visit:
• http://javascript.crockford.com/
Questions?
Thank You!
Feel free to contact me:
<anant@kix.in>
http://www.kix.in/
The Web9 Project implements a new protocol handler
entirely in Javascript:
http://code.kix.in/projects/web9

More Related Content

What's hot

Evolution of .NET Framework and Features of different versions
Evolution of .NET Framework and Features of different versionsEvolution of .NET Framework and Features of different versions
Evolution of .NET Framework and Features of different versionsNilanshu Srivastava
 
Dr. Strangelove, or how I learned to love plugin development
Dr. Strangelove, or how I learned to love plugin developmentDr. Strangelove, or how I learned to love plugin development
Dr. Strangelove, or how I learned to love plugin developmentUlrich Krause
 
docker : how to deploy Digital Experience in a container drinking a cup of co...
docker : how to deploy Digital Experience in a container drinking a cup of co...docker : how to deploy Digital Experience in a container drinking a cup of co...
docker : how to deploy Digital Experience in a container drinking a cup of co...Matteo Bisi
 
IBM Think Session 8598 Domino and JavaScript Development MasterClass
IBM Think Session 8598 Domino and JavaScript Development MasterClassIBM Think Session 8598 Domino and JavaScript Development MasterClass
IBM Think Session 8598 Domino and JavaScript Development MasterClassPaul Withers
 
Bootstrapping a simple enterprise application with Java EE successor, Jakarta...
Bootstrapping a simple enterprise application with Java EE successor, Jakarta...Bootstrapping a simple enterprise application with Java EE successor, Jakarta...
Bootstrapping a simple enterprise application with Java EE successor, Jakarta...Buhake Sindi
 
Docker for .NET Developers
Docker for .NET DevelopersDocker for .NET Developers
Docker for .NET DevelopersTaswar Bhatti
 
.Net platform .Net core fundamentals
.Net platform .Net core  fundamentals.Net platform .Net core  fundamentals
.Net platform .Net core fundamentalsHosein Mansouri
 
Servlets made easy. 
Write once and run everywhere.
Servlets made easy. 
Write once and run everywhere.Servlets made easy. 
Write once and run everywhere.
Servlets made easy. 
Write once and run everywhere.ICON UK EVENTS Limited
 
BP207 - Meet the Java Application Server You Already Own – IBM Domino
BP207 - Meet the Java Application Server You Already Own – IBM DominoBP207 - Meet the Java Application Server You Already Own – IBM Domino
BP207 - Meet the Java Application Server You Already Own – IBM DominoSerdar Basegmez
 
MozTW Jetpack Workshop: Taipei
MozTW Jetpack Workshop: TaipeiMozTW Jetpack Workshop: Taipei
MozTW Jetpack Workshop: Taipeilittlebtc
 
Jetpack SDK: The new possibility of the extensions on browser
Jetpack SDK: The new possibility of the extensions on browserJetpack SDK: The new possibility of the extensions on browser
Jetpack SDK: The new possibility of the extensions on browserlittlebtc
 
MozTW Jetpack Workshop: Taichung
MozTW Jetpack Workshop: TaichungMozTW Jetpack Workshop: Taichung
MozTW Jetpack Workshop: Taichunglittlebtc
 
Find your data - use GraphDB capabilities in XPages applications - and beyond
Find your data - use GraphDB capabilities in XPages applications - and beyond	Find your data - use GraphDB capabilities in XPages applications - and beyond
Find your data - use GraphDB capabilities in XPages applications - and beyond ICON UK EVENTS Limited
 
Overview of the new .NET Core and .NET Platform Standard
Overview of the new .NET Core and .NET Platform StandardOverview of the new .NET Core and .NET Platform Standard
Overview of the new .NET Core and .NET Platform StandardAlex Thissen
 
What's New in NetBeans IDE 7.x
What's New in NetBeans IDE 7.xWhat's New in NetBeans IDE 7.x
What's New in NetBeans IDE 7.xGeertjan Wielenga
 

What's hot (20)

Evolution of .NET Framework and Features of different versions
Evolution of .NET Framework and Features of different versionsEvolution of .NET Framework and Features of different versions
Evolution of .NET Framework and Features of different versions
 
Dr. Strangelove, or how I learned to love plugin development
Dr. Strangelove, or how I learned to love plugin developmentDr. Strangelove, or how I learned to love plugin development
Dr. Strangelove, or how I learned to love plugin development
 
docker : how to deploy Digital Experience in a container drinking a cup of co...
docker : how to deploy Digital Experience in a container drinking a cup of co...docker : how to deploy Digital Experience in a container drinking a cup of co...
docker : how to deploy Digital Experience in a container drinking a cup of co...
 
IBM Think Session 8598 Domino and JavaScript Development MasterClass
IBM Think Session 8598 Domino and JavaScript Development MasterClassIBM Think Session 8598 Domino and JavaScript Development MasterClass
IBM Think Session 8598 Domino and JavaScript Development MasterClass
 
Bootstrapping a simple enterprise application with Java EE successor, Jakarta...
Bootstrapping a simple enterprise application with Java EE successor, Jakarta...Bootstrapping a simple enterprise application with Java EE successor, Jakarta...
Bootstrapping a simple enterprise application with Java EE successor, Jakarta...
 
Docker for .NET Developers
Docker for .NET DevelopersDocker for .NET Developers
Docker for .NET Developers
 
Let me introduce you: DOTS
Let me introduce you: DOTSLet me introduce you: DOTS
Let me introduce you: DOTS
 
.Net platform .Net core fundamentals
.Net platform .Net core  fundamentals.Net platform .Net core  fundamentals
.Net platform .Net core fundamentals
 
.Net standard 2.0
.Net standard 2.0.Net standard 2.0
.Net standard 2.0
 
Servlets made easy. 
Write once and run everywhere.
Servlets made easy. 
Write once and run everywhere.Servlets made easy. 
Write once and run everywhere.
Servlets made easy. 
Write once and run everywhere.
 
BP207 - Meet the Java Application Server You Already Own – IBM Domino
BP207 - Meet the Java Application Server You Already Own – IBM DominoBP207 - Meet the Java Application Server You Already Own – IBM Domino
BP207 - Meet the Java Application Server You Already Own – IBM Domino
 
MozTW Jetpack Workshop: Taipei
MozTW Jetpack Workshop: TaipeiMozTW Jetpack Workshop: Taipei
MozTW Jetpack Workshop: Taipei
 
Jetpack SDK: The new possibility of the extensions on browser
Jetpack SDK: The new possibility of the extensions on browserJetpack SDK: The new possibility of the extensions on browser
Jetpack SDK: The new possibility of the extensions on browser
 
Docker Workshop
Docker WorkshopDocker Workshop
Docker Workshop
 
MozTW Jetpack Workshop: Taichung
MozTW Jetpack Workshop: TaichungMozTW Jetpack Workshop: Taichung
MozTW Jetpack Workshop: Taichung
 
Find your data - use GraphDB capabilities in XPages applications - and beyond
Find your data - use GraphDB capabilities in XPages applications - and beyond	Find your data - use GraphDB capabilities in XPages applications - and beyond
Find your data - use GraphDB capabilities in XPages applications - and beyond
 
Java Class 2
Java Class 2Java Class 2
Java Class 2
 
Overview of the new .NET Core and .NET Platform Standard
Overview of the new .NET Core and .NET Platform StandardOverview of the new .NET Core and .NET Platform Standard
Overview of the new .NET Core and .NET Platform Standard
 
What's New in NetBeans IDE 7.x
What's New in NetBeans IDE 7.xWhat's New in NetBeans IDE 7.x
What's New in NetBeans IDE 7.x
 
Extending NetBeans IDE
Extending NetBeans IDEExtending NetBeans IDE
Extending NetBeans IDE
 

Viewers also liked

From OCaml To Javascript At Skydeck
From OCaml To Javascript At SkydeckFrom OCaml To Javascript At Skydeck
From OCaml To Javascript At SkydeckJake Donham
 
Mozilla Full Text Search
Mozilla Full Text SearchMozilla Full Text Search
Mozilla Full Text Searchguest9513f3
 
A Study of SVG-based Application Development @ OSDC 2010
A Study of SVG-based Application Development @ OSDC 2010A Study of SVG-based Application Development @ OSDC 2010
A Study of SVG-based Application Development @ OSDC 2010Rex Tsai
 
Your First Xulrunner-based application
Your First Xulrunner-based applicationYour First Xulrunner-based application
Your First Xulrunner-based applicationDaniel Glazman
 
ずーるらんなー
ずーるらんなーずーるらんなー
ずーるらんなーRyoma Sasaki
 
Rich Desktop Applications
Rich Desktop ApplicationsRich Desktop Applications
Rich Desktop Applicationsgoldoraf
 

Viewers also liked (7)

From OCaml To Javascript At Skydeck
From OCaml To Javascript At SkydeckFrom OCaml To Javascript At Skydeck
From OCaml To Javascript At Skydeck
 
Mozilla Full Text Search
Mozilla Full Text SearchMozilla Full Text Search
Mozilla Full Text Search
 
A Study of SVG-based Application Development @ OSDC 2010
A Study of SVG-based Application Development @ OSDC 2010A Study of SVG-based Application Development @ OSDC 2010
A Study of SVG-based Application Development @ OSDC 2010
 
Your First Xulrunner-based application
Your First Xulrunner-based applicationYour First Xulrunner-based application
Your First Xulrunner-based application
 
ずーるらんなー
ずーるらんなーずーるらんなー
ずーるらんなー
 
Pcom xpcom
Pcom xpcomPcom xpcom
Pcom xpcom
 
Rich Desktop Applications
Rich Desktop ApplicationsRich Desktop Applications
Rich Desktop Applications
 

Similar to Introduction to XPConnect

Build 2017 - Whats new for Xamarin Devs
Build 2017 - Whats new for Xamarin DevsBuild 2017 - Whats new for Xamarin Devs
Build 2017 - Whats new for Xamarin DevsMike James
 
[DanNotes] XPages - Beyound the Basics
[DanNotes] XPages - Beyound the Basics[DanNotes] XPages - Beyound the Basics
[DanNotes] XPages - Beyound the BasicsUlrich Krause
 
XPages -Beyond the Basics
XPages -Beyond the BasicsXPages -Beyond the Basics
XPages -Beyond the BasicsUlrich Krause
 
FITC - Node.js 101
FITC - Node.js 101FITC - Node.js 101
FITC - Node.js 101Rami Sayar
 
Firefox extension Development
Firefox extension DevelopmentFirefox extension Development
Firefox extension DevelopmentAbhinav Chittora
 
.NET Core: a new .NET Platform
.NET Core: a new .NET Platform.NET Core: a new .NET Platform
.NET Core: a new .NET PlatformAlex Thissen
 
Introduction to vb.net
Introduction to vb.netIntroduction to vb.net
Introduction to vb.netsuraj pandey
 
Intro to Microsoft.NET
Intro to Microsoft.NET Intro to Microsoft.NET
Intro to Microsoft.NET rchakra
 
.Net introduction
.Net introduction.Net introduction
.Net introductionSireesh K
 
Node.js 101 with Rami Sayar
Node.js 101 with Rami SayarNode.js 101 with Rami Sayar
Node.js 101 with Rami SayarFITC
 
Plug yourself in and your app will never be the same (2 hr editon)
Plug yourself in and your app will never be the same (2 hr editon)Plug yourself in and your app will never be the same (2 hr editon)
Plug yourself in and your app will never be the same (2 hr editon)Mikkel Flindt Heisterberg
 
Plug yourself in and your app will never be the same (2 hour edition)
Plug yourself in and your app will never be the same (2 hour edition)Plug yourself in and your app will never be the same (2 hour edition)
Plug yourself in and your app will never be the same (2 hour edition)Mikkel Flindt Heisterberg
 
Moving microsoft .net applications one container at a time
 Moving microsoft .net applications one container at a time  Moving microsoft .net applications one container at a time
Moving microsoft .net applications one container at a time Amazon Web Services
 
ITB_2023_Extend_your_contentbox_apps_with_custom_modules_Javier_Quintero.pdf
ITB_2023_Extend_your_contentbox_apps_with_custom_modules_Javier_Quintero.pdfITB_2023_Extend_your_contentbox_apps_with_custom_modules_Javier_Quintero.pdf
ITB_2023_Extend_your_contentbox_apps_with_custom_modules_Javier_Quintero.pdfOrtus Solutions, Corp
 
AWS Summit Auckland - Moving MS .NET Applications One Container at a Time
AWS Summit Auckland - Moving MS .NET Applications One Container at a TimeAWS Summit Auckland - Moving MS .NET Applications One Container at a Time
AWS Summit Auckland - Moving MS .NET Applications One Container at a TimeAmazon Web Services
 
Extension Library - Viagra for XPages
Extension Library - Viagra for XPagesExtension Library - Viagra for XPages
Extension Library - Viagra for XPagesUlrich Krause
 

Similar to Introduction to XPConnect (20)

Build 2017 - Whats new for Xamarin Devs
Build 2017 - Whats new for Xamarin DevsBuild 2017 - Whats new for Xamarin Devs
Build 2017 - Whats new for Xamarin Devs
 
[DanNotes] XPages - Beyound the Basics
[DanNotes] XPages - Beyound the Basics[DanNotes] XPages - Beyound the Basics
[DanNotes] XPages - Beyound the Basics
 
XPages -Beyond the Basics
XPages -Beyond the BasicsXPages -Beyond the Basics
XPages -Beyond the Basics
 
Firefox (in)Security
Firefox (in)SecurityFirefox (in)Security
Firefox (in)Security
 
FITC - Node.js 101
FITC - Node.js 101FITC - Node.js 101
FITC - Node.js 101
 
Firefox extension Development
Firefox extension DevelopmentFirefox extension Development
Firefox extension Development
 
.NET Core: a new .NET Platform
.NET Core: a new .NET Platform.NET Core: a new .NET Platform
.NET Core: a new .NET Platform
 
B2g
B2gB2g
B2g
 
Introduction to vb.net
Introduction to vb.netIntroduction to vb.net
Introduction to vb.net
 
Intro to Microsoft.NET
Intro to Microsoft.NET Intro to Microsoft.NET
Intro to Microsoft.NET
 
.Net introduction
.Net introduction.Net introduction
.Net introduction
 
Node.js 101 with Rami Sayar
Node.js 101 with Rami SayarNode.js 101 with Rami Sayar
Node.js 101 with Rami Sayar
 
Kushal
KushalKushal
Kushal
 
Plug yourself in and your app will never be the same (2 hr editon)
Plug yourself in and your app will never be the same (2 hr editon)Plug yourself in and your app will never be the same (2 hr editon)
Plug yourself in and your app will never be the same (2 hr editon)
 
Plug yourself in and your app will never be the same (2 hour edition)
Plug yourself in and your app will never be the same (2 hour edition)Plug yourself in and your app will never be the same (2 hour edition)
Plug yourself in and your app will never be the same (2 hour edition)
 
Getting started with add ons
Getting started with add onsGetting started with add ons
Getting started with add ons
 
Moving microsoft .net applications one container at a time
 Moving microsoft .net applications one container at a time  Moving microsoft .net applications one container at a time
Moving microsoft .net applications one container at a time
 
ITB_2023_Extend_your_contentbox_apps_with_custom_modules_Javier_Quintero.pdf
ITB_2023_Extend_your_contentbox_apps_with_custom_modules_Javier_Quintero.pdfITB_2023_Extend_your_contentbox_apps_with_custom_modules_Javier_Quintero.pdf
ITB_2023_Extend_your_contentbox_apps_with_custom_modules_Javier_Quintero.pdf
 
AWS Summit Auckland - Moving MS .NET Applications One Container at a Time
AWS Summit Auckland - Moving MS .NET Applications One Container at a TimeAWS Summit Auckland - Moving MS .NET Applications One Container at a Time
AWS Summit Auckland - Moving MS .NET Applications One Container at a Time
 
Extension Library - Viagra for XPages
Extension Library - Viagra for XPagesExtension Library - Viagra for XPages
Extension Library - Viagra for XPages
 

More from Anant Narayanan

Enterprise Scale Knowledge Graphs
Enterprise Scale Knowledge GraphsEnterprise Scale Knowledge Graphs
Enterprise Scale Knowledge GraphsAnant Narayanan
 
Building an Intelligent Assistant
Building an Intelligent AssistantBuilding an Intelligent Assistant
Building an Intelligent AssistantAnant Narayanan
 
WebRTC: A Practical Introduction
WebRTC: A Practical IntroductionWebRTC: A Practical Introduction
WebRTC: A Practical IntroductionAnant Narayanan
 
Message Passing vs. Data Synchronization
Message Passing vs. Data SynchronizationMessage Passing vs. Data Synchronization
Message Passing vs. Data SynchronizationAnant Narayanan
 
Firebase: Tales from the Trenches
Firebase: Tales from the TrenchesFirebase: Tales from the Trenches
Firebase: Tales from the TrenchesAnant Narayanan
 
Error Handling in WebRTC
Error Handling in WebRTCError Handling in WebRTC
Error Handling in WebRTCAnant Narayanan
 
WebRTC: User Security & Privacy
WebRTC: User Security & PrivacyWebRTC: User Security & Privacy
WebRTC: User Security & PrivacyAnant Narayanan
 
Firefox Architecture Overview
Firefox Architecture OverviewFirefox Architecture Overview
Firefox Architecture OverviewAnant Narayanan
 
Next Generation Browser Add-Ons
Next Generation Browser Add-OnsNext Generation Browser Add-Ons
Next Generation Browser Add-OnsAnant Narayanan
 
An Overview of Distributed Debugging
An Overview of Distributed DebuggingAn Overview of Distributed Debugging
An Overview of Distributed DebuggingAnant Narayanan
 
A Brief Incursion into Botnet Detection
A Brief Incursion into Botnet DetectionA Brief Incursion into Botnet Detection
A Brief Incursion into Botnet DetectionAnant Narayanan
 
Mozilla Weave: Integrating Services into the Browser
Mozilla Weave: Integrating Services into the BrowserMozilla Weave: Integrating Services into the Browser
Mozilla Weave: Integrating Services into the BrowserAnant Narayanan
 
Distributed File Systems: An Overview
Distributed File Systems: An OverviewDistributed File Systems: An Overview
Distributed File Systems: An OverviewAnant Narayanan
 
Innovating with Mozilla Labs
Innovating with Mozilla LabsInnovating with Mozilla Labs
Innovating with Mozilla LabsAnant Narayanan
 
Glendix: The Why and the How
Glendix: The Why and the HowGlendix: The Why and the How
Glendix: The Why and the HowAnant Narayanan
 

More from Anant Narayanan (20)

Enterprise Scale Knowledge Graphs
Enterprise Scale Knowledge GraphsEnterprise Scale Knowledge Graphs
Enterprise Scale Knowledge Graphs
 
Building an Intelligent Assistant
Building an Intelligent AssistantBuilding an Intelligent Assistant
Building an Intelligent Assistant
 
WebRTC: A Practical Introduction
WebRTC: A Practical IntroductionWebRTC: A Practical Introduction
WebRTC: A Practical Introduction
 
Message Passing vs. Data Synchronization
Message Passing vs. Data SynchronizationMessage Passing vs. Data Synchronization
Message Passing vs. Data Synchronization
 
Firebase: Tales from the Trenches
Firebase: Tales from the TrenchesFirebase: Tales from the Trenches
Firebase: Tales from the Trenches
 
WebRTC: An Overview
WebRTC: An OverviewWebRTC: An Overview
WebRTC: An Overview
 
Error Handling in WebRTC
Error Handling in WebRTCError Handling in WebRTC
Error Handling in WebRTC
 
WebRTC Demystified
WebRTC DemystifiedWebRTC Demystified
WebRTC Demystified
 
WebRTC: User Security & Privacy
WebRTC: User Security & PrivacyWebRTC: User Security & Privacy
WebRTC: User Security & Privacy
 
Firefox Architecture Overview
Firefox Architecture OverviewFirefox Architecture Overview
Firefox Architecture Overview
 
πP
πPπP
πP
 
Next Generation Browser Add-Ons
Next Generation Browser Add-OnsNext Generation Browser Add-Ons
Next Generation Browser Add-Ons
 
An Overview of Distributed Debugging
An Overview of Distributed DebuggingAn Overview of Distributed Debugging
An Overview of Distributed Debugging
 
A Brief Incursion into Botnet Detection
A Brief Incursion into Botnet DetectionA Brief Incursion into Botnet Detection
A Brief Incursion into Botnet Detection
 
Mozilla Weave: Integrating Services into the Browser
Mozilla Weave: Integrating Services into the BrowserMozilla Weave: Integrating Services into the Browser
Mozilla Weave: Integrating Services into the Browser
 
about:labs
about:labsabout:labs
about:labs
 
Distributed File Systems: An Overview
Distributed File Systems: An OverviewDistributed File Systems: An Overview
Distributed File Systems: An Overview
 
Innovating with Mozilla Labs
Innovating with Mozilla LabsInnovating with Mozilla Labs
Innovating with Mozilla Labs
 
Glendix: The Why and the How
Glendix: The Why and the HowGlendix: The Why and the How
Glendix: The Why and the How
 
Mozilla Prism
Mozilla PrismMozilla Prism
Mozilla Prism
 

Recently uploaded

Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsHyundai Motor Group
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraDeakin University
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Hyundai Motor Group
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetHyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetEnjoy Anytime
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 

Recently uploaded (20)

Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
The transition to renewables in India.pdf
The transition to renewables in India.pdfThe transition to renewables in India.pdf
The transition to renewables in India.pdf
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptxVulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetHyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 

Introduction to XPConnect

  • 1. An Introduction to XPConnect Writing Extensions in Pure JavaScript Anant Narayanan Malaviya National Institute of Technology FOSS.IN 2007
  • 2. Why is Firefox successful? Apart from the fact that it is Open Source EXTENSIONS No other browser provides such a feature-rich extensible development environment
  • 3. Community • There is a thriving community behind extension development • There are extensions to help you do every imaginable task with web pages (Firefox) and email (Thunderbird) • Powered by the Mozilla platform
  • 4. Contribution • Writing extensions is one of the easiest and most useful ways of contributing to Mozilla • You just have to scratch your own itch, or come up with an idea for your extension • We’ll look into the technical aspect of developing your extension in this presentation
  • 5. Overview • XPCOM & why it is useful • XPConnect & why it is useful • How XPConnect packs punch into Javascript • How you can develop your very own extension in pure Javascript in a matter of hours (You need to know basic JavaScript)
  • 6. XPCOM • Cross Platform Component Object Model • Provides a framework for writing crossplatform, modular software • Provides the abstraction required to write applications that will run on the Mozilla platform across the variety of operating systems that Mozilla supports
  • 7. Components • Core: Type System, Data Structures, Streams • UI: Clipboard, Drag-and-Drop, XUL • Application: Preferences, Profiles, WM • Network: Channels, Protocol Handlers • DOM, Mail and several others • You can even create you own!
  • 8. Interface Description • Language neutral way to specify interfaces to the XPCOM components • The Interface Definition Language used by Mozilla (IDL) is slightly different than the conventional ones • XPCOM initially meant to be used in C++
  • 9. XPConnect • Allows scriptability of XPCOM components • Simple interoperation between XPCOM and languages like Javascript, Perl and Python • Allows transparent access and manipulation of XPCOM objects via the XPIDL definitions
  • 10. Javascript & XPConnect • Javascript run in the Mozilla environment will have access to all XPCOM components • Caveat: Only those components that have interfaces defined in XPIDL will be available • Developing extensions is breeze, assuming you already know Javascript • JS is considerably easier than C++!
  • 11. Development Tools • Best way to work with Javascript is Firefox • Plugins that you will find helpful: • Console • Extension Developer • Firebug • jsLib • XPCOMViewer 2
  • 13. Skeleton of an Extension • Every extension is made up of a set of base files and directory • This hierarchy is zipped to create your .xpi re-distributable extension
  • 14. Visit the Wizard • Don’t waste time in creating these base files and directories • Get your skeleton at • http://ted.mielczarek.org/code/mozilla/ extensionwiz/ • Will generate a zip file containing the base extension code
  • 15. The Code • All the JavaScript code goes into the components/ directory • Put all your other resources - HTML, Images et. al. in content/ • This content will be available as chrome://<name>/content/
  • 16. Power Javascript • Think of Javascript as a language • All XPCOM components are available as regular Javascript OBJECTS
  • 17. The Lifecycle of an XPConnect Object • Every component is uniquely identified by a Contract ID • Usually something like: • • @mozilla.org/network/simple-uri;1 @mozilla.org/consoleservice;1
  • 18. Instantiating a Component • Usually, you will just call the getService method on the component class passing an interface along • Components.classes[“@mozilla.org/ moz/jssubscript-loader;1]. getService(Components.interfaces. mozIJSSubScriptLoader);
  • 20. Logging function jsLog(msg, error) { var consoleService = Components.classes ["@mozilla.org/consoleservice;1"].getService (Components.interfaces.nsIConsoleService); if (error) { consoleService.logStringError(msg); } else { consoleService.logStringMessage(msg); } }
  • 21. Loading other JS files into a given Object function jsImport(obj, fName) { var loader = Components.classes ["@mozilla.org/moz/jssubscript-loader; 1"].getService (Components.interfaces.mozIJSSubScriptLoader); loader.loadSubScript ("file://"+__LOCATION__.parent.path+"/"+fName, obj); }
  • 22. Some Theory • Mozilla introduces the Components object into the Global JS Namespace • Components.classes • Components.interfaces • Components.results • etc...
  • 23. Preventing Clashes • Since everything Javascript is in the global namespace... • ... you need to protect your code by wrapping them suitably into objects • Remember, multiple extensions may run on a single Mozilla instance, and they all share the namespace
  • 24. Resources • Use the XPCOMViewer for offline ready documentation on the various scriptable XPCOM components available to you • eg: Ever felt the need for sockets in Javascript? @mozilla.org/network/sockettransport-service;1
  • 25. Resources (Contd.) • A lot of repetitive tasks and frequently used components in Javascript are available as friendly JS objects via jsLib • Disadvantage: If your code uses jsLib, it becomes a pre-requisite for your extension • Mozilla normally doesn’t allow dependencies between extensions, but it’s Ok in this case
  • 26. Resources (Contd.) • Run XPConnect powered code in Firebug to get instantaneous results (kind of like working in the python interpreter) • Firebug also will give you helpful error messages when something goes wrong. Use the Logger to segregate different types of messages and view them in Console2
  • 27. Resources (Contd.) • Visit XULPlanet for comprehensive online documentation on XPCOM scriptable components: • http://www.xulplanet.com/references/ xpcomref/ • Every serious JS programmer must visit: • http://javascript.crockford.com/
  • 28. Questions? Thank You! Feel free to contact me: <anant@kix.in> http://www.kix.in/ The Web9 Project implements a new protocol handler entirely in Javascript: http://code.kix.in/projects/web9