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: Added braces around the if body Created April 28, 2015, 9:28 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 {
33 try
34 {
35 value = getter(preconfiguredBranch, pref);
36 }
37 catch (e) {}
38 }
29 setter(defaultBranch, pref, value); 39 setter(defaultBranch, pref, value);
30 defineProperty(pref, false, getter, setter); 40 defineProperty(pref, false, getter, setter);
31 } 41 }
32 }; 42 };
33 Services.scriptloader.loadSubScript(addonRoot + "defaults/prefs.js", scope); 43 Services.scriptloader.loadSubScript(addonRoot + "defaults/prefs.js", scope);
34 44
35 // Add preference change observer 45 // Add preference change observer
36 try 46 try
37 { 47 {
38 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
181 { 191 {
182 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);
183 str.data = newValue; 193 str.data = newValue;
184 branch.setComplexValue(pref, Ci.nsISupportsString, str); 194 branch.setComplexValue(pref, Ci.nsISupportsString, str);
185 } 195 }
186 196
187 function getJSONPref(branch, pref) JSON.parse(getCharPref(branch, pref)) 197 function getJSONPref(branch, pref) JSON.parse(getCharPref(branch, pref))
188 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))
189 199
190 init(); 200 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