/*  Unplugged.java by Mark D. LaDue */

/*  April 15, 1998 */

/*  Copyright (c) 1998 Mark D. LaDue
    You may study, use, modify, and distribute this example for any purpose.
    This example is provided WITHOUT WARRANTY either expressed or implied.  */

/*  This applet conspires with JavaScript to count the number of plugins
    that are installed with your Communicator and gives their full path
    names on your system.  Note that JavaScript is allowed to do this,
    while Java applets alone are not.  It then goes on to report how many
    entries are in your browser's history at the moment, though this
    is not supposed to be allowed.  To see how JavaScript helps the applet,
    take a look at Unplugged.html. */


import netscape.applet.*;
import netscape.javascript.*;

public class Unplugged extends java.applet.Applet implements Runnable{

    Thread controller = null;
    JSObject jso = null;
    int numplugs = 0;
    String npname = null;
    String[] plugs = null;
    int histlen = 0;


    public void init() {

        jso  = JSObject.getWindow(this);

    }

    public void start() {

        if (controller == null) {
        controller = new Thread(this);
        controller.start();
        }

    }

    public void stop() {}

    public void run() {

        Control.showConsole();

        numplugs = (new Float((jso.eval("pcount()")).toString())).intValue();
        System.out.println("\nTotal number of plugins: " + numplugs + "\n");
        plugs = new String[numplugs];
        for (int i = 0; i < numplugs; i++) {
            plugs[i] = (String) jso.eval("nextPlug()");
            System.out.println("Plugin " + (i+1) + ": " + plugs[i] + "\n");
        }

        histlen = (new Float((jso.eval("hcount()")).toString())).intValue();
        System.out.println("Total number of history entries: " + histlen);

    }
}
