tor-browser

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

prefs.js (1326B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 "use strict";
      6 
      7 function getPreferenceName(hud, suffix) {
      8  if (!suffix) {
      9    console.error("Suffix shouldn't be falsy", { suffix });
     10    return null;
     11  }
     12 
     13  if (!hud) {
     14    console.error("hud shouldn't be falsy", { hud });
     15    return null;
     16  }
     17 
     18  if (suffix.startsWith("devtools.")) {
     19    // We don't have a suffix but a full pref name. Let's return it.
     20    return suffix;
     21  }
     22 
     23  const component = hud.isBrowserConsole ? "browserconsole" : "webconsole";
     24  return `devtools.${component}.${suffix}`;
     25 }
     26 
     27 function getPrefsService(hud) {
     28  const getPrefName = pref => getPreferenceName(hud, pref);
     29 
     30  return {
     31    getBoolPref: (pref, deflt) =>
     32      Services.prefs.getBoolPref(getPrefName(pref), deflt),
     33    getIntPref: (pref, deflt) =>
     34      Services.prefs.getIntPref(getPrefName(pref), deflt),
     35    setBoolPref: (pref, value) =>
     36      Services.prefs.setBoolPref(getPrefName(pref), value),
     37    setIntPref: (pref, value) =>
     38      Services.prefs.setIntPref(getPrefName(pref), value),
     39    clearUserPref: pref => Services.prefs.clearUserPref(getPrefName(pref)),
     40    getPrefName,
     41  };
     42 }
     43 
     44 module.exports = {
     45  getPrefsService,
     46 };