/usr/share/xul-ext/adblock-plus-element-hiding-helper/prefs.js is in xul-ext-adblock-plus-element-hiding-helper 1.2.2-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | /*
* This Source Code is subject to the terms of the Mozilla Public License
* version 2.0 (the "License"). You can obtain a copy of the License at
* http://mozilla.org/MPL/2.0/.
*/
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
let {addonRoot, addonName} = require("info");
let branchName = "extensions." + addonName + ".";
let branch = Services.prefs.getBranch(branchName);
let ignorePrefChanges = false;
function init()
{
// Load default preferences and set up properties for them
let defaultBranch = Services.prefs.getDefaultBranch(branchName);
let scope =
{
pref: function(pref, value)
{
if (pref.substr(0, branchName.length) != branchName)
{
Cu.reportError(new Error("Ignoring default preference " + pref + ", wrong branch."));
return;
}
pref = pref.substr(branchName.length);
let [getter, setter] = typeMap[typeof value];
setter(defaultBranch, pref, value);
defineProperty(pref, false, getter, setter);
}
};
Services.scriptloader.loadSubScript(addonRoot + "defaults/preferences/prefs.js", scope);
// Add preference change observer
try
{
branch.QueryInterface(Ci.nsIPrefBranch2).addObserver("", Prefs, true);
onShutdown.add(function() branch.removeObserver("", Prefs));
}
catch (e)
{
Cu.reportError(e);
}
}
/**
* Sets up getter/setter on Prefs object for preference.
*/
function defineProperty(/**String*/ name, defaultValue, /**Function*/ readFunc, /**Function*/ writeFunc)
{
let value = defaultValue;
Prefs["_update_" + name] = function()
{
try
{
value = readFunc(branch, name);
triggerListeners(name);
}
catch(e)
{
Cu.reportError(e);
}
};
Prefs.__defineGetter__(name, function() value);
Prefs.__defineSetter__(name, function(newValue)
{
if (value == newValue)
return value;
try
{
ignorePrefChanges = true;
writeFunc(branch, name, newValue);
value = newValue;
triggerListeners(name);
}
catch(e)
{
Cu.reportError(e);
}
finally
{
ignorePrefChanges = false;
}
return value;
});
Prefs["_update_" + name]();
}
let listeners = [];
function triggerListeners(/**String*/ name)
{
for (let i = 0; i < listeners.length; i++)
{
try
{
listeners[i](name);
}
catch(e)
{
Cu.reportError(e);
}
}
}
/**
* Manages the preferences for an extension, object properties corresponding
* to extension's preferences are added automatically. Setting the property
* will automatically change the preference, external preference changes are
* also recognized automatically.
*/
let Prefs = exports.Prefs =
{
/**
* Migrates an old preference to a new name.
*/
migrate: function(/**String*/ oldName, /**String*/ newName)
{
if (newName in this && Services.prefs.prefHasUserValue(oldName))
{
let [getter, setter] = typeMap[typeof this[newName]];
try
{
this[newName] = getter(Services.prefs, oldName);
} catch(e) {}
Services.prefs.clearUserPref(oldName);
}
},
/**
* Adds a preferences listener that will be fired whenever a preference
* changes.
*/
addListener: function(/**Function*/ listener)
{
if (listeners.indexOf(listener) < 0)
listeners.push(listener);
},
/**
* Removes a preferences listener.
*/
removeListener: function(/**Function*/ listener)
{
let index = listeners.indexOf(listener);
if (index >= 0)
listeners.splice(index, 1);
},
observe: function(subject, topic, data)
{
if (ignorePrefChanges || topic != "nsPref:changed")
return;
if ("_update_" + data in this)
this["_update_" + data]();
},
QueryInterface: XPCOMUtils.generateQI([Ci.nsISupportsWeakReference, Ci.nsIObserver])
};
// Getter/setter functions for difference preference types
let typeMap =
{
boolean: [getBoolPref, setBoolPref],
number: [getIntPref, setIntPref],
string: [getCharPref, setCharPref],
object: [getJSONPref, setJSONPref]
};
function getIntPref(branch, pref) branch.getIntPref(pref)
function setIntPref(branch, pref, newValue) branch.setIntPref(pref, newValue)
function getBoolPref(branch, pref) branch.getBoolPref(pref)
function setBoolPref(branch, pref, newValue) branch.setBoolPref(pref, newValue)
function getCharPref(branch, pref) branch.getComplexValue(pref, Ci.nsISupportsString).data
function setCharPref(branch, pref, newValue)
{
let str = Cc["@mozilla.org/supports-string;1"].createInstance(Ci.nsISupportsString);
str.data = newValue;
branch.setComplexValue(pref, Ci.nsISupportsString, str);
}
function getJSONPref(branch, pref) JSON.parse(getCharPref(branch, pref))
function setJSONPref(branch, pref, newValue) setCharPref(branch, pref, JSON.stringify(newValue))
init();
|