tor-browser

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

localStorageCommon.js (3519B)


      1 function localStorageFlush(cb) {
      2  if (SpecialPowers.Services.domStorageManager.nextGenLocalStorageEnabled) {
      3    SimpleTest.executeSoon(function () {
      4      cb();
      5    });
      6    return;
      7  }
      8 
      9  var ob = {
     10    observe(sub, top, dat) {
     11      os().removeObserver(ob, "domstorage-test-flushed");
     12      cb();
     13    },
     14  };
     15  os().addObserver(ob, "domstorage-test-flushed");
     16  notify("domstorage-test-flush-force");
     17 }
     18 
     19 function localStorageReload(callback) {
     20  if (SpecialPowers.Services.domStorageManager.nextGenLocalStorageEnabled) {
     21    localStorage.close();
     22    let qms = SpecialPowers.Services.qms;
     23    let principal = SpecialPowers.wrap(document).nodePrincipal;
     24    let request = qms.resetStoragesForClient(principal, "ls", "default");
     25    request.callback = SpecialPowers.wrapCallback(function () {
     26      localStorage.open();
     27      callback();
     28    });
     29    return;
     30  }
     31 
     32  notify("domstorage-test-reload");
     33  SimpleTest.executeSoon(function () {
     34    callback();
     35  });
     36 }
     37 
     38 function localStorageFlushAndReload(callback) {
     39  if (SpecialPowers.Services.domStorageManager.nextGenLocalStorageEnabled) {
     40    localStorage.close();
     41    let qms = SpecialPowers.Services.qms;
     42    let principal = SpecialPowers.wrap(document).nodePrincipal;
     43    let request = qms.resetStoragesForClient(principal, "ls", "default");
     44    request.callback = SpecialPowers.wrapCallback(function () {
     45      localStorage.open();
     46      callback();
     47    });
     48    return;
     49  }
     50 
     51  localStorageFlush(function () {
     52    localStorageReload(callback);
     53  });
     54 }
     55 
     56 function localStorageClearAll(callback) {
     57  if (SpecialPowers.Services.domStorageManager.nextGenLocalStorageEnabled) {
     58    let qms = SpecialPowers.Services.qms;
     59    let ssm = SpecialPowers.Services.scriptSecurityManager;
     60 
     61    qms.getUsage(
     62      SpecialPowers.wrapCallback(function (request) {
     63        if (request.resultCode != SpecialPowers.Cr.NS_OK) {
     64          callback();
     65          return;
     66        }
     67 
     68        let clearRequestCount = 0;
     69        for (let item of request.result) {
     70          let principal = ssm.createContentPrincipalFromOrigin(item.origin);
     71          let clearRequest = qms.clearStoragesForClient(
     72            principal,
     73            "ls",
     74            "default"
     75          );
     76          clearRequestCount++;
     77          clearRequest.callback = SpecialPowers.wrapCallback(function () {
     78            if (--clearRequestCount == 0) {
     79              callback();
     80            }
     81          });
     82        }
     83      })
     84    );
     85    return;
     86  }
     87 
     88  os().notifyObservers(null, "cookie-changed", "cleared");
     89  SimpleTest.executeSoon(function () {
     90    callback();
     91  });
     92 }
     93 
     94 function localStorageClearDomain(domain, callback) {
     95  if (SpecialPowers.Services.domStorageManager.nextGenLocalStorageEnabled) {
     96    let qms = SpecialPowers.Services.qms;
     97    let principal = SpecialPowers.wrap(document).effectiveStoragePrincipal;
     98    let request = qms.clearStoragesForClient(principal, "ls", "default");
     99    let cb = SpecialPowers.wrapCallback(callback);
    100    request.callback = cb;
    101    return;
    102  }
    103 
    104  os().notifyObservers(null, "extension:purge-localStorage", domain);
    105  SimpleTest.executeSoon(function () {
    106    callback();
    107  });
    108 }
    109 
    110 function os() {
    111  return SpecialPowers.Services.obs;
    112 }
    113 
    114 function notify(top) {
    115  os().notifyObservers(null, top);
    116 }
    117 
    118 /**
    119 * Enable testing observer notifications in DOMStorageObserver.cpp.
    120 */
    121 function localStorageEnableTestingMode(cb) {
    122  SpecialPowers.pushPrefEnv(
    123    {
    124      set: [
    125        ["dom.storage.testing", true],
    126        ["dom.quotaManager.testing", true],
    127      ],
    128    },
    129    cb
    130  );
    131 }