indexedDB
API is typically used to store data in the user's browser from content JavaScript. (See
使用 IndexedDB
for an overview.) However, the APIs can also be accessed from system-privileged JavaScript using the
Components.utils.importGlobalProperties()
函数:
Components.utils.importGlobalProperties(["indexedDB"]);
// From here on, it's like using IndexedDB from content
var req = indexedDB.open("my-database");
// ...
If you are creating a sandbox, and want
indexedDB
to be available in it, use the
wantGlobalProperties
option in the
Sandbox
构造函数:
var options = {
"wantGlobalProperties": ["indexedDB"]
}
var principal = Cc["@mozilla.org/systemprincipal;1"].createInstance(Ci.nsIPrincipal);
var sandbox = Components.utils.Sandbox(principal, options);
// The sandbox will have access to indexedDB
var sandboxScript = 'var req = indexedDB.open("my-database");';
Components.utils.evalInSandbox(sandboxScript, sandbox);
Before Firefox 33, you would access
indexedDB
from chrome code using the
initWindowless
方法在
nsIIndexedDatabaseManager
service. This method was removed in Firefox 33.
IDBCursor
IDBCursorSync
IDBCursorWithValue
IDBDatabase
IDBDatabaseException
IDBDatabaseSync
IDBEnvironment
IDBEnvironmentSync
IDBFactory
IDBFactorySync
IDBIndex
IDBIndexSync
IDBKeyRange
IDBObjectStore
IDBObjectStoreSync
IDBOpenDBRequest
IDBRequest
IDBTransaction
IDBTransactionSync
IDBVersionChangeEvent
IDBVersionChangeRequest