Bug 1361333 - move sdk/util/indexed-db to devtools;r=ochameau

MozReview-Commit-ID: Lt4V6kmQACq

--HG--
extra : rebase_source : 80bdaa517bdfa6863f963c7ed8a5275ba7415c18
This commit is contained in:
Julian Descottes 2017-07-31 21:55:33 +02:00
parent 40b5eb5426
commit dc05133f8b
4 changed files with 57 additions and 4 deletions

View File

@ -20,8 +20,6 @@ this.EXPORTED_SYMBOLS = ["DevToolsLoader", "devtools", "BuiltinProvider",
* Providers are different strategies for loading the devtools.
*/
var sharedGlobalBlocklist = ["sdk/indexed-db"];
/**
* Used when the tools should be loaded from the Firefox package itself.
* This is the default case.
@ -73,7 +71,7 @@ BuiltinProvider.prototype = {
paths,
invisibleToDebugger: this.invisibleToDebugger,
sharedGlobal: true,
sharedGlobalBlocklist,
sharedGlobalBlocklist: [],
sandboxName: "DevTools (Module loader)",
noSandboxAddonId: true,
requireHook: (id, require) => {

View File

@ -302,5 +302,7 @@ lazyGlobal("WebSocket", () => {
return Services.appShell.hiddenDOMWindow.WebSocket;
});
lazyGlobal("indexedDB", () => {
return require("sdk/indexed-db").indexedDB;
let { indexedDB } = Cu.Sandbox(CC("@mozilla.org/systemprincipal;1", "nsIPrincipal")(),
{wantGlobalProperties: ["indexedDB"]});
return require("devtools/shared/indexed-db").createDevToolsIndexedDB(indexedDB);
});

View File

@ -0,0 +1,52 @@
/* 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 } = require("chrome");
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, {});
/**
* Create the DevTools dedicated DB, by relying on the real indexedDB object passed as a
* parameter here.
*
* @param {IDBFactory} indexedDB
* Real indexedDB object.
* @return {Object} Wrapper object that implements IDBFactory methods, but for a devtools
* specific principal.
*/
exports.createDevToolsIndexedDB = function (indexedDB) {
return Object.freeze({
/**
* Only the standard version of indexedDB.open is supported.
*/
open(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(name) {
return indexedDB.deleteForPrincipal(principal, name, { storage: "persistent" });
},
cmp: indexedDB.cmp.bind(indexedDB),
});
};

View File

@ -57,6 +57,7 @@ DevToolsModules(
'flags.js',
'generate-uuid.js',
'indentation.js',
'indexed-db.js',
'l10n.js',
'loader-plugin-raw.jsm',
'Loader.jsm',