Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: lib/prefs.js

Issue 6647895159734272: Issue 1489 - Support preconfigured defaults (Closed)
Patch Set: Read preconfigured defaults from a dedicated branch Created April 3, 2015, 11:09 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 =
12 Services.prefs.getBranch(branchName + "preconfigured.");
11 let ignorePrefChanges = false; 13 let ignorePrefChanges = false;
12 14
13 function init() 15 function init()
14 { 16 {
15 // Load default preferences and set up properties for them 17 // Load default preferences and set up properties for them
16 let defaultBranch = Services.prefs.getDefaultBranch(branchName); 18 let defaultBranch = Services.prefs.getDefaultBranch(branchName);
17 let scope = 19 let scope =
18 { 20 {
19 pref: function(pref, value) 21 pref: function(pref, value, preconfigurable)
20 { 22 {
21 if (pref.substr(0, branchName.length) != branchName) 23 if (pref.substr(0, branchName.length) != branchName)
22 { 24 {
23 Cu.reportError(new Error("Ignoring default preference " + pref + ", wron g branch.")); 25 Cu.reportError(new Error("Ignoring default preference " + pref + ", wron g branch."));
24 return; 26 return;
25 } 27 }
26 pref = pref.substr(branchName.length); 28 pref = pref.substr(branchName.length);
27 29
28 let [getter, setter] = typeMap[typeof value]; 30 let [getter, setter] = typeMap[typeof value];
31 if (preconfigurable)
32 try
33 {
34 value = getter(preconfiguredBranch, pref);
35 }
36 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.
29 setter(defaultBranch, pref, value); 37 setter(defaultBranch, pref, value);
30 defineProperty(pref, false, getter, setter); 38 defineProperty(pref, false, getter, setter);
31 } 39 }
32 }; 40 };
33 Services.scriptloader.loadSubScript(addonRoot + "defaults/prefs.js", scope); 41 Services.scriptloader.loadSubScript(addonRoot + "defaults/prefs.js", scope);
34 42
35 // Add preference change observer 43 // Add preference change observer
36 try 44 try
37 { 45 {
38 branch.QueryInterface(Ci.nsIPrefBranch2).addObserver("", Prefs, true); 46 branch.QueryInterface(Ci.nsIPrefBranch2).addObserver("", Prefs, true);
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 { 189 {
182 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);
183 str.data = newValue; 191 str.data = newValue;
184 branch.setComplexValue(pref, Ci.nsISupportsString, str); 192 branch.setComplexValue(pref, Ci.nsISupportsString, str);
185 } 193 }
186 194
187 function getJSONPref(branch, pref) JSON.parse(getCharPref(branch, pref)) 195 function getJSONPref(branch, pref) JSON.parse(getCharPref(branch, pref))
188 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))
189 197
190 init(); 198 init();
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld