50
Jetpack SDK: The New possibility of the extensions on browser 尤孝庭 / 笨笨的小 B Hsiao-Ting Yu / Littlebtc

Jetpack SDK: The new possibility of the extensions on browser

Embed Size (px)

Citation preview

Page 1: Jetpack SDK: The new possibility of the extensions on browser

Jetpack SDK:The New possibility of the extensions on browser

尤孝庭 / 笨笨的小BHsiao-Ting Yu / Littlebtc

Page 2: Jetpack SDK: The new possibility of the extensions on browser

I'm back again!COSCUP 2009 Reviewhttp://www.youtube.com/watch?v=f_1cLDVIom8

Page 3: Jetpack SDK: The new possibility of the extensions on browser

Who I Am

• 尤孝庭 (Hsiao-Ting Yu)

• Undergraduate in NTUEE

• One of the Jetpack Ambassadors, volunteers to spread addons development tips on Mozilla platform

• Developer of NicoFox and Voyage

• http://plurk.com/littlebtc

• or search 「笨笨的小B」, 「littlebtc」little-b-t-c

Page 4: Jetpack SDK: The new possibility of the extensions on browser

Overview

• 快樂地擴充你的瀏覽器!Extend your Firefox happily!

• 不打高空、不放嘴砲、實戰重視• Not just talking about it, do something about it

Page 5: Jetpack SDK: The new possibility of the extensions on browser

Not so related to HTML5

Page 6: Jetpack SDK: The new possibility of the extensions on browser

...But related to the browser.

Page 7: Jetpack SDK: The new possibility of the extensions on browser

Jetpack SDK:A brand new way to develop extension on Mozilla platform (e.g. Firefox).

Page 8: Jetpack SDK: The new possibility of the extensions on browser

Old Jetpack?

Deprecated and labeled as a prototype

Page 9: Jetpack SDK: The new possibility of the extensions on browser

Writing extension in HTML5...

• Google Chrome

• Safari

• Jetpack Prototype

• So what's new in Jetpack SDK?????

Page 10: Jetpack SDK: The new possibility of the extensions on browser

It's ALL ABOUT OPEN!

Page 11: Jetpack SDK: The new possibility of the extensions on browser

Open API Purposal

Page 12: Jetpack SDK: The new possibility of the extensions on browser

Open Web Standard

JavaScript

HTML5

XUL

CSS3

Page 13: Jetpack SDK: The new possibility of the extensions on browser

Open development & deployment environment

Page 14: Jetpack SDK: The new possibility of the extensions on browser

So how to develop?

Page 15: Jetpack SDK: The new possibility of the extensions on browser

Using Jetpack SDK

• A toolkit based on Python

• Able to test Jetpack SDK extensions

• Able to pack the extension into XPI file

• But ... command Line IT'S TOO HARD...

Page 16: Jetpack SDK: The new possibility of the extensions on browser

Simpler way...?

• https://builder.mozillalabs.com/

Page 17: Jetpack SDK: The new possibility of the extensions on browser

All-in-one development IDE

Page 18: Jetpack SDK: The new possibility of the extensions on browser

Jetpack SDK Basics

Page 19: Jetpack SDK: The new possibility of the extensions on browser

Coding on Jetpack SDK

• Package-based

• Reusable code, document, data

• JavaScript Code

• CommonJS Module Specification

• Modular and simple to maintain

• Every module works as a "sandbox"(only exports objects will be public)

• Limited accesses to XPCOM

Page 20: Jetpack SDK: The new possibility of the extensions on browser

Default packages of Jetpack SDK

Page 21: Jetpack SDK: The new possibility of the extensions on browser

Package file structure

• manifest.json - Manifest

• lib

• main.js - Main program entry

• xxx.js - Module

• data

• abc.htm - Static data

Page 22: Jetpack SDK: The new possibility of the extensions on browser

NEVER

NEVER

NEVERLive Demo!!

Page 23: Jetpack SDK: The new possibility of the extensions on browser

Example 1:"Push to Plurk"

tabs widget

Page 24: Jetpack SDK: The new possibility of the extensions on browser

Purpose

• Share current viewing page to Plurk, a microblogging service

• In very simple way: Open a tab with URL containing specific parameters

Page 25: Jetpack SDK: The new possibility of the extensions on browser

API needed

• widget:

• Create a space for extension icon / small UI

• Will be integrated with Firefox 4 UI

• tabs:

• Operate tabs on browser

