LEFT | RIGHT |
1 /* This Source Code Form is subject to the terms of the Mozilla Public | 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 | 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/. */ | 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
4 | 4 |
5 Cu.import("resource://gre/modules/Services.jsm"); | 5 Cu.import("resource://gre/modules/Services.jsm"); |
6 Cu.import("resource://gre/modules/XPCOMUtils.jsm"); | 6 Cu.import("resource://gre/modules/XPCOMUtils.jsm"); |
7 | 7 |
8 let {addonRoot, addonName} = require("info"); | 8 let {addonRoot, addonName} = require("info"); |
9 let branchName = "extensions." + addonName + "."; | 9 let branchName = "extensions." + addonName + "."; |
10 let branch = Services.prefs.getBranch(branchName); | 10 let branch = Services.prefs.getBranch(branchName); |
11 let preconfiguredBranch = | 11 let preconfiguredBranch = |
12 Services.prefs.getBranch(branchName + "preconfigured."); | 12 Services.prefs.getBranch(branchName + "preconfigured."); |
13 let ignorePrefChanges = false; | 13 let ignorePrefChanges = false; |
14 | 14 |
15 function init() | 15 function init() |
16 { | 16 { |
17 // Load default preferences and set up properties for them | 17 // Load default preferences and set up properties for them |
18 let defaultBranch = Services.prefs.getDefaultBranch(branchName); | 18 let defaultBranch = Services.prefs.getDefaultBranch(branchName); |
19 | 19 |
20 let request = new XMLHttpRequest(); | 20 let request = new XMLHttpRequest(); |
21 request.open("GET", addonRoot + "defaults/prefs.json", false); | 21 request.open("GET", addonRoot + "defaults/prefs.json", false); |
22 request.responseType = "json"; | 22 request.responseType = "json"; |
23 request.send(); | 23 request.send(); |
24 | 24 |
25 let defaults = request.response.defaults; | 25 let defaults = request.response.defaults; |
| 26 let preconfigurable = new Set(request.response.preconfigurable); |
26 for (let pref in defaults) | 27 for (let pref in defaults) |
27 { | 28 { |
28 let value = defaults[pref]; | 29 let value = defaults[pref]; |
29 let [getter, setter] = typeMap[typeof value]; | 30 let [getter, setter] = typeMap[typeof value]; |
30 if ("preconfigurable" in request.response && | 31 if (preconfigurable.has(pref)) |
31 request.response.preconfigurable.indexOf(pref) != -1) | |
32 { | 32 { |
33 try | 33 try |
34 { | 34 { |
35 value = getter(preconfiguredBranch, pref); | 35 value = getter(preconfiguredBranch, pref); |
36 } | 36 } |
37 catch (e) {} | 37 catch (e) {} |
38 } | 38 } |
39 setter(defaultBranch, pref, value); | 39 setter(defaultBranch, pref, value); |
40 defineProperty(pref, false, getter, setter); | 40 defineProperty(pref, false, getter, setter); |
41 } | 41 } |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 { | 189 { |
190 let str = Cc["@mozilla.org/supports-string;1"].createInstance(Ci.nsISupportsSt
ring); | 190 let str = Cc["@mozilla.org/supports-string;1"].createInstance(Ci.nsISupportsSt
ring); |
191 str.data = newValue; | 191 str.data = newValue; |
192 branch.setComplexValue(pref, Ci.nsISupportsString, str); | 192 branch.setComplexValue(pref, Ci.nsISupportsString, str); |
193 } | 193 } |
194 | 194 |
195 function getJSONPref(branch, pref) JSON.parse(getCharPref(branch, pref)) | 195 function getJSONPref(branch, pref) JSON.parse(getCharPref(branch, pref)) |
196 function setJSONPref(branch, pref, newValue) setCharPref(branch, pref, JSON.stri
ngify(newValue)) | 196 function setJSONPref(branch, pref, newValue) setCharPref(branch, pref, JSON.stri
ngify(newValue)) |
197 | 197 |
198 init(); | 198 init(); |
LEFT | RIGHT |