Hi,
There was quite interesting feedback from Salvador, Fernando and
Francisco regarding the Inter Application Communication to make it more
Web-y.
Trying to come up with APIs that would work as well in the Web than in
our app ecosystem is something I would like to do more. Generally
speaking, I would like to see the "apps" as the Web and not do this
distinction any more in API we design.
In the past I thought about using XHR instead of the IAC API but there
are some high level issues that would need to be solved. However, I
think that we can give this a try...
Currently, the Web allows communication between different parties using
XHR. From a Web Client, you can do various things trough a REST API by
communication with a given Web Server. A Web App can be considered as a
Web Client and as a basic Web page, it can use XHR to communicate with a
given Web Server. But you can't use XHR to communicate with a Web App.
To summarise, we have:
Web Client <-- XHR --> Web Server
Web App <-- XHR --> Web Server
Web Client <-- ??? --> Web App
Web App <-- ??? --> Web App
If we want to allow XHRs to be handled by Web Apps, we need to solve two
things: getting a Web App to behave like a Web Server and having a way
to identify a Web App.
The former problem is pretty simple to use: we can have a 'xhr' system
message that would be sent to the Web App when it will get a XHR. The
message payload will contain the XHR payload and the app will have to
reply following a certain payload format, as usual.
The later problem is the real one: in the Web, we identify things using
URIs but this doesn't work that well with our application system. Hosted
applications have a URI identifier that is a manifest and their origin
can't be differentiated from a simple web page. And packaged
applications doesn't really have a URI (it is random).
Regarding, packaged applications, they are already not part of the web
and I wouldn't feel bad if we have them opt-in only when they have a
deterministic origin (ie. when the manifest has an origin set and it is
allowed by the runtime).
Hosted applications are more tricky. How to know if a XHR to
"
http://example.com/foo/bar/" should go to "
example.com" or the
application at "
http://example.com/manifest.webapp"? My first thought
would be to say that the UA will redirect the XHR to the application if
it has an application installed under that origin but that might not
work for a couple of reasons.
First of all, there are some REST API that are available at
"
api.example.com" (or another subdomain) like flickr [1] and as a
consequence, a flickr app (in
www.flickr.com) wouldn't be able to handle
requests to
api.flickr.com.
Secondly, the opposite situation might be true: some XHR might end up to
the application while it is not expected. This could be easily fixed by
simply forwarding the call to the actual server from the application but
it can be a source of bugs.
A proposal to solve this could then be to add a "xhr" entry in the
manifest that says which origin the application would like to "capture"
if a XHR is performed. On top of my head I believe that we could require
those origins to be same domain but if we go forward with that idea, our
security team should have a look into this.
Note that with the intent of moving the manifest to normal web pages
[2], we might end up with web pages handling XHR themselves :)
Finally, with a system like that in place, the latest feature to be
complete would be services discoverability. That might still have some
security issues related to it.
All of this written, we should consider the implication of something
like that for the general platform and I would be more comfortable with
a system that would be limited to a subset of apps to start with in
order to experiment before pushing something new and experimental to the
Web.
WDYT?
[1]
https://www.flickr.com/services/api/request.rest.html
[2]
http://mounir.lamouri.fr/2013/05/the-web-manifest.html
--
Mounir
>> I like the concept of the Inter-App Communication API, but I also
>> really like the idea of having this API functions related to HTTP
>> verbs as Francisco mentioned before. Why not allowing apps to expose a
>> REST API to be consumed by other apps? It would be great to have an
>> API that allows web apps to easily expose web services in a secure
>> way. I am not sure if this could be an alternative to the proposed IAC
>> API or yet another API for inter app communication, but I would love
>> something like (trying to elaborate Francisco's examples a bit more):
>>
>> // The first parameter is the origin of the app exposing the web
>> service. The origin could also be an http(s) origin.
>> // The second parameter is an array of API functions to be consumed.
>> // **The user will be explicitily asked to allow permissions for these
>> functions**.
>> let webService = navigator.getWebService("app://
email.gaiamobile.org",
>> ["send", "emails"]);
>>
>> // Send a new email.
>> webService.post("send", { ... });
>>
>> // Get email with id.
>> let email = webService.get("emails/id/123");
>> // Get emails from
ferjm...@gmail.com
>> let emails = webService.get("emails/from/
ferjm...@gmail.com");
>> // Get emails received since 23 May 2013.
>> let emails = webService.get("emails/latestEmailsSince/1369305573");
>>
>> // An app could also subscribe to notifications about changes in the
>> content shared by
>> // the web service or events related to its functionality.
>> webService.subscribe("new-email", function onNewEmail() {...});
>>
>> // So the app exposing the web service could notify about these
>> changes/events.
>> navigator.notifyWebServiceObservers(["new"], {...});
>>
>>
>> The manifest of the app exposing the web service could include
>> something like:
>>
>> "webservice": {
>>
>> "api": {
>> "send": {
>> "allowed-actions": ["post"],
>> "allowed-apps": "privileged",
>> "permission-details": "Allow apps to send new
>> emails"
>> },
>> "emails": {
>> "allowed-action": ["get"],
>> "allowed-apps": "installed",
>> "permission-details": "Allow apps to read the
> ________________________________
>
> Este mensaje se dirige exclusivamente a su destinatario. Puede consultar
> nuestra política de envío y recepción de correo electrónico en el enlace
> situado más abajo.
> This message is intended exclusively for its addressee. We only send and
> receive email on the basis of the terms set out at:
>
http://www.tid.es/ES/PAGINAS/disclaimer.aspx