W3C

Push API

W3C Working Draft 18 October 2012

This version:
http://www.w3.org/TR/2012/WD-push-api-20121018/
Latest published version:
http://www.w3.org/TR/push-api/
Latest editor's draft:
http://dvcs.w3.org/hg/push/raw-file/tip/index.html
Editors:
Bryan Sullivan, AT&T
Eduardo Fullea, Telefonica

Abstract

This specification defines a “Push API” that provides webapps with scripted access to server-sent application data, for simplicity referred to here as "Push messages" as delivered by "Push services". Push services are a way for application servers to send messages to webapps, whether or not the webapp is active in a browser window.

Push messages may be delivered via various methods, either via standardized protocols (e.g. Server-Sent Events [SSE], the GSM Short Message Service [GSM-SMS], SIP MESSAGE [RFC3428], or OMA Push [OMA-PUSH]), or via browser-specific methods. The specific method to be used by a webapp is either selected by the user through selecting a Web Intent Push Service provider, or by the browser. The Push API is defined to promote compatibility with any underlying delivery method.

Status of This Document

This section describes the status of this document at the time of its publication. Other documents may supersede this document. A list of current W3C publications and the latest revision of this technical report can be found in the W3C technical reports index at http://www.w3.org/TR/.

This document was published by the Web Applications Working Group as a First Public Working Draft. This document is intended to become a W3C Recommendation. If you wish to make comments regarding this document, please send them to public-webapps@w3.org (subscribe, archives) using a subject prefix of [push-api]. All feedback is welcome.

Publication as a Working Draft does not imply endorsement by the W3C Membership. This is a draft document and may be updated, replaced or obsoleted by other documents at any time. It is inappropriate to cite this document as other than work in progress.

This document was produced by a group operating under the 5 February 2004 W3C Patent Policy. W3C maintains a public list of any patent disclosures made in connection with the deliverables of the group; that page also includes instructions for disclosing a patent. An individual who has actual knowledge of a patent which the individual believes contains Essential Claim(s) must disclose the information in accordance with section 6 of the W3C Patent Policy.

Table of Contents

1. Introduction

This section is non-normative.

As defined here, Push services support delivery of application server messages in the following contexts and related use cases:

2. Conformance

As well as sections marked as non-normative, all authoring guidelines, diagrams, examples, and notes in this specification are non-normative. Everything else in this specification is normative.

The key words must, must not, required, should, should not, recommended, may, and optional in this specification are to be interpreted as described in [RFC2119].

This specification defines conformance criteria that apply to a single product: the user agent that implements the interfaces that it contains.

Implementations that use ECMAScript to implement the APIs defined in this specification must implement them in a manner consistent with the ECMAScript Bindings defined in the Web IDL specification [WEBIDL], as this specification uses that specification and terminology.

3. Terminology

The Function interface represents a function in the scripting language being used as defined in [HTML5].

The concepts queue a task and fires a simple event are defined in [HTML5].

The terms event handlers and event handler event types are defined in [HTML5].

The term Web Intent Push Service provider refers to a service implemented as described in [WEBINTENTS], and offering Push API binding to event delivery via the service.

The term push server refers to a system via which a push service is provided.

The term webapp refers to Web applications, i.e. applications implemented using Web technologies, and executing within the context of a Web user agent, e.g. a Web browser or other Web runtime environment.

4. Security and privacy considerations

User agents must not provide Push API access to Webapps without the express permission of the user. User agents must acquire consent for permission through a user interface for each call to the requestRemotePermission() method, unless a prearranged trust relationship applies.

user agents may support prearranged trust relationships that do not require such per-request user interfaces.

Permissions that are preserved beyond the current browsing session must be revocable.

Issue 1
Jonas raised a number of concerns in http://lists.w3.org/Archives/Public/public-webapps/2012OctDec/0042.html. These concerns (and the responses to them) are expected to be discussed in the upcoming TPAC meeting.

5. Push Framework

This section is non-normative.

