Netscape Plug-Ins

Developer's Kit

by Michael Morgan


C  O  N  T  E  N  T  S




Chapter 1   Bridging the Gap from CGI and Helper Applications to Netscape Plug-Ins

Chapter 2   A C++ Primer

Chapter 3   Integrating Plug-Ins into Web Site Design

Chapter 4   Building a Simple Plug-In

Chapter 5   Design Issues

Chapter 6   NPP Methods: Starting the Plug-In

Chapter 7   NPP Methods: Handling Interaction

Chapter 8   NPP Methods: Other Tasks

Chapter 9   Understanding NPN Methods

Chapter 10   Example: Simple Plug-In

Chapter 11   Example: CharFlipper Plug-In

Chapter 12   Example: npAVI Plug-In

Chapter 13   Getting Back on the Network

Chapter 14   If All the World Used Microsoft…

Chapter 15   ActiveX and Plug-Ins in Other Browsers

Chapter 16   Spanning the Windows World

Chapter 17   Using Class Libraries and Frameworks

Chapter 18   Plug-Ins as a Programming Resource

Chapter 19   Installing the Plug-In

Appendix A   Glossary


Credits


Netscape Plug-Ins Developer's Kit

Copyright 1997 by Que Corporation.

All rights reserved. Printed in the United States of America. No part of this book may be used or reproduced in any form or by any means, or stored in a database or retrieval system, without prior written permission of the publisher except in the case of brief quotations embodied in critical articles and reviews. Making copies of any part of this book for any purpose other than your own personal use is a violation of United States copyright laws. For information, address Que Corporation, 201 W. 103rd Street, Indianapolis, IN, 46290. You may reach Que's direct sales line by calling 1-800-428-5331.

ISBN: 0-7897-0844-2

HTML conversion by :
    M/s. LeafWriters (India) Pvt. Ltd.
    Website : http://leaf.stpn.soft.net
    e-mail : leafwriters@leaf.stpn.soft.net


PresidentRoland Elgey PublisherJoseph B. Wikert
Director of marketing Lynn Zingraf Publishing Manager Jim Minatel
Editorial Services Director Elizabeth Keaffaber Managing Editor Sandy Doell
Strategic Marketing Manager Barry Pruett Product Director Stephen L. Miller
Production Editor Don EamonCopy Editor Judith Goode
Product Marketing Manager Kristine Ankney Assistant Product Marketing Managers Karen Hagen, Christy M. Miller
Technical Editor Sunil Hazari Technical Support Specialist Nadeem Muhammed
Acquisitions Coordinator Jane K. Brownlow Software Relations Coordinator Patty Brooks
Editorial Assistant Jennifer L. Condon, Andrea Duvall Book Designer Ruth Harvey
Cover Designers Ruth Harvey, Barbara Kordesh
Production Team Stephen Adams, Melissa Coffey, Amy Gornik, Tammy Graham, Jason Hand, Kay Hoskin, Clint Lahnen, Tony McDonald, Laura Robbins, Sossity Smith, Marvin Van Tiem
IndexerJoy Dean Lee, Tim Tate

About the Author

Michael Morgan is founder and president of DSE, Inc., a full-service Web presence provider and software development shop. The DSE team has developed software for such companies as Intelect, Magnavox, DuPont, the American Biorobotics Company, and Satellite Systems Corporation, as well as for the Government of Iceland and the Royal Saudi Air Force. DSE's Web sites include the prestigious Nikka Galleria, an on-line art gallery. DSE's sites are noted for their effectiveness-one of the company's sites generated sales of over $100,000 within 30 days of being announced.

During Academic Year 1989-1990, Mike was invited by retired Navy admiral Ron Hays to serve as the first Fellow of the Pacific International Center for High Technology Research (PICHTR) in Honolulu. PICHTR is a spin-off of the the University of Hawaii and bridges the gap between academic research and industrial applications. Mike directed the first technology-transfer initiatives at PICHTR, and helped PICHTR win its first industrial contract. Mike assisted Admiral Hays in presenting PICHTR and its mission to the Hawaii research community, the Hawaii legislature, and Hawaii's representatives to Congress.

Mike is a frequent speaker at seminars on information technology, and has taught computer science and software engineering at Chaminade University (the University of Honolulu) and in the graduate program of Hawaii Pacific University. He has given seminars for the IEEE, National Seminars, the University of Hawaii, Purdue University, and Notre Dame.

Prior to founding DSE in 1988, Mike was a member of the technical staff at Magnavox Electronic Systems Company in Fort Wayne, Indiana. As a Magnavox engineer, he developed the first expert system for use in airborne AntiSubmarine Warfare. As a member of the Magnavox Industrial Modernization Team (IMIP), he identified and performed the conceptual design of three information-technology projects with a total value in the tens of millions of dollars.

