Netscape Navigator is a well-designed, highly functional product. Netscape's innovations have catapulted the company to its position as leader of the Web browser vendors. Navigator provides native support for a variety of graphics formats as well as the Hypertext Markup Language (HTML), the language of Web pages.
Netscape, however, recognizes that the needs of the Web community are changing faster and growing wider than Navigator can support. Starting with version 1 of the product, Netscape provided ways to extend Navigator with "helper applications," which support data formats beyond the built-in graphics and HTML.
Starting with Netscape Navigator 2, Navigator supports "plug-ins," another way to extend the range of data types that can be presented on or with a Web page.
To see why plug-ins are useful, go to the desktop of your computer and double-click a few documents. If you choose a document that your system associates with a particular application, that application is launched. But, if you double-click a document whose type is not associated with a known application, you see a dialog box like the one shown in Figure 9.1.
Figure 9.1 : A Windows 95 user is invited to "associate" a file extension with an application.
Note |
Most of the examples in this book were developed by using Netscape Navigator 3.0. If you are using an older version of Navigator, your results may differ markedly from the figures and examples given here. The latest versions of Netscape Navigator, for all platforms (OS/2 Warp, Mac, UNIX, and the various members of the Windows family), are available online at the Netscape home site, http://home.netscape.com/. |
On the whole, Apple and Microsoft have developed workable schemes for mapping documents to applications. Even most UNIX vendors provide similar schemes with the X Windows System.
The users' world today, however, goes far beyond their local hard drive. They may have files on a file server on the local area network. They may access files on a coworker's machine on the other side of the room or, through a company intranet, the other side of the world. They also may use a variety of files from the Internet.
When a Netscape Navigator user attempts to open a document that Navigator does not recognize, the dialog box shown in Figure 9.2 appears. This dialog box allows the user to select an external viewer application through the Pick App button or save the file.
Figure 9.2 : A Navigator user attempts to open an unrecognized file type.
External viewers, also known as helper applications, allow the Web user to see a variety of data types that are not built into Netscape Navigator or other popular browsers. Figure 9.3, for example, shows a graphic stored in Computer Graphics Metafile (CGM) format-a format popular with the Computer-Aided Design (CAD) community. This image is viewed from Netscape using FIGleaf, a plug-in from Carberry Technology.
Figure 9.3 : CGM graphics can be viewed through helper applications or plug-ins.
The downside of helper applications is that they are, indeed, applications. To view a file with a helper application the user's machine must start an entirely new program, which means that:
To understand helper applications, you must first understand MIME types. Multimedia Internet Message Extensions, or MIME, was developed to allow users to exchange files by e-mail. Although the Web doesn't use the full MIME standard, it is convenient to use media types (formerly known as MIME types) to tell a Web browser how the file is formatted.
MIME is described in detail in Request for Comments (RFC) 1590.
RFC 1590 updates the registration process originally described
in RFC 1521. Although MIME was originally intended for use in
e-mail systems (and RFC 1521 was written with this application
in mind), today's user encounters MIME in a variety of multimedia
settings.
Tip |
For more information on MIME, check out the Frequently Asked Questions list at ftp://ftp.uu.net/usenet/news.answers/mail/mime-faq or http://www.cis.ohio-state.edu/text/faq/usenet/mail/mime-faq/top.html. |
MIME is designed to have a limited number of top-level types,
such as application, text,
and video, which can be extended
by subtypes. Table 9.1 shows some typical MIME-compliant media
types.
Type | Subtype | Meaning |
application | msword | Format of Microsoft Word documents |
application | rtf | The Rich Text Format for word processors |
application | octet-stream | A catchall type for a collection of bytes |
application | zip | The compressed-file format of PKZIP and its kin |
application | Adobe's Portable Document Format | |
audio | aiff | An audio interchange format developed by Apple Computer |
audio | midi | A music format based on instruments |
audio | wav | The RIFF WAVE sound format developed by Microsoft and IBM |
image | cgm | Computer Graphics Metafile image format |
image | gif | Graphics Interchange Format image format |
image | jpeg | File interchange format of the Joint Photographic Experts Group |
text | plain | ASCII text |
text | html | The Hypertext Markup Language |
video | mpeg | Video format of the Motion Picture Experts Group |
video | quicktime | Format developed by Apple Computer |
When a Web browser requests a document from a server, the server sends several header lines before it sends the document. One header is Content-type. This header line contains the MIME type and subtype, separated by a slash. Therefore, most Web pages are preceded by the following line:
Content-type: text/html
Most Web servers have a file that associates file extensions with MIME types. On NCSA, Apache, and similar servers, the file is named mime.types. A typical line in mime.types says the following:
text/html html
This line tells the server that if the file has an extension of .html the server should send text/html in the Content-type header.
Suppose that you want to serve Microsoft Word documents, in their proprietary format, directly from your Web server. If your Word documents use the file extension .doc, and they are the only documents with that extension, you can add the following to mime.types:
application/msword doc
Equivalently, you could put the following line into the configuration file srm.conf:
AddType application/msword doc
Tip |
After changing a configuration file such as mime.types or srm.conf, you need to either restart your server or explicitly tell the server to reread the configuration files. In UNIX, you can tell the server to reread the configuration files by sending the following SIGHUP signal: kill -SIGHUP processID Here, processID is the process number of the parent server daemon. |
Note |
Under UNIX, many processes are detached from any terminal and run in the background, waiting for user requests. These processes are known as daemons. A typical UNIX machine that is being used as a Web server may have several instances of the httpd daemon (the Web server software) running, as well as an ftp dameon, a telnet daemon, and various service daemons such as timed and whois. By convention, many daemon names end in the character d. |
Start Netscape Navigator and go to Options, General Preferences. From the General Preferences dialog box, choose the Helpers tab. The result should resemble the screen shown in Figure 9.5. (Figure 9.5 shows the screen in the Macintosh version of Navigator. The exact appearance of the screen may vary slightly from one platform and one version of Navigator to the next.)
Figure 9.5 : Navigator allows the user to associate applications with media types.
Note that if Navigator recognizes the media type, it uses the common name (such as CompuServe Image Format for image/gif). Some formats, such as GIF and JPEG, are handled internally by Navigator. Others are handled by helper applications or plug-ins, which are discussed throughout the rest of this book.
Select a media type that is handled by a helper application and click the Edit button. The Edit Type dialog box is shown in Figure 9.6. Notice that in this dialog box, the user can specify the MIME-compliant media type and subtype as well as a file extension. The information in Figure 9.6 says that if Navigator encounters a header from the server that identifies the content type as image/cgm or if it is asked to open a file that has a file extension of .cgm, Navigator should launch the helper application, PowerPoint PowerMac Stub.
To add a new media type to the list that Navigator recognizes,
go to the Helpers tab in the General Preferences dialog box, and
click the New button. The resulting dialog box is identical to
the one used by the Edit button. Fill in the fields and click
OK.
Note |
The Macintosh operating system does not use file extensions to associate documents with applications. Instead, each file has two four-character fields, called Creator and Type. Most applications can handle more than one file type. Microsoft Word can recognize 18 different file types-Figure 9.7 shows a few of these types. Using the New dialog box, Navigator users on the Mac can specify which file type to associate with the media type. MSWD is the Creator of a native Word document. W6BN is the type for Word 6.0. |
Figure 9.7 : Microsoft Word 6.0.1 for Macintosh recognizes 18 different Macintosh file types.
Helper applications represented a good first-step at extending Navigator to non-native data types, but there are limitations. This section explores some of the reasons that helper applications, by themselves, may not meet the needs of many Web users.
Many Different Applications Recall that common applications such as Microsoft Word can be configured as helper applications to read their own proprietary formats. Many such applications occupy tens of megabytes and cost hundreds of dollars. Although intranet users may have a standardized set of applications, Internet users are unlikely to buy the full application in order to read a document in a proprietary format.
A reader application is needed that will allow the user to see the data, without necessarily having the capability to change the data.
Separate Windows Helper applications are, after all, applications. As shown in the example with Microsoft Word, they do not need to be written in a special way-Navigator downloads the file from the Web and then invokes the application. The application opens the file and displays it in its own window, with its own menu bar, just as though a user had launched the application and chosen File, Open.
When the application launches, it takes several seconds to load into memory. If the computer memory is already full (with Navigator and other applications), the application may not load at all. If it does load, the user is very much aware that he or she no longer is interacting with Navigator-the user now is in the helper application.
Many Webmasters wish they could embed files from a variety of formats in their documents and keep the user in the Navigator window and menu bar. Navigator needs a way to reference a file from inside an HTML document and have Navigator invoke a reader to display the file inline.
No Interaction with Navigator Many data types require more interaction than just "reading." Audio and video data can be started, stopped, played at normal speed, played faster, or played slower. Navigator is being positioned as the "universal client"-to live up to that name, it should take control of embedded data.
Many Webmasters would appreciate the capability to hook buttons or other controls on an HTML page to the helper application so that a user can interact with the application and the data through controls on the page.
Waiting for the File Hypertext Transfer Protocol (HTTP)-the protocol of the Web-is designed to allow browsers to request an entire file from the server. When the file contains HTML, it usually downloads in only a few seconds. A graphic image such as a GIF or JPEG may take half-a-minute or more but multimedia files, such as sound and video, can take many minutes-so long that most users are not pleased with having to wait. This "dead air" that accompanies large files is one reason that more multimedia is not displayed on the Web.
Some vendors, such as Progressive Networks, makers of RealAudio, developed alternative protocols that allow their clients to present the data as it downloads. A user listening to RealAudio begins to hear sound a few seconds after he or she connects, while the rest of the file continues to download.
Users would welcome a byte-oriented protocol (rather than a file-oriented protocol) because it would allow them to begin to display, play, or listen to the data as soon as it is available, rather than being forced to wait until the entire file has downloaded.
No Interaction with the Web Site Much data on today's Web is static-the file is stored on the server until it is requested, and then it is downloaded to the browser. But some applications would benefit from more interaction. An application, for example, that displays video data as it is downloaded would benefit from a Fast Forward control that tells the server to skip part of the video.
Application programmers could use a mechanism that allows them to communicate (through Navigator) back to the server.
In Navigator 2.0, Netscape introduced inline plug-ins as an alternative to helper applications. Plug-ins are platform-specific pieces of code that display their contents inside the Navigator window, very similar to the way the HTML <IMG> tag displays an image inline rather than in a separate window. This technology affords the following features:
In mid-1996, Netscape released Navigator 3.0. Navigator 3.0 supports additional plug-in capabilities. In particular, it includes a technology Netscape calls LiveConnect, which integrates plug-ins with client-side JavaScript and Java. Figure 9.8 illustrates LiveConnect.
JavaScript is a high-level object-oriented language, principally designed for use in the browser. (There also is a server-side version of the language that works with Netscape's second-generation servers and the LiveWire toolset.) JavaScript is an approachable language, and many programs have been written in JavaScript by people who do not consider themselves professional programmers.
Java is a powerful object-oriented language. Java programs can be compiled into applets and stored on the server. When the browser requests a page that references these applets, the applets are downloaded and run on the browser.
Although plug-ins are written in the native code of the client platform (OS/2 Warp, Windows, Macintosh, or a specific version of UNIX), Java is platform-independent. A Java applet can run on any platform that supports the Netscape Navigator browser.
With LiveConnect, a JavaScript programmer can include plug-ins and Java applets on the same page and can issue calls to both entities to control them or send them information. Plug-ins and applets can also call JavaScript functions to determine how they should proceed. This level of integration means that applets and plug-ins, which are usually written by skilled programmers, become a code resource for use by page designers, extending the reach of page designers who do not necessarily have to be able to write sophisticated programs.
See Part V, "LiveConnect."
See "Client-Side JavaScript," p. 139
See "Overview of Java," p. 185
Unlike Java applets, which are mini-applications, plug-ins are intended to be built around data. Before you can build a plug-in, you (the developer) must specify the MIME media type(s) that the plug-in handles. Many plug-ins will be able to work with an existing MIME media type, such as the Computer Graphics Metafile format shown earlier in this chapter (in the section titled "The World Before Plug-Ins") or those listed in Table 9.1. However, sooner or later you will need to give users access to data that has no MIME-compliant media type. This section explains two ways of dealing with this situation, depending on whether your data will be distributed privately or publicly.
Private MIME Types If you develop a plug-in
strictly for an intranet or for a limited Internet audience, you
may decide to specify your own type of MIME media. Usually, you
can use an existing type, which only requires that you select
a subtype. By convention (and in accordance with RFC 1590), unregistered
types and subtypes begin with x-.
Therefore, you may see application/x-zip,
audio/x-mpeg, and image/x-png.
Tip |
Many developers do not take the time to register their media type, so you see common formats, such as the Portable Network Graphic (PNG), with x- subtypes. The RFC 1590 registration process is streamlined compared with the requirements of RFC 1512. To avoid conflict with other types, and to "stake your claim" on a name, register your type if there is a possibility of your data being distributed publicly. |
Note |
MIME media types are intended to reflect data formats rather than applications. Therefore, application/msword may be better named application/msword6 to reflect the version of the proprietary MS-Word data format. Some types were registered or came into general use early in the life of the standard and do not reflect the latest thinking in naming standards. |
Registering a MIME Type The procedure for registering
MIME media types is given in Part 2 and Appendix A of RFC 1590,
which updates RFC 1521. RFC 1590 was issued in March 1994. Before
you start the registration process, always check the list of RFCs
to see if there is a newer RFC that updates RFC 1590.
Tip |
The Internet Assigned Numbers Authority (IANA) is the central registry for MIME types. They are set up primarily to process new subtypes. If you believe that you have a justification for a new top-level type, you should write an RFC on the new type and publish it in accordance with the current Internet standards process. Only if your RFC is approved should you use it as a top-level media type. |
To register a new media type, first select a top-level type from the current list (such as application, image, video, or audio). Then select a unique name for the subtype. Send a message to the mailing list [email protected]-readers of this list will comment on the appropriateness of your choice. A typical message format would be as follows:
To: [email protected] Subject: Proposed new Media Type content-type/subtype Media Type name: Media Subtype name: Required parameters: Optional parameters: Encoding considerations: Security considerations: Published specification: Person and e-mail address to contact for further information:
If the Media Type name field
does not contain an existing top-level Media Type, the IANA needs
an explanation of why an existing top-level Media Type cannot
be used.
Tip |
New top-level types have to be standards-track RFCs. Only one top-level type, MODEL, has been registered. Think long and hard before requesting a new top-level type-most users are best served by using one of the existing top-level types. |
Tip |
If you want a new media type for strictly personal or commercial use, you may be able to use some of the ideas in an Internet draft proposal (which expired in December 1996). You can find this proposal online at ftp://ftp.isi.edu/internet-drafts/draft-ietf-822ext-mime-reg-04.txt. Note especially the sections on "Vendor Tree" and "Personal or Vanity Tree." Under the provisions of this draft, you could register a media type that begins with vnd. or prs. without public review of your proposed type. You would, however, need to look on the current list of media types (at ftp://ftp.isi.edu/in-notes/iana/assignments/media-types/) to see if your proposed type was already in use. Many vendors, such as Microsoft, have already begun to adopt this simplified procedure. To see if this proposal becomes a standard, search for updates to RFC 822 in one of the online RFC archives (such as http://ds.internic.net/ds/dspg1intdoc.html) or check the archives of the newsgroup comp.mail.mime. |
The Published specification field should contain a reference to a publicly available specification. If the request is for a new top-level Media Type, the field should reference the RFC or RFC-to-be, specifying the new type.
The Security considerations field is the place to list any known security risks. The IANA does not require that your application be secure, only that all known risks be identified.
Allow two weeks for comments and feedback. If, based on the comments, you decide to change the name of your type, it is a good idea to send the amended proposal back to the mailing list.
After your proposal is reviewed by the ietf-types mailing list, send a message to [email protected] to start the registration process. Use the same format as the ietf-types mailing list but make the subject "Registration of new Media Type content-type/subtype."
The IANA will ensure that your proposal has been reviewed by members of the Internet Engineering Task Force through the ietf-types mailing list. Then they will register your new type, assign an Object Identifier (OID) under the IANA branch, and post the registration on their FTP server, at ftp://ftp.isi.edu/in-notes/media-types.
Your media type also will be published in RFC 1340, "Assigned
Numbers." If you expect that the Internet public will want
to put data into your new format or will write plug-ins or other
applications to read your data, put the full specification into
an informational RFC.
Tip |
To publish an informational RFC, follow the guidelines given in RFC 1543, "Instructions to RFC Authors." This document serves as a checklist of sections and elements to include. Then send the completed RFC to [email protected]. Remember that an RFC is, literally, a Request For Comments. Before making a final commitment to a format, consider releasing a Draft RFC and then modifying it in accordance with the feedback you get from the Internet community. |
ON THE WEB |
http://domen.uninett.no/~hta/ietf/media-types.html This page, maintained by Harold T. Alvestrand, gives a good overview of the current registration process. |
Many software publishers have developed applications that generate and read documents that can be sent over the Web. Plug-ins are an excellent way to extend the viability of an application. Get a media type assigned for each data format your application produces, and then write a plug-in that reads and presents your data to the user. You may even want to use JavaScript and LiveConnect to allow the Web user to interact with the data.
One example of this approach is Adobe's Portable Document Format
(PDF). Adobe makes the plug-in (and before that, the helper application)
available at no charge from its Web site. Adobe sells Acrobat,
which writes these PDF files, through commercial channels. The
result? The Internet community has a huge demand for PDF files
and sales of Acrobat are brisk.
Tip |
If you are registering a MIME media type based on a commercially available software package, you don't need to release an RFC with the data format. In the Published specification field, name the software package and version number. |
In the late 1970s, when the first desktop computers were being offered, thousands of people who did not consider themselves professional programmers learned BASIC, an interpreted language that was built into most desktop machines. Teachers, insurance agents, and bankers all wrote small BASIC applications that met specific needs in their industry. The same phenomenon occurred again in the early 1980s when spreadsheets appeared.
During the late 1980s and the early 1990s, the computer industry
realized that the number of trained programmers would fall far
short of the demand. Many companies are building on the BASIC
and spreadsheet models-they are making it possible for professional
programmers to build reusable components, which then are used
by sophisticated users to build complete systems. A skilled user
can use client-side and server-side JavaScript to stitch together
data, plug-ins, and Java applets into a complete solution for
use on an intranet or the Internet.
Note |
Chapter 7, "Overview of Java," introduces the idea of using Java applets as platform-independent components that can be added to a Netscape ONE application by someone who is not necessarily a professional programmer. Whenever possible, you should use Java rather than plug-ins in order to make the component portable across platforms. If your application needs to use native methods, of course, you can use plug-ins for the same purpose. |
For plug-ins to be used as components, they must have the following three characteristics:
Caution |
Because plug-ins run in the address space of Navigator, failures in plug-ins can crash the browser. Moreover, users may not know that a page they are trying to access contains data that is displayed by a plug-in-they may conclude that their browser is crashing because of defects in Navigator. At a minimum, this conclusion makes it unlikely that you will get timely defect reports. Therefore, it is important that plug-ins be thoroughly exercised by in-house testers and knowledgeable reviewers before release to the general public. |
Unlike Java applets, plug-ins are written in platform-specific code. Netscape Navigator is available for OS/2 Warp, Windows 3.x, Windows 95, Windows NT, 680x0-based Macintoshes, PowerPC-based Macintoshes, and a variety of UNIX platforms. If you want your data to be readable by any Navigator user, you need to develop versions of your plug-in for all of these platforms.
The good news is that the code for plug-ins is quite similar across platforms. In some cases, you can use the same code and compile for different targets. Microsoft's Visual C++, for example, can generate code for Intel processors (running all manner of Windows), the Macintosh (both 680x0 and PowerPC), and even the DEC Alpha chip (running Windows NT). MetroWorks CodeWarrior Gold for the Macintosh can generate code for both types of Mac processors as well as Windows 95 and Windows NT.
Differences between platforms usually have more to do with the graphical user interface (GUI) than with the interface between Navigator and the plug-in. Windows applications will call the Windows API (possibly through Borland's Object Windows Library, OWL, or Microsoft's Foundation Classes, also known as MFC). Macintosh applications use the Macintosh toolbox, which is built into every Mac. UNIX programmers can choose from a wide variety of "widgets"-pre-built objects that fit into an X Windows System environment.
Because a complete plug-in should be available on all platforms,
this book contains information relevant to all four major operating
systems. Where the operating system is irrelevant, most examples
are drawn from the Windows 95 platform and are shown in Microsoft
Visual C++.
Note |
Users sometimes complain that, in Navigator 2.0 and 3.0, they must explicitly download the plug-in before they can view non-native data. Starting in Navigator 4.0, Netscape is offering the capability to automatically download and install a plug-in (called AutoInstall). The HTML programmer can identify the URL of the plug-in and allow the browser to fetch the plug-in and install it. Before the plug-in downloads, the end user is asked if he or she wants to download the plug-in. The user may optionally be given a license to approve. Finally, the user gives final approval for the download based on whether or not they trust the electronic signature of the plug-in. |
Netscape distributes its plug-in Software Development Kit on its Web site, at http://home.netscape.com/eng/mozilla/3.0/handbook/plugins/index.html. You can also get this information from http://home.netscape.com/comprod/development_partners/plugin_api/index.html, shown in Figure 9.9.
Figure 9.9 : You can develop plug-ins on all major platforms.
Note |
Although you may eventually write plug-ins for all four platforms, pick one platform to learn on first. Most examples in this book are given for development on Windows 95 and Microsoft Visual C++. If you don't have access to this platform, follow along on your own system, and pay close attention to the notes that discuss OS/2 Warp, Macintosh, and UNIX development. |
Visit the Netscape site and download the version of the SDK appropriate for your development platform.
Each version of the SDK is compressed in a way that is appropriate
for the platform (for example, the Windows version is ZIPped,
the Macintosh version is a Stuff-it archive, and the UNIX version
is compressed using tar).
Copy the SDK to the directory of your choice and unpack it.
Tip |
Use WinZIP or PKUNZIP with Windows and OS/2. Use StuffIt Expander on the Macintosh. If you use UNIX, your machine probably came with the compression utility tar. For an even better version, check out GNU tar, which comes from the Free Software Foundation. GNU software is widely available online. For an online copy, visit http://www.cs.pdx.edu/~trent/gnu/sites.html for a starting point. The "official" site of the Free Software Foundation, http://www.gnu.ai.mit.edu/, is almost as useful as the unofficial site (http://www.cs.pdx.edu/~trent/gnu/). If you're distributing your files or plug-ins through the Internet, you should also learn about gzip. This product is the Free Software Foundation's leading compression utility and is available on the standard GNU sites. Since gzip is available on all common platforms, you can store a single gzipped file that can be downloaded by Mac, Windows, OS/2, or UNIX users. |
You need a C++ compiler to build Navigator plug-ins. Netscape's
SDKs are built from its engineers' computers and do reflect the
software tools that Netscape uses internally. On Windows, Netscape
uses Microsoft's Visual C++. On the Mac, it uses Metrowork's CodeWarrior.
Most versions of UNIX come with a native C/C++ compiler. IBM recommends
IBM's Visual Age C++ 3.0 for building plug-ins for OS/2 Warp.
Tip |
The Free Software Foundation has a C++ compiler, g++, which runs on nearly all versions of UNIX. You can download the source from any GNU site, but, of course, you need a compiler to compile the source. Some GNU sites have precompiled binaries of g++ for various versions of UNIX to get you started. For information about precompiled binaries online, visit the "Precompiled GNU Binaries" section of http://www.cs.pdx.edu/~trent/gnu/. That page also contains links to information about g++, including the Frequently Asked Questions list at http://www.cis.ohio-state.edu/hypertext/faq/usenet/g++-FAQ/plain/faq.html. If you don't have any compiler at all, and can't find (or don't want to download) the precompiled binaries online, you should visit Ready-to-Run Software, Inc. at http://www.rtr.com/. Ready-to-Run specializes in packaging the binaries of publicly available software into "ReadyPacks," which include an intelligent installation system that allows you to quickly select the programs you want to install and where you want to install them. Often, GNU software has dependencies-to run Program A, you need Program B. Ready-to-Run's ReadyPacks include a cross-reference utility to show you just which programs you have to load from the ReadyPack. g++ is part of Ready-To-Run's "Language Pack #1," described in detail at http://www.rtr.com/rtr01/lp1.htm. In addition to their online information, you can order a printed Ready-to-Run catalog from their Web site or by phone at 800-743-1723 or 508-692-9922. |
Although you can build plug-ins with any C++ compiler, you have less work to do if you use the same compilers as Netscape. For example, some portions of the Windows example plug-in rely on Microsoft Foundation Classes. The Symantec compiler comes with MFC-the Borland compiler is bundled with OWL, which offers similar capabilities. The Borland compiler also can be used to recompile MFC, if you get this library from Microsoft. Visual C++, however, is available in versions starting at under $100-for learning to build plug-ins, a copy of Visual C++ shortens your learning time.
Figure 9.10 illustrates the process of turning a high-level language such as C or C++ into an executable file. The compiler produces object code, often signified with a file extension of .obj or, occasionally, .o. The linker puts together these object files with platform-specific code, like the code that makes up the Windows or Macintosh API. The finished product is an executable file. On either a DOS or a Windows computer, this executable has a file extension of .exe.
Note |
The use of the term "object file" as the output of a compiler has nothing to do with object-oriented programming. The use of these two terms is completely coincidental. |
For years, all linking was done by the developer when the product was built. Today, all major platforms allow programmers to build code resources that can be linked into applications when the application loads or even during runtime. Libraries designed to be linked on the user's computer are known as dynamic libraries; libraries designed to be linked on the developer's machine are static libraries.
When an application statically links a library, the object files from the library become a permanent part of the application, and the size of the application grows. Dynamic libraries are attractive when the libraries will probably be used by more than one application. Then, applications take up less disk space and memory because they share the library. Figures 9.11 and 9.12 illustrate this difference.
Figure 9.11 : Static libraries are built into the application when it is developed.
Caution |
If you deliver an application that relies on a dynamic library, you must make sure that each end user has a copy of the library. For example, Windows applications that dynamically link MFC fail if the end user does not have a copy of MFCxxx.dll (where xxx represents the localized version of the Microsoft Foundation Classes library). |
Each SDK comes with a copy of Netscape's documentation in HTML files. After the kit is unpacked, use Navigator to open the doc/index.html page and then to bookmark it. You use this page as the starting point to the online documentation.
Windows Microsoft Windows allows programmers to write code either as applications or as dynamic link libraries (DLLs). The principal difference is that applications have a function named WINMAIN() that serves as their starting point and DLLs do not. This design makes it easier to build a DLL that can, with few changes, be readily compiled into an executable application-a technique demonstrated in Chapter 13, "Analysis of a Simple Plug-In." Rather than defining a WINMAIN() function, Windows DLL programmers must explicitly export function names from the DLL to the calling program.
Netscape plug-ins keep information about which MIME types they handle in their VERSION resource. When Navigator starts, it looks in the directory that holds the Navigator executable for a folder labeled Programs. Inside this directory, it looks for a folder labeled Plug-ins. It examines the VERSION resources of each file in the Plug-ins folder and reads out the MIME type.
Later, when it encounters a Content-type header with a type it does not recognize, it scans the list of MIME types that are registered by the plug-ins. If it finds a match, it loads that plug-in DLL into memory and calls the exported functions.
OS/2 Warp Early in the life of the Web, IBM
announced its own browser (Web Explorer) for OS/2. In mid-1996,
IBM announced that it was adopting Netscape 2.02 as the standard
browser for OS/2 (though they have adapted it to include some
of the nicer features of Web Explorer, such as speech input).
IBM and Netscape also took a different approach to integrating
Java. Since OS/2 version 4 already has Java integrated into the
operating system, Navigator calls OS/2's Java rather than its
own Java interpreter. These differences should be transparent
to the user and the developer.
Note |
If the end user is using OS/2 Warp version 3, encourage them to get the adapter kit from IBM so that they can use Java with Navigator 2.02. |
IBM will probably not offer Netscape 3.0 for OS/2. Instead, they are working with Netscape to bring Netscape 4.0 (Galileo) to OS/2 Warp. Look for Netscape 4.0 for OS/2 early in 1997.
Unlike the SDKs for the other platforms, the OS/2 Warp Plug-Ins SDK is stored on the IBM site, rather than on the Netscape site. You get it from http://www.internet.ibm.com/browsers/netscape/warp/.
If you develop OS/2 Warp plug-ins before Galileo is released for OS/2, remember that you only have Netscape 2.02 features. Most importantly, this fact means you have no LiveConnect capabilities, so you cannot integrate Java and JavaScript with your plug-in.
Be sure to download the plug-in documentation that comes from
the IBM site. This version is almost identical to the version
on the Netscape site but includes the instructions specific to
OS/2 Warp development.
Tip |
The OS/2 Warp version of the plug-ins SDK is compressed with PKZIP. If you use PKUNZIP to decompress the files, be sure to use the -d flag to maintain the directory structure. |
Visual Age C++ relies heavily on makefiles. To specify the MIME media type and file extensions in your plug-in, use the compiler's editor to modify the makefile. The easiest way to do this is to make a working directory in the SDK directory and copy the contents of the npshell directory into your new working directory. (You may want to name the working directory myplugin.) Now open the makefile copied in from npshell, changing the RCDATA lines to reflect values appropriate for your plug-in. For example, if you are writing a plug-in that plays AVI movies, the makefile should include:
#include "npapi.h" RCDATA NP_INFO_ProductVersion { 1,0,0,1} RCDATA NP_INFO_MIMEType {"video/x-msvideo\0"} RCDATA NP_INFO_FileExtents {"avi\0"} RCDATA NP_INFO_FileOpenName {"OS/2 Video Plugin\0"}
To include multiple MIME types in the plug-in, use a vertical
bar to delimit each value in the MIME type. For example, VALUE
"MIMEType", "video/x-msvideo | video/quicktime\0"
specifies that the plug-in will handle both AVU (x-msvideo)
and Quicktime video types.
Tip |
While you have the makefile open, you may want to specify OPT=DEBUG and CRT=DYNAMIC. These options will give you a debug version with dynamic linking (comparable to a Windows DLL), respectively. The makefile gives the plug-in the .dll file extension. |
On OS/2, Netscape looks for plug-ins by starting at the directory
that holds netscape.exe and by looking "down" for a
plug-ins subdirectory. You don't have to start the plug-in name
with np unless you want to for consistency
with the Windows versions of the plug-in.
Tip |
Try to avoid putting non-plug-in files in the OS/2 plug-ins directory. If you need to provide your plug-in with additional files, put them in a subdirectory inside the plug-ins directory. |
Caution |
Be sure to check the "Known Problems" section of the OS/2 version of the plug-ins SDK. (In the initial release, it's at file://path-to-sdk/ht4.htm#C3.) For example, the initial release does not support printing and does not properly handle two instances of the same data. Most of these problems should be eliminated when IBM and Netscape release Navigator 4.0 for OS/2 Warp. |
Macintosh Applications in the Macintosh operating system are based on resources. Each Macintosh application has two CODE resources. (It may have more, but it must have these two.) CODE resource 1 is known as the "main segment." This segment is loaded when the application starts and is not unloaded until the application exits. (CODE resource 0 is used for housekeeping and is not a concern here.)
Not all code is kept in CODE resources. The Mac has a lot of little code resources tucked into resources like CDEFs (Control Definition Functions, for drawing controls) and MDEFs (Menu Definition Functions, for drawing menus). It switches from one printer to another by switching PDEFs (Printer Drivers) at runtime.
When Navigator is launched on the Macintosh, it looks for the folder that contains the Navigator executable; then it looks for a subfolder named Plug-ins. Finally, it searches each file in the Plug-ins folder for a resource named NSPL with an ID of 128. If it finds this combination, it knows that file contains a plug-in. Navigator then looks for a string resource (STR#) with ID 128. Macintosh STR# resources contain lists of strings. STR# 128 contains the MIME types that this plug-in recognizes.
Later, when Navigator encounters a stream from a server, it compares Content-type headers with the MIME types it read from the plug-ins. If it finds a match, it loads the resources of this plug-in into memory and calls functions in the plug-in.
UNIX Most versions of UNIX allow a program to build what are named .so libraries, shared object files that function like Windows DLLs. The instructions for building a shared object library vary slightly between UNIX versions. Significantly, AIX (IBM's version of UNIX) supports shared object libraries by using the same export mechanism as Windows. This process is sufficiently different that Netscape does not yet support plug-ins on its AIX version of Navigator.
UNIX uses a mechanism similar to the mechanism described for Windows and Macintosh. It looks through the shared objects in the Plug-ins directory for libraries that advertise Netscape plug-in functions. When UNIX finds these libraries, it looks up the MIME types they handle and then links and loads the correct plug-in at runtime.
From the beginning, Netscape Navigator has supported helper applications that allow users to access data types other than the ones built into Navigator. The mechanism for describing these data types is the MIME-compliant media type.
Starting with Navigator 2.0, Netscape supports inline plug-ins, which allow programmers to write native code to read data and to present it inside the Netscape window.
With Navigator 3.0, Netscape introduced LiveConnect, which integrates plug-ins, JavaScript, and Java. Now all of the programming techniques for the client can be brought together into an integrated solution.
Starting with Navigator 4.0, Netscape is supporting automated downloading and installation of plug-ins, making the use of plug-ins even more transparent to the end user.
The programmer who wants to field a complete plug-in solution
will need to build his or her plug-in on all major platforms.
This book presents solutions for the OS/2 Warp, Macintosh, and
UNIX machines, while emphasizing Windows 95 and the Microsoft
Visual C++ compiler as an appropriate and readily available learning
environment.
ON THE WEB |
http://home.netscape.com/comprod/development_partners/plugin_api/index.html Start at this page to download a copy of the LiveWire/Plug-Ins SDK for your platform. For a full set of information about this technology, you should also visit http:// home.netscape.com/eng/mozilla/3.0/handbook/plugins/index.html and follow the links from that page. |