OLD | NEW |
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 let {Services} = Cu.import("resource://gre/modules/Services.jsm", {}); | 5 let {Services} = Cu.import("resource://gre/modules/Services.jsm", {}); |
6 let {XPCOMUtils} = Cu.import("resource://gre/modules/XPCOMUtils.jsm", {}); | 6 let {XPCOMUtils} = 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 prefsData = require("prefs.json"); |
21 request.open("GET", addonRoot + "defaults/prefs.json", false); | 21 let defaults = prefsData.defaults; |
22 request.responseType = "json"; | 22 let preconfigurable = new Set(prefsData.preconfigurable); |
23 request.send(); | |
24 | |
25 let defaults = request.response.defaults; | |
26 let preconfigurable = new Set(request.response.preconfigurable); | |
27 for (let pref in defaults) | 23 for (let pref in defaults) |
28 { | 24 { |
29 let value = defaults[pref]; | 25 let value = defaults[pref]; |
30 let [getter, setter] = typeMap[typeof value]; | 26 let [getter, setter] = typeMap[typeof value]; |
31 if (preconfigurable.has(pref)) | 27 if (preconfigurable.has(pref)) |
32 { | 28 { |
33 try | 29 try |
34 { | 30 { |
35 value = getter(preconfiguredBranch, pref); | 31 value = getter(preconfiguredBranch, pref); |
36 } | 32 } |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 // Getter/setter functions for difference preference types | 188 // Getter/setter functions for difference preference types |
193 let typeMap = | 189 let typeMap = |
194 { | 190 { |
195 boolean: [getBoolPref, setBoolPref], | 191 boolean: [getBoolPref, setBoolPref], |
196 number: [getIntPref, setIntPref], | 192 number: [getIntPref, setIntPref], |
197 string: [getCharPref, setCharPref], | 193 string: [getCharPref, setCharPref], |
198 object: [getJSONPref, setJSONPref] | 194 object: [getJSONPref, setJSONPref] |
199 }; | 195 }; |
200 | 196 |
201 init(); | 197 init(); |
OLD | NEW |