michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: "use strict"; michael@0: michael@0: module.metadata = { michael@0: "stability": "experimental" michael@0: }; michael@0: michael@0: const { Cc, Ci } = require("chrome"); michael@0: const { id } = require("./self"); michael@0: michael@0: // placeholder, copied from bootstrap.js michael@0: let sanitizeId = function(id){ michael@0: let uuidRe = michael@0: /^\{([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})\}$/; michael@0: michael@0: let domain = id. michael@0: toLowerCase(). michael@0: replace(/@/g, "-at-"). michael@0: replace(/\./g, "-dot-"). michael@0: replace(uuidRe, "$1"); michael@0: michael@0: return domain michael@0: }; michael@0: michael@0: const PSEUDOURI = "indexeddb://" + sanitizeId(id) // https://bugzilla.mozilla.org/show_bug.cgi?id=779197 michael@0: michael@0: // Firefox 26 and earlier releases don't support `indexedDB` in sandboxes michael@0: // automatically, so we need to inject `indexedDB` to `this` scope ourselves. michael@0: if (typeof(indexedDB) === "undefined") { michael@0: Cc["@mozilla.org/dom/indexeddb/manager;1"]. michael@0: getService(Ci.nsIIndexedDatabaseManager). michael@0: initWindowless(this); michael@0: michael@0: // Firefox 14 gets this with a prefix michael@0: if (typeof(indexedDB) === "undefined") michael@0: this.indexedDB = mozIndexedDB; michael@0: } michael@0: michael@0: // Use XPCOM because `require("./url").URL` doesn't expose the raw uri object. michael@0: let principaluri = Cc["@mozilla.org/network/io-service;1"]. michael@0: getService(Ci.nsIIOService). michael@0: newURI(PSEUDOURI, null, null); michael@0: michael@0: let principal = Cc["@mozilla.org/scriptsecuritymanager;1"]. michael@0: getService(Ci.nsIScriptSecurityManager). michael@0: getCodebasePrincipal(principaluri); michael@0: michael@0: exports.indexedDB = Object.freeze({ michael@0: open: indexedDB.openForPrincipal.bind(indexedDB, principal), michael@0: deleteDatabase: indexedDB.deleteForPrincipal.bind(indexedDB, principal), michael@0: cmp: indexedDB.cmp michael@0: }); michael@0: michael@0: exports.IDBKeyRange = IDBKeyRange; michael@0: exports.DOMException = Ci.nsIDOMDOMException;