Preface

A technology is only a tool.

No matter how creative its design, innovative its approach, or impressive its performance, a technology is still defined (according to Webster) as “a manner of accomplishing a task.”

The successful adoption of a technology into the community of those who rely on it to conduct business is a complicated journey—one that starts with the unyielding work of designers who see something that others don’t. But without the efforts of those who believe in its value and are willing to promote (evangelize), to educate, and to adapt the tool to the needs of the community, the technology remains little more than a subject of academic interest.

The Mozilla component framework, and its implementation in a form more commonly known as the Firefox browser, represents one technology that aspires to be a useful tool for the community that relies on the Internet to communicate, learn, and express (we often coldly refer to these people as “users”).

The evangelists of the Mozilla framework promote its technology as a premier contribution of the open source community, a team of developers whose mission is to develop the best possible software for browsing the Internet (Firefox) and exchanging messages (Thunderbird). This community is also strongly committed to demonstrating how applying the most current standards in electronic document rendition and data exchange can make possible new techniques that improve the richness of expression and the ability to move those rich ideas throughout the community.

But to evangelize is not enough. I hope this text will play a modest role in helping to educate application developers in how to use Mozilla technology—not for the sake of using a different technical platform, but to demonstrate what is possible when the collective knowledge of the international standards community finds its voice in the marketplace. With such a diverse and creative pool of contributors, new Internet applications are possible that feature improvements in responsiveness, greater flexibility of interface design, and more expressive graphics.

The goal of this book has little to do with searching for a victor in the browser wars. Rather, this book is intended to discuss, through example, the application of international standards in helping to launch the “next generation” of Internet applications. The Mozilla technology is one of the best technologies, and one of the best tools available, to make such a discussion possible.

Intended Audience

This book is intended for designers and developers charged with delivering innovative standards-based Internet applications. This includes those responsible for server applications or for the development of Internet-enabled desktop applications.

This book is designed to cover many of the practical issues related to the nuances of XML User Interface (XUL)-based design. Rather than trying to be the authoritative resource on browser internals, it focuses on the nuts and bolts of using the existing tools to take advantage of the Firefox framework.

The development setting for this audience may involve any number of tools—the Personal Hypertext Processor (PHP) or Java on the server side, and the Firefox browser engine on the client side. The dominant language for the client platform is most likely to be JavaScript, and developers should have a good understanding of HTML and, hopefully, some exposure to eXtensible Markup Language (XML)-based documents such as XHTML.

Members of the target audience could be developers of commercial applications, extensions to the Firefox browser, or corporate applications. Some knowledge of JavaScript will be very helpful, although most developers can pick up the language quickly enough to learn it on the fly.

Most importantly, this book is targeted to those developers who are interested in (and maybe committed to) using this technology to see what the next generation of Internet applications will look like.

Why Buy This Book?

There is no doubt that online documentation, Wikis, and newsgroups provide the lion’s share of information to developers using technologies such as XUL (pronounced “zool”). A precious element of constant availability characterizes the webcentric support community—you need not carry around a 500-page book to guarantee access to important information.

But web access to online documentation can go only so far. Online documents are best designed for quick searches and linked references that point to pages that, generally speaking, are read for only a few minutes at a time. Such spontaneous access works well for reference lookups or quick reminders, but thoroughly covering a topic from start to finish (as in the case of building XUL applications) requires a more comprehensive approach that involves text, illustrations, and code.

The Web is also at a crossroads. Browser technologies are now stabilizing to the point where security and reliability are a given. Growing use of web standards to encode page content is also helping to improve the consistent look of content across rendering engines.

The time is now ripe for the browser community to explore the next generation of web standards, and to initiate a wider range of support for new document models to render graphics, deliver music, and audit user input without needlessly imposing simple tasks on tomorrow’s web servers.

This book doesn’t serve as just a reference source; it is a practical, hands-on introduction to some of these evolving standards that allow developers to combine creativity with technology. Programming Firefox is less of a how-to book and more of a what-if exploration that encourages developers to push the envelope of the Internet experience.

Conventions Used in This Book

The following conventions are used throughout this book:

Constant width

Used in code segments, or in terms and phrases in the text that represent code entries.

Constant width bold

Code that is being referenced in the text.

Constant width italic

Used in code segments meant to be customized by the reader.

Italic

Used to introduce new technical terms, to emphasize certain terms, and to refer to filenames or pathnames.

Menu items

Used with arrows to illustrate a menu hierarchy, such as File → Open.

Tip

This icon signifies a tip, suggestion, or general note.

Warning

This icon signifies a warning or caution.

Terms and Usage

This book discusses applications of a software engine consisting of a collection of cross-platform libraries written in C++. This collection of libraries was first wrapped together as a browser named Mozilla.

Technically, I should call this book’s main topic the Mozilla Cross-Platform Component Model (XPCOM) framework. Not all XPCOM libraries are used in the Firefox browser, however, so I use the term Firefox framework—those libraries that are distributed as part of the browser-only components supported by the Mozilla Foundation.

A Tag or an Element?

This book is about interface elements, document elements, and technologies, each having its own terminology. Several terms are used repeatedly throughout this book and should be clarified here:

Widget

The actual physical representation of an interface element. The term widget is most often used when discussing the physical appearance of a document. Widgets include buttons, listboxes, and checkboxes.

Element

The basic unit that composes XHTML documents. Tables and divs are examples of elements.

Tag

The XML encoding of a document element. Examples of tags are <table>, <div>, and <button>.

How This Book Is Organized

This book comprises a number of chapters designed to demonstrate the combination of the XUL interface and emerging Internet standards.

