| Left: | ||
| Right: |
| 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); |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 22 { | 22 { |
| 23 if (pref.substr(0, branchName.length) != branchName) | 23 if (pref.substr(0, branchName.length) != branchName) |
| 24 { | 24 { |
| 25 Cu.reportError(new Error("Ignoring default preference " + pref + ", wron g branch.")); | 25 Cu.reportError(new Error("Ignoring default preference " + pref + ", wron g branch.")); |
| 26 return; | 26 return; |
| 27 } | 27 } |
| 28 pref = pref.substr(branchName.length); | 28 pref = pref.substr(branchName.length); |
| 29 | 29 |
| 30 let [getter, setter] = typeMap[typeof value]; | 30 let [getter, setter] = typeMap[typeof value]; |
| 31 if (preconfigurable) | 31 if (preconfigurable) |
| 32 { | |
| 32 try | 33 try |
| 33 { | 34 { |
| 34 value = getter(preconfiguredBranch, pref); | 35 value = getter(preconfiguredBranch, pref); |
| 35 } | 36 } |
| 36 catch (e) {} | 37 catch (e) {} |
|
Wladimir Palant
2015/04/28 21:25:19
Nit: Please put brackets around this block.
Felix Dahlke
2015/04/28 21:28:32
Done.
| |
| 38 } | |
| 37 setter(defaultBranch, pref, value); | 39 setter(defaultBranch, pref, value); |
| 38 defineProperty(pref, false, getter, setter); | 40 defineProperty(pref, false, getter, setter); |
| 39 } | 41 } |
| 40 }; | 42 }; |
| 41 Services.scriptloader.loadSubScript(addonRoot + "defaults/prefs.js", scope); | 43 Services.scriptloader.loadSubScript(addonRoot + "defaults/prefs.js", scope); |
| 42 | 44 |
| 43 // Add preference change observer | 45 // Add preference change observer |
| 44 try | 46 try |
| 45 { | 47 { |
| 46 branch.QueryInterface(Ci.nsIPrefBranch2).addObserver("", Prefs, true); | 48 branch.QueryInterface(Ci.nsIPrefBranch2).addObserver("", Prefs, true); |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 189 { | 191 { |
| 190 let str = Cc["@mozilla.org/supports-string;1"].createInstance(Ci.nsISupportsSt ring); | 192 let str = Cc["@mozilla.org/supports-string;1"].createInstance(Ci.nsISupportsSt ring); |
| 191 str.data = newValue; | 193 str.data = newValue; |
| 192 branch.setComplexValue(pref, Ci.nsISupportsString, str); | 194 branch.setComplexValue(pref, Ci.nsISupportsString, str); |
| 193 } | 195 } |
| 194 | 196 |
| 195 function getJSONPref(branch, pref) JSON.parse(getCharPref(branch, pref)) | 197 function getJSONPref(branch, pref) JSON.parse(getCharPref(branch, pref)) |
| 196 function setJSONPref(branch, pref, newValue) setCharPref(branch, pref, JSON.stri ngify(newValue)) | 198 function setJSONPref(branch, pref, newValue) setCharPref(branch, pref, JSON.stri ngify(newValue)) |
| 197 | 199 |
| 198 init(); | 200 init(); |
| LEFT | RIGHT |