tor-browser

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

system.js (1870B)


      1 /**
      2 * Any copyright is dedicated to the Public Domain.
      3 * http://creativecommons.org/publicdomain/zero/1.0/
      4 */
      5 
      6 const PR_USEC_PER_SEC = 1000000;
      7 
      8 const NS_ERROR_STORAGE_BUSY = Cr.NS_ERROR_STORAGE_BUSY;
      9 
     10 loadScript("dom/quota/test/common/global.js");
     11 
     12 function getProfileDir() {
     13  return Services.dirsvc.get("ProfD", Ci.nsIFile);
     14 }
     15 
     16 // Given a "/"-delimited path relative to a base file (or the profile
     17 // directory if a base file is not provided) return an nsIFile representing the
     18 // path.  This does not test for the existence of the file or parent
     19 // directories.  It is safe even on Windows where the directory separator is
     20 // not "/", but make sure you're not passing in a "\"-delimited path.
     21 function getRelativeFile(relativePath, baseFile) {
     22  if (!baseFile) {
     23    baseFile = getProfileDir();
     24  }
     25 
     26  let file = baseFile.clone();
     27 
     28  if (Services.appinfo.OS === "WINNT") {
     29    let winFile = file.QueryInterface(Ci.nsILocalFileWin);
     30    winFile.useDOSDevicePathSyntax = true;
     31  }
     32 
     33  relativePath.split("/").forEach(function (component) {
     34    if (component == "..") {
     35      file = file.parent;
     36    } else {
     37      file.append(component);
     38    }
     39  });
     40 
     41  return file;
     42 }
     43 
     44 function getCurrentPrincipal() {
     45  return Cc["@mozilla.org/systemprincipal;1"].createInstance(Ci.nsIPrincipal);
     46 }
     47 
     48 function getSimpleDatabase(principal, persistence) {
     49  let connection = Cc["@mozilla.org/dom/sdb-connection;1"].createInstance(
     50    Ci.nsISDBConnection
     51  );
     52 
     53  if (!principal) {
     54    principal = getCurrentPrincipal();
     55  }
     56 
     57  connection.init(principal, persistence);
     58 
     59  return connection;
     60 }
     61 
     62 async function requestFinished(request) {
     63  await new Promise(function (resolve) {
     64    request.callback = function () {
     65      resolve();
     66    };
     67  });
     68 
     69  if (request.resultCode !== Cr.NS_OK) {
     70    throw new RequestError(request.resultCode, request.resultName);
     71  }
     72 
     73  return request.result;
     74 }