This specification defines a System Level API which offers a simple interface to manage user's contacts stored in the system's address book. A typical use case of the Contacts API is the implementation of an application to manage said address book.
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 defines a System Level API to manage the user's contacts that are stored in the system's address book. Future versions of this specification are expected to align the contact data model with the Contacts API being defined by the Device APIs Working Group.
This document was published by the System 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-sysapps@w3.org (subscribe, archives). 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.
Navigator Interface
ContactsManager
Interface
ContactFindOptions
Interface
ContactField Interface
ContactTelField
Interface
ContactAddress
Interface
ContactProperties
Interface
Contact Interface
ContactsRequest
Interface
ContactsChangeEvent
Interface
This section is non-normative.
The Contacts API allows applications to provide the functionality of a usual an application to manage an address book, thus allowing the display and management (create, edit, remove, etc.) of contacts.
An example of use is provided below:
var contact = new Contact(); contact.givenName[0] = 'John' contact.familyName[0] = 'Doe' var mobilephone = new contactField(); mobilephone.value = '+34698765432' mobilephone.type[0] = 'PREF' contact.tel[0] = mobilephone var request = navigator.contacts.save(contact); request.onsuccess = function() { window.console.log('Contact saved!'); } request.onerror = function(e) { window.console.error(e); }
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.
The EventHandler
interface represents a callback used for event handlers as
defined in [HTML5].
The concepts queue a task and fire a simple event are defined in [HTML5].
The terms event handler and event handler event types are defined in [HTML5].
This API must be only exposed to trusted content
ContactsManager InterfaceThe ContactsManager interface
exposes the contacts management functionality.
[NoInterfaceObject]
interface ContactsManager : EventTarget {
ContactsRequest find (ContactFindOptions options);
ContactsRequest clear ();
ContactsRequest save (Contact contact);
ContactsRequest remove (Contact contact);
attribute EventHandler oncontactschange;
};
oncontactschange of type EventHandlerclearContactsRequest
findContactsRequest object intended to search
contacts within the address book that match the criteria
indicated in the options parameter.
| Parameter | Type | Nullable | Optional | Description |
|---|---|---|---|---|
| options | |
✘ | ✘ | Set of criteria that a contact
needs to match to be included in the outcomes of the
find operation. |
ContactsRequest
remove| Parameter | Type | Nullable | Optional | Description |
|---|---|---|---|---|
| contact | |
✘ | ✘ | The Contact object
that is requested to be removed from the address
book. |
ContactsRequest
saveid,
already exists in the address book, it will be updated.
| Parameter | Type | Nullable | Optional | Description |
|---|---|---|---|---|
| contact | |
✘ | ✘ | The Contact object
that is requested to be saved in the address
book. |
ContactsRequest
The find method when
invoked MUST run the
following steps:
options parameter.ContactsRequest object and set
readyState of the ContactsRequest
object to 'processing' and return the
ContactsRequest to the calleronerror
event handler of the
ContactsRequest object
readyState of the
ContactsRequest object to 'done'result of the
ContactsRequest object to array of
Contact objects returned by the system.onsuccess event handler of the
ContactsRequest
The clear method when
invoked MUST run the
following steps:
ContactsRequest object and set
readyState of the ContactsRequest
object to 'processing' and return the
ContactsRequest to the calleronerror
event handler of the
ContactsRequest object
readyState of the
ContactsRequest object to 'done'result of the
ContactsRequest object to 'true'onsuccess event handler of the
ContactsRequest
The save method when
invoked MUST run the
following steps:
Contact object passed as parameter in the
address book.ContactsRequest object and set
readyState of the ContactsRequest
object to 'processing' and return the
ContactsRequest to the calleronerror
event handler of the
ContactsRequest object
readyState of the
ContactsRequest object to 'done'result of the
ContactsRequest object to the saved
Contact object as returned by the system,
and which therefore includes the id,
published and updated
parameters, which could be not present in the original
Contact object passed as parameter, for
instance if it is a brand new Contact object
not yet stored in the address bookonsuccess event handler of the
ContactsRequest
The remove method
when invoked MUST run the
following steps:
Contact object passed as parameter from the
address book.ContactsRequest object and set
readyState of the ContactsRequest
object to 'processing' and return the
ContactsRequest to the calleronerror
event handler of the
ContactsRequest object
readyState of the
ContactsRequest object to 'done'result of the
ContactsRequest object to 'true'onsuccess event handler of the
ContactsRequest
Upon a change in a contact or set thereof is performed (i.e.
contact(s) added / modified / removed) the system MUST fire a simple event named contactschange that
implements the ContactsChangeEvent interface
at the ContactsManager object
The following are the event handlers (and their
corresponding event handler event types) that
MUST be supported as
attributes by the ContactsManager object:
| event handler | event handler event type |
|---|---|
oncontactschange |
contactschange |
The event named contactschange MUST implement the ContactsChangeEvent
interface.
ContactFindOptions
InterfaceThe ContactFindOptions interface
represents the criteria used to select the contacts to be
returned by a find operation.
[NoInterfaceObject]
interface ContactFindOptions {
attribute DOMString filterValue;
attribute DOMString filterOp;
attribute DOMString[] filterBy;
attribute DOMString sortBy;
attribute DOMString sortOrder;
attribute unsigned long filterLimit;
};
filterBy of type array of DOMStringfilterLimit of type unsigned longfilterOp of type DOMStringfilterValue of type DOMStringsortBy
of type DOMStringsortOrder of type DOMStringIt is for further study whether the level of flexibility of the filters needs to be increased and/or additional mechanisms need to be put in place so that applications can keep a local copy of the address book and perform the filtering locally (e.g. startTrackingChanges() and getNewChanges() methods)
ContactField InterfaceThe ContactField interface
represents a user's contact address and the type associated to
it.
[NoInterfaceObject]
interface ContactField {
attribute DOMString[] type;
readonly attribute DOMString value;
};
type of type
array of DOMStringtype attributes are possible for each
single contact address.value of type
DOMString,
readonlyContactTelField InterfaceThe ContactTelField interface
represents a telephone number as well as metadata associated to
it, namely the type of address and the carrier providing
service to the telephony subscription associated to that
number.
[NoInterfaceObject]
interface ContactTelField : Contact Field {
attribute DOMString carrier;
};
carrier
of type DOMStringContactAddress InterfaceThe ContactAddress interface
represents a user's phisical address and the type associated to
it. This interface is based on vCard 4.0 ADR
attribute.
[NoInterfaceObject]
interface ContactAddress {
attribute DOMString[] type;
attribute DOMString streetAddress;
attribute DOMString locality;
attribute DOMString region;
attribute DOMString postalCode;
attribute DOMString countryName;
};
countryName of type DOMStringlocality
of type DOMStringpostalCode of type DOMStringregion of
type DOMStringstreetAddress of type DOMStringtype of type
array of DOMStringtype attributes are possible for each
single contact address.ContactProperties
InterfaceThe ContactProperties interface
contains all the properties associated to the contact. As a
principle the attributes are based on vCard 4.0 and reuse
the literal used in that standard. Any deviation is mentioned
in the description of the corresponding attribute.
[NoInterfaceObject]
interface ContactProperties {
attribute DOMString[] name;
attribute DOMString[] honorificPrefix;
attribute DOMString[] givenName;
attribute DOMString[] additionalName;
attribute DOMString[] familyName;
attribute DOMString[] honorificSuffix;
attribute DOMString[] nickname;
attribute ContactField[] email;
attribute DOMString[] photo;
attribute ContactField[] url;
attribute DOMString[] categories;
attribute ContactAddress[] adr;
attribute ContactTelField[] tel;
attribute DOMString[] org;
attribute DOMString[] jobTitle;
attribute Date bday;
attribute DOMString[] note;
attribute ContactAddress[] impp;
attribute Date anniversary;
attribute DOMString sex;
attribute DOMString genderIdentity;
};
additionalName of type array of DOMStringadr of
type array of ContactAddressContactAddress element or set thereof
containing the user's phisical address(es). It maps to
vCard's ADR attributeanniversary of type DateDate element representing the contact's
anniversary. It maps to vCard's ANNIVERSARY attributebday of
type DateDate element representing the contact's
birth date. It maps to vCard's BDAY attributecategories of type array of DOMStringemail of
type array of ContactFieldContactField element or set thereof
containing the contact's email address(es). It maps to
vCard's EMAIL attribute.familyName of type array of DOMStringgenderIdentity of type DOMStringgivenName of type array of DOMStringhonorificPrefix of type array of DOMStringhonorificSuffix of type array of DOMStringimpp of
type array of ContactAddressContactAddress element or set thereof
containing the user's instant messaging address(es). It
maps to vCard's IMPP attributejobTitle of type array of DOMStringname of
type array of DOMStringnickname of type array of DOMStringnote of
type array of DOMStringorg of
type array of DOMStringphoto of
type array of DOMStringsex of
type DOMStringtel of
type array of ContactTelFieldContactTelField element or set thereof
containing the user's telephone numbers.It maps to vCard's
TEL attributeurl of
type array of ContactFieldContactField element or set thereof
containing the user's urls (e.g. personal blog). It maps to
vCard's URL attribute.Contact InterfaceThe Contact interface represents a
contact stored in the address book.
[NoInterfaceObject]
interface Contact {
readonly attribute DOMString id;
readonly attribute boolean readOnly;
readonly attribute Date lastUpdated;
};
id of type
DOMString,
readonlylastUpdated
of type Date,
readonlyDate element representing the date when
the contact was last updated.readOnly of
type boolean,
readonlyContactsRequest InterfaceThe ContactsRequest interface
represents an ongoing operation. It provides callbacks that are
called when the operation completes, as well as a reference to
the operation's result. A method that initiates an operation
(e.g. remove contact via the remove method in the
ContactsManager interface) may return a
ContactsRequest object that can be used to monitor the progress
of that operation.
[NoInterfaceObject]
interface ContactsRequest {
readonly attribute DOMString readyState;
readonly attribute DOMError? error;
readonly attribute any? result;
attribute EventHandler onsuccess;
attribute EventHandler onerror;
};
error of
type DOMError,
readonly, nullableonerror
of type EventHandleronsuccess of type EventHandlerreadyState of type DOMString, readonlyresult of
type any, readonly,
nullableContactsRequest
object, e.g. remove method of the
ContactsManager object.The following are the event handlers (and their
corresponding event handler event types) that
MUST be supported as
attributes by the ContactsRequest object:
| event handler | event handler event type |
|---|---|
onsuccess |
success |
onerror |
error |
ContactsChangeEvent
InterfaceThe ContactsChangeEvent interface
represents events related to the set of contacts that have been
simultaneously added, removed and/or modified. Changes that are
applied to the address book in batches cause a ContactsChangeEvent with
multiple contact references to be fired, whereas changes
applied sequentially cause a ContactsChangeEvent with a
single contact reference to be fired
[NoInterfaceObject]
interface ContactsChangeEvent : Event {
readonly attribute DOMString[] added;
readonly attribute DOMString[] modified;
readonly attribute DOMString[] removed;
};
added
of type array of DOMString, readonlyContact
object(s) that have been added.modified of type array of DOMString, readonlyContact
object(s) that have been modified.removed of type array of DOMString, readonlyContact
object(s) that have been removed.The editors would like to express their gratitude to the Mozilla B2G Team for their technical guidance, implementation work and support