This specification defines an Application Management API that for example exposes methods for installing and uninstalling applications and methods for launching and terminating applications. A typical use case for this API is a web based home screen (application dashboard.

Introduction

Examples of use cases for this API are:

The functionality in this API is.

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.

Terminology

The EventHandler interface represents a callback used for event handlers as defined in [[!HTML5]].

The concepts queue a task and fire an event are defined in [[!HTML5]].

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

Security and privacy considerations

This API must be only exposed to trusted content.

Application Management

Application interface

Web Applications are represented by the Application interface.

readonly attribute DOMString origin
The attribute MUST return the application's origin.
readonly attribute Object manifest
The attribute MUST return an object representing the parsed application manifest.
readonly attribute DOMString installOrigin
The attribute MUST return the origin of the page from which the application was installed. [[!ORIGIN]]
readonly attribute unsigned long installTime
The attribute MUST return the time in milliseconds since epoch at which the application was installed.
readonly attribute Object parameters
The attribute MUST return the parameters that were provided at install time. See install() in ApplicationRegistry.
DOMRequest launch()
This method MUST return a DOMRequest instance and then run the following steps asynchronously:
  1. If the caller is not allowed by the UA to launch the application, the UA MUST fire an error event to the DOMRequest object with the "NotAllowedError" error code and exit those steps.
  2. If the caller is allowed to launch the application, the UA SHOULD launch the application.
  3. If the application has been successfully launched, the UA MUST fire a success event to the DOMRequest object and set result to null.
    Otherwise, the UA MUST fire an error event to the DOMRequest object with an error code that describes the error.
DOMRequest uninstall()
This method MUST return a DOMRequest instance and then run the following steps asynchronously:
  1. If the application is not currently installed, the UA MUST fire an error event to the DOMRequest object with the "NotInstalledError" error code and exit those steps.
  2. If the caller is not allowed by the UA to uninstall the application, the UA MUST fire an error event to the DOMRequest object with the "NotAllowedError" error code and exit those steps.
  3. If the caller is allowed to uninstall the application, the UA SHOULD uninstall the application.
  4. If the application has been successfully uninstalled, the UA MUST fire a success event to the DOMRequest object and set result to null.
    Otherwise, the UA MUST fire an error event to the DOMRequest object with an error code that describes the error.
readonly attribute DOMString updateState
The attribute MUST return the empty string, available, downloading, downloaded or installing, depending on the state of the application.
If the application is being updated, the attribute MUST return installing.
If the application is ready to be updated, with the update fully downloaded or if there is no download to proceed to the update, the attribute MUST return downloaded.
If the application's update is being downloaded, the attribute MUST return downloading.
If there is an application update available, it is not being installed, nor downloaded, nor downloading, the attribute MUST return available. Otherwise, the attribute MUST return the empty string.
readonly attribute unsigned long downloadSize
The attribute SHOULD return the size of the download that would be required to update the application in kilobytes, if any. If the application does not have an available update, if the download has already been done or if the UA can't find out the size of the download required for the update, the attribute MUST return 0.
If the download is happening, the attribute MUST return 0.
If the download has been made but interrupted and the UA is able to continue it, the attribute SHOULD return the remaining size to download.
DownloadRequest downloadUpdate()
The method MUST return a DownloadRequest object and asynchronously run the following steps:
  1. If the application does not have an available update, the UA MUST send an error message to the request object with the value InvalidState and abort these steps.
  2. If the application does not require a download to process the update, the UA MUST send a success message to the request object with no value and abort these steps.
  3. If the application's update is currently being downloaded, the request MUST reflect the current state of the download. Otherwise, the request must start the download.
readonly attribute DOMString state;
The attribute MUST return running if the current application state is running. Otherwise, if the current application state is paused, it MUST return paused. Otherwise, it MUST return terminated.
void hide()
When this method is called, the UA SHOULD hide the application from the user. Hiding the application SHOULD fire visibility events as described in [[!PAGE-VISIBILITY]].
If the application was already not visible, this method MUST be a no-op.
void exit()
When this method is called, the UA MUST put the application state to terminated and fire the appropriate events.
If the application was already in the terminated state, this method MUST be a no-op.
attribute EventHandler onlaunch
TBD
attribute EventHandler onpause
TBD
attribute EventHandler onresume
TBD
attribute EventHandler onterminate
TBD

The following are the event handlers (and their corresponding event handler event types) that MUST be supported as attributes by the Application objects:

event handler event handler event type
onlaunch launch
onpause pause
onresume resume
onterminate terminate

DownloadRequest interface

void cancel()
This method MUST stops the download and asynchronously send an error message to itself with the value UserCancel.
attribute double progress
If the current state is error the attribute MUST return 0.0. Otherwise, if the current state is success, the attribute MUST return 1.0. Otherwise, the attribute SHOULD return the current progress of the download expressed between 0.0 and 1.0.
attribute EventHandler onprogress
TBD

When the caller start the download, the DownloadRequest SHOULD start downloading the resource.

If the resource fails to download, the UA MUST send an error message to the request.

If the resource succeed to download, the UA MUST send a success message to the request.

While the resource is downloading, which means as long as readyState is pending, the UA SHOULD regularly fire a simple event named progress on the object. The UA should note that sending too much events might have an impact on performance but sending too few of them might impact the user experience.

The following are the event handlers (and their corresponding event handler event types) that MUST be supported as attributes by the DOMRequest objects:

event handler event handler event type
onprogress progress

Extension to the Navigator interface

An ApplicationRegistry instance is exposed on the Navigator object trough the an app attribute.

readonly attribute ApplicationRegistry app
The attribute MUST return an ApplicationRegistry instance.

ApplicationRegistry interface

The ApplicationRegistry interface allows handling applications and query there status.

DOMRequest install(in DOMString manifestUrl, [Optional] in Object parameters)
This method MUST return a DOMRequest instance and then run the following steps asynchronously:
  1. If the caller is not allowed by the UA to install the application, the UA MUST fire an error event to the DOMRequest object with the "NotAllowedError" error code and exit those steps.
  2. If the caller is allowed to install the application, the UA SHOULD install the application as described in the manifest at manifestUrl.
  3. If the application has been successfully installed, the UA MUST fire a success event to the DOMRequest object and set result to null.
    Otherwise, the UA MUST fire an error event to the DOMRequest object with an error code that describes the error.

The UA SHOULD verify at any moment before installing that manifestUrl points to a valid manifest. If this is not the case, the UA MUST fire an error event to the DOMRequest object with the "InvalidArgumentError" and exit the steps.

The UA SHOULD save the parameters if some are passed so they can later be retrieved by the parameters attribute on the Application interface.

DOMRequest getSelf()
The UA SHOULD return a DOMRequest object and asynchronously check if the current context is an application context.
When the check is done, the UA SHOULD send a success event to the DOMRequest object and sets its result attribute to the Application object representing the current context or null if the current context is not an application context.
DOMRequest getInstalled()
The UA SHOULD return a DOMRequest object and asynchronously get all applications that have been installed by the caller's origin. [[!ORIGIN]]
When those applications are collected, the UA SHOULD send a success event to the DOMRequest object and populate its result attribute with an array of Application objects representing the applications.
DOMRequest checkInstalled(DOMString manifestURL)
The UA SHOULD return a DOMRequest object and asynchronously check if there is an installed application in the system with a manifest URL matching manifestURL.
After the asynchronous operation is done, the IA SHOULD send a success event to the DOMRequest object and populate its result attribute with the boolean value true if there is an installed application fulfilling the condition, otherwise result should be set to false.
attribute ApplicationManagement management
If the caller is not allowed to manage applications, the UA MUST return null. Otherwise, it MUST return an ApplicationManagement object.
  • Permission check is not clearly defined here. Should it be better?
  • checkInstalled() could be synchronous. Seems way more convenient.

ApplicationManagement interface

The ApplicationManagement interface allows access to all applications and is being informed any time an application is being installed or uninstalled. The intent of this interface is to be restricted to privileged callers.

DOMRequest getAll()
TBD
DOMRequest applyUpdate(Application application)
TBD
attribute EventHandler oninstall
TBD
attribute EventHandler onuninstall
TBD

The getAll method SHOULD return a DOMRequest object and asynchronously get all installed applications.
When those applications are collected, the UA SHOULD send a success event to the DOMRequest object and populate its request attribute with an array of Application objects representing the applications.

The applyUpdate method MUST return a DOMRequest object and perform the following steps asynchronously:

  1. If the application does not have an update or the update is not fully downloaded, the UA MUST send an error message to the request with the value InvalidState and abort these steps.
  2. Stop application from running if it is currently running.
  3. Replace the previous version with the new version of the application.
  4. If an error has occurred during the previous steps, the UA MUST send an error message to the request with any appropriate value. Otherwise, the UA MUST send a success message to the request with an Application object representing the updated application as a value.

Events

An install event using the ApplicationEvent interface MUST be fired on all ApplicationManagement instances as soon as an application is installed with the application attribute set to the Application object representing the installed application.

The uninstall event using the ApplicationEvent interface MUST be fired on all ApplicationManagement instances as soon as an application is uninstalled with the application attribute set to the Application object representing the uninstalled application.

The following are the event handlers (and their corresponding event handler event types) that MUST be supported as attributes by the ApplicationManagement object:

event handler event handler event type
oninstall install
onuninstall uninstall

Application Event Types

Application Events are sent when an event happen on the application level like an application being installed or uninstalled.

readonly attribute Application application
TBD
Application application
TBD

ApplicationEvent objects MUST contain a non-null application attribute representing the application on each the action happened.
The application events are always sent asynchronously, do not bubble and are not cancelable.

There are currently two types of Application Events:

Acknowledgments

TBD.