Developing a working application is one of the best ways to illustrate how to use a new feature. Chapter 4 through Chapter 7 of this book focus on an embedded annotation tool for citing and storing references to visited web sites. This project (dubbed NewsSearch) is designed to demonstrate a progression of tasks and feature enhancements for a real-world project. When added to the balance of the text, each chapter can stand on its own to demonstrate a particular topic:

Chapter 1

Provides an overview of Firefox technology and its history, and a review of the technologies that are the focus of this book.

Chapter 2

Gives an introduction to the graphical elements that compose a XUL application.

Chapter 3

Explains how to use the tools for development, including the JavaScript debugger and Document Object Model (DOM) inspector. This chapter is a good foundation for understanding the Firefox development tools and the process used to design and build applications.

Chapter 4

Sketches out the first NewsSearch application—understanding the chrome URL and how Firefox applications can communicate with a server using the asynchronous HTTP Request protocol.

Chapter 5

Covers managing an application with multiple content areas, and moving content selections between windows. This section deals somewhat with accessing DOM data structures, and dealing with the sometimes thorny issue of managing multiple frames of content.

Chapter 6

Describes connecting interface elements to the server-based Resource Description Framework (RDF). Here you’ll find a good introduction to RDF and how the Firefox interface renders RDF content with trees, as well as how a JavaScript program can manipulate RDF content.

Chapter 7

Discusses altering document content and appearance using the DOM. This is a more extensive discussion than that in Chapter 5, including steps to insert content and dynamically modify display styles.

Chapter 8

Covers displaying graphics-rich documents using the Scalable Vector Graphics (SVG) standard, and painting document regions using the drawing features of the HTML Canvas element.

Chapter 9

Explains how to make the most of the Firefox framework by extending the functionality of existing graphics elements as well as the Firefox interface.

Chapter 10

Discusses implementing the next-generation Forms interface through XForms, a technology designed to increase validation features while reducing the overhead on server logic.

Chapter 11

Outlines developing for different languages and different deployment options.

Chapter 12

Gives an overview of the XUL widgets.

XUL Widgets: Attributes, Properties, and Methods

Provides a list of attribute names used within the Firefox framework.

Demonstration Platforms

Throughout this book are numerous screenshots of example sessions using code samples. Many of the images are from an OS X implementation; I’ve also included several images from the Windows XP platform. There is no (intentional) emphasis on one operating system’s implementation over another—only a reasonable effort to show a good mix of cross-platform support.

Using Code Examples

This book is here to help you get your job done. In general, you may use the code in this book in your programs and documentation. You do not need to contact us for permission unless you’re reproducing a significant portion of the code. For example, writing a program that uses several chunks of code from this book does not require permission. Selling or distributing a CD-ROM of examples from O’Reilly books does require permission. Answering a question by citing this book and quoting example code does not require permission. Incorporating a significant amount of example code from this book into your product’s documentation does require permission.

We appreciate, but do not require, attribution. An attribution usually includes the title, author, publisher, and ISBN. For example: Programming Firefox by Kenneth C. Feldt. Copyright 2007 O’Reilly Media, Inc., 978-0-596-10243-2.”

If you feel your use of code examples falls outside fair use or the permission given above, feel free to contact us at .

Comments and Questions

Please address comments and questions concerning this book to the publisher:

O’Reilly Media, Inc.
1005 Gravenstein Highway North
Sebastopol, CA 95472
800-998-9938 (in the United States or Canada)
707-829-0515 (international or local)
707-829-0104 (fax)

We have a web page for this book, where we list errata, examples, and any additional information. You can access this page at:

http://www.oreilly.com/catalog/9780596102432

To comment or ask technical questions about this book, send email to:

For more information about our books, conferences, Resource Centers, and the O’Reilly Network, see our web site at:

http://www.oreilly.com

Safari® Enabled

When you see a Safari® Enabled icon on the cover of your favorite technology book, that means the book is available online through the O’Reilly Network Safari Bookshelf.

Safari offers a solution that’s better than e-books. It’s a virtual library that lets you easily search thousands of top tech books, cut and paste code samples, download chapters, and find quick answers when you need the most accurate, current information. Try it for free at http://safari.oreilly.com.

Acknowledgments

Designing reusable frameworks and writing the implementation code is grueling, exhausting work.

Making that effort pay off requires patient, persistent work to promote it and educate users about how such a new product can be used, what benefits it provides, and yes, even what shortcomings exist.

This book would not be possible if it weren’t for those developers and designers who took the time to explain the technology through newsgroups, emails, and online documentation.

Particularly critical was the work done at XULPlanet.com (Aaron Anderson and Neil Deakin). Their original documentation and examples gave me the confidence that a sufficient foundation of information was available to take the “next step” in presenting an updated overview of XUL technology.

Also helpful were the contributors at mozilla.dev.tech.xul on news.mozilla.org who responded to my questions with patience and grace. The work being done there by Christian Biesinger and the other “regulars” has resulted in an invaluable tool available to the online community in supporting Mozilla/Firefox technology.

I also extend thanks to my editor, Simon St.Laurent, who provided positive feedback when I needed it most. Sincere thanks also goes to those who provided technical and editorial review—those who took the time to point out that even in technical books, readers expect to be able to read and understand sentences.

I would also be remiss if I did not extend a thank you to the pioneering companies and businesses that risk much to integrate Mozilla and forward-looking Internet technologies into their operations. No single event is more important to a new technology than the choice to use it in the affairs of business. The decision to tie one’s economic future to an evolving family of technologies is the ultimate commitment to “just make it work.” And without that commitment, there would be no need for bug fixes, new revisions, conferences ... or this book.

Finally, my thanks goes to the family members who sacrificed much in companionship and demeanor during the difficult weeks that accompany such a project. I am especially grateful to my mom, who gave me passion for the written word, and to Betsy, whose interest and pride helped sustain my effort.

Get Programming Firefox now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.