There are different deployment alternatives to allow application servers to deliver Push messages to webapps. In a typical deployment application servers send push messages to a push server, e.g. by a RESTful interface, which in turn delivers the message to the user agent providing the execution context for the webapp. The user agent then delivers the Push message to the corresponding webapp to which the Push message was addressed.

This API allows webapps to ask the user for permission to receive Push messages and to provide the user agent with the necessary information to activate the Push service. For instance, the webapp provides a unique application token that is used by the application server when sending a message to the push server to address an specific instance (or set thereof) of the application. In case several instances of a webapp register the same application token, e.g. in different user agents, then the push server deliver Push messages addressed to that application token to all of those instances (e.g. when a mail webapp is active in two browsers using the same mail account)

Also the webapp may provide additional information in order to allow the push server to verify that Push messages come from the right application server. Namely it can provide a public key that the push server can use to verify that the Push message comes from the right application server, which has signed the message with the associated private key

Example 1
var token = getGuid(); // get GUID as unique token
var mypush = requestRemotePermission(token);
mypush.onerror = function () {
  alert("darn! "+e.message);
  };
mypush.onsuccess = function () {
  var activate = "http://example.com/push/activate?token="+token+
    "&serviceUrl="+encodeURIComponent(mypush.serviceUrl)+
    "&serverProtocols="+mypush.serverProtocols;
  asyncXHR(activate); // send activation request to application server
	 
  mypush.wakeup = true;
	 
  mypush.onmessage = function (event) {
    document.getElementById('message').innerHTML = event.data;
  };
};

/* Hypothetical end-to-end flow
  +--------+           +--------+             +--------+           +--------+
  | webapp |           |  user  |             |  push  |           |  app   |
  |        |           | agent  |             | server |           | server |
  +--------+           +--------+             +--------+           +--------+
      |                    |                      |                     |
  requestRemotePermission->|                      |                     |
      |                    |                      |                     |
      |              (user accepts)               |                     |
      |                    |                      |                     |
      |                    |<-setup push service->|                     |
      |                    |                      |                     |
      |<---success event---|                      |                     |
      |                    |                      |                     |
      |<--activate service with PushService attributes----------------->|
      |                    |                      |                     |
      |                    |                      |<----push message----|
      |                    |                      |   per service API   |
      |                    |                      |                     |
      |                    |             (match to user agent)          |
      |                    |                      |                     |
      |                    |<----push message-----|                     |
      |                    | per service protocol |                     |
      |                    |                      |                     |
      |            (match to webapp)              |                     |
      |                    |                      |                     |
      |<---message event---|                      |                     |
      |                    |                      |                     |
*/

7. The PushManager Interface

This interface defines the operations that enable webapps to establish access to Push services.

interface PushManager {
    PushService requestRemotePermission (DOMString appToken, optional DOMString publicKey, optional DOMString algorithm);
    PushService checkRemotePermission (DOMString appToken);
};

7.1 Methods

checkRemotePermission
Lets the webapp ask the browser if the webapp has been granted permission to receive Push messages, without bothering the user. The success callback would return the same PushService object that requestRemotePermission() received, but if the user has never allowed notifications for the webapp the error callback would run.
ParameterTypeNullableOptionalDescription
appTokenDOMString
Return type: PushService
requestRemotePermission
Asks the user if they'd like to allow this webapp to receive Push messages. The webapp conveys an application token, which is a unique token generated by the application that identifies the instance (or set thereof) that is (are) intended to receivethe Push messages that are addressed to this application token by the application server. In case several instances of a webapp register the same application token, e.g. in different user agents, then the push server must deliver Push messages addressed to that application token to all of those instances(e.g. when a mail webapp is active in two browsers using the same mail account).

In order to verify that Push messages received by the push server come from the right server, the application server may sign Push messages. In case messages are signed by the corresponding application server then the webapp must include in the publicKey attribute the public key that the push server can use to verify the signature of Push messages.The default signature algorithm is RSA-SHA256, which must be supported by push servers, although the webapp may propse the use of a different algorithm. If the webapp wants to indicate the use of a different signature algorithm it will indicate it in the algorithm attribute, which will be enconded according to [XMLSEC-ALGORITHMS]

