Integrating applications and the World Wide Web


Matthijs van Doorn
Vrije Universiteit
Faculty of Mathematics and Computer Science
De Boelelaan 1081a
1081 HV Amsterdam
The Netherlands
thijs@cs.vu.nl
http://www.cs.vu.nl/~thijs/

Anton Eliëns
Vrije Universiteit
Faculty of Mathematics and Computer Science
De Boelelaan 1081a
1081 HV Amsterdam
The Netherlands
eliens@cs.vu.nl
http://www.cs.vu.nl/~eliens/


Abstract:
This paper describes how to integrate the World Wide Web (WWW) with applications. By means of the web widget, which is part of Hush, the WWW is made available to Tcl/Tk/Hush programmers. Apart from using WWW as part of an application, it also allows one to embed scripts into a web page. This results in a mutual integration of applications and the WWW.

Both forms of integration will be described. Some new possibilities of embedded scripts such as inline MPEG, interactive games and navigation facilities will be discussed.

Keywords:
WWW, embedded scripts, integration, Hush, Tcl/Tk

What is Hush?

Hush (Hyper Utility Shell) is a C++ library that can be used to build applications with a graphical user interface. It contains classes that provide convenient yet flexible access to the functionality offered by the Tcl/Tk toolkit and its extensions. Tcl is an interpreted script language, Tk is a window and graphics toolkit based on X11. Hush provides a C++ class interface on top of Tcl/Tk. It provides flexible access to script languages. Not only Tcl, but also other script languages such as Python are supported. New widgets, written in C++, can be accessed from the script language.

The Hush library is intended to support the needs of both novice and experienced (window) programmers. Although Hush can be used to write all sorts of programs with a graphical user interface, it mainly focusses on hypermedia applications (i.e. the combination of hypertext and multimedia).

Currently Hush provides several hypermedia extensions, including a MPEG widget. MPEG is a widely used video standard. Hush also includes a C++ API and a Tcl interface for Csound, a software sound synthesis package developed at MIT's Media Lab. Another extension is the web widget, described in this paper, which gives access to the World Wide Web.

World Wide Web

The "World Wide Web", also refered to as WWW, W3 or simply "The Web", is a distributed hypermedia project started by CERN. To access WWW, you need a browser program (e.g. Mosaic). The browser can fetch documents from servers set up by information providers.

An important feature missing in current WWW browsing systems is the lack of integration with other applications. That should change, because the WWW can be a very valuable part of an application. This paper describes two forms of integration:

Using WWW as part of an application

Starting up a separate browser from an application is not the most natural way of accessing information. Users who are viewing information should not necessarily be aware of the fact that the documents are coming from the World Wide Web. Therefore it is desirable that the WWW can be accessed as an integral part of an application. The web widget can be used to accomplish this.

The Tcl/Tk/Hush environment offers numerous widgets which can be used to build a graphical user interface, e.g. button, scrollbar and listbox. These widgets are not only accessible from a Tcl script, but also from C++ (because of the Hush API). The web widget is a new widget, implemented in C++. It can be used exactly the same way as a standard widget in Tcl/Tk.

The following Tcl-script builds a very simple WWW browser by creating a web widget together with a back button:

    web .w -home "http://www.cs.vu.nl/"
    button .b -text "Back" -command {.w back}
    pack .w
    pack .b
The '-home' option is used to specify the URL of the home page. If the button is pressed, the attached command ".w back" will be executed. This will notify the web to go one page back in history. The "pack" commands place the created widgets on the screen.

The previous example was written in Tcl. In C++ the same functionality can be achieved as follows:

    web *w = new web(".w");
    w->home("http://www.cs.vu.nl/");
    button *b = new button(".w", "-command {.w back}");
    b->text("Back");
    w->pack();
    b->pack();
Note that ".w back" is still a Tcl command. It is also possible to bind a C++ handler function or object to the button.

The web widget makes it possible to access the WWW from within an application. It can be used to view HTML files which are stored locally, but because of the network facilities the information can also be retrieved from servers all over the world. For example, it is possible to provide all on-line help as WWW-pages. Advantages of this approach are:

Of course usage of the WWW within an application is not limited to on-line help. It can also be used to provide other information, to represent the output of some processes (e.g simulations) or the web widget may simply be used for it's hypertext capabilities without employing the network.

