WebAPI/DeviceIndexedDB: Difference between revisions
Line 47: | Line 47: | ||
*** A chooser UI is showed between the request and returning the list. | *** A chooser UI is showed between the request and returning the list. | ||
** With access control defined in the manifest, an app can request for predefined intents. (in the list of index keys) | ** With access control defined in the manifest, an app can request for predefined intents. (in the list of index keys) | ||
=== Application Chooser === | |||
Following is an example of finding Apps providing DataCloudStorage services with DeviceIndexedDB as the application chooser. | |||
var request = window.deviceIndexedDB.open("[SystemService]"); | |||
request.onsuccess = function () { | |||
var db = request.result; | |||
var tx = db.transaction("Applications"); | |||
var store = tx.objectStore("Applications"); | |||
var chooserByIntent = store.index("chooserByIntent"); | |||
var chooserrequest = chooserByIntent.get("DataCloudStorage"); | |||
chooserrequest.onsuccess = function () { | |||
var app = chooserrequest.result; | |||
talkToDataCloudStorage(app.id); | |||
} | |||
} | |||
The "[SystemService]" database is not necessary a real persistent data storage, it is implemented by the platform (Gecko) to provide the service. The line, chooserByIntent.get("DataCloudStorage"), would launch a application chooser by the platform. It return a list of applications once the user finish his selection. |
Revision as of 05:51, 15 July 2013
IndexedDB is widely used for WebApps as a storage at devices. However, data stores of IndexedDB are private for the App, and it can not be used for sharing data among Apps. DeviceIndexedDB is intent to be a way of sharing data among Apps and can be queried.
What is different from DataStoreAPI?
DataStoreAPI is supposed for sync data among Apps. It is not for querying objects in the store. IndexedDB provide a good feature for querying objects, and DeviceIndexedDB extend it to share data among Apps and get access controlling.
API
DeviceIndexedDB is a modification of IndexedDB. Here only depicts changes introduced by DeviceIndexedDB.
var request = window.deviceIndexedDB.open("ADeviceDatabase")
This function is used to open or create a database. It returns an DOMRequest, then everything is exactly like what IndexedDB is. The namespace of databases, here, is shared by all Apps on a device. So, every Apps with feasible permissions, can access a database.
MANIFEST
{ name: "My Applicaiton", ...... deviceIndexedDB: { "database1": { "store1": { // name of the object store "ObjectStore": "none", // can be "none", "read-only", // "read-write" "index": { "index-name-1": ["key1", "key2", ...], // allowed to // get objects with given keys "index-name-2": [......] } } }, "database2": {......} } }
The property named "deviceIndexedDB" defines permissions for access control of DeviceIndexedDB databases. The children of "deviceIndexedDB" are names of databases. Databases not in the children of a "deviceIndexedDB" of an App can not be accessed by the App.
The children of a database is names of data stores. Data stores not in the children of a database can not be accessed by the App. The "ObjectStore" property defines whether the App can read or read-write a data store. If the value of "ObjectStore" is "none", it means the App can not read or write the data store, but it can access indices according setting in "index" child of the data store.
The "index" child of a data store defines how the App can access indices. Indices not children of "index" property can not be accessed by the App. The value of an index is a list of keys. The App can only use keys in the list to query the index. Basically, "index" property of a data store is only meaningful for the value of "ObjectStoe" is "none".
Usecases
- Share data among Apps
- Expose system/device information to Apps
- Network usage statistic
- Apps list
- API for Application Chooser
- Get a list of Apps by querying applications with different index keys as an intent.
- A chooser UI is showed between the request and returning the list.
- With access control defined in the manifest, an app can request for predefined intents. (in the list of index keys)
- Get a list of Apps by querying applications with different index keys as an intent.
Application Chooser
Following is an example of finding Apps providing DataCloudStorage services with DeviceIndexedDB as the application chooser.
var request = window.deviceIndexedDB.open("[SystemService]"); request.onsuccess = function () { var db = request.result; var tx = db.transaction("Applications"); var store = tx.objectStore("Applications"); var chooserByIntent = store.index("chooserByIntent"); var chooserrequest = chooserByIntent.get("DataCloudStorage"); chooserrequest.onsuccess = function () { var app = chooserrequest.result; talkToDataCloudStorage(app.id); } }
The "[SystemService]" database is not necessary a real persistent data storage, it is implemented by the platform (Gecko) to provide the service. The line, chooserByIntent.get("DataCloudStorage"), would launch a application chooser by the platform. It return a list of applications once the user finish his selection.