Upon success, a PushService object is returned, with a Push service URL where the application server can send messages to this webapp. If the webapp has been granted permission already and is calling requestRemotePermission() again, the Push service URL will be returned without asking again for permission.

ParameterTypeNullableOptionalDescription
appTokenDOMString
publicKeyDOMString
algorithmoptional DOMString
Return type: PushService

If the user permits webapp access to Push service upon a call to the requestRemotePermission() method, the user agent must activate the service.

The particular Push service used by the user agent is transparent to the webapp and the requirements for its activation are either unspecified or as defined here.

8. The PushService Interface

The PushService interface enables webapps to access Push services that have been permitted by the user.

interface PushService : EventTarget {
    readonly attribute DOMString      appToken;
    readonly attribute DOMString      publicKey;
    readonly attribute DOMString      algorithm;
    readonly attribute DOMString      serviceUrl;
    readonly attribute DOMString[]    serverProtocols;
    readonly attribute DOMError       error;
             attribute boolean        wakeup;
    
             attribute Function?      onsuccess;
    
             attribute Function?      onerror;
    
             attribute Function?      onmessage;
    void close ();
    readonly attribute unsigned short readyState;
    const unsigned short CONNECTING = 0;
    const unsigned short OPEN = 1;
    const unsigned short CLOSED = 2;
};

8.1 Attributes

algorithm of type DOMString, readonly
The signature algorithm used by the application server to sign push messages and that was passed as a parameter to requestRemotePermission().
appToken of type DOMString, readonly
A unique token generated by the application that identifies the instance or set of instances that are intended to receive Push messages and that was passed as a parameter to requestRemotePermission().
error of type DOMError, readonly
An error that occured in processing the request, or during operation of the Push service. Errors are as defined in [DOM4].
onerror of type Function, nullable
Code to be executed when an error result is returned from requestRemotePermission() or checkRemotePermission().
onmessage of type Function, nullable
Code to be executed when a Push message has been received.
onsuccess of type Function, nullable
Code to be executed when a successful result is returned from requestRemotePermission() or checkRemotePermission().
publicKey of type DOMString, readonly
The public key that the push server can use to verify the signature of the push message and that was passed as a parameter to requestRemotePermission().
readyState of type unsigned short, readonly
The state of the Push service.
serverProtocols of type array of DOMString, readonly
An array of push service protocols which are supported by the push server via the serviceUrl.
serviceUrl of type DOMString, readonly
A URL where the application server can send messages to this webapp.
wakeup of type boolean
An indication that the webapp requests to be invoked if possible, when a Push message is available for delivery and the webapp is not active in a browser window.

8.2 Constants

CLOSED of type unsigned short
CONNECTING of type unsigned short
OPEN of type unsigned short

The appToken attribute must return the application token that was passed as a parameter to requestRemotePermission().

The publicKey attribute must return the public key that was passed as a parameter to requestRemotePermission().

The algorithm attribute must return the signature algorithm that was passed as a parameter to requestRemotePermission().

The serviceUrl attribute must return the absolute URL where the application server can send Push service messages to this webapp.

The serverProtocols attribute must return an array of push service protocols which are supported by the push server via the serviceUrl. The list should be ordered by preference (e.g. protocols more likely to be deprecated first should go later in the array). Application servers are expected to use the first supported protocol in this list.

Note
How push service protocol versions are defined and administered is TBD.

The error attribute must return any error that occured in processing the request, or during operation of the Push service.

If set to true, the wakeup, when a Push message is received and the webapp is not active in a browser window, the browser must invoke the webapp if possible, and deliver the Push message to it. Examples of cases in which webapps should be invokable include:

The readyState attribute represents the state of the Push service. It can have the following values:

