Confirmed users
1,340
edits
No edit summary |
|||
(16 intermediate revisions by one other user not shown) | |||
Line 7: | Line 7: | ||
DeviceIndexedDB is a modification of IndexedDB. Here only depicts changes introduced by DeviceIndexedDB. | DeviceIndexedDB is a modification of IndexedDB. Here only depicts changes introduced by DeviceIndexedDB. | ||
var request = window. | var request = window.mozDeviceIndexedDB.open("ADeviceDatabase") | ||
This function is used to open or create a database. It returns an DOMRequest, then everything is exactly like what IndexedDB is. | This function is used to open or create a database. It returns an DOMRequest, then everything is exactly like what IndexedDB is. | ||
Line 16: | Line 16: | ||
name: "My Applicaiton", | name: "My Applicaiton", | ||
...... | ...... | ||
mozDeviceIndexedDB: { | |||
"database1": { | "database1": { | ||
"store1": { // name of the object store | "store1": { // name of the object store | ||
Line 32: | Line 32: | ||
} | } | ||
The property named " | The property named "mozDeviceIndexedDB" defines permissions for access control of DeviceIndexedDB databases. The children of "mozDeviceIndexedDB" are names of databases. Databases not in the children of a "mozDeviceIndexedDB" 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 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. | ||
Line 39: | Line 39: | ||
== Use Cases == | == Use Cases == | ||
* 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) | |||
=== Application Chooser === | |||
Following is an example of finding Apps providing DataCloudStorage services with DeviceIndexedDB as the application chooser. | |||
var request = window.mozDeviceIndexedDB.open("[SystemServices]"); | |||
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 "[SystemServices]" 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. | |||
{ | |||
name: "My Applicaiton", | |||
...... | |||
mozDeviceIndexedDB: { | |||
"[SystemServices]": { | |||
"Applications": { | |||
"ObjectStore": "none", | |||
"index": { | |||
"chooserByIntent": ["DataCloudStorage"], | |||
} | |||
} | |||
} | |||
} | |||
} | |||
This App is only allowed to pick a list of Apps providing "DataCloudStorage" services. | |||
Since "[SystemServices]" database is implemented by the platform code, writing actions may be forbidden by the implementation according the security model of the data. | |||
=== Expose Network Statistic of Apps === | |||
This is an example of exposing network statistics of Apps with DeviceIndexedDB. | |||
var request = window.mozDeviceIndexedDB.open("[SystemServices]"); | |||
request.onsuccess = function () { | |||
var db = request.result; | |||
var tx = db.transaction("NetworkStatistics"); | |||
var store = tx.objectStore("NetworkStatistics"); | |||
var apps = store.index("apps"); | |||
var statisrequest = apps.get("any-app-id"); | |||
statisrequest.onsuccess = function () { | |||
var statistic = statisrequest.result; | |||
showStatisticForApp(statistic); | |||
} | |||
} | |||
{ | |||
name: "My Applicaiton", | |||
...... | |||
mozDeviceIndexedDB: { | |||
"[SystemServices]": { | |||
"NetworkStatistics": { | |||
"ObjectStore": "none", | |||
"index": { | |||
"apps": ["any-app-id"], | |||
} | |||
} | |||
} | |||
} | |||
} | |||
[[Category:Web APIs]] |