WebAPI/Inter App Communication Alt proposal: Difference between revisions

no edit summary
No edit summary
 
(41 intermediate revisions by 6 users not shown)
Line 1: Line 1:
= Description =
= Description =


This proposal is just a tweaked version of the [https://wiki.mozilla.org/WebAPI/Inter_App_Communication Inter App Communication API]. Its description, intend and use cases do not defer from the previous proposal, only the API does.
This proposal is just a tweaked version of the [https://wiki.mozilla.org/WebAPI/Inter_App_Communication Inter App Communication API]. Its description, intent, and use cases do not defer from the previous proposal, only the API does. See [https://bugzilla.mozilla.org/show_bug.cgi?id=876397 bug 876397] for implementation.


= API =
= API =
== Caller ==
== Publisher ==
   partial interface Application {
   partial interface Application {
     // The returned Promise will be resolved if at least one peer is
     // The returned Promise will be resolved if at least one peer is
     // allowed to connect with the application and will contain in that
     // allowed to connect with the application and will contain in that
     // case an array of MessagePort, each of them representing a peer
     // case an array of InterAppMessagePort, each of them representing a peer
     // that allowed the connection.
     // that allowed the connection.
     // If no peer is allowed to connect with the app, the Promise will
     // If no peer is allowed to connect with the app, the Promise will
Line 14: Line 14:
     Promise connect(DOMString keyword, jsval rules);
     Promise connect(DOMString keyword, jsval rules);
    
    
     // The returned Future will contain an array of Connection objects each
     // The returned Future will contain an array of InterAppConnection objects each
     // of them representing a connection with a peer through a specific
     // of them representing an InterAppconnection with a peer through a specific
     // keyword.
     // keyword.
     Promise connectionsRegistered();
     Promise getConnections();
   };
   };


Line 24: Line 24:
* ''keyword'' is the key string subject of the connection. Only apps advertising themselves as able to connect through this keyword will receive a connection request (if the user allows to and the app fulfills the requirements specified in the ''rules'' argument).
* ''keyword'' is the key string subject of the connection. Only apps advertising themselves as able to connect through this keyword will receive a connection request (if the user allows to and the app fulfills the requirements specified in the ''rules'' argument).
* ''rules'' (optional) is an object containing a set of constraints for the requested connection. Only apps fulfilling these constraints will receive a connection request. These rules may contain:
* ''rules'' (optional) is an object containing a set of constraints for the requested connection. Only apps fulfilling these constraints will receive a connection request. These rules may contain:
** ''minimumAccessLevel'' is the minimum level of access (one of https://developer.mozilla.org/en-US/docs/Web/Apps/Manifest#type) that the receiver app requires in order to be able to receive the connection request. The default value will be 'web'.
** ''minimumAccessLevel'' is the minimum level of access (one of https://developer.mozilla.org/en-US/docs/Web/Apps/Manifest#type) that the subscriber app requires in order to be able to receive the connection request. The default value will be 'web'.
** ''origin'' (array) can be used to set specific receivers by a list of origins.
** ''installOrigins'' (array) list of install origins from where subscriber apps should have been installed. Since certified apps has not a ''valid'' install origin, these constraint does not apply to them.
** ''developer'' (array) list of objects identifying app authors whose apps are allowed to receive a connection request.
** ''installOrigin'' (array) list of install origins from where receiver apps should have been installed. Since certified apps has not a ''valid'' install origin, these constraint does not apply to them.


== Receiver ==
== Subscriber ==
Applications can advertise themselves as able to connect given an specific keyword by adding an entry named ''connections'' in their manifests containing an object list where each object represents the description and details of each potential connection.
Applications can advertise themselves as able to connect given an specific keyword by adding an entry named ''connections'' in their manifests containing an object list where each object represents the description and details of each potential connection.


Line 41: Line 39:
         'rules': {
         'rules': {
           'minimumAccessLevel': 'web',
           'minimumAccessLevel': 'web',
           'origin': ['origin_1', 'origin_n'],
           'installOrigins': ['install_origin_1', 'install_origin_n']
          'installOrigin': ['install_origin_1', 'install_origin_n'],
          'developer': [{
            'name': 'developer_name',
            'url': 'developer_url'
          }]
         }
         }
       },
       },
Line 62: Line 55:
* ''rules'' is an object containing a set of constraints to be fulfilled by connection requesters. These rules may contain:
* ''rules'' is an object containing a set of constraints to be fulfilled by connection requesters. These rules may contain:
** ''minimumAccessLevel'' is the minimum level of access (one of https://developer.mozilla.org/en-US/docs/Web/Apps/Manifest#type) that the requester app requires in order to be able to send a connection request. The default value will be 'web'.
** ''minimumAccessLevel'' is the minimum level of access (one of https://developer.mozilla.org/en-US/docs/Web/Apps/Manifest#type) that the requester app requires in order to be able to send a connection request. The default value will be 'web'.
** ''origin'' (array) can be used to set specific requesters by a list of origins.
** ''installOrigins'' (array) list of install origins from where the requester apps should have been installed. Since certified apps has not a ''valid'' install origin, these constraint does not apply to them.
** ''developer'' (array) list of objects identifying app authors whose apps are allowed to send connection requests.
** ''installOrigin'' (array) list of install origins from where the requester apps should have been installed. Since certified apps has not a ''valid'' install origin, these constraint does not apply to them.


=== Connection acknowledgement ===
=== Connection acknowledgement ===
Applications that fulfill the rules specified in the ''.connect()'' call and have explicitly been allowed by the user to connect with the caller application will receive a system message named 'connection' containing a ''ConnectionRequest'' object of this form as a ''message''.
Applications that fulfill the rules specified in the ''.connect()'' call and have explicitly been allowed by the user to connect with the publisher application will receive a system message named 'connection' containing a ''InterAppConnectionRequest'' object of this form as a ''message''.


   Dictionary ConnectionRequest {
   interface InterAppConnectionRequest {
     MessagePort port;
     DOMString keyword;
     DOMString  keyword;
     InterAppMessagePort port;
   };
   };


where
where


* ''port'' is an instance of ''MessagePort'' that will be the message channel for the connection.
* ''keyword'' is the key string given with the ''.connect()'' call.
* ''keyword'' is the key string given with the ''.connect()'' call.
* ''port'' is an instance of ''InterAppMessagePort'' that will be the message channel for the connection.


== MessagePort ==
== InterAppMessagePort ==
A ''MessagePort'' is the channel that connects two applications and allow them to send and receive messages.
A ''InterAppMessagePort'' is the channel that connects two applications and allow them to send and receive messages.


  interface MessagePort {
  interface InterAppMessagePort {
     void start();
     void start();
     void close();
     void close();
     void postMessage(...);
     void postMessage(in jsval message);
     attribute jsval onmessage;
     attribute jsval onmessage;
     attribute jsval onstart;
     // To Fernando: we should try to avoid defining the following two event handlers
     attribute jsval onclose;
    // so that we can reuse the formal W3C MessagePort. Need to discuss about this.
    <strike>attribute jsval onstart;</strike>
     <strike>attribute jsval onclose;</strike>
   };
   };


== Connection ==
== InterAppConnection ==
A ''Connection'' object represents a connection between two apps through an specific keyword.
A ''InterAppConnection'' object represents a connection between two apps through an specific keyword.


  interface Connection {
  interface InterAppConnection {
  readonly attribute DOMString keyword;
   readonly attribute DOMString publisher;
   readonly attribute DOMString publisher;
   readonly attribute DOMString subscriber;
   readonly attribute DOMString subscriber;
   cancel();
   void cancel();
  };
  };


''Connection'' objects will be obtained within a resolved ''Promise'' returned by a ''connectionsRegistered()'' call. This function is likely going to be called by a settings application that intends to show the user a list of existing connections, allowing her to cancel them if needed.
''InterAppConnection'' objects will be obtained within a resolved ''Promise'' returned by a ''getConnections()'' call. This function is likely going to be called by a settings application that intends to show the user a list of existing connections, allowing her to cancel them if needed.


= Defer mechanism =
= Defer mechanism =
Line 110: Line 104:
== Lockscreen and Music ==
== Lockscreen and Music ==


(Disclaimer: this is just a rough example of a possible solution for this use case. The permission model does not need to meet the real requirements for these apps. Also this use cases can probably be done with an unique keyword, different access rules and an agreed bidirectional API, but I just wanted a wider example)
'''(Disclaimer: this is just a rough example of a possible solution for this use case. The permission model does not need to meet the real requirements for these apps. Also this use cases can probably be done with an unique keyword, different access rules and an agreed bidirectional API, but I just wanted a wider example)'''


The lockscreen (Gaia System app) wants to be able to:  
The lockscreen (Gaia System app) wants to be able to:  
Line 125: Line 119:
         'description': 'Show the currently played music track information in the lockscreen',
         'description': 'Show the currently played music track information in the lockscreen',
         'rules': {
         'rules': {
           'installOrigin': ['marketplace.firefox.com']
           'installOrigins': ['marketplace.firefox.com']
         }
         }
       }
       }
Line 133: Line 127:
where it advertises itself as able to receive connections through the 'musictrack' keyword, requested by apps installed from the Firefox Marketplace and handled within the ''musicmanager.html'' page.
where it advertises itself as able to receive connections through the 'musictrack' keyword, requested by apps installed from the Firefox Marketplace and handled within the ''musicmanager.html'' page.


On the other side, the Gaia Music app that wants to be controlled from the lockscreen (and only from there) should add the following 'connect' field to its manifest:
On the other side, the Gaia Music app that wants to be controlled from the lockscreen (and only from there) should add the following 'connections' field to its manifest:
   {
   {
     'name': 'Music',
     'name': 'Music',
Line 141: Line 135:
         'description': 'Play, pause and stop music tracks',
         'description': 'Play, pause and stop music tracks',
         'rules': {
         'rules': {
          'origin': ['system.gaiamobile.org']
         }
         }
       }
       }
Line 164: Line 157:
=== Current track showed in the lockscreen ===
=== Current track showed in the lockscreen ===


Gaia Music starts playing a random track and wants to share the information about this track with other apps. Since the shared information is harmless, it doesn't care about the receiver, so no rules are required while requesting the connection.
Gaia Music starts playing a random track and wants to share the information about this track with other apps. Since the shared information is harmless, it doesn't care about the subscriber, so no rules are required while requesting the connection.


  connect('musictrack').then(function onConnectionAccepted(ports) {
  connect('musictrack').then(function onConnectionAccepted(ports) {
   // If the connection is allowed at least by one peer, the resolved callback
   // If the connection is allowed at least by one peer, the resolved callback
   // will be triggered with a list of MessagePorts as parameter (ports in this case).
   // will be triggered with a list of InterAppMessagePort as parameter (ports in this case).
   ports.forEach(function(port) {
   ports.forEach(function(port) {
     // We still need to wait for the connected peer to notify as able to start
     // We still need to wait for the connected peer to notify as able to start
Line 181: Line 174:
       // In this example approach, we probably don't need a bidirectional communication
       // In this example approach, we probably don't need a bidirectional communication
       // as we have that through a different keyword, but we can always set a message
       // as we have that through a different keyword, but we can always set a message
       // handler via MessagePort.onmessage at this point to handle the messages sent from
       // handler via InterAppMessagePort.onmessage at this point to handle the messages sent from
       // the peer on the other side of the port.
       // the peer on the other side of the port.
       port.onmessage = myMessageHandler;     
       port.onmessage = myMessageHandler;     
Line 193: Line 186:
  });
  });


The System app only allows connections with apps installed from the Firefox Marketplace (or from certified apps). In this case, the caller (Gaia Music app) is a certified app, so the connection request is allowed by the platform. Assuming that the lockscreen (System app) is the only application advertising itself as able to connect through the 'musictrack' keyword and there is no record of a previously allowed connection between this two apps through this keyword, a popup will be shown to the user saying something like:
The System app only allows connections with apps installed from the Firefox Marketplace (or from certified apps). In this case, the publisher (Gaia Music app) is a certified app, so the connection request is allowed by the platform. Assuming that the lockscreen (System app) is the only application advertising itself as able to connect through the 'musictrack' keyword and there is no record of a previously allowed connection between this two apps through this keyword, a popup will be shown to the user saying something like:


  Do you want to allow ''Music'' (music.gaiamobile.org) to connect with ''System'' (system.gaiamobile.org) to ''Show the currently played music track information in the lockscreen''? [Allow|Deny]
  Do you want to allow ''Music'' (music.gaiamobile.org) to connect with ''System'' (system.gaiamobile.org) to ''Show the currently played music track information in the lockscreen''? [Allow|Deny]
Line 213: Line 206:
  });
  });


A similar connection request coming from Sonbirdy would also be allowed by the platform, cause we said that this app was installed from the Firefox Marketplace. However a connection request coming from iTunos would be rejected by the platform, since this app is unprivileged web content installed from an unknown source non listed within the lockscreen app rules. This request will not trigger any system messages and so the receiver won't ever be awake because of it (in this case the receiver (System app) is already live though).
A similar connection request coming from Sonbirdy would also be allowed by the platform, cause we said that this app was installed from the Firefox Marketplace. However a connection request coming from iTunos would be rejected by the platform, since this app is unprivileged web content installed from an unknown source non listed within the lockscreen app rules. This request will not trigger any system messages and so the subscriber won't ever be awake because of it (in this case the subscriber (System app) is already live though).


=== Music controls in the lockscreen ===
=== Music controls in the lockscreen ===
Line 226: Line 219:
    
    
   let musicPort = ports[0];
   let musicPort = ports[0];
   musicPort.onstart(function() {
   musicPort.onstart((function() {
     this.enableControlButtons();
     this.enableControlButtons();
     this.madeUpPlayButton.onclick = function() {
     this.madeUpPlayButton.onclick = function() {
Line 243: Line 236:
       });
       });
     };
     };
   });
   }).bind(this));
   musicPort.onstop(function() {
   musicPort.onclose((function() {
     this.disableControlButtons();
     this.disableControlButtons();
   });
   }).bind(this));
  }, function onConnectionRejected(reason) {
  }).bind(this), (function onConnectionRejected(reason) {
   ...
   ...
}, {
  origin: ['music.gaiamobile.org']
  }).bind(this));
  }).bind(this));


