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

Side by Side Diff: lib/prefs.js

Issue 5702539706105856: Issue 2444 - Make preconfigurable property optional (Closed)
Patch Set: Created May 4, 2015, 5:05 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 = 11 let preconfiguredBranch =
12 Services.prefs.getBranch(branchName + "preconfigured."); 12 Services.prefs.getBranch(branchName + "preconfigured.");
13 let ignorePrefChanges = false; 13 let ignorePrefChanges = false;
14 14
15 function init() 15 function init()
16 { 16 {
17 // Load default preferences and set up properties for them 17 // Load default preferences and set up properties for them
18 let defaultBranch = Services.prefs.getDefaultBranch(branchName); 18 let defaultBranch = Services.prefs.getDefaultBranch(branchName);
19 19
20 let request = new XMLHttpRequest(); 20 let request = new XMLHttpRequest();
21 request.open("GET", addonRoot + "defaults/prefs.json", false); 21 request.open("GET", addonRoot + "defaults/prefs.json", false);
22 request.responseType = "json"; 22 request.responseType = "json";
23 request.send(); 23 request.send();
24 24
25 let defaults = request.response.defaults; 25 let defaults = request.response.defaults;
26 for (let pref in defaults) 26 for (let pref in defaults)
27 { 27 {
28 let value = defaults[pref]; 28 let value = defaults[pref];
29 let [getter, setter] = typeMap[typeof value]; 29 let [getter, setter] = typeMap[typeof value];
30 if (request.response.preconfigurable.indexOf(pref) != -1) 30 if ("preconfigurable" in request.response &&
31 request.response.preconfigurable.indexOf(pref) != -1)
31 { 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) {}
37 } 38 }
38 setter(defaultBranch, pref, value); 39 setter(defaultBranch, pref, value);
39 defineProperty(pref, false, getter, setter); 40 defineProperty(pref, false, getter, setter);
40 } 41 }
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 { 189 {
189 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);
190 str.data = newValue; 191 str.data = newValue;
191 branch.setComplexValue(pref, Ci.nsISupportsString, str); 192 branch.setComplexValue(pref, Ci.nsISupportsString, str);
192 } 193 }
193 194
194 function getJSONPref(branch, pref) JSON.parse(getCharPref(branch, pref)) 195 function getJSONPref(branch, pref) JSON.parse(getCharPref(branch, pref))
195 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))
196 197
197 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