Previous Page TOC Next Page See Page



- 16 -
Navigator Plug-ins


Netscape provides a set of specifications for plug-ins to Navigator. Plug-ins allow Navigator to handle new MIME types not supported natively by the browser but that are different from the helper applications historically used by Web browsers to handle unsupported file formats.

Plug-ins from third-party developers already exist to support numerous standard and proprietary formats, ranging from Microsoft Word documents to a wide range of graphics formats, including TIFF, EPS, and PICT files.

JavaScript provides the plug-in and mimeType objects to allow scripts to be aware of the currently available plug-ins. This can enable a Web author to dynamically produce a page based on supported MIME types and plug-ins.

In this chapter, the details of plug-ins and how to work with them in JavaScript are covered, including the following topics:


What are Plug-ins?


As mentioned above, plug-ins provide a method of adding support for new file formats and MIME-types to Navigator. Plug-ins are small libraries of code written to directly extend the capabilities of Navigator—they work within the Navigator environment to handle new MIME types, display their content and additional information, perform network communication, and more.

When Navigator loads, it searches for available plug-ins and registers the MIME-types they support. Then, in the course of browsing, if Navigator receives a file with a MIME type supported by one of the plug-ins, Navigator loads the plug-in and hands the file off to the plug-in for processing.

This is different from the helper applications, which have traditionally been used on the Web to display and handle unsupported file formats. In the case of helper applications, browsers are configured to launch a separate standalone application to handle a specified file format. These helper applications are not integrated into the Navigator environment—they generally can't communicate with Navigator and they can't work with other Navigator components, such as JavaScript and Java applets.

Popular Plug-ins


There are presently numerous popular plug-ins for Navigator (mostly for Windows and the Macintosh platforms—UNIX is behind in this regard). The types of applications these plug-ins perform include:

Figure 16.1. Plug-ins extend Navigator to support new file formats, including real-time video streaming.

Table 16.1 lists a selection of the major plug-ins available today.

Table 16.1. Selected Navigator Plug-ins

