tor-browser

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

head.js (1761B)


      1 // This url must sync with the table, url in SafeBrowsing.sys.mjs addMozEntries
      2 const PHISH_TABLE = "moztest-phish-simple";
      3 const PHISH_URL = "https://www.itisatrap.org/firefox/its-a-trap.html";
      4 
      5 // This function is mostly ported from classifierCommon.js
      6 // under toolkit/components/url-classifier/tests/mochitest.
      7 function waitForDBInit(callback) {
      8  // Since there are two cases that may trigger the callback,
      9  // we have to carefully avoid multiple callbacks and observer
     10  // leaking.
     11  let didCallback = false;
     12  function callbackOnce() {
     13    if (!didCallback) {
     14      Services.obs.removeObserver(obsFunc, "mozentries-update-finished");
     15      callback();
     16    }
     17    didCallback = true;
     18  }
     19 
     20  // The first part: listen to internal event.
     21  function obsFunc() {
     22    ok(true, "Received internal event!");
     23    callbackOnce();
     24  }
     25  Services.obs.addObserver(obsFunc, "mozentries-update-finished");
     26 
     27  // The second part: we might have missed the event. Just do
     28  // an internal database lookup to confirm if the url has been
     29  // added.
     30  let principal = Services.scriptSecurityManager.createContentPrincipal(
     31    Services.io.newURI(PHISH_URL),
     32    {}
     33  );
     34 
     35  let dbService = Cc["@mozilla.org/url-classifier/dbservice;1"].getService(
     36    Ci.nsIUrlClassifierDBService
     37  );
     38  dbService.lookup(principal, PHISH_TABLE, value => {
     39    if (value === PHISH_TABLE) {
     40      ok(true, "DB lookup success!");
     41      callbackOnce();
     42    }
     43  });
     44 }
     45 
     46 Services.prefs.setCharPref(
     47  "urlclassifier.malwareTable",
     48  "moztest-malware-simple,moztest-unwanted-simple,moztest-harmful-simple"
     49 );
     50 Services.prefs.setCharPref("urlclassifier.phishTable", "moztest-phish-simple");
     51 Services.prefs.setCharPref(
     52  "urlclassifier.blockedTable",
     53  "moztest-block-simple"
     54 );
     55 SafeBrowsing.init();