Mozilla Technology Introduction
Mozilla Technology Introduction Part A: Web sites with Gecko { For Web Authoring { Req.: HTML/CSS/JavaScript NTU CSIE and csie.org Part B: Extending Mozilla: XUL-World! Mozilla Localization: Traditional Chinese { For Mozilla extensions developer Hung-Te Lin 林弘 德 { Req.: XML*/JavaScript Part C: Hack the source icos’03 { For source level programmers { Req.: Programming common sense
1 2
Outline
Part A: Web sites with Gecko Websites INCOMPATIBLE! { Presentational Error
{ Functional Error For Web Authoring { Misc Error Req.: HTML/CSS/JavaScript Writing Good Pages
3 4
1 Pages INCOMPATIBLE!!!!! Presentational Error: Plugins
Presentational Error Plugin presentational error
{ CSS rendering { Flash not transparent no solution until Macromedia fixed it Functional Error { Java cannot display ODBC like Chinese { JavaScript error Incorrect version, or many reasons Misc Error { ActiveX Controls Currently not available { Content-Type Error { Windows Media not playing Must follow Mozilla’s embed rule
5 6
Presentation Error: HTML Tags Presentational Error: CSS!!
IE-specific tags like
7 8
2 Functional Error: Functional Error Common JavaScript Error
Use “JavaScript Console” to see if any error occurs, and click VB Script? will bring you to the location of source The most common error is “Cannot find object: XXXX” which { No Solution is due to IE’s syntax. We DO have innerHTML but you must get the object first JavaScript Error? Mozilla has no ‘all’ attribute { You may use all other ways to find elements, actually even { Mostly only small piece of code needs to document.NAME is better. See also: document.getElementById, be modified document.getElementByTagName. There is no “children”. We have childNodes { Fix it if you can access the page, or ask Cannot submit Forms { IE can sometimes just use object’s name to access it. Mozilla is the site maintainer to do so. more restricted. Only forms can use this format for compatible with old pages { Or, Save the page and change it locally
9 10
Functional Error: JavaScript Error -- Sample Misc Error: Content-Type
http://www.kingstone.com.tw/, the search is not functional. Mozilla trusts HTTP Header “Content-Type”, while IE trusts on JS Console says “input_form is not defined”, line 122 content preload. Click to view: Situation: downloaded some file and Mozilla treated as plain/text { document.search_form.p19.value = ""; if (input_form.p.value=="") { Solution: alert("請至少輸入一個查詢條件!") } { Update remote magic { Submit is O.K now, but this page has more bugs { Use .htaccess { // ------Check and fixup incoming data block AddType application/x-msdos-program .xpi if(!document.body.children.incoming.children.properties) { document.all.incoming.innerHTML = "
11 12
3 The Standards Writing Good Pages
What JavaScripts can we use in Use CSS, because you can avoid some Gecko? useless HTML Tables, JavaScript and images. { ECMA262-Edition 3 Try to make your page available to Gecko, { DOM IE, and text-based like lynx { Netscape JavaScript You may choose the best presentation http://www.xulplanet.com/references/elemref/ target, like Gecko and IE JavaScript should run on most browsers
13 14
Q & A Part B: Extending Mozilla: Websites INCOMPATIBLE! XUL-World! { Presentational Error
{ Functional Error { Misc Error For Mozilla extensions developer Writing Good Pages Req.: XML*/JavaScript
15 16
4 Outline XULPlanet
XULPlanet XULPlanet: http://www.xulplanet.com/ XUL: XML, JavaScript, XBL, XPCOM A good tutorial and source for XUL
{ Writing XUL Programs
{ Mozilla packages and Layout userChrome and userContent XPInstall, Localization, Themes Sidebar and Sherlock
17 18
XUL: XML and JavaScript XUL: Packaging
XUL: pronounced as “zool”, like “cool” Chrome: UI elements in application XML User-interface Language { Content: Windows and Scripts Case sensitive { Skin: Style sheets, images Usually split into: { Locale: Locale and resource { XML/RDF for layout and elements { CSS for style { chrome://
19 20
5 XUL: Manifest XUL: XUL for a simple window
To specify package location css"?> Sample:
XUL: Menus XUL: Add Events! (DOM2)
23 24
6 XUL: XBL, XUL: Style it eXtensible Bindings Language
Declaring behavior of XUL widgets. HTML styles Limitation of XUL: {
{ { Use HTML ‘class=‘ ‘id=‘ and other style
XPCOM: Cross-Platform XUL/XBL: Making OO widgets! Component Object Model
Limits of XUL JavaScripts: Attribute Inheritance { You cannot access low level APIs XBL Bindings: Solution: { Write native code to do low level API { Content { Provide an interface for JavaScript to call Appearance of widget { Like most OO Models with interface/implementation { Property/Field Using: (ActiveX way) Field: Generated variables like random { Get a component Property: Get/Set { Get the part that implements interface you want { Call the function { Method and event descriptions var aFile = Components.classes["@mozilla.org/file/local;1"].createInstance(); Action of some event if (!aFile) return false; var LocalFile=aFile.QueryInterface(Components.interfaces.nsILocalFile); 27 28 if (!aLocalFile) return false;
7 Mozilla Themes (Skins) and Locales Why’re Mozilla themes so hard?
Change chrome files! The most flexible than others Change Skin/Locale: switch specified package in manifest file. Hardest than others Locales: UTF8 defined in DTD files { Most themes only change toolbar { Use: { Declare: You have to style all CSS DTD for XUL, and properties for scripts All of these applies to langpacks { In XUL:
29 30
XPInstall Mozilla Package and Layout
Cross Platform Installation mozilla/bin/ { chrome/ the chrome (XUL) Package your work and make a en-US.jar, en-win/mac/unix.jar, US.jar: locale install.js then name it “.xpi” comm.jar, messenger.jar: content modern.jar, classic.jar: skin Many ways to install it, like Installed-chrome.txt text index chrome.rdf: registered chrome { Javascript: var xpi = {}; xpi[caption]= url; { components/ XPCOM native InstallTrigger.install(xpi); { defaults/ default settings { InstallTrigger.startSoftwareUpdate(url); { plugins/ Plug-ins { res/ resources like HTML { Just Open XPI! { searchplugins/ Sherlock
31 32
8 Profile Layout ~/chrome/userChrome|Content
[personal folder]/[.]mozilla/ userChrome.css and userContent.css { registry.dat Profile Index { Customize your favorite style { profiles/PROFILE_NAME userChrome sample: XXXXXXXX.slt { Change the Mozilla Status Bar small font { chrome/ User chrome { * { { XUL.mfl XUL cache font-size: 14pt !important; { pref.js, user.js pref (now about:config) } { bookmarks.html { …… userContent sample: { Mail/ { MSDN wrong text format
33 34
Sidebar: Just As Easy As XUL Sherlock
Sidebar is a small area Easy to be modified You may use both HTML and XUL Look at searchplugins/* javascript:window.sidebar.addPanel( Each file for .gif logo and .src file caption, URL, customizeURL); Javascript: http://developer.netscape.com/docs/ window.sidebar.addSearchEngine( manuals/browser/sidebar/ srcURL, gifURL, Caption, Category);
35 36
9 Sherlock: Sample Q&A
http://www.google.com/search?q=blah&hl=zh-TW&num=20&sourceid=mozilla-search&start=0 XULPlanet # Mozilla/Google plug-in by amitp@google.com
37 38
Outline
Part C: Hack the source Getting the source Build the lizard Where should I get started? For source level programmers Porting: NSPR and XPToolkit Req.: Programming common sense
39 40
10 Getting the source Build the lizard
You can download the tarball http://www.mozilla.org/build/ { Currently Firebird has only source tarballs for releases, not nightly CVS: :pserver:anonymous@cvs-mirror.mozilla.org:/cvsroot Browse online at lxr.mozilla.org
41 42
Where should I get started? Porting
Simple APPs: Just use XUL! NSPR: non-GUI OS facilities When you need Native support: { Threading { Look at XPCOM { File and network I/O { XPConnect: binding of XPCOM and JS { Timing { Memory allocation When you want to write plugins: { Shared library linking { http://www.mozilla.org/projects/plugins/ XPToolkit(XPFE or Toolkit) I want to use Gecko Engine! { The key to XUL { http://www.mozilla.org/projects/embedding/ { http://lxr.mozilla.org/seamonkey/source/widget/
43 44
11 Q&A
Getting the source Build the lizard Where should I get started? Porting: NSPR and XPToolkit
Thanks all!
45
12