CONNECTING (numeric value 0)
The Push service is not yet activated, or was closed and the user agent is reconnecting.
OPEN (numeric value 1)
The Push service is active and the user agent is dispatching Push messages as it receives them.
CLOSED (numeric value 2)
The Push service is not open. Either there was a fatal error or the close() method was invoked.

When the PushService object is created its readyState must be set to OPEN (1) if Push messages may be immediately received by the webapp (i.e. no further processing is required to activate the Push service). Otherwise readyState must be set to CONNECTING (0), and transition to OPEN (1) only when Push messages may be received by the webapp.

The close() method must abort any further operation of a Push service related to the PushService object, and must set the readyState attribute to CLOSED.

The following are the event handlers (and their corresponding event handler event types) that must be supported, as IDL attributes, by all objects implementing the PushService interface:

Event handler Event handler event type
onsuccess success
onmessage message
onerror error

When a Push message is received, the user agent must deliver the message data via the onmessage handler, if possible. If delivery is not possible, the user agent may discard the message, or may queue it for later delivery.

9. Specific Service Bindings

User agents that support Push API binding to the [OMA-PUSH] protocol must deliver related [OMA-PUSH] messages as a message event with the interface MessageEvent on the PushService object, with the event's data attribute set to the textual representation of the body of the received [OMA-PUSH] message.

User agents that support Push API binding to the [GSM-SMS] protocol must deliver related [GSM-SMS] messages as a message event with the interface MessageEvent on the PushService object, with the event's data attribute set to the textual representation of the body of the received [GSM-SMS] message.

User agents that support Push API binding to the [RFC3428] protocol must deliver related [RFC3428] messages as a message event with the interface MessageEvent on the PushService object, with the event's data attribute set to the textual representation of the body of the received [RFC3428] message.

10. Examples

This section is non-normative.

To be provided.

A. Acknowledgements

To be provided.

B. References

B.1 Normative references

[DOM4]
Anne van Kesteren; Aryeh Gregor; Ms2ger. DOM4. URL: http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html/
[GSM-SMS]
3G Partnership Project. Technical realization of the Short Message Service (SMS). 11 January 2002. 3GPP 0340-750. URL: http://www.3gpp.org/ftp/Specs/archive/03_series/03.40/0340-750.zip
[HTML5]
Ian Hickson; David Hyatt. HTML5. 29 March 2012. W3C Working Draft. (Work in progress.) URL: http://www.w3.org/TR/html5
[OMA-PUSH]
Open Mobile Alliance. OMA Push Version 2.3. URL: http://www.openmobilealliance.org/Technical/release_program/push_v2_3.aspx
[RFC2119]
S. Bradner. Key words for use in RFCs to Indicate Requirement Levels. March 1997. Internet RFC 2119. URL: http://www.ietf.org/rfc/rfc2119.txt
[RFC3428]
B. Campbell, Ed.; J. Rosenberg, et al. Session Initiation Protocol (SIP) Extension for Instant Messaging. December 2002. Internet RFC 3428. URL: http://www.ietf.org/rfc/rfc3428.txt
[SSE]
Ian Hickson; Server-Sent Events.W3C Editor Draft. (Work in progress.) URL: http://www.w3.org/TR/eventsource/
[WEBIDL]
Cameron McCormack. Web IDL. 27 September 2011. W3C Working Draft. (Work in progress.) URL: http://www.w3.org/TR/2011/WD-WebIDL-20110927/
[WEBINTENTS]
Greg Billock; James Hawkins; Paul Kinlan. Web Intents. Editors' Draft. (Work in progress.) URL: http://dvcs.w3.org/hg/web-intents/raw-file/tip/spec/Overview.html
[XMLSEC-ALGORITHMS]
Thomas Roessler; Frederick Hirsch; Kelvin Yiu. XML Security Algorithm Cross-Reference. 5 January 2012. W3C Working Draft. (Work in progress.) URL: http://www.w3.org/TR/2012/WD-xmlsec-algorithms-20120105/