Because the web widget itself runs in the same Hush environment as the program, the look-and-feel of the browser can be adjusted to fit the needs of the situation.

Embedding scripts into WWW pages

The previous section described the usage of the WWW as part of a program. It dealt with the integration of WWW in an application. There is however another form of integration as well: integrating a program into a WWW page.

Most graphical based WWW browsers support inline images with the <img> tag. Using inline images can result in attractive web pages. It would nice if other kind of objects could be embedded as well (for example videoclips). Allowing to embed an arbitrary script with commands is even better, because this way almost anything can be included as an inline object in a web page. Otherwise a new version of a browser should have been made to enable the embedding of a new kind of object.

The web widget makes it possible to embed an arbitrary script. The script is executed when the page is displayed. Currently only Tcl-based scripts can be used, but using other languages should be possible as well, because the Hush framework also supports other script languages.

To include a Tcl-script in a web page, HTML is extended with a new tag <hush>. It supports an attribute 'tcl', which contains the Tcl code that will be executed. For example, to include a button in a web page, the following HTML code can be used:

    <hush tcl="button $this.b -text {Hello}; pack $this.b">
    </hush>
This creates a button called "$this.b". The variable 'this' always contains the name of a frame in which the embedded object should be packed. Note that the contents of the 'tcl' attribute is a normal Tcl-script. It can be used in a standard Tcl-interpreter without modification, except that the 'this' variable should be set. Any Tcl-script can be embedded in a web page this way, almost without modifications. The only necessary change is the usage of the 'this' variable to specify the root-window in which all created widgets should be packed. A well written Tcl-program already uses a similar method, because the same kind of modification would be necessary to place an already existing Tcl-script in a toplevel (a separate window) instead of the root frame (which is standardly called '.').

We left unmentioned why the <hush> tag requires a closing </hush>. If something is put between <hush> and </hush>, it is ignored by the web widget. However, other browsers which ignore the <hush> tag (such as Mosaic) do display the intermediate text. Therefore it can be used to specify a message for backward-compatibility. E.g.:

    <hush tcl="...">
    Sorry, this browser does not support the <em>hush</em> tag.
    </hush>

Examples of embedded scripts

We will now take a look at how embedded scripts can be used to enhance the functionality of a web page.

Figure 1
Figure 1 shows an screendump of a WWW page with an inline MPEG videoclip, including play, pause and stop buttons. It is implemented by including a '<hush>' tag in the HTML file:

    <hush tcl="source /usr/local/demo/mpeg.tcl">
    Sorry, this browser does not support inline MPEG
    </hush>
The Tcl 'source' command reads and executes the given file.

Figure 2
Figure 2 demonstrates how inline sound can be added to a web page. When the page is accessed the intro-tune of 'Veronica' (a Dutch TV and radio station) is played. The following hush tag is used to embed the sound:

    <hush tcl="exec audioplay [urlfile http://www.cs.vu.nl/sounds/tune.au] &">
    </hush>
Because the audioplay command is spawned in the background (by using '&'), the sound will play simultaneously with the loading of the rest of the page (the 'urlfile' command will be explained in the next section), while normal browsers can only play sound if the user clicks on an anchor. Of course the synchronization isn't very advanced. It just gives an impression of the possibilities of inline scripts in a web page.

Figure 3
The next example (Figure 3) shows an already existing application, in this case an interactive game, embedded in a web page, with only a minor modification (the this variable). It is a variant of the nim game, in which each player has to pick one or two matches (in this case coins) in turn. The goal is to prevent that you have to pick the last coin.

We have now seen three examples of scripts which are embedded into the web page. Because both the script and the web widget itself are programmed in the same Tcl-environment, it is possible for them to act interoperable. By using the 'thiswidget' variable, the script can influence the behavior of the web widget in which it is embedded, thus enhancing the integration even more. The 'thiswidget' variable contains the path name of the web widget.

A good example of this is the following code which creates an inline back button:

    <hush tcl="button $this.b -text Back -command \"$thiswidget back\"; pack $this.b">
    </hush>
It creates a button labeled "Back", which executes "$thiswidget back" when it is pressed. Clicking it will make the web widget in which the code is embedded go back one page in history. In fact it is the back button which browsers already offer, except that it can be placed in the web page itself.