In the early 1980's Mike was employed by the City of Virginia Beach, where he completed the development of the world's first automated municipal water distribution system. He is credited with saving the City several hundred thousand dollars in connection with that system.

Mike was an Army Signal Corps officer with active duty in the 5th Infantry Division and Reserve duty with the U.S. Rapid Deployment Force. He was among the youngest officers ever awarded the Meritorious Service Medal.

The author of over twenty technical papers and presentations on various aspects of information technology, he is the co-developer of the Project Unit Costing Method, which allows project managers to construct justifications for information technology projects based on cost savings and cost avoidance. He is also the inventor of GAELIC, the Gallium Arsenide Experimental Lisp Integrated Circuit, an ultra-high-speed processor optimized for artificial intelligence applications, and the co-inventor of MEND, a Multiple Expert iNtelligent Diagnostics system.

Mike is the co-manager of the CGI archives of the HTML Writers Guild, and is a member of the Help Team for Matt Wright's Script Archive. In these capacities, he works with programmers around the world helping set up advanced solutions on the Web.

He holds a Master of Science in Systems Management from the Florida Institute of Technology, and a Bachelor of Science in Mathematics from Wheaton College, where he concentrated his studies on computer science. He has also taken numerous graduate courses in computer science through the National Technological University. Mike is a member of the IEEE Computer Society.

Mike usually can be found in his office at DSE, drinking Diet Pepsi and writing Perl and C++. He lives in Virginia Beach with his wife, Jean, and their six children.

Acknowledgments

While my name appears on the cover of this book, many people worked together to produce the manuscript, and to turn the manuscript into the book you are now holding. If you find this book useful, you have them to thank.

