Bug 1361333 - move sdk/util/indexed-db to devtools;r=ochameau
MozReview-Commit-ID: Lt4V6kmQACq
--- a/devtools/shared/Loader.jsm
+++ b/devtools/shared/Loader.jsm
@@ -15,17 +15,17 @@ var { requireRawId } = Cu.import("resour
this.EXPORTED_SYMBOLS = ["DevToolsLoader", "devtools", "BuiltinProvider",
"require", "loader"];
/**
* Providers are different strategies for loading the devtools.
*/
-var sharedGlobalBlocklist = ["sdk/indexed-db"];
+var sharedGlobalBlocklist = ["devtools/shared/indexed-db"];
/**
* Used when the tools should be loaded from the Firefox package itself.
* This is the default case.
*/
function BuiltinProvider() {}
BuiltinProvider.prototype = {
load: function () {
--- a/devtools/shared/builtin-modules.js
+++ b/devtools/shared/builtin-modules.js
@@ -297,10 +297,10 @@ lazyGlobal("CSS", () => {
= Cu.Sandbox(CC("@mozilla.org/systemprincipal;1", "nsIPrincipal")(),
{wantGlobalProperties: ["CSS"]});
return sandbox.CSS;
});
lazyGlobal("WebSocket", () => {
return Services.appShell.hiddenDOMWindow.WebSocket;
});
lazyGlobal("indexedDB", () => {
- return require("sdk/indexed-db").indexedDB;
+ return require("devtools/shared/indexed-db").indexedDB;
});
new file mode 100644
--- /dev/null
+++ b/devtools/shared/indexed-db.js
@@ -0,0 +1,43 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+/**
+ * This indexedDB helper is a simplified version of sdk/indexed-db. It creates a DB with
+ * a principal dedicated to DevTools.
+ */
+
+const { Cc, Ci, Cu, CC } = require("chrome");
+const { indexedDB } = Cu.Sandbox(CC("@mozilla.org/systemprincipal;1", "nsIPrincipal")(),
+ {wantGlobalProperties: ["indexedDB"]});
+
+const PSEUDOURI = "indexeddb://fx-devtools";
+const principaluri = Cc["@mozilla.org/network/io-service;1"]
+ .getService(Ci.nsIIOService).newURI(PSEUDOURI);
+
+const ssm = Cc["@mozilla.org/scriptsecuritymanager;1"]
+ .getService(Ci.nsIScriptSecurityManager);
+
+const principal = ssm.createCodebasePrincipal(principaluri, {});
+
+exports.indexedDB = Object.freeze({
+ /**
+ * Only the standard version of indexedDB.open is supported.
+ */
+ open: function (name, version) {
+ let options = { storage: "persistent" };
+ if (typeof version === "number") {
+ options.version = version;
+ }
+ return indexedDB.openForPrincipal(principal, name, options);
+ },
+ /**
+ * Only the standard version of indexedDB.deleteDatabase is supported.
+ */
+ deleteDatabase: function (name) {
+ return indexedDB.deleteForPrincipal(principal, name, { storage: "persistent" });
+ },
+ cmp: indexedDB.cmp.bind(indexedDB),
+});
--- a/devtools/shared/moz.build
+++ b/devtools/shared/moz.build
@@ -52,16 +52,17 @@ DevToolsModules(
'DevToolsUtils.js',
'dom-node-constants.js',
'dom-node-filter-constants.js',
'event-emitter.js',
'extend.js',
'flags.js',
'generate-uuid.js',
'indentation.js',
+ 'indexed-db.js',
'l10n.js',
'loader-plugin-raw.jsm',
'Loader.jsm',
'Parser.jsm',
'path.js',
'plural-form.js',
'protocol.js',
'system.js',