tor-browser

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

content.js (2333B)


      1 /**
      2 * Any copyright is dedicated to the Public Domain.
      3 * http://creativecommons.org/publicdomain/zero/1.0/
      4 */
      5 
      6 // This cannot be `const` due to the lexical scope used by eval.
      7 var NS_ERROR_STORAGE_BUSY = SpecialPowers.Cr.NS_ERROR_STORAGE_BUSY;
      8 
      9 loadScript("dom/quota/test/common/global.js");
     10 
     11 function clearAllDatabases(callback) {
     12  let qms = SpecialPowers.Services.qms;
     13  let principal = SpecialPowers.wrap(document).nodePrincipal;
     14  let request = qms.clearStoragesForPrincipal(principal);
     15  let cb = SpecialPowers.wrapCallback(callback);
     16  request.callback = cb;
     17  return request;
     18 }
     19 
     20 // SimpleDB connections and SpecialPowers wrapping:
     21 //
     22 // SpecialPowers provides a SpecialPowersHandler Proxy mechanism that lets our
     23 // content-privileged code borrow its chrome-privileged principal to access
     24 // things we shouldn't be able to access.  The proxies wrap their returned
     25 // values, so once we have something wrapped we can rely on returned objects
     26 // being wrapped as well.  The proxy will also automatically unwrap wrapped
     27 // arguments we pass in.  However, we need to invoke wrapCallback on callback
     28 // functions so that the arguments they receive will be wrapped because the
     29 // proxy does not automatically wrap content-privileged functions.
     30 //
     31 // Our use of (wrapped) SpecialPowers.Cc results in getSimpleDatabase()
     32 // producing a wrapped nsISDBConnection instance.  The nsISDBResult instances
     33 // exposed on the (wrapped) nsISDBRequest are also wrapped.
     34 // In particular, the wrapper takes responsibility for automatically cloning
     35 // the ArrayBuffer returned by nsISDBResult.getAsArrayBuffer into the content
     36 // compartment (rather than wrapping it) so that constructing a Uint8Array
     37 // from it will succeed.
     38 
     39 function getSimpleDatabase() {
     40  let connection = SpecialPowers.Cc[
     41    "@mozilla.org/dom/sdb-connection;1"
     42  ].createInstance(SpecialPowers.Ci.nsISDBConnection);
     43 
     44  let principal = SpecialPowers.wrap(document).nodePrincipal;
     45 
     46  connection.init(principal);
     47 
     48  return connection;
     49 }
     50 
     51 async function requestFinished(request) {
     52  await new Promise(function (resolve) {
     53    request.callback = SpecialPowers.wrapCallback(function () {
     54      resolve();
     55    });
     56  });
     57 
     58  if (request.resultCode != SpecialPowers.Cr.NS_OK) {
     59    throw new RequestError(request.resultCode, request.resultName);
     60  }
     61 
     62  return request.result;
     63 }