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

Delta Between Two Patch Sets: lib/prefs.js

Issue 6647895159734272: Issue 1489 - Support preconfigured defaults (Closed)
Left Patch Set: Created March 19, 2015, 10:14 p.m.
Right 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:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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];
29 try 31 if (preconfigurable)
30 { 32 {
31 getter(defaultBranch, pref); 33 try
34 {
35 value = getter(preconfiguredBranch, pref);
36 }
37 catch (e) {}
32 } 38 }
33 catch (e) 39 setter(defaultBranch, pref, value);
34 {
35 setter(defaultBranch, pref, value);
36 }
37 defineProperty(pref, false, getter, setter); 40 defineProperty(pref, false, getter, setter);
38 } 41 }
39 }; 42 };
40 Services.scriptloader.loadSubScript(addonRoot + "defaults/prefs.js", scope); 43 Services.scriptloader.loadSubScript(addonRoot + "defaults/prefs.js", scope);
41 44
42 // Add preference change observer 45 // Add preference change observer
43 try 46 try
44 { 47 {
45 branch.QueryInterface(Ci.nsIPrefBranch2).addObserver("", Prefs, true); 48 branch.QueryInterface(Ci.nsIPrefBranch2).addObserver("", Prefs, true);
46 onShutdown.add(function() branch.removeObserver("", Prefs)); 49 onShutdown.add(function() branch.removeObserver("", Prefs));
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 { 191 {
189 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);
190 str.data = newValue; 193 str.data = newValue;
191 branch.setComplexValue(pref, Ci.nsISupportsString, str); 194 branch.setComplexValue(pref, Ci.nsISupportsString, str);
192 } 195 }
193 196
194 function getJSONPref(branch, pref) JSON.parse(getCharPref(branch, pref)) 197 function getJSONPref(branch, pref) JSON.parse(getCharPref(branch, pref))
195 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))
196 199
197 init(); 200 init();
LEFTRIGHT
« no previous file | no next file » | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

Powered by Google App Engine
This is Rietveld