Bug 1361333 - move sdk/util/indexed-db to devtools;r=ochameau draft
authorJulian Descottes <jdescottes@mozilla.com>
Mon, 31 Jul 2017 21:55:33 +0200
changeset 618921 51d8afbf67fc52661e9934f9fcb5e4ceca38668f
parent 618288 a6c502679d442596b8b4410d6413cd310ac46408
child 640226 aa3a68c4a0ae8093c4e9bab1ffa50a262538eb4c
push id71500
push userjdescottes@mozilla.com
push dateTue, 01 Aug 2017 08:18:53 +0000
reviewersochameau
bugs1361333
milestone56.0a1
Bug 1361333 - move sdk/util/indexed-db to devtools;r=ochameau MozReview-Commit-ID: Lt4V6kmQACq
devtools/shared/Loader.jsm
devtools/shared/builtin-modules.js
devtools/shared/indexed-db.js
devtools/shared/moz.build
--- 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',