Guile Applet Specification

Cygnus Support, March 22, 1996
(Gordon Irlam, gordoni@cygnus.com)

This document provides the specification for writing Guile applets for use with the SurfIt! demo browser.

HTML Applet Extension

Guile Scheme applets are denoted by the mime type application/guile. This is the default type for the file extension .scm.

An applet can be inlined within a HTML document.

<a href="applet.scm" rel=embed>
fallback_html
</a>
The applet applet.scm will be loaded, inserted into the page, and run when the document containing it is first loaded. fallback_html will be displayed by browsers that don't support Guile applets.

An applet may also be invoked when a hyperlink is followed.

<a href="applet.scm"
fallback_html
</a>
When the hyperlink is selected the applet applet.scm will be loaded and executed. The original document will be cleared from the page only if the applet explicitly requests it to be. fallback_html will be displayed by browsers that don't support Guile applets.

Applet Requirements

An applet is required to be a syntactically well formed Guile Scheme program. When an applet is invoked the corresponding Guile program is retrieved, loaded, and executed.

Every applet is required to include the applet library:

(require 'applet)
Incorporate the applet library into a Guile application. This is needed as a prerequisite to performing any of the other applet commands.

Every applet is required to define a routine to be called by the browser when the browser requires the applet to terminate execution:

(define-applet-terminate routine)
If used, this routine should be called by an applet when it first starts executing. routine is a routine having no arguments that will be invoked by the browser when the applet is required to terminate execution. If the applet is visible it should destroy the Tk canvas upon which it is visible, free up any other resources it might have allocated, and then exit.

An applet will persist for as long as it is accessible -- either externally through it's being displayed on a page, or internally through the Scheme environment.

Applet API

All applets reside in the same top level environment. This allows state to be shared between applets and to persist between applet invocations.

An applet has access to all the features of a regular Guile Scheme program and to the gtcl/gtk Guile extensions. The features of gtk allow the Guile applet to interactively display itself within the parent document.

Note: While Guile provides the ability to control namespaces, and this is necessary to provide a secure environment within which applets can be run, this has not been done for the SurfIt! Guile demo browser. The SurfIt! Guile demo browser is mainly intended as a research prototype, not a production web browser.

browser-window-name
(browser-window args)
browser-window-name is a string containing the Tk window name of the browser window. browser-window is the corresponding Tcl proc to which window commands can be sent.
applet-window-name
(applet-window args)
applet-window-name is a string containing a Tk window name for a frame that can be used to contain the applet. applet-window is the corresponding Tcl proc to which window commands can be sent. The frame still needs inserting into the browser window, assuming the applet is visible.
applet-embedindex
applet-embedindex is a string containing the offset within the browser window of the applet's anchor. Most commonly this is used when insert the applet into the browser window at the same location as the original html:
(browser-window 'window 'create applet-embedindex
:window applet-window-name)
.
(applet-newpage)
This routine clears the current contents of the browser window.
(applet-parsehtml html)
This routine parses the html text specified by html and renders the result adding it to bottom of the browser window.
(applet-loadurl url)
This routine initiates the loading and rendering in the applet window the contents of the object specified by URL url retrieved using a HTTP GET request. This routine is equivalent to (applet-loaddata url applet-parsehtml).
(applet-loaddata url callback)
This routine initiates the loading of the object specified by URL url using a HTTP GET request, and then immediately returns. Later on, once the object has been fully loaded, (callback result) will be asynchronously invoked, with the string result containing the data for the requested object.
(applet-posturl url datavar postdata)
This routine initiates the loading and rendering in the applet window the results of posting postdata to the URL url using a HTTP POST request. datavar is a string containing the name to use for a global Tcl variable that accumulates intermediate results. postdata must be an association list of the form ((name1, value1), (name2, value2), ...) mapping from unencoded strings representing field names to unencoded strings representing the data values associated with these field names. This routine is equivalent to (applet-postdata url datavar postdata applet-parsehtml).
(applet-postdata url datavar callback postdata)
This routine initiates the posting of postdata to the URL url using a HTTP POST request, and then immediately returns. Later on, once the resulting return value has been fully loaded, (callback result) will be asynchronously invoked, with the string result containing the resulting data. datavar is a string containing the name to use for a global Tcl variable that accumulates intermediate results. postdata must be an association list of the form ((name1, value1), (name2, value2), ...) mapping from unencoded strings representing field names to unencoded strings representing the data values associated with these field names.

Applet Behavior

Applets should not monopolize the cpu. Instead they should be written using a callback or event loop polling based style so that the Tk event handler can continues to operate, and the user can continue to interact with the browser.

Browser Behavior

An run time error occurring within an applet that goes uncaught will cause the applet to exit, but the browser will continue to function.