Page 26: Jetpack SDK: The new possibility of the extensions on browser

main.js: 16 Lines!

Page 27: Jetpack SDK: The new possibility of the extensions on browser

Try it now!http://dl.dropbox.com/u/8093476/COSCUP10/plurk-pusher.xpi

Page 28: Jetpack SDK: The new possibility of the extensions on browser

Example 2:"Say sorry" pt 2 feat. littlebtc

page-worker

context-menu

Page 29: Jetpack SDK: The new possibility of the extensions on browser

Purpose

• A fun extension to "say sorry"

• doggy Lots of people occupied the bandwidth, the network on COSCUP sucks!

• jack @doggy I'm sorry, it's my fault!

• 這是一個對號入座的時代• 所以我們需要時常說「對不起」

• Re-do Bob's work on Jetpack SDK

Page 30: Jetpack SDK: The new possibility of the extensions on browser

API needed

• page-worker:

• Create a invisible page, and work with its DOM object

• "Visible page" - Panels, are expected in future release.

• context-menu:

• Add items to context menu.

Page 31: Jetpack SDK: The new possibility of the extensions on browser

HTML5Eventually!!!! 總算!

audio

sorry.htm

Page 32: Jetpack SDK: The new possibility of the extensions on browser

put it to data or...

Page 33: Jetpack SDK: The new possibility of the extensions on browser

main.js: 25 Lines!

Page 34: Jetpack SDK: The new possibility of the extensions on browser

馬上玩玩看!http://dl.dropbox.com/u/8093476/COSCUP10/sorry.xpi

Page 35: Jetpack SDK: The new possibility of the extensions on browser

Example 3:"Plurk unread tracker"

request timer ?????simple-storage

Page 36: Jetpack SDK: The new possibility of the extensions on browser

Purpose

• Get unread counts on Plurk and display on the widget

• We don't have panel, so can't do a complex UI like microblogging viewer

• When writing the extension...

• (But there is no good way to make preference UI in Jetpack SDK now)

Plurk API needs username/passwordeven if the user had logged in!!!!!!

Page 37: Jetpack SDK: The new possibility of the extensions on browser

API Required

• widget

• simple-storage: Store simple object

• request:Make request to HTTP server with XML, JSON, or plain text return

• timer:Timer function like setTimeout()、setInterval()

• Self-made module:Some prompt dialog

• Provided by XPCOM API in Firefox

Page 38: Jetpack SDK: The new possibility of the extensions on browser

Self-made module

• Using nsIPromptService XPCOM API, display dialog for username / password input and alert()-like dialog. 20 lines

Page 39: Jetpack SDK: The new possibility of the extensions on browser

Actual code on main.js

• 73 lines

• Doing lots of jobs:

• Handle very simple login/logout

• Communicate with Plurk API

Page 40: Jetpack SDK: The new possibility of the extensions on browser

Result (unstable!)

Page 41: Jetpack SDK: The new possibility of the extensions on browser

Package and deploy

Page 42: Jetpack SDK: The new possibility of the extensions on browser

or cfx xpi

Page 43: Jetpack SDK: The new possibility of the extensions on browser

Upload your workon Mozilla Addons

Page 44: Jetpack SDK: The new possibility of the extensions on browser

Advantages and Possibility

Page 45: Jetpack SDK: The new possibility of the extensions on browser

Install?

Compatibility?

Restart browser?

No difference from any otherextension on Firefox

Not your job!

Not Required onFx4.0/Gecko2!

Solve some classical problem for extensionon Mozilla platform

Page 46: Jetpack SDK: The new possibility of the extensions on browser

More Open Development

• Everyone can share their package as library on Addon Builder

• Code can be widely reused and remixed into new extensions!

• Good for open source development ecosystem

A Library

A Extension

B Library

B Extension C Extension

Page 47: Jetpack SDK: The new possibility of the extensions on browser

Future

Page 48: Jetpack SDK: The new possibility of the extensions on browser

API parts

• Panel API

• PageMods API (UserScript 支援)

• Sidebar API

• Notification API

• E10S (multiprocess) support

• Jetpack SDK team are working hard on them...

Page 49: Jetpack SDK: The new possibility of the extensions on browser

Non-API Parts

• Firefox 4

• New addon widget UI

• Auto and silent update for Jetpack extensions

• Mozilla Addons Website

• Addon Marketplace

Page 50: Jetpack SDK: The new possibility of the extensions on browser

https://jetpack.mozillalabs.com/