* MessagePort isn't compatible with the structured clone algorithm
* requires two separate messaging mechanisms, postResult and
port.postMessage, depending on chattiness, rather than one that works
regardless
* initial data cannot be passed via `window.intent.data` since it has
to hold the MessagePort
* service needs to check `window.intent.data instanceof MessagePort`
* client cannot end or cancel the interaction, only the service can
(via postResult)
There is also no support for letting the service and UA know whether
response data is expected back. The UA needs to know this because if
it is "fire and forget", then the service browsing context should
remain open until it is explicitly closed by the user. If it is *not*
"fire and forget", the UA should close the service browsing context
and focus the client browsing context anytime the client and service
can no longer communicate with one another. In the case of "fire and
forget", the UA could even allow the user to choose multiple services
if they want. This would be similar to the "broadcast" method in
android.
Since messaging is an orthogonal issue to finding a matching service
for a given intent, we should let web messaging do as much of the work
as possible. One way to do this would be to change the optional
onResult argument to `window.navigator.startActivity` to an optional
onMessage argument, which if passed causes a MessageChannel to be
created whose port1's "onmessage" attribute is set to the onMessage
argument and returned from startActivity, and whose port2 is assigned
to `window.intent.source` in the service browsing context. If the
ports become disentangled (via either side calling its port's "close"
method or the client browsing context closing, then the service
browsing context will be closed. This approach should solve the
problems mentioned above with the current approach.
Examples:
Share:
// client: fire and forget
window.navigator.startActivity(new Intent(http://webintents.org/share,
"text/uri-list", "http://news.bbc.co.uk"));
...
// client: success response expected
var intent = new Intent(http://webintents.org/share", "text/uri-list",
"http://news.bbc.co.uk");
var onMessage = function(event) { event.data && log("success!");};
var port = window.navigator.startActivity(intent, onMessage);
...
// service
var success = share(window.intent.data);
var source = window.intent.source;
if(source) {
source.postMessage(success);
source.close();
}
Chatty intent:
// client
var onMessage = function(event) {
shouldContinue(event.data) ? event.source.postMessage(foo()) :
event.source.close();
};
var port = new Intent(onMessage).startActivity(new
Intent("http://chattyintent.org", "*", initialData), onMessage);
...
// service
var message = handleInitialData(window.intent.data);
var source = window.intent.source;
if(source) {
source.onmessage = function(event) {
shouldContinue(event.data) ? event.source.postMessage(foo()) :
event.source.close();
}
source.postMessage(foo());
}
One addition to the web messaging spec that would be nice would be a
"close" event on MessagePorts so you can know when a port has become
disentangled, which in this case would correspond to when the service
browsing context is closed.
Thanks,
Sean Eagan