Bug 760402 - Map debugger preference to mozSettings. r=fabrice

--HG--
extra : rebase_source : 61783ea299853396eea461b79dd5766da5e39217
This commit is contained in:
Vivien Nicolas 2012-06-06 14:19:33 +02:00
parent 3f61927d18
commit 3fccc2d637
4 changed files with 96 additions and 69 deletions

View File

@ -0,0 +1,93 @@
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 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;"
// 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.getLock().get(name);
req.addEventListener('success', (function onsuccess() {
callback(typeof(req.result[name]) != 'undefined' ?
req.result[name] : defaultValue);
}));
this._callbacks[name] = callback;
}
};
SettingsListener.init();
// =================== Languages ====================
SettingsListener.observe('language.current', 'en-US', function(value) {
Services.prefs.setCharPref('intl.accept_languages', value);
});
// =================== RIL ====================
(function RILSettingsToPrefs() {
['ril.data.enabled', 'ril.data.roaming.enabled'].forEach(function(key) {
SettingsListener.observe(key, false, function(value) {
Services.prefs.setBoolPref(key, value);
});
});
let strPrefs = ['ril.data.apn', 'ril.data.user', 'ril.data.passwd',
'ril.data.mmsc', 'ril.data.mmsproxy'];
strPrefs.forEach(function(key) {
SettingsListener.observe(key, false, function(value) {
Services.prefs.setCharPref(key, value);
});
});
['ril.data.mmsport'].forEach(function(key) {
SettingsListener.observe(key, false, function(value) {
Services.prefs.setIntPref(key, value);
});
});
})();
// =================== Debugger ====================
SettingsListener.observe('devtools.debugger.enabled', false, function(enabled) {
Services.prefs.setBoolPref('devtools.debugger.enabled', value);
});
SettingsListener.observe('devtools.debugger.log', false, function(value) {
Services.prefs.setBoolPref('devtools.debugger.log', value);
});
SettingsListener.observe('devtools.debugger.port', 6000, function(value) {
Services.prefs.setIntPref('devtools.debugger.port', value);
});

View File

@ -528,52 +528,6 @@ window.addEventListener('ContentStart', function(evt) {
}
});
// 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.getLock().get(name);
req.addEventListener('success', (function onsuccess() {
callback(typeof(req.result[name]) != 'undefined' ?
req.result[name] : defaultValue);
}));
this._callbacks[name] = callback;
}
};
SettingsListener.init();
SettingsListener.observe('language.current', 'en-US', function(value) {
Services.prefs.setCharPref('intl.accept_languages', value);
});
(function PowerManager() {
// This will eventually be moved to content, so use content API as
// much as possible here. TODO: Bug 738530
@ -644,26 +598,3 @@ SettingsListener.observe('language.current', 'en-US', function(value) {
});
})();
(function RILSettingsToPrefs() {
['ril.data.enabled', 'ril.data.roaming.enabled'].forEach(function(key) {
SettingsListener.observe(key, false, function(value) {
Services.prefs.setBoolPref(key, value);
});
});
let strPrefs = ['ril.data.apn', 'ril.data.user', 'ril.data.passwd',
'ril.data.mmsc', 'ril.data.mmsproxy'];
strPrefs.forEach(function(key) {
SettingsListener.observe(key, false, function(value) {
Services.prefs.setCharPref(key, value);
});
});
['ril.data.mmsport'].forEach(function(key) {
SettingsListener.observe(key, false, function(value) {
Services.prefs.setIntPref(key, value);
});
});
})();

View File

@ -14,7 +14,9 @@
onload="shell.start();"
onunload="shell.stop();">
<script type="application/javascript" src="chrome://browser/content/settings.js"/>
<script type="application/javascript" src="chrome://browser/content/shell.js"/>
#ifndef ANDROID
<!-- this script handles the screen argument for desktop builds -->
<script type="application/javascript" src="chrome://browser/content/screen.js"/>

View File

@ -9,6 +9,7 @@ chrome.jar:
% content browser %content/
content/dbg-browser-actors.js (content/dbg-browser-actors.js)
content/settings.js (content/settings.js)
* content/shell.xul (content/shell.xul)
* content/shell.js (content/shell.js)
#ifndef ANDROID