addon-sdk/source/lib/sdk/indexed-db.js

branch
TOR_BUG_9701
changeset 15
b8a032363ba2
equal deleted inserted replaced
-1:000000000000 0:9b50db02d2ea
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
5 "use strict";
6
7 module.metadata = {
8 "stability": "experimental"
9 };
10
11 const { Cc, Ci } = require("chrome");
12 const { id } = require("./self");
13
14 // placeholder, copied from bootstrap.js
15 let sanitizeId = function(id){
16 let uuidRe =
17 /^\{([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})\}$/;
18
19 let domain = id.
20 toLowerCase().
21 replace(/@/g, "-at-").
22 replace(/\./g, "-dot-").
23 replace(uuidRe, "$1");
24
25 return domain
26 };
27
28 const PSEUDOURI = "indexeddb://" + sanitizeId(id) // https://bugzilla.mozilla.org/show_bug.cgi?id=779197
29
30 // Firefox 26 and earlier releases don't support `indexedDB` in sandboxes
31 // automatically, so we need to inject `indexedDB` to `this` scope ourselves.
32 if (typeof(indexedDB) === "undefined") {
33 Cc["@mozilla.org/dom/indexeddb/manager;1"].
34 getService(Ci.nsIIndexedDatabaseManager).
35 initWindowless(this);
36
37 // Firefox 14 gets this with a prefix
38 if (typeof(indexedDB) === "undefined")
39 this.indexedDB = mozIndexedDB;
40 }
41
42 // Use XPCOM because `require("./url").URL` doesn't expose the raw uri object.
43 let principaluri = Cc["@mozilla.org/network/io-service;1"].
44 getService(Ci.nsIIOService).
45 newURI(PSEUDOURI, null, null);
46
47 let principal = Cc["@mozilla.org/scriptsecuritymanager;1"].
48 getService(Ci.nsIScriptSecurityManager).
49 getCodebasePrincipal(principaluri);
50
51 exports.indexedDB = Object.freeze({
52 open: indexedDB.openForPrincipal.bind(indexedDB, principal),
53 deleteDatabase: indexedDB.deleteForPrincipal.bind(indexedDB, principal),
54 cmp: indexedDB.cmp
55 });
56
57 exports.IDBKeyRange = IDBKeyRange;
58 exports.DOMException = Ci.nsIDOMDOMException;

mercurial