I have a similar model in mind; when a document is recieved, it is sent out
to different modules depending on the content type. So anything with a type
of 'text/html' would be sent to the HTML browser, one with 'image/gif' would
be sent to a GIF viewer, etc.
The HTML browsing module consists of two parts: a dispatcher and one or more
viewers. The dispatcher has a mapping table associated with it; when a document
comes in, it looks in the table to see which viewer that document should be
sent to. If there is an entry, it sends the document there; otherwise it
creates a new viewer. Here is part of the code:
url_index={}
def Register(url, callback):
url_index[url]=callback
def Display(url, name, (file, header)):
data = getdata(file)
if url in url_index.keys():
showurl = url_index[url]
del url_index[url]
showurl(name,data, file, header)
else:
window = HTMLWindow()
window.showurl(name, data, file, header)
RegisterExtension(('html','text'), Display)
RegisterContentType(('text/html','text/plain'), Display)
When 'Display' is called, it checks the index to see if the document's
URL (HREF? I'm not sure of the correct terminology) has been registered; if
so, it sends the document to that window. Otherwise, it creates a new window
and sends the document there.
Of course, this requires that a document's URL be registered if you want it
to appear in the same window.
> Steve, you seem to suggest that :
>
> - there is only one viewer instance, which handles all docs of a
> particular type (you say `URL' but that can't be right)
Sorry; wrong word. Content types are linked to a particular module which
handles
it; there may be multiple content types that can be displayed with a particular
module.
> - its single window is registered with the browser by some means
> outside of the program (you say `HTML browser', don't you mean
> `WWW browser'?)
There can be multiple windows. I'm not sure whether the correct terminology
is "HTML browser" or "WWW browser"; I'm referring specifically to a browser
which displays HTML (and text/plain, but that isn't important to the topic
at hand.)
> - in-lined material
If you mean tags like <IMG SRC=...>, the model allows you to specify a callback
when the document has been retrieved, instead of the normal handling. (This
is how downloading is implemented; the document is requested with a callback
saving the data on disk instead of trying to create a viewer for it.)
Hope this helps,
Steve