tor-browser

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

xpcshell.js (2397B)


      1 /**
      2 * Any copyright is dedicated to the Public Domain.
      3 * http://creativecommons.org/publicdomain/zero/1.0/
      4 */
      5 
      6 loadScript("dom/quota/test/common/system.js");
      7 
      8 function enableStorageTesting() {
      9  Services.prefs.setBoolPref("dom.quotaManager.testing", true);
     10  Services.prefs.setBoolPref("dom.simpleDB.enabled", true);
     11  if (Services.appinfo.OS === "WINNT") {
     12    Services.prefs.setBoolPref("dom.quotaManager.useDOSDevicePathSyntax", true);
     13  }
     14 }
     15 
     16 function resetStorageTesting() {
     17  Services.prefs.clearUserPref("dom.quotaManager.testing");
     18  Services.prefs.clearUserPref("dom.simpleDB.enabled");
     19  if (Services.appinfo.OS === "WINNT") {
     20    Services.prefs.clearUserPref("dom.quotaManager.useDOSDevicePathSyntax");
     21  }
     22 }
     23 
     24 function clear(callback) {
     25  let request = Services.qms.clear();
     26  request.callback = callback;
     27 
     28  return request;
     29 }
     30 
     31 function reset(callback) {
     32  let request = Services.qms.reset();
     33  request.callback = callback;
     34 
     35  return request;
     36 }
     37 
     38 function installPackage(packageRelativePath, allowFileOverwrites) {
     39  let currentDir = Services.dirsvc.get("CurWorkD", Ci.nsIFile);
     40 
     41  let packageFile = getRelativeFile(packageRelativePath + ".zip", currentDir);
     42 
     43  let zipReader = Cc["@mozilla.org/libjar/zip-reader;1"].createInstance(
     44    Ci.nsIZipReader
     45  );
     46  zipReader.open(packageFile);
     47 
     48  let entryNames = Array.from(zipReader.findEntries(null));
     49  entryNames.sort();
     50 
     51  for (let entryName of entryNames) {
     52    if (entryName.match(/^create_db\.(html|js)/)) {
     53      continue;
     54    }
     55 
     56    let zipentry = zipReader.getEntry(entryName);
     57 
     58    let file = getRelativeFile(entryName);
     59 
     60    if (zipentry.isDirectory) {
     61      if (!file.exists()) {
     62        file.create(Ci.nsIFile.DIRECTORY_TYPE, parseInt("0755", 8));
     63      }
     64    } else {
     65      if (!allowFileOverwrites && file.exists()) {
     66        throw new Error("File already exists!");
     67      }
     68 
     69      let istream = zipReader.getInputStream(entryName);
     70 
     71      var ostream = Cc[
     72        "@mozilla.org/network/file-output-stream;1"
     73      ].createInstance(Ci.nsIFileOutputStream);
     74      ostream.init(file, -1, parseInt("0644", 8), 0);
     75 
     76      let bostream = Cc[
     77        "@mozilla.org/network/buffered-output-stream;1"
     78      ].createInstance(Ci.nsIBufferedOutputStream);
     79      bostream.init(ostream, 32768);
     80 
     81      bostream.writeFrom(istream, istream.available());
     82 
     83      istream.close();
     84      bostream.close();
     85    }
     86  }
     87 
     88  zipReader.close();
     89 }