[webkit-dev] opera unite api: extensions to add web server capability to browser engines

Luke Kenneth Casson Leighton lkcl at lkcl.net
Tue Jun 16 07:10:18 PDT 2009


http://dev.opera.com/libraries/unite/

this is a stunningly cool idea, so much so i had to let people know
about it and invite webkit developers (i'll ping the mozilla ones
separately) to provide an implementation, too.  the key bit is best
hinted at from http://dev.opera.com/articles/view/opera-unite-developer-primer/
- exerpt here:


The request event listeners

A Web server handles requests from clients and sends reponses back to
them. The Opera Unite Web server is event-based and will raise a DOM
event in the service every time a Web browser makes a connection to
the server asking for files related to the Opera Unite Service. In
order to respond to such events, we need to set up event listeners.
This is done in window.onload:

var webserver;
var entries = [];

window.onload = function () {

    webserver = opera.io.webserver

    if (webserver)
    {
        //Handle requests for various URLs
        webserver.addEventListener('_index', showEntryList, false);
        webserver.addEventListener('entry', showEntry, false);
        webserver.addEventListener('form', showForm, false);
        webserver.addEventListener('save', saveEntry, false);
    }
}

What is going on here?

We are checking if the service is actually a Web service, by checking
for the webserver object. If it is present, we add four event
listeners _index, entry, form and save.


The code for the _index request, the showEntryList function, is quite
simple. When receiving a request, it writes back a HTML page with a
list of the saved entries.

function showEntryList(e)
{
    var response = e.connection.response;
    response.write( '<!DOCTYPE html>'
        + '<html><head><title>Entries</title></head>'
        + '<body><ul>'
    );

    for ( var i = 0, entry; entry = entries[i]; i++ )
    {
        response.write('<li>'+entry.date+': <a
href="entry?id='+i+'">'+entry.title+'</a></li>');
    }

    response.write('</ul>'
      + '<p><a href="form">Add en entry</a>.</p>'
      + '</body></html>'
    );
    response.close();
}


in other words, this really is an actual implementation of a web
server - in javascript - as part of the opera browser engine itself.

implementation details of the proxy service, operaunite.com, are
understandably sketchy.  it provides firewall-busting technology which
duh is kinda important to have, otherwise everyone running private web
services in their browser are completely inaccessible.

i can think of a ton of uses for this, well beyond just a few "web
pages".  if implementations are made truly peer-to-peer (and not
dependent on operaunite.com) then ... dang.

imagine for example the combination of xmpp, unite, and google wave services.

l.


More information about the webkit-dev mailing list