1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
|
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- /
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
window.performance.mark('gecko-settings-loadstart');
var Cc = Components.classes;
var Ci = Components.interfaces;
var Cu = Components.utils;
var Cr = Components.results;
// The load order is important here SettingsRequestManager _must_ be loaded
// prior to using SettingsListener otherwise there is a race in acquiring the
// lock and fulfilling it. If we ever move SettingsListener or this file down in
// the load order of shell.html things will likely break.
Cu.import('resource://gre/modules/SettingsRequestManager.jsm');
Cu.import('resource://gre/modules/XPCOMUtils.jsm');
Cu.import('resource://gre/modules/Services.jsm');
Cu.import('resource://gre/modules/AppConstants.jsm');
const isGonk = AppConstants.platform === 'gonk';
if (isGonk) {
XPCOMUtils.defineLazyGetter(this, "libcutils", function () {
Cu.import("resource://gre/modules/systemlibs.js");
return libcutils;
});
}
XPCOMUtils.defineLazyServiceGetter(this, "uuidgen",
"@mozilla.org/uuid-generator;1",
"nsIUUIDGenerator");
// Once Bug 731746 - Allow chrome JS object to implement nsIDOMEventTarget
// is resolved this helper could be removed.
var SettingsListener = {
_callbacks: {},
init: function sl_init() {
if ('mozSettings' in navigator && navigator.mozSettings) {
navigator.mozSettings.onsettingchange = this.onchange.bind(this);
}
},
onchange: function sl_onchange(evt) {
var callback = this._callbacks[evt.settingName];
if (callback) {
callback(evt.settingValue);
}
},
observe: function sl_observe(name, defaultValue, callback) {
var settings = window.navigator.mozSettings;
if (!settings) {
window.setTimeout(function() { callback(defaultValue); });
return;
}
if (!callback || typeof callback !== 'function') {
throw new Error('Callback is not a function');
}
var req = settings.createLock().get(name);
req.addEventListener('success', (function onsuccess() {
callback(typeof(req.result[name]) != 'undefined' ?
req.result[name] : defaultValue);
}));
this._callbacks[name] = callback;
}
};
SettingsListener.init();
// =================== Mono Audio ======================
SettingsListener.observe('accessibility.monoaudio.enable', false, function(value) {
Services.prefs.setBoolPref('accessibility.monoaudio.enable', value);
});
// =================== Console ======================
SettingsListener.observe('debug.console.enabled', true, function(value) {
Services.prefs.setBoolPref('consoleservice.enabled', value);
Services.prefs.setBoolPref('layout.css.report_errors', value);
});
SettingsListener.observe('homescreen.manifestURL', 'Sentinel Value' , function(value) {
Services.prefs.setCharPref('dom.mozApps.homescreenURL', value);
});
// =================== Languages ====================
SettingsListener.observe('language.current', 'en-US', function(value) {
Services.prefs.setCharPref('general.useragent.locale', value);
let prefName = 'intl.accept_languages';
let defaultBranch = Services.prefs.getDefaultBranch(null);
let intl = '';
try {
intl = defaultBranch.getComplexValue(prefName,
Ci.nsIPrefLocalizedString).data;
} catch(e) {}
// Bug 830782 - Homescreen is in English instead of selected locale after
// the first run experience.
// In order to ensure the current intl value is reflected on the child
// process let's always write a user value, even if this one match the
// current localized pref value.
if (!((new RegExp('^' + value + '[^a-z-_] *[,;]?', 'i')).test(intl))) {
value = value + ', ' + intl;
} else {
value = intl;
}
Services.prefs.setCharPref(prefName, value);
if (shell.hasStarted() == false) {
shell.bootstrap();
}
});
// =================== RIL ====================
(function RILSettingsToPrefs() {
// DSDS default service IDs
['mms', 'sms', 'telephony'].forEach(function(key) {
SettingsListener.observe('ril.' + key + '.defaultServiceId', 0,
function(value) {
if (value != null) {
Services.prefs.setIntPref('dom.' + key + '.defaultServiceId', value);
}
});
});
})();
//=================== DeviceInfo ====================
Components.utils.import('resource://gre/modules/XPCOMUtils.jsm');
Components.utils.import('resource://gre/modules/ctypes.jsm');
(function DeviceInfoToSettings() {
// MOZ_B2G_VERSION is set in b2g/confvars.sh, and is output as a #define value
// from configure.in, defaults to 1.0.0 if this value is not exist.
let os_version = AppConstants.MOZ_B2G_VERSION;
let os_name = AppConstants.MOZ_B2G_OS_NAME;
let appInfo = Cc["@mozilla.org/xre/app-info;1"]
.getService(Ci.nsIXULAppInfo);
// Get the hardware info and firmware revision from device properties.
let hardware_info = null;
let firmware_revision = null;
let product_manufacturer = null;
let product_model = null;
let product_device = null;
let build_number = null;
if (isGonk) {
hardware_info = libcutils.property_get('ro.hardware');
firmware_revision = libcutils.property_get('ro.firmware_revision');
product_manufacturer = libcutils.property_get('ro.product.manufacturer');
product_model = libcutils.property_get('ro.product.model');
product_device = libcutils.property_get('ro.product.device');
build_number = libcutils.property_get('ro.build.version.incremental');
}
// Populate deviceinfo settings,
// copying any existing deviceinfo.os into deviceinfo.previous_os
let lock = window.navigator.mozSettings.createLock();
let req = lock.get('deviceinfo.os');
req.onsuccess = req.onerror = () => {
let previous_os = req.result && req.result['deviceinfo.os'] || '';
let software = os_name + ' ' + os_version;
let setting = {
'deviceinfo.build_number': build_number,
'deviceinfo.os': os_version,
'deviceinfo.previous_os': previous_os,
'deviceinfo.software': software,
'deviceinfo.platform_version': appInfo.platformVersion,
'deviceinfo.platform_build_id': appInfo.platformBuildID,
'deviceinfo.hardware': hardware_info,
'deviceinfo.firmware_revision': firmware_revision,
'deviceinfo.product_manufacturer': product_manufacturer,
'deviceinfo.product_model': product_model,
'deviceinfo.product_device': product_device
}
lock.set(setting);
}
})();
// =================== DevTools ====================
var developerHUD;
SettingsListener.observe('devtools.overlay', false, (value) => {
if (value) {
if (!developerHUD) {
let scope = {};
Services.scriptloader.loadSubScript('chrome://b2g/content/devtools/hud.js', scope);
developerHUD = scope.developerHUD;
}
developerHUD.init();
} else {
if (developerHUD) {
developerHUD.uninit();
}
}
});
if (isGonk) {
var LogShake;
(function() {
let scope = {};
Cu.import('resource://gre/modules/LogShake.jsm', scope);
LogShake = scope.LogShake;
LogShake.init();
})();
SettingsListener.observe('devtools.logshake.enabled', false, value => {
if (value) {
LogShake.enableDeviceMotionListener();
} else {
LogShake.disableDeviceMotionListener();
}
});
SettingsListener.observe('devtools.logshake.qa_enabled', false, value => {
if (value) {
LogShake.enableQAMode();
} else {
LogShake.disableQAMode();
}
});
}
// =================== Device Storage ====================
SettingsListener.observe('device.storage.writable.name', 'sdcard', function(value) {
if (Services.prefs.getPrefType('device.storage.writable.name') != Ci.nsIPrefBranch.PREF_STRING) {
// We clear the pref because it used to be erroneously written as a bool
// and we need to clear it before we can change it to have the correct type.
Services.prefs.clearUserPref('device.storage.writable.name');
}
Services.prefs.setCharPref('device.storage.writable.name', value);
});
// =================== Privacy ====================
SettingsListener.observe('privacy.donottrackheader.value', 1, function(value) {
Services.prefs.setIntPref('privacy.donottrackheader.value', value);
// If the user specifically disallows tracking, we set the value of
// app.update.custom (update tracking ID) to an empty string.
if (value == 1) {
Services.prefs.setCharPref('app.update.custom', '');
return;
}
// Otherwise, we assure that the update tracking ID exists.
setUpdateTrackingId();
});
// =================== Crash Reporting ====================
SettingsListener.observe('app.reportCrashes', 'ask', function(value) {
if (value == 'always') {
Services.prefs.setBoolPref('app.reportCrashes', true);
} else if (value == 'never') {
Services.prefs.setBoolPref('app.reportCrashes', false);
} else {
Services.prefs.clearUserPref('app.reportCrashes');
}
// This preference is consulted during startup.
Services.prefs.savePrefFile(null);
});
// ================ Updates ================
/**
* For tracking purposes some partners require us to add an UUID to the
* update URL. The update tracking ID will be an empty string if the
* do-not-track feature specifically disallows tracking and it is reseted
* to a different ID if the do-not-track value changes from disallow to allow.
*/
function setUpdateTrackingId() {
try {
let dntEnabled = Services.prefs.getBoolPref('privacy.donottrackheader.enabled');
let dntValue = Services.prefs.getIntPref('privacy.donottrackheader.value');
// If the user specifically decides to disallow tracking (1), we just bail out.
if (dntEnabled && (dntValue == 1)) {
return;
}
let trackingId =
Services.prefs.getPrefType('app.update.custom') ==
Ci.nsIPrefBranch.PREF_STRING &&
Services.prefs.getCharPref('app.update.custom');
// If there is no previous registered tracking ID, we generate a new one.
// This should only happen on first usage or after changing the
// do-not-track value from disallow to allow.
if (!trackingId) {
trackingId = uuidgen.generateUUID().toString().replace(/[{}]/g, "");
Services.prefs.setCharPref('app.update.custom', trackingId);
}
} catch(e) {
dump('Error getting tracking ID ' + e + '\n');
}
}
setUpdateTrackingId();
(function syncUpdatePrefs() {
// The update service reads the prefs from the default branch. This is by
// design, as explained in bug 302721 comment 43. If we are to successfully
// modify them, that's where we need to make our changes.
let defaultBranch = Services.prefs.getDefaultBranch(null);
function syncPrefDefault(prefName) {
// The pref value at boot-time will serve as default for the setting.
let defaultValue = defaultBranch.getCharPref(prefName);
let defaultSetting = {};
defaultSetting[prefName] = defaultValue;
// We back up that value in order to detect pref changes across reboots.
// Such a change can happen e.g. when the user installs an OTA update that
// changes the update URL format.
let backupName = prefName + '.old';
try {
// Everything relies on the comparison below: When pushing a new Gecko
// that changes app.update.url or app.update.channel, we overwrite any
// existing setting with the new pref value.
let backupValue = Services.prefs.getCharPref(backupName);
if (defaultValue !== backupValue) {
// If the pref has changed since our last backup, overwrite the setting.
navigator.mozSettings.createLock().set(defaultSetting);
}
} catch(e) {
// There was no backup: Overwrite the setting and create a backup below.
navigator.mozSettings.createLock().set(defaultSetting);
}
// Initialize or update the backup value.
Services.prefs.setCharPref(backupName, defaultValue);
// Propagate setting changes to the pref.
SettingsListener.observe(prefName, defaultValue, value => {
if (!value) {
// If the setting value is invalid, reset it to its default.
navigator.mozSettings.createLock().set(defaultSetting);
return;
}
// Here we will overwrite the pref with the setting value.
defaultBranch.setCharPref(prefName, value);
});
}
syncPrefDefault('app.update.url');
syncPrefDefault('app.update.channel');
})();
// ================ Debug ================
(function Composer2DSettingToPref() {
//layers.composer.enabled can be enabled in three ways
//In order of precedence they are:
//
//1. mozSettings "layers.composer.enabled"
//2. a gecko pref "layers.composer.enabled"
//3. presence of ro.display.colorfill at the Gonk level
var req = navigator.mozSettings.createLock().get('layers.composer2d.enabled');
req.onsuccess = function() {
if (typeof(req.result['layers.composer2d.enabled']) === 'undefined') {
var enabled = false;
if (Services.prefs.getPrefType('layers.composer2d.enabled') == Ci.nsIPrefBranch.PREF_BOOL) {
enabled = Services.prefs.getBoolPref('layers.composer2d.enabled');
} else if (isGonk) {
let androidVersion = libcutils.property_get("ro.build.version.sdk");
if (androidVersion >= 17 ) {
enabled = true;
} else {
enabled = (libcutils.property_get('ro.display.colorfill') === '1');
}
}
navigator.mozSettings.createLock().set({'layers.composer2d.enabled': enabled });
}
SettingsListener.observe("layers.composer2d.enabled", true, function(value) {
Services.prefs.setBoolPref("layers.composer2d.enabled", value);
});
};
req.onerror = function() {
dump("Error configuring layers.composer2d.enabled setting");
};
})();
// ================ Accessibility ============
(function setupAccessibility() {
let accessibilityScope = {};
SettingsListener.observe("accessibility.screenreader", false, function(value) {
if (!value) {
return;
}
if (!('AccessFu' in accessibilityScope)) {
Cu.import('resource://gre/modules/accessibility/AccessFu.jsm',
accessibilityScope);
accessibilityScope.AccessFu.attach(window);
}
});
})();
// ================ Theming ============
(function themingSettingsListener() {
let themingPrefs = ['ui.menu', 'ui.menutext', 'ui.infobackground', 'ui.infotext',
'ui.window', 'ui.windowtext', 'ui.highlight'];
themingPrefs.forEach(function(pref) {
SettingsListener.observe('gaia.' + pref, null, function(value) {
if (value) {
Services.prefs.setCharPref(pref, value);
}
});
});
})();
// =================== Telemetry ======================
(function setupTelemetrySettings() {
let gaiaSettingName = 'debug.performance_data.shared';
let geckoPrefName = 'toolkit.telemetry.enabled';
SettingsListener.observe(gaiaSettingName, null, function(value) {
if (value !== null) {
// Gaia setting has been set; update Gecko pref to that.
Services.prefs.setBoolPref(geckoPrefName, value);
return;
}
// Gaia setting has not been set; set the gaia setting to default.
let prefValue = AppConstants.MOZ_TELEMETRY_ON_BY_DEFAULT;
try {
prefValue = Services.prefs.getBoolPref(geckoPrefName);
} catch (e) {
// Pref not set; use default value.
}
let setting = {};
setting[gaiaSettingName] = prefValue;
window.navigator.mozSettings.createLock().set(setting);
});
})();
// =================== Low-precision buffer ======================
(function setupLowPrecisionSettings() {
// The gaia setting layers.low-precision maps to two gecko prefs
SettingsListener.observe('layers.low-precision', null, function(value) {
if (value !== null) {
// Update gecko from the new Gaia setting
Services.prefs.setBoolPref('layers.low-precision-buffer', value);
Services.prefs.setBoolPref('layers.progressive-paint', value);
} else {
// Update gaia setting from gecko value
try {
let prefValue = Services.prefs.getBoolPref('layers.low-precision-buffer');
let setting = { 'layers.low-precision': prefValue };
window.navigator.mozSettings.createLock().set(setting);
} catch (e) {
console.log('Unable to read pref layers.low-precision-buffer: ' + e);
}
}
});
// The gaia setting layers.low-opacity maps to a string gecko pref (0.5/1.0)
SettingsListener.observe('layers.low-opacity', null, function(value) {
if (value !== null) {
// Update gecko from the new Gaia setting
Services.prefs.setCharPref('layers.low-precision-opacity', value ? '0.5' : '1.0');
} else {
// Update gaia setting from gecko value
try {
let prefValue = Services.prefs.getCharPref('layers.low-precision-opacity');
let setting = { 'layers.low-opacity': (prefValue == '0.5') };
window.navigator.mozSettings.createLock().set(setting);
} catch (e) {
console.log('Unable to read pref layers.low-precision-opacity: ' + e);
}
}
});
})();
// ======================= Dogfooders FOTA ==========================
if (AppConstants.MOZ_B2G_RIL) {
XPCOMUtils.defineLazyModuleGetter(this, "AppsUtils",
"resource://gre/modules/AppsUtils.jsm");
SettingsListener.observe('debug.performance_data.dogfooding', false,
isDogfooder => {
if (!isDogfooder) {
dump('AUS:Settings: Not a dogfooder!\n');
return;
}
if (!('mozTelephony' in navigator)) {
dump('AUS:Settings: There is no mozTelephony!\n');
return;
}
if (!('mozMobileConnections' in navigator)) {
dump('AUS:Settings: There is no mozMobileConnections!\n');
return;
}
let conn = navigator.mozMobileConnections[0];
conn.addEventListener('radiostatechange', function onradiostatechange() {
if (conn.radioState !== 'enabled') {
return;
}
conn.removeEventListener('radiostatechange', onradiostatechange);
navigator.mozTelephony.dial('*#06#').then(call => {
return call.result.then(res => {
if (res.success && res.statusMessage
&& (res.serviceCode === 'scImei')) {
Services.prefs.setCharPref("app.update.imei_hash",
AppsUtils.computeHash(res.statusMessage, "SHA512"));
}
});
});
});
});
}
// =================== Various simple mapping ======================
var settingsToObserve = {
'accessibility.screenreader_quicknav_modes': {
prefName: 'accessibility.accessfu.quicknav_modes',
resetToPref: true,
defaultValue: ''
},
'accessibility.screenreader_quicknav_index': {
prefName: 'accessibility.accessfu.quicknav_index',
resetToPref: true,
defaultValue: 0
},
'app.update.interval': 86400,
'apz.overscroll.enabled': true,
'browser.safebrowsing.phishing.enabled': true,
'browser.safebrowsing.malware.enabled': true,
'debug.fps.enabled': {
prefName: 'layers.acceleration.draw-fps',
defaultValue: false
},
'debug.log-animations.enabled': {
prefName: 'layers.offmainthreadcomposition.log-animations',
defaultValue: false
},
'debug.paint-flashing.enabled': {
prefName: 'nglayout.debug.paint_flashing',
defaultValue: false
},
// FIXME: Bug 1185806 - Provide a common device name setting.
// Borrow device name from developer's menu to avoid multiple name settings.
'devtools.discovery.device': {
prefName: 'dom.presentation.device.name',
defaultValue: 'Firefox OS'
},
'devtools.eventlooplag.threshold': 100,
'devtools.remote.wifi.visible': {
resetToPref: true
},
'devtools.telemetry.supported_performance_marks': {
resetToPref: true
},
'dom.presentation.discovery.enabled': false,
'dom.presentation.discoverable': false,
'dom.serviceWorkers.testing.enabled': false,
'gfx.layerscope.enabled': false,
'layers.draw-borders': false,
'layers.draw-tile-borders': false,
'layers.dump': false,
'layers.enable-tiles': AppConstants.platform !== "win",
'layers.enable-tiles': true,
'layers.effect.invert': false,
'layers.effect.grayscale': false,
'layers.effect.contrast': '0.0',
'layout.display-list.dump': false,
'mms.debugging.enabled': false,
'network.debugging.enabled': false,
'privacy.donottrackheader.enabled': false,
'privacy.trackingprotection.enabled': false,
'ril.debugging.enabled': false,
'ril.radio.disabled': false,
'ril.mms.requestReadReport.enabled': {
prefName: 'dom.mms.requestReadReport',
defaultValue: true
},
'ril.mms.requestStatusReport.enabled': {
prefName: 'dom.mms.requestStatusReport',
defaultValue: false
},
'ril.mms.retrieval_mode': {
prefName: 'dom.mms.retrieval_mode',
defaultValue: 'manual'
},
'ril.sms.requestStatusReport.enabled': {
prefName: 'dom.sms.requestStatusReport',
defaultValue: false
},
'ril.sms.strict7BitEncoding.enabled': {
prefName: 'dom.sms.strict7BitEncoding',
defaultValue: false
},
'ril.sms.maxReadAheadEntries': {
prefName: 'dom.sms.maxReadAheadEntries',
defaultValue: 7
},
'services.sync.enabled': {
defaultValue: false,
notifyChange: true
},
'ui.touch.radius.leftmm': {
resetToPref: true
},
'ui.touch.radius.topmm': {
resetToPref: true
},
'ui.touch.radius.rightmm': {
resetToPref: true
},
'ui.touch.radius.bottommm': {
resetToPref: true
},
'ui.click_hold_context_menus.delay': {
resetToPref: true
},
'wap.UAProf.tagname': 'x-wap-profile',
'wap.UAProf.url': ''
};
if (AppConstants.MOZ_GRAPHENE) {
// Restart required
settingsToObserve['layers.async-pan-zoom.enabled'] = false;
}
function settingObserver(setPref, prefName, setting) {
return value => {
setPref(prefName, value);
if (setting.notifyChange) {
SystemAppProxy._sendCustomEvent('mozPrefChromeEvent', {
prefName: prefName,
value: value
});
}
};
}
for (let key in settingsToObserve) {
let setting = settingsToObserve[key];
// Allow setting to contain flags redefining prefName and defaultValue.
let prefName = setting.prefName || key;
let defaultValue = setting.defaultValue;
if (defaultValue === undefined) {
defaultValue = setting;
}
let prefs = Services.prefs;
// If requested, reset setting value and defaultValue to the pref value.
if (setting.resetToPref) {
switch (prefs.getPrefType(prefName)) {
case Ci.nsIPrefBranch.PREF_BOOL:
defaultValue = prefs.getBoolPref(prefName);
break;
case Ci.nsIPrefBranch.PREF_INT:
defaultValue = prefs.getIntPref(prefName);
break;
case Ci.nsIPrefBranch.PREF_STRING:
defaultValue = prefs.getCharPref(prefName);
break;
}
let setting = {};
setting[key] = defaultValue;
window.navigator.mozSettings.createLock().set(setting);
}
// Figure out the right setter function for this type of pref.
let setPref;
switch (typeof defaultValue) {
case 'boolean':
setPref = prefs.setBoolPref.bind(prefs);
break;
case 'number':
setPref = prefs.setIntPref.bind(prefs);
break;
case 'string':
setPref = prefs.setCharPref.bind(prefs);
break;
}
SettingsListener.observe(key, defaultValue,
settingObserver(setPref, prefName, setting));
};
|