Bug 1291834 - make indexDB a global via devtools loader; r=jryans
authorTom Tromey <tom@tromey.com>
Wed, 03 Aug 2016 13:26:34 -0600
changeset 308570 006c9345adb4292862a1513533d06177a33e564d
parent 308569 c4ad9dd4deae89d221373ba46768b4d3e4a23435
child 308571 d40036e732c863c786f58a7b67c94ebb66c667e0
push id31152
push userttromey@mozilla.com
push dateMon, 08 Aug 2016 14:29:37 +0000
treeherderautoland@006c9345adb4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjryans
bugs1291834
milestone51.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1291834 - make indexDB a global via devtools loader; r=jryans MozReview-Commit-ID: 3NnhUWaBBra
devtools/.eslintrc
devtools/client/webide/modules/app-projects.js
devtools/server/actors/storage.js
devtools/shared/async-storage.js
devtools/shared/builtin-modules.js
--- a/devtools/.eslintrc
+++ b/devtools/.eslintrc
@@ -10,16 +10,17 @@
     "clearInterval": true,
     "clearTimeout": true,
     "console": true,
     "CSS": true,
     "DOMParser": true,
     "dump": true,
     "exports": true,
     "isWorker": true,
+    "indexedDB": true,
     "loader": true,
     "module": true,
     "reportError": true,
     "require": true,
     "setInterval": true,
     "setTimeout": true,
     "uneval": true,
     "URL": true,
--- a/devtools/client/webide/modules/app-projects.js
+++ b/devtools/client/webide/modules/app-projects.js
@@ -3,17 +3,16 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 const {Cc, Ci, Cu, Cr} = require("chrome");
 const promise = require("promise");
 
 const EventEmitter = require("devtools/shared/event-emitter");
 const {generateUUID} = Cc["@mozilla.org/uuid-generator;1"].getService(Ci.nsIUUIDGenerator);
 const {FileUtils} = Cu.import("resource://gre/modules/FileUtils.jsm", {});
-const {indexedDB} = require("sdk/indexed-db");
 
 /**
  * IndexedDB wrapper that just save project objects
  *
  * The only constraint is that project objects have to have
  * a unique `location` object.
  */
 
--- a/devtools/server/actors/storage.js
+++ b/devtools/server/actors/storage.js
@@ -1,28 +1,42 @@
 /* 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";
 
-const {Cc, Ci} = require("chrome");
+const {Cc, Ci, Cu, CC} = require("chrome");
 const events = require("sdk/event/core");
 const protocol = require("devtools/shared/protocol");
 const {LongStringActor} = require("devtools/server/actors/string");
 const {DebuggerServer} = require("devtools/server/main");
 const Services = require("Services");
 const promise = require("promise");
 const {isWindowIncluded} = require("devtools/shared/layout/utils");
 const specs = require("devtools/shared/specs/storage");
 const { Task } = require("devtools/shared/task");
 
 loader.lazyImporter(this, "OS", "resource://gre/modules/osfile.jsm");
 loader.lazyImporter(this, "Sqlite", "resource://gre/modules/Sqlite.jsm");
 
+// We give this a funny name to avoid confusion with the global
+// indexedDB.
+loader.lazyGetter(this, "indexedDBForStorage", () => {
+  // On xpcshell, we can't instantiate indexedDB without crashing
+  try {
+    let sandbox
+      = Cu.Sandbox(CC("@mozilla.org/systemprincipal;1", "nsIPrincipal")(),
+                   {wantGlobalProperties: ["indexedDB"]});
+    return sandbox.indexedDB;
+  } catch (e) {
+    return {};
+  }
+});
+
 var gTrackedMessageManager = new Map();
 
 // Maximum number of cookies/local storage key-value-pairs that can be sent
 // over the wire to the client in one request.
 const MAX_STORE_OBJECT_COUNT = 50;
 // Delay for the batch job that sends the accumulated update packets to the
 // client (ms).
 const BATCH_DELAY = 200;
@@ -1731,22 +1745,22 @@ var indexedDBHelpers = {
     return success.promise;
   }),
 
   /**
    * Opens an indexed db connection for the given `principal` and
    * database `name`.
    */
   openWithPrincipal(principal, name) {
-    return require("indexedDB").openForPrincipal(principal, name);
+    return indexedDBForStorage.openForPrincipal(principal, name);
   },
 
   removeDB: Task.async(function* (host, principal, name) {
     let result = new promise(resolve => {
-      let request = require("indexedDB").deleteForPrincipal(principal, name);
+      let request = indexedDBForStorage.deleteForPrincipal(principal, name);
 
       request.onsuccess = () => {
         resolve({});
         this.onItemUpdated("deleted", host, [name]);
       };
 
       request.onblocked = () => {
         console.warn(`Deleting indexedDB database ${name} for host ${host} is blocked`);
--- a/devtools/shared/async-storage.js
+++ b/devtools/shared/async-storage.js
@@ -37,17 +37,16 @@
  * retrieve them together, in a single asynchronous operation, just group the
  * values into a single object. The properties of this object may not include
  * DOM elements, but they may include things like Blobs and typed arrays.
  *
  */
 
 "use strict";
 
-const {indexedDB} = require("sdk/indexed-db");
 const Promise = require("promise");
 
 const DBNAME = "devtools-async-storage";
 const DBVERSION = 1;
 const STORENAME = "keyvaluepairs";
 var db = null;
 
 function withStore(type, onsuccess, onerror) {
--- a/devtools/shared/builtin-modules.js
+++ b/devtools/shared/builtin-modules.js
@@ -199,29 +199,16 @@ defineLazyGetter(exports.modules, "Timer
     clearTimeout
   };
 });
 
 defineLazyGetter(exports.modules, "xpcInspector", () => {
   return Cc["@mozilla.org/jsinspector;1"].getService(Ci.nsIJSInspector);
 });
 
-defineLazyGetter(exports.modules, "indexedDB", () => {
-  // On xpcshell, we can't instantiate indexedDB without crashing
-  try {
-    let sandbox
-      = Cu.Sandbox(CC("@mozilla.org/systemprincipal;1", "nsIPrincipal")(),
-                   {wantGlobalProperties: ["indexedDB"]});
-    return sandbox.indexedDB;
-
-  } catch (e) {
-    return {};
-  }
-});
-
 defineLazyGetter(exports.modules, "FileReader", () => {
   let sandbox
     = Cu.Sandbox(CC("@mozilla.org/systemprincipal;1", "nsIPrincipal")(),
                  {wantGlobalProperties: ["FileReader"]});
   return sandbox.FileReader;
 });
 
 // List of all custom globals exposed to devtools modules.
@@ -290,8 +277,9 @@ defineLazyGetter(globals, "CSS", () => {
   let sandbox
     = Cu.Sandbox(CC("@mozilla.org/systemprincipal;1", "nsIPrincipal")(),
                  {wantGlobalProperties: ["CSS"]});
   return sandbox.CSS;
 });
 defineLazyGetter(globals, "WebSocket", () => {
   return Services.appShell.hiddenDOMWindow.WebSocket;
 });
+lazyRequireGetter(globals, "indexedDB", "sdk/indexed-db", true);