tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

indexed-db.js (1330B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 "use strict";
      6 
      7 /**
      8 * This indexedDB helper is a simplified version of sdk/indexed-db. It creates a DB with
      9 * a principal dedicated to DevTools.
     10 */
     11 
     12 const PSEUDOURI = "indexeddb://fx-devtools";
     13 const principaluri = Services.io.newURI(PSEUDOURI);
     14 const principal = Services.scriptSecurityManager.createContentPrincipal(
     15  principaluri,
     16  {}
     17 );
     18 
     19 // indexedDB is only exposed to document globals.
     20 // We are retrieving an instance from a Sandbox, which has to be loaded
     21 // from the system principal in order to avoid having wrappers around
     22 // all indexed DB objects.
     23 const systemPrincipal = Services.scriptSecurityManager.getSystemPrincipal();
     24 const sandbox = Cu.Sandbox(systemPrincipal, {
     25  wantGlobalProperties: ["indexedDB"],
     26 });
     27 const { indexedDB } = sandbox;
     28 
     29 module.exports = Object.freeze({
     30  open(name, version) {
     31    const options = {};
     32    if (typeof version === "number") {
     33      options.version = version;
     34    }
     35    return indexedDB.openForPrincipal(principal, name, options);
     36  },
     37 
     38  deleteDatabase(name) {
     39    return indexedDB.deleteForPrincipal(principal, name);
     40  },
     41 
     42  cmp: indexedDB.cmp.bind(indexedDB),
     43 });