+ },
+
+ observe: null,
+ observers: {
+ "nsPref:changed": function (subject, data) {
+ let observers = this._observers[data];
+ if (observers) {
+ let value = this.get(data, false);
+ this._observers[data] = observers.filter(function (callback) {
+ if (!callback.get())
+ return false;
+ util.trapErrors(callback.get(), null, value);
+ return true;
+ });
+ }
+ }
+ },
+
+ /**
+ * Adds a new preference observer for the given preference.
+ *
+ * @param {string} pref The preference to observe.
+ * @param {function(object)} callback The callback, called with the
+ * new value of the preference whenever it changes.
+ */
+ watch: function watch(pref, callback, strong) {
+ if (!this.observe) {
+ util.addObserver(this);
+ this.branch.addObserver("", this, false);
+ }
+
+ if (!this._observers[pref])
+ this._observers[pref] = [];
+ this._observers[pref].push(!strong ? util.weakReference(callback) : { get: function () callback });
+ },
+
+ /**
+ * Lists all preferences matching *filter* or only those with changed
+ * values if *onlyNonDefault* is specified.
+ *
+ * @param {boolean} onlyNonDefault Limit the list to prefs with a
+ * non-default value.
+ * @param {string} filter The list filter. A null filter lists all
+ * prefs.
+ * @optional
+ */
+ list: function list(onlyNonDefault, filter) {
+ if (!filter)
+ filter = "";
+
+ let prefArray = this.getNames();
+ prefArray.sort();
+ function prefs() {
+ for (let [, pref] in Iterator(prefArray)) {
+ let userValue = services.pref.prefHasUserValue(pref);
+ if (onlyNonDefault && !userValue || pref.indexOf(filter) == -1)
+ continue;
+
+ let value = this.get(pref);
+
+ let option = {
+ isDefault: !userValue,
+ default: this.defaults.get(pref, null),
+ value: <>={template.highlight(value, true, 100)}</>,
+ name: pref,
+ pre: "\u00a0\u00a0" // Unicode nonbreaking space.
+ };
+
+ yield option;
+ }
+ };
+
+ return template.options(_("pref.hostPreferences", config.host), prefs.call(this));
+ },