Plug-in Description
Acrobat Reader By Adobe. Acrobat Reader allows Portable Document Format (PDF) files to be viewed within a Navigator window. (http://www.adobe.com)
Carbon Copy/Net By Microcom. Carbon Copy/Net lets users remotely control another PC on the Internet. (http://www.microcom.com)
CoolFusion By Iterated Systems. CoolFusion streams and displays AVI video files as they're received by Navigator. (http://www.iterated.com)
EarthTime By Starfish Software. EarthTime displays the time and date for up to eight locations around the globe at once. (http://www.starfishsoftware.com)
Formula One/NET By Visual Components. Formula One/NET is an Excel-compatible spreadsheet that allows Navigator users to edit and view spreadsheets within Navigator. (http://www.visualcomp.com)
KEYview for Windows By FTP Software. This plug-in can view, print and convert 200 file formats including Word, WordPerfect, Excel and image formats. (http://www.ftp.com)
PointCast Network By PointCast. A free service that broadcasts news and other information to be accessed from within Navigator. (http://www.pointcast.com)
PowerPoint Animation Player & Publisher By Microsoft. This PowerPoint plug-in lets users view PowerPoint presentations in Navigator. (http://www.microsoft.com)
RealAudio By Progressive Networks. RealAudio provides real-time audio on the Internet. (http://www.realaudio.com)
Shockwave for Director By Macromedia. Allows interaction with Director files in a Navigator window. (http://www.macromedia.com)
ToolVox By VoxWare. ToolVox can be used to play synthesized speech in a Web page. (http://www.voxware.com)
VDOLive By VDONet. VDOLive delivers compressed video without reducing quality at as much as 15 frames per second. (http://www.vdo.net)
WebXpresso By Dataviews. WebXpresso displays two-dimensional and three-dimensional images and controls with support for real-time interaction, continuous updating and Java Native Methods. (http://www.dvcorp.com)
Word Viewer By Inso Corporation. Allows Navigator users to view Microsoft Word 6.0 and Word 7.0 documents inside Navigator. (http://www.inso.com)

A more extensive list of plug-ins is available in Appendix G. Netscape also maintains an extensive list of plug-ins at http://home.netscape.com/comprod/products/navigator/version_2.0/plugins/index.html.

The <EMBED> Tag


The list of plug-ins in Table 16.1 demonstrates that most plug-ins are triggered when a particular file format is included in an HTML file. In traditional HTML, the <IMG> tag provided a mechanism to include images in documents. Similarly, the <APPLET> tag allows Java applets to be embedded in Web pages.

Another tag is needed to include the variety of file formats potentially supported by plug-ins in Web documents. This requirement is fulfilled by the <EMBED> tag.

The <EMBED> tag is similar to the <IMG> tag and the <APPLET> tag. It allows the embedding of a file supported by a plug-in to be downloaded when the page is being rendered by the browser and displayed within the Web page.

The tag takes the following attributes:

For example, the following HTML code would produce results similar to those shown in Figure 16.2. if a QuickTime-capable plug-in were installed in Navigator:

<BODY>
This is a QuickTime movie:<BR>
<EMBED SRC="sample.qt" WIDTH=100 HEIGHT=100 UNITS=pixels>
</BODY>

Figure 16.2. The <EMBED> includes plug-in objects in Web pages.

By changing the WIDTH and HEIGHT tags, the size of the displayed image is changed. For instance, changing WIDTH=100 to WIDTH=300 would stretch the resulting display area on the horizontal axis.

Figure 16.3. The WIDTH and HEIGHT attributes of the <EMBED> tag can change the size of the display area.

In addition, plug-ins can define their own custom attributes to be included in the <EMBED> tag. Navigator ignores these and passes them straight to the plug-in for processing.

The <NOEMBED> Tag


Similar to frames where the <NOFRAMES> tag provided a mechanism to include alternate HTML code for browsers that don't support frames, the <NOEMBED> tag enables authors to specify HTML code to display in browsers that don't support the <EMBED> tag, and therefore don't support plug-ins.

For example, the HTML code

<BODY>
This is a QuickTime movie:<BR>
<EMBED SRC="sample.qt" WIDTH=100 HEIGHT=100 UNITS=pixels>
<NOEMBED>
<H1>Sorry!</H1>
You need a plug-ins capable browser.
</NOEMBED>
</BODY>

displays the text "Sorry! You need a plug-ins capable browser." in browsers that don't support the <EMBED> tag.

Figure 16.4. The <NOEMBED> tag defines text to display when a browser doesn't support plug-ins.

Using Plug-ins in JavaScript


JavaScript includes two objects—mimeTypes and plug-ins—which can be used in scripts to determine if specific plug-ins or MIME types are supported. Both are properties of the navigator object.

The plugins Object


The plugins object is an array of plugin objects, reflecting each of the available plug-ins in the browser.

For instance, the first plug-in in a document could be accessed with document.plugins[0]. As with applets, plug-ins also can be referenced with the name specified in the NAME attribute of the <EMBED> tag. For the plug-in object,

<EMBED SRC="srcFile" NAME="samplePlugin" HEIGHT=100 WIDTH=100>

the associated plugin object is document.samplePlugin.

Each plugin object has five properties:

It is also possible to check for the existence of a particular plug-in by evaluating the plug-in object itself. The code segment

if (navigator.plugins["ShockWave"])
   document.writeln('<EMBED SRC="sample.dir" HEIGHT=50 WIDTH=50>');
else
   document.writeln('Install the Shockwave plug-in');

outputs the appropriate HTML, based on the existence of the Shockwave plug-in.

Figure 16.5. Using JavaScript, it is possible to embed plug-in files only when the plug-in is available. Otherwise the user can be told to install the plug-in.

The mimeTypes Object


mimeTypes is an array of all the MIME types supported by the browser through any means, including plug-ins and helper applications. Each MIME type is represented by a mimeType object. The array itself is indexed by number or by MIME type names.

The mimeType object has three properties:

For instance, for TIFF images, navigator.mimeTypes["image/tiff"].suffixes might have the value "tiff, tif" and navigator.mimeTypes["images/tiff"].description might be equal to "TIFF Image".

Plug-ins and LiveConnect


Just as LiveConnect allows Java and JavaScript to communication, LiveConnect provides similar capabilities for plug-ins.

The basic LiveConnect model allows two-way communication between Java and plug-ins and between Java and JavaScript. Because Java and JavaScript are tightly integrated, JavaScript is able to call plug-in functions that have been made available to the Java Environment.

Figure 16.6. LiveConnect puts Java at the center of communication between JavaScript and plug-ins.

The Java Runtime Interface

The core of LiveConnect is in the Java Runtime Interface (JRI). The JRI makes it possible for so-called native methods written in C or C++ to be called from Java. These native methods can be part of plug-ins.

The technical use of the JRI requires knowledge of C or C++ and is beyond the scope of this book.

Calling Native Methods from Java and JavaScript

Although this book doesn't cover the mechanics of writing native methods into plug-ins, an increasing number of third-party plug-ins make native methods available to the Java environment. Being able to call these methods from JavaScript is important.

The Java environment includes the netscape.plugin.Plugin class. Each plug-in is an instance of this class. Individual plug-ins—and their available native methods—can be accessed through the documents.plugins array.

For instance, most versions of Navigator 3 come with the LiveVideo plug-in. This plug-in's object is accessible in Java (and therefore in JavaScript).

The LiveVideo plug-in documentation indicates that it makes four native methods available to the Java environment:

Using these methods, it is possible to use JavaScript to create a simple control panel for an embedded audio file:

<BODY>
<EMBED SRC="demo.avi" NAME="testVideo" HEIGHT=100 WIDTH=100>
<FORM>
<INPUT TYPE=button VALUE="Play" onClick="document.plugins[0].play(false);">
<INPUT TYPE=button VALUE="Stop" onClick="document.testVideo.stop(false);">
</FORM>
</BODY>

This file uses JavaScript event handlers to provide control buttons for the video file specified in the <EMBED> tag.

Figure 16.7. JavaScript can be used to call native methods in plug-ins.

Creating Your Own Plug-ins


The process of creating plug-ins requires knowledge of C or C++ and, as such, is beyond the scope of this book. However, a more general discussion of how plug-ins are created should help you understand the way they fit into Navigator and LiveConnect.

Plug-ins are platform-specific code libraries that are dynamically loaded by the browser as needed. Plug-ins are written based on an Application Programmers Interface provided by Netscape. There are different plug-in APIs for the Windows, Macintosh, and UNIX versions of Netscape and while they are not identical across platforms, Netscape says that the plug-ins are designed to be functionally equivalent across platforms while maintaining flexibility for developers.

The APIs provide several areas of functionality:



Note:

Netscape's documentation for the plug-in API is available on the Web at http://home.netscape.com.eng/mozilla/3.0/handbook/plugins/index.html.


Developers who want to experiment with plug-in development should download the Plug-in Software Development Kit from Netscape. Three kits are available—Windows, Macintosh, and UNIX.

Things Plug-ins can do


There are several things that the programmer can do to customize his or her plug-in. Plug-ins can have different appearances, can open data streams from the network or the local file system, can extend the <EMBED> tag to allow HTML files to pass parameters to the plug-in, and can be automatically installed when the user first accesses a new data type.

Plug-in Appearance

In it's current form, the plug-in API provides two different appearances to plug-in developers: Embedded and full-page.

Embedded plug-ins are used as part of larger HTML documents. The plug-in is given a rectangular space on the page for its display and works strictly within this area. These plug-ins are specified with the <EMBED> tag discussed earlier.

By contrast, full-page plug-ins are for document types that won't be embedded as part of an HTML document. These plug-ins are displayed in the entire inner frame of a Navigator window.

Plug-ins also can be used in a hidden mode by specifying HIDDEN=TRUE in the <EMBED> tag. Hidden plug-ins run in the background without any display. These could be used, for example, for audio players.

Data Streams

One of the primary functions of plug-ins is to perform network access. Plug-ins can request URLs for which a data stream is opened and the data made available to the plug-in as it arrives.

Plug-ins can request as many streams as the host Navigator browser has been configured to allow. The data received in a data stream for a plug-in is cached like other data fetched by the browser.

Streams can be opened in two modes by a plug-in: Push mode—where the plug-in is provided data as it arrives from the server, and pull mode—where the plug-in explicitly requests data as it needs it.

Assisted Installation

Plug-ins need to be installed in the correct directory for them to be available to the browser. This can be done manually by the user or automatically, with an installation program provided by the plug-in developer.

Alternately, Netscape provides an assisted installation feature. The system is simple:

  1. The HTML page author uses the PLUGINSPAGE attribute of the <EMBED> tag for the document. The attribute specifies a URL for a page, with information about how to download and install the plug-in.

  2. When the user requests the page with the embedded document, Navigator presents a dialog box that enables the user to go to the URL containing more information about the plug-in.

  3. If the user chooses to go to the URL specified in the PLUGINSPAGE attribute, he or she can download and install the plug-in and then restart Navigator.

  4. If the user chooses cancel in the dialog box, Navigator won't prompt the user with the dialog box in the future.


Summary


Plug-ins extend Navigator's ability to handle new MIME types. Plug-in objects can be embedded in Web pages using the <EMBED> tag, and text for other browsers can be provided with the <NOEMBED> tags.

JavaScript and Java can communicate with plug-ins which have native methods, and plug-ins can make calls back to the Java environment.

In the next section, the methods and technique discussed up to this point will be applied to a variety of example applications, including a multi-lingual interface, a solitaire game, and a search engine interface.

Previous Page Page Top TOC Next Page See Page