Why is this useful? A lot of pages on the web include a "go back" link to return to the previous page. The problem is that this kind of link does not have the same effect as the browser's back button, because it records the movement in the history. For example, suppose we have some information divided over four pages A, B, C and D. On each of these pages we will include a hyperlink to the next and the previous page. Suppose the user follows the path A, B, C and then clicks on the hyperlink back to page B. If (s)he then presses the browser's back button, it will take the user to page C, and not A as one would expect. This is because following a hyperlink on page C to the previous page is nothing else than moving forward to another page which already happens to be in the history. So the followed path will be A, B, C, B. If the browser's back button was used to go from C to B instead of the hyperlink, the followed path would have been A, B. Therefore it might be more convenient to use the browser's back button, and not the hyperlink to go back. However, it may be desirable to include text like "press here to go back" in your page. By offering an inline back button in the web page, this is possible.

Besides going back one page in the history, the '$thiswidget' variable can also be used to influence the browser from within a web page in some other way (e.g. changing the color of the widget, resizing the window etc).

The previous four examples just give an indication of the possibilities. In principal almost anything can be done.

Accessing remote files in Tcl scripts

It is not very convenient to include a complete Tcl-script into a HTML page, especially if the code gets bigger than the two instructions of the example above. Tcl offers a 'source' command, which executes code in a given file:
    <hush tcl="source /usr/local/www/tcl/inline.tcl">
    Sorry, this browser does not support embedded scripts.
    </hush>
This works, but the problem is that it can only be used locally. If a remote user accesses this web page, it is not possible to open the file /usr/local/www/tcl/inline.tcl because it is stored on a non-local disk. We had the same problem with the inline MPEG example above. Therefore the script should be retrieve from the remote site by using the "urlfile" command:
    <hush tcl="source [urlfile http://www.cs.vu.nl/tcl/inline.tcl]">
    Sorry, this browser does not support embedded scripts.
    </hush>
Calling "urlfile" results in getting the file of which the URL is specified in the argument, storing it locally in a temporary directory, and returning the name of this temporary file. So "[urlfile http://www.cs.vu.nl/tcl/inline.tcl]" will be substituted by e.g. "/tmp/inline.tcl", a local copy of inline.tcl. Then the "source" command is used to execute the script.

The usage of the "urlfile" command is not limited to the "tcl" attribute. It can also be used in the Tcl-script itself. For example, the contents of the "inline.tcl" script mentioned in the previous example could be:

    button $this.m -bitmap "@[urlfile http://www.cs.vu.nl/images/press_me.gif]"
    pack $this.m
This creates a button with the image "press_me.gif", which is retrieved from a remote site. The "urlfile" command allows you to split code in separate files and to use external files (e.g. images), while still being able to execute it remotely.

All filenames used in scripts should be specified as URL's, otherwise the script cannot be used by remote users, because they don't have access to the local filesystem.

Security

The embedded scripts are executed at the client's side under the user's account, not on the server's side. This is necessary because scripts require special permissions only the local user has, e.g. often graphical objects will be created on the screen. Another advantage of this client side computation approach is that it will not put extra load on the server.

But executing scripts locally which are written by some unknown remote user can be very dangerous (e.g. it could contain commands like "/bin/rm -rf *" to delete all your files). Therefore the script should be executed in an environment which assures us no damage can be done. A possible choice is Safe-Tcl.

Originally Safe-Tcl is developed to allow the sending of scripts by email that will be executed when they arrive or when the message is read (this is called active mail). Because that could cause damage, they are executed in a safe environment where all dangerous commands are removed. Almost the same security problem arises when embedding scripts in a web page. In the web widget the script should also be executed in a protected environment.

Conclusions and future plans

Integrating the World Wide Web with applications can enhance the functionality of both the application and the web. We have explored two forms of integration. First of all the WWW can be used as part of an application e.g. as on-line help which has several advantages. Secondly a script can be embedded into a web page, which offers new possibilities. We have seen some examples of embedded scripts: inline Mpeg, sound and interactive games.

Influencing the browser from the embedded script might be useful in some occasions, as we have seen in the inline back button example. The 'urlfile' command enables scripts to access remote files.

Because of the security risks that arise when executing the scripts, it is necessary to run them in a safe environment. Safe-Tcl seems to be a good starting point. Exploring this is the next step.


References


Matthijs van Doorn (thijs@cs.vu.nl), Anton Eliëns (eliens@cs.vu.nl)