Line 257: Line 248:
'Do you want to allow ''System'' (system.gaiamobile.org) to communicate with ''Music'' (music.gaiamobile.org) to ''Play, pause and stop music tracks''? [Accept|Reject]'
'Do you want to allow ''System'' (system.gaiamobile.org) to communicate with ''Music'' (music.gaiamobile.org) to ''Play, pause and stop music tracks''? [Accept|Reject]'


Even if ''Songbirdy'' and ''iTunos'' advertise themselves as able to connect through the 'musicremotecontrol' keyword, as the request is done with a specific rule that requires the receiver to have the 'music.gaiamobile.org' origin, these apps won't be listed in the above UI and won't receive any system message with a connection request.
Even if ''Songbirdy'' and ''iTunos'' advertise themselves as able to connect through the 'musicremotecontrol' keyword, as the request is done with a specific rule that requires the subscriber to have the 'music.gaiamobile.org' origin, these apps won't be listed in the above UI and won't receive any system message with a connection request.


The user allows that connection and a system message is sent to the Music app.
The user allows that connection and a system message is sent to the Music app.
Line 289: Line 280:


* We might want to have a bigger set of types to allow apps to connect (web, installed, signed, privileged, certified).
* We might want to have a bigger set of types to allow apps to connect (web, installed, signed, privileged, certified).
[[Category:Web APIs]]
Confirmed users
1,340

edits