Miguel Pating, Director of Development at Visionary Systems, Inc. (http://www.visi.net) and Ed Fang, Director of that organization, provided invaluable assistance and key resources throughout the development process.

As with all my books, I am again indebted to my colleague, Christopher Kepilino, and to my wife, Jean. Chris and Jean attended to the myriad of details that are needed to turn an idea into a book. They produced screen shots, reviewed the manuscript, and made sure that files and e-mail moved smoothly between my desk and the publisher's.

As always, the folks at Que have been capable and professional. Stephen Miller reviewed the entire manuscript, providing insight into many new technology topics. Don Eamon (with copy-edit help from Judith Goode) production edited the entire manuscript-a monumental task, calling for incredible patience. Thanks, guys.

I am also indebted to the readers of this and my previous books for your feedback. Please feel free to visit my Web site (http://www.dse.com/General/2.MLM_Home.shtml) or send me e-mail at morganm@mail.dse.com. I look forward to hearing from you.

As always, any errors or omissions are my responsibility.

Michael Morgan
Virginia Beach
October 16, 1996

We'd Like to Hear from You!

As part of our continuing effort to produce books of the highest possible quality, Que would like to hear your comments. To stay competitive, we really want you, as a computer book reader and user, to let us know what you like or dislike most about this book or other Que products.

You can mail comments, ideas, or suggestions for improving future editions to the address below, or send us a fax at (317) 581-4663. For the online inclined, Macmillan Computer Publishing has a forum on CompuServe (type GO QUEBOOKS at any prompt) through which our staff and authors are available for questions and comments. The address of our Internet site is http://www.mcp.com (World Wide Web).

In addition to exploring our forum, please feel free to contact me personally to discuss your opinions of this book: I'm 76103,1334 on CompuServe, and I'm at slmiller@que.mcp.com on the Internet.

Thanks in advance-your comments will help us to continue publishing the best books available on computer topics in today's market.

Stephen L. Miller
Product Development Specialist
Que Corporation
201 W. 103rd Street
Indianapolis, Indiana 46290
USA


Introduction

Welcome to the world of Web browser plug-ins, and more particularly to the plug-ins for Netscape Navigator. Plug-ins are a powerful programming technique for extending Netscape Navigator 2.0x and beyond to deal with non-native types and offer new functionality. The demand for Web page designers has grown at an extraordinary rate. Although many talented people have entered the field of HTML authoring, the demand for specialty programs such as plug-ins promises to keep professional programmers busy for years to come.

Using plug-ins, programmers can build code resources that allow HTML programmers to embed new media types such as audio, video, and specialty graphics in their Web pages. With advanced plug-ins, the programmer can write a complete application, including calls back to the server and communications with multiple clients.

Netscape Plug-Ins Developer's Kit shows how to make your site come alive-first with high-quality static content, and then with full interaction between the browser and the native graphical environment, which gives users access to all the features of their PC, Macintosh, or UNIX workstations from inside Navigator.

Who Should Read This Book?

This book is for you if you already know how to program and if you develop or maintain a site on the World Wide Web. This book will help you decide whether the plug-in capabilities of Netscape's latest browsers can benefit your site.

If you have been building pages with static HTML, Netscape Plug-Ins Developer's Kit shows you how to start by mixing existing plug-ins with code you write in Java and JavaScript. You'll want to read Chapter 1, "Bridging the Gap from CGI and Helper Applications to Netscape Plug-Ins," to learn what plug-ins can do for your site. You also will want to review Chapter 18, "Plug-Ins as a Programming Resource," which explains how to connect plug-ins and Java to JavaScript by using LiveConnect, and Chapter 19, "Installing the Plug-In," to learn about the latest techniques in auto-installation.

If you're a programmer new to C++, go to Chapter 2, "A C++ Primer," which starts with object-oriented concepts, and then moves through templates and the Standard Template Library.

If you support an intranet or other Windows-only environment, pay particular attention to the discussion of Microsoft's OLE capabilities in Chapter 14, "If All the World Used Microsoft…." You also may want to see Chapter 15, "ActiveX and Plug-Ins in Other Browsers," for a comparison between plug-ins for Navigator and in the Microsoft Internet Explorer's ActiveX technology.

If you are new to HTML, the author recommends Special Edition Using HTML by Mark Brown and John Jung.

If you are new to running a Web site, you may benefit from Webmaster Expert Solutions (Que, 1996).

If you're not (yet) a programmer, or if you're new to C++, see SE Using Borland C++, SE Using Microsoft Visual C++, and Borland C++ by Example, all by Que Corporation.

Netscape Plug-Ins Developer's Kit picks up where these books leave off, and describes the features available in plug-ins that allow you to increase the quality of your site by reusing platform-specific code.

What This Book Is About

Netscape Plug-Ins Developer's Kit is a "how-to" book. It starts with a description of the methods of a plug-in and shows, step-by-step, how to produce pages on the World Wide Web that take advantage of the features in Netscape's newest browsers. The following list catalogues a few capabilities offered by Navigator through plug-ins:

The primary focus of this book is helping you become familiar with the plug-in internals, so that you can build effective, high-quality pages with reusable components, resulting in a lower development cost. These pages include both static multimedia content, document viewers, and advanced interactive applications with platform-specific code.

What Will I Learn In This Book?

Although Netscape Plug-Ins Developer's Kit contains many examples and "cookbook" solutions, there also is a component of "understanding" in each chapter. We describe why things work as they do. This level of understanding helps the reader adapt to different configurations, change with new technology, and troubleshoot problems when their site is not working correctly.

Most chapters contain two to three sections on "understanding" as well as examples and sample code. Many chapters also describe a step-by-step process that programmers can use to ensure high-quality results in their plug-ins.

How This Book Is Organized

The Netscape sample plug-ins that come with the software development kit are notorious for their lack of clear instructions. Only a handful of people have built plug-ins based on the example code alone-indeed, several sites have sprung up on the Web to "correct" misimpressions left by the sample plug-ins.

Netscape Plug-Ins Developer's Kit places the best of on-line information together with material unavailable from any other source-the source code and discussion of real plug-ins, which can be used as a starting point for your own applications. The first chapter meets the needs of programmers who are ready to download the Netscape samples and start writing plug-ins. This part warns you of the limitations of the Netscape sample, and shows how to download the Software Development Kit (SDK) and configure it for the platform.

Chapter 2, "A C++ Primer," is designed if you are new to C++ or if you need a refresher to come up to speed on new techniques such as exceptions, templates, and the Standard Template Library.

Chapters 3, 4, and 5, "Integrating Plug-Ins into Web Site Design," "Building a Simple Plug-In," and "Design Issues," focus on issues that get you, as a programmer, started quickly-the architecture of a basic plug-in.

Chapters 6, "NPP Methods: Starting the Plug-In," through 9, "Understanding NPN Methods," serve as a reference, with examples of each basic plug-in method. Chapters 10, "Example: Simple Plug-In," through 12, "Example: npAVI Plug-In," show how to code various plug-ins by using the methods presented in earlier chapters.

Chapter 13, "Getting Back on the Network," shows how the plug-in can call Navigator and have it access the Net on behalf of the plug-in.

Chapters 14, "If All the World Used Microsoft…," 15, "ActiveX and Plug-Ins in Other Browsers," and 16, "Spanning the Windows World," highlight the features of Microsoft Windows and OLE as they apply to both Navigator and Microsoft Internet Explorer plug-ins.

The book concludes with three chapters on reusable code: Chapter 17, "Using Class Libraries and Frameworks," shows how to take advantage of the thousands of lines in Microsoft Foundation Classes and other commercial libraries. Chapter 18, "Plug-Ins as a Programming Resource," shows how to use Netscape's LiveConnect technology to integrate Java, JavaScript, and plug-ins. Chapter 19, "Installing the Plug-In," shows how to automate the installation process so that plug-ins become transparent (or nearly so) to the end user.

The book is organized to ease your transition from experienced programmer to plug-in developer. To get started quickly, read the first chapter, then go right to Chapter 4, "Building a Simple Plug-In." If you are new to C++, reading Chapter 2, "A C++ Primer," is a must do before moving into the chapters on plug-in methods. Before you write plug-ins for serious applications, you'll want to have Chapters 3, "Integrating Plug-Ins into Web Site Design," through 9, "Understanding NPN Methods," and at least one of the "Example" chapters (10, 11, and 12) under your belt. If your plug-ins will be used mostly on Windows platforms, make sure that you read Chapters 14, "If All the World Used Microsoft…" through 17, "Using Class Libraries and Frameworks." To build integrated client applications by using LiveConnect, see Chapter 18, "Plug-Ins as a Programming Resource."

Finally, Appendix A is a glossary of terms to help those of you who are unfamiliar with some of the territory covered in this book. Appendix B describes the amount of material contained on this book's companion CD-ROM.

How to Use This Book

This book assumes that you are an experienced programmer, and that you know both HTML and the architecture of the Web. For more information about programming in C++ on various platforms, see SE Using Borland C++, SE Using Microsoft Visual C++, and Borland C++ by Example, all by Que Corporation.

To write LiveConnect applications, you want to have Java and JavaScript to integrate with your plug-ins. See Special Edition Using Java, Special Edition Using JavaScript, and Java by Example, Que Corporation.

If you already know how to program in JavaScript, you are ready for Chapter 18 on LiveConnect. If most of your plug-ins will be used in a Windows environment, start by reading the first nine chapters, then read at least one Example chapter (Chapters 10, 11, and 12), and then move on to Chapters 14, "If All the World Used Microsoft…," through 17, "Using Class Libraries and Frameworks." Pay particular attentions to the section on Microsoft Foundation Classes in Chapter 17.

Conventions Used in This Book

Within each chapter you find italicized text, bulleted lists, and numbered lists. Italics are used to mark important words or phrases and to introduce new technical terms. An italicized term is followed by a definition or an explanation.

Bulleted lists are used when the order of the items isn't important. The items represent related concepts that are explained in the list.

Numbered lists are used when the numbering, or sequence, is important. Steps in a procedure appear in numbered lists. Follow the steps from beginning to end. Make sure that you understand each step-don't just skip one because you don't understand it.

The chapters also contain figures (which often are screen shots that show what to expect on your computer) and code listings (which contain complete programs, usually in JavaScript, to illustrate a technique).

Code fragments are contained in the text and set in monospace font. These fragments illustrate a technique, but they are not by themselves a complete program.

Sometimes in these code listings a line runs beyond the page width of this book. When this happens, you see a small arrow, at the beginning of the new line. When you see this arrow, it means that all of this material can actually be entered into the program on a single line.

Characters that you are asked to type are set in bold font. If you must substitute a file name or other element into the line, a placeholder for the file name or element is used and is set in bold italics.

The syntax of a particular command or tag is shown with a special kind of code fragment. A syntax form looks like the following example:

<P [ALIGN=Left|Center|Right]>

Here, optional elements appear in [square brackets]. Variants are separated by the vertical bar |. Monospaced font must be typed exactly as it appears. According to the preceding syntax form, all of the following HTML is legal:

<P>
<P ALIGN=Left>
<P ALIGN=Center>
<P ALIGN=Right>

The following HTML, however, is illegal:

<P ALIGN=Center
<P ALIGN=CenterRight>
<P COLOR="#110000">

Tables are used when appropriate.

Icons appear in the margins of this book to indicate either that a file or application exists on this book's companion CD-ROM or that an Internet address appears within the adjacent text.

What Technical Assumptions Does This Book Make?

The plug-in SDK is available for nearly every modern operating system: Macs, Windows machines, and a variety of UNIX computers. Netscape Plug-Ins Developer's Kit uses Microsoft Visual C++ on Windows 95 for many of its examples, and provides notes that show the differences between that environment and Macintosh, UNIX, and non-Microsoft Windows compilers. Most readers will find it easy to adapt this standard description to the configuration on their development platform.

This book also emphasizes direct writing and debugging of the plug-in with a text editor. Although advanced development environments can build much of the plug-in with little guidance from the designer, there is no substitute for learning about each method by writing it yourself.