Hi,
I've been working on designing an alternative/counter-proposal to the
Web Intents specification [1] in order to be able to use Activies in B2G.
This version (v0) aims to solve the use cases of installed applications.
That means it is not handling registering story for non-installed
applications. Adding this part shouldn't change the general API. It is
mostly a matter of choosing between a <meta> directive and/or JS
methods. I'm not including this in this version so consensus will be
easier to reach.
** The name **
I named this API Web Activities instead of Web Intents because I think
"activity" is a better name than "intent". I don't know if "intent" is a
clear name for native English speaker but it's kind of vague for me.
Note that the Web Intents specification is coming from Google so we can
imagine that they just took the name from Android APIs and in Android,
intents have actually a very vague meanings: they can mean activity or
events.
In addition, the scope of this API is different from the scope of Web
Intents as proposed by Google [1]. Given that, picking a different name
seems less confusing.
** The scope **
NOTE: as said above, the v0 of this API doesn't take into consideration
non-installed web applications which might want to handle activities. It
will be handled in the v1 but that is still in the scope of the API.
This API is trying to solve simple use cases like:
- SHARE something from APP A; APP A will put in |data| the stuff it
wants to share and send it to APP B which is going to handle the sharing.
- EDIT something from APP A; APPP A will put in |data| the stuff it
wants to edit and send it to APP B which is going to handle the edition.
APP B will then send back the edited |data| in |request.result| to APP A.
- PICK something from APP A; APP A will start an activity and APP B will
handle the file picking and return it to APP A.
- etc.
Basically, an activity can be started from an application which is going
to attach data or not and the application handling the activity can pass
back data when done.
The major difference with Web Intents is that I do not believe we need
to handle a situation where APP A and APP B have to dialog. All examples
I've seen seem to be out of scope of Activities/Intents. For example,
this one [2] should be changed to have APP A asking to VIEW a video and
APP B handling the control of the video and the communication with the
device. There is no reason to have APP A handling the controlling. If
APP B wants to expose an API for that, I don't think there is any reason
why Intents should be involved.
I've seen another use case for application dialog: APP A asking APP B to
edit an image but instead of letting APP B to handle the edition, APP A
actually send messages to APP B to say what it should do. That seems
pretty weird. That also means APP A is in foreground and has the focus
while as I see it, APP B should be bring to foreground when APP A starts
the activity...
** Activity **
An activity is defined by:
- an action which is a string that can be "share", "view", "edit" or
even "foobar". The specification should define a few actions but any
string should be allowed except the empty string;
- a type which is a mime type like "foo/bar", "image/png";
- some |data| that can be an URL, an object or anything.
Action and data are related. That means an application handling action A
will except |data| to be in a specific format. The specification will
have to define how |data| should look like for pre-defined actions.
Web Intents defines an |extra| attribute which comes directly from
Android. Given that we can pass whatever we want in |data| that seems a
bit weird to have |extra|.
** Starting an activity **
Starting an activity can be done in two ways:
startActivity(action, type, data)
or
startActivity(activity)
The method will return a |DOMRequest|. When the activity will be done,
the |result| attribute on the request will contain the data sent back if
the activity has been successful. If there was an issue, the |error|
attribute will be filed with a string.
** Handling activities **
When an application will be opened to handle an activity, an "activity"
event will be sent to the |window|. This approach seems better than
adding a new property on the |window| object. However, we will have to
define clearly when this event should be sent (before or after the load
event for example).
The event will contain an object with an |activity| property which is
going to contain the activity object as created by the startActivity
method. Also, the object will have two methods: |postResult| and
|postError| that will have to be called to send back data to the calling
application.
** Registering activity handling **
For the moment, this part concerns only installed applications. We
should add a new property to the OWA Manifest to be able to declare that
the application handles some activities. It would look like this:
"activities": {
"share": {
"type": ["foo/bar", "image/png"],
"href": "foo.html",
"disposition": "window" // or "inline"
}
}
** Overview of the API **
interface Activity {
readonly attribute DOMString action;
readonly attribute DOMString type;
readonly attribute any data;
};
[NoInterfaceObject]
interface NavigatorActivity {
// .result contains the data sent back.
DOMRequest startActivity(action, type, data);
DOMRequest startActivity(activity);
// COMMENT:
// We could add registerActivityHandler, unregisterActivityHandler and
// isActivityHandlerRegistered methods later if needed.
};
Navigator implements NavigatorActivity;
[NoInterfaceObject]
interface WindowActivity {
attribute Function onactivity;
};
DOMWindow implements WindowActivity;
[Constructor(Activity activity)]
interface ActivityEvent : Event {
readonly attribute Activity activity;
// COMMENT: data will go to request.result.
void postResult(any data);
// COMMENT: data will go to request.error.
void postError(DOMString data);
};
As usual, feedback is welcome! :)
[1]
http://dvcs.w3.org/hg/web-intents/raw-file/tip/spec/Overview.html
[2]
http://www.w3.org/wiki/WebIntents/Home_Discovery_and_Web_Intents#Use_case:_push_play
Cheers,
--
Mounir