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 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 ignorePrefChanges = false; | 11 let ignorePrefChanges = false; |
12 | 12 |
13 function init() | 13 function init() |
14 { | 14 { |
15 // Load default preferences and set up properties for them | 15 // Load default preferences and set up properties for them |
16 let defaultBranch = Services.prefs.getDefaultBranch(branchName); | 16 let defaultBranch = Services.prefs.getDefaultBranch(branchName); |
17 let scope = | 17 let scope = |
18 { | 18 { |
19 pref: function(pref, value) | 19 pref: function(pref, value) |
20 { | 20 { |
21 if (pref.substr(0, branchName.length) != branchName) | 21 if (pref.substr(0, branchName.length) != branchName) |
22 { | 22 { |
23 Cu.reportError(new Error("Ignoring default preference " + pref + ", wron
g branch.")); | 23 Cu.reportError(new Error("Ignoring default preference " + pref + ", wron
g branch.")); |
24 return; | 24 return; |
25 } | 25 } |
26 pref = pref.substr(branchName.length); | 26 pref = pref.substr(branchName.length); |
27 | 27 |
28 let [getter, setter] = typeMap[typeof value]; | 28 let [getter, setter] = typeMap[typeof value]; |
29 setter(defaultBranch, pref, value); | 29 try |
| 30 { |
| 31 getter(defaultBranch, pref); |
| 32 } |
| 33 catch (e) |
| 34 { |
| 35 setter(defaultBranch, pref, value); |
| 36 } |
30 defineProperty(pref, false, getter, setter); | 37 defineProperty(pref, false, getter, setter); |
31 } | 38 } |
32 }; | 39 }; |
33 Services.scriptloader.loadSubScript(addonRoot + "defaults/prefs.js", scope); | 40 Services.scriptloader.loadSubScript(addonRoot + "defaults/prefs.js", scope); |
34 | 41 |
35 // Add preference change observer | 42 // Add preference change observer |
36 try | 43 try |
37 { | 44 { |
38 branch.QueryInterface(Ci.nsIPrefBranch2).addObserver("", Prefs, true); | 45 branch.QueryInterface(Ci.nsIPrefBranch2).addObserver("", Prefs, true); |
39 onShutdown.add(function() branch.removeObserver("", Prefs)); | 46 onShutdown.add(function() branch.removeObserver("", Prefs)); |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 { | 188 { |
182 let str = Cc["@mozilla.org/supports-string;1"].createInstance(Ci.nsISupportsSt
ring); | 189 let str = Cc["@mozilla.org/supports-string;1"].createInstance(Ci.nsISupportsSt
ring); |
183 str.data = newValue; | 190 str.data = newValue; |
184 branch.setComplexValue(pref, Ci.nsISupportsString, str); | 191 branch.setComplexValue(pref, Ci.nsISupportsString, str); |
185 } | 192 } |
186 | 193 |
187 function getJSONPref(branch, pref) JSON.parse(getCharPref(branch, pref)) | 194 function getJSONPref(branch, pref) JSON.parse(getCharPref(branch, pref)) |
188 function setJSONPref(branch, pref, newValue) setCharPref(branch, pref, JSON.stri
ngify(newValue)) | 195 function setJSONPref(branch, pref, newValue) setCharPref(branch, pref, JSON.stri
ngify(newValue)) |
189 | 196 |
190 init(); | 197 init(); |
OLD | NEW |