2014-03-03 01:41:36 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
const {Cc, Ci, Cu, CC} = require("chrome");
|
2016-05-06 07:19:00 +00:00
|
|
|
const protocol = require("devtools/shared/protocol");
|
2014-03-03 01:41:36 +00:00
|
|
|
const {Arg, method, RetVal} = protocol;
|
2016-02-27 12:51:10 +00:00
|
|
|
const Services = require("Services");
|
2016-06-03 17:45:10 +00:00
|
|
|
const {preferenceSpec} = require("devtools/shared/specs/preference");
|
2014-03-03 01:41:36 +00:00
|
|
|
|
2016-05-17 18:25:54 +00:00
|
|
|
exports.register = function (handle) {
|
2014-03-03 01:41:36 +00:00
|
|
|
handle.addGlobalActor(PreferenceActor, "preferenceActor");
|
|
|
|
};
|
|
|
|
|
2016-05-17 18:25:54 +00:00
|
|
|
exports.unregister = function (handle) {
|
2014-03-03 01:41:36 +00:00
|
|
|
};
|
|
|
|
|
2016-06-03 17:45:10 +00:00
|
|
|
var PreferenceActor = exports.PreferenceActor = protocol.ActorClassWithSpec(preferenceSpec, {
|
2014-03-03 01:41:36 +00:00
|
|
|
typeName: "preference",
|
|
|
|
|
2016-06-03 17:45:10 +00:00
|
|
|
getBoolPref: function (name) {
|
2014-03-03 01:41:36 +00:00
|
|
|
return Services.prefs.getBoolPref(name);
|
2016-06-03 17:45:10 +00:00
|
|
|
},
|
2014-03-03 01:41:36 +00:00
|
|
|
|
2016-06-03 17:45:10 +00:00
|
|
|
getCharPref: function (name) {
|
2014-03-03 01:41:36 +00:00
|
|
|
return Services.prefs.getCharPref(name);
|
2016-06-03 17:45:10 +00:00
|
|
|
},
|
2014-03-03 01:41:36 +00:00
|
|
|
|
2016-06-03 17:45:10 +00:00
|
|
|
getIntPref: function (name) {
|
2014-03-03 01:41:36 +00:00
|
|
|
return Services.prefs.getIntPref(name);
|
2016-06-03 17:45:10 +00:00
|
|
|
},
|
2014-03-03 01:41:36 +00:00
|
|
|
|
2016-06-03 17:45:10 +00:00
|
|
|
getAllPrefs: function () {
|
2014-03-03 01:41:36 +00:00
|
|
|
let prefs = {};
|
2016-05-17 18:25:54 +00:00
|
|
|
Services.prefs.getChildList("").forEach(function (name, index) {
|
2014-03-03 01:41:36 +00:00
|
|
|
// append all key/value pairs into a huge json object.
|
|
|
|
try {
|
|
|
|
let value;
|
|
|
|
switch (Services.prefs.getPrefType(name)) {
|
|
|
|
case Ci.nsIPrefBranch.PREF_STRING:
|
|
|
|
value = Services.prefs.getCharPref(name);
|
|
|
|
break;
|
|
|
|
case Ci.nsIPrefBranch.PREF_INT:
|
|
|
|
value = Services.prefs.getIntPref(name);
|
|
|
|
break;
|
|
|
|
case Ci.nsIPrefBranch.PREF_BOOL:
|
|
|
|
value = Services.prefs.getBoolPref(name);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
}
|
|
|
|
prefs[name] = {
|
|
|
|
value: value,
|
|
|
|
hasUserValue: Services.prefs.prefHasUserValue(name)
|
|
|
|
};
|
|
|
|
} catch (e) {
|
|
|
|
// pref exists but has no user or default value
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return prefs;
|
2016-06-03 17:45:10 +00:00
|
|
|
},
|
2014-03-03 01:41:36 +00:00
|
|
|
|
2016-06-03 17:45:10 +00:00
|
|
|
setBoolPref: function (name, value) {
|
2014-03-03 01:41:36 +00:00
|
|
|
Services.prefs.setBoolPref(name, value);
|
|
|
|
Services.prefs.savePrefFile(null);
|
2016-06-03 17:45:10 +00:00
|
|
|
},
|
2014-03-03 01:41:36 +00:00
|
|
|
|
2016-06-03 17:45:10 +00:00
|
|
|
setCharPref: function (name, value) {
|
2014-03-03 01:41:36 +00:00
|
|
|
Services.prefs.setCharPref(name, value);
|
|
|
|
Services.prefs.savePrefFile(null);
|
2016-06-03 17:45:10 +00:00
|
|
|
},
|
2014-03-03 01:41:36 +00:00
|
|
|
|
2016-06-03 17:45:10 +00:00
|
|
|
setIntPref: function (name, value) {
|
2014-03-03 01:41:36 +00:00
|
|
|
Services.prefs.setIntPref(name, value);
|
|
|
|
Services.prefs.savePrefFile(null);
|
2016-06-03 17:45:10 +00:00
|
|
|
},
|
2014-03-03 01:41:36 +00:00
|
|
|
|
2016-06-03 17:45:10 +00:00
|
|
|
clearUserPref: function (name) {
|
2014-03-03 01:41:36 +00:00
|
|
|
Services.prefs.clearUserPref(name);
|
|
|
|
Services.prefs.savePrefFile(null);
|
|
|
|
},
|
|
|
|
});
|