toolkit/devtools/server/actors/preference.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5 const {Cc, Ci, Cu, CC} = require("chrome");
michael@0 6 const protocol = require("devtools/server/protocol");
michael@0 7 const {Arg, method, RetVal} = protocol;
michael@0 8 const {Promise: promise} = Cu.import("resource://gre/modules/Promise.jsm", {});
michael@0 9
michael@0 10 Cu.import("resource://gre/modules/Services.jsm");
michael@0 11
michael@0 12 exports.register = function(handle) {
michael@0 13 handle.addGlobalActor(PreferenceActor, "preferenceActor");
michael@0 14 };
michael@0 15
michael@0 16 exports.unregister = function(handle) {
michael@0 17 };
michael@0 18
michael@0 19 let PreferenceActor = protocol.ActorClass({
michael@0 20 typeName: "preference",
michael@0 21
michael@0 22 getBoolPref: method(function(name) {
michael@0 23 return Services.prefs.getBoolPref(name);
michael@0 24 }, {
michael@0 25 request: { value: Arg(0) },
michael@0 26 response: { value: RetVal("boolean") }
michael@0 27 }),
michael@0 28
michael@0 29 getCharPref: method(function(name) {
michael@0 30 return Services.prefs.getCharPref(name);
michael@0 31 }, {
michael@0 32 request: { value: Arg(0) },
michael@0 33 response: { value: RetVal("string") }
michael@0 34 }),
michael@0 35
michael@0 36 getIntPref: method(function(name) {
michael@0 37 return Services.prefs.getIntPref(name);
michael@0 38 }, {
michael@0 39 request: { value: Arg(0) },
michael@0 40 response: { value: RetVal("number") }
michael@0 41 }),
michael@0 42
michael@0 43 getAllPrefs: method(function() {
michael@0 44 let prefs = {};
michael@0 45 Services.prefs.getChildList("").forEach(function(name, index) {
michael@0 46 // append all key/value pairs into a huge json object.
michael@0 47 try {
michael@0 48 let value;
michael@0 49 switch (Services.prefs.getPrefType(name)) {
michael@0 50 case Ci.nsIPrefBranch.PREF_STRING:
michael@0 51 value = Services.prefs.getCharPref(name);
michael@0 52 break;
michael@0 53 case Ci.nsIPrefBranch.PREF_INT:
michael@0 54 value = Services.prefs.getIntPref(name);
michael@0 55 break;
michael@0 56 case Ci.nsIPrefBranch.PREF_BOOL:
michael@0 57 value = Services.prefs.getBoolPref(name);
michael@0 58 break;
michael@0 59 default:
michael@0 60 }
michael@0 61 prefs[name] = {
michael@0 62 value: value,
michael@0 63 hasUserValue: Services.prefs.prefHasUserValue(name)
michael@0 64 };
michael@0 65 } catch (e) {
michael@0 66 // pref exists but has no user or default value
michael@0 67 }
michael@0 68 });
michael@0 69 return prefs;
michael@0 70 }, {
michael@0 71 request: {},
michael@0 72 response: { value: RetVal("json") }
michael@0 73 }),
michael@0 74
michael@0 75 setBoolPref: method(function(name, value) {
michael@0 76 Services.prefs.setBoolPref(name, value);
michael@0 77 Services.prefs.savePrefFile(null);
michael@0 78 }, {
michael@0 79 request: { name: Arg(0), value: Arg(1) },
michael@0 80 response: {}
michael@0 81 }),
michael@0 82
michael@0 83 setCharPref: method(function(name, value) {
michael@0 84 Services.prefs.setCharPref(name, value);
michael@0 85 Services.prefs.savePrefFile(null);
michael@0 86 }, {
michael@0 87 request: { name: Arg(0), value: Arg(1) },
michael@0 88 response: {}
michael@0 89 }),
michael@0 90
michael@0 91 setIntPref: method(function(name, value) {
michael@0 92 Services.prefs.setIntPref(name, value);
michael@0 93 Services.prefs.savePrefFile(null);
michael@0 94 }, {
michael@0 95 request: { name: Arg(0), value: Arg(1) },
michael@0 96 response: {}
michael@0 97 }),
michael@0 98
michael@0 99 clearUserPref: method(function(name) {
michael@0 100 Services.prefs.clearUserPref(name);
michael@0 101 Services.prefs.savePrefFile(null);
michael@0 102 }, {
michael@0 103 request: { name: Arg(0) },
michael@0 104 response: {}
michael@0 105 }),
michael@0 106 });
michael@0 107
michael@0 108 let PreferenceFront = protocol.FrontClass(PreferenceActor, {
michael@0 109 initialize: function(client, form) {
michael@0 110 protocol.Front.prototype.initialize.call(this, client);
michael@0 111 this.actorID = form.preferenceActor;
michael@0 112 client.addActorPool(this);
michael@0 113 this.manage(this);
michael@0 114 },
michael@0 115 });
michael@0 116
michael@0 117 const _knownPreferenceFronts = new WeakMap();
michael@0 118
michael@0 119 exports.getPreferenceFront = function(client, form) {
michael@0 120 if (_knownPreferenceFronts.has(client))
michael@0 121 return _knownPreferenceFronts.get(client);
michael@0 122
michael@0 123 let front = new PreferenceFront(client, form);
michael@0 124 _knownPreferenceFronts.set(client, front);
michael@0 125 return front;
michael@0 126 };

mercurial