Bug 760402 - Map debugger preference to mozSettings. r=fabrice
authorVivien Nicolas <21@vingtetun.org>
Wed, 06 Jun 2012 14:19:33 +0200
changeset 100782 abecec00a124a7d079a5124abf5e0ed8d48b4096
parent 100781 bfe1733ba6062581933a44e78e0f5a96eff5964b
child 100783 2e509c91883aaed7cb11a9b0c2ae29cfd61f0a70
push id1316
push userakeybl@mozilla.com
push dateMon, 27 Aug 2012 22:37:00 +0000
treeherdermozilla-beta@db4b09302ee2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfabrice
bugs760402
milestone16.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 760402 - Map debugger preference to mozSettings. r=fabrice
b2g/chrome/content/settings.js
b2g/chrome/content/shell.js
b2g/chrome/content/shell.xul
b2g/chrome/jar.mn
new file mode 100644
--- /dev/null
+++ b/b2g/chrome/content/settings.js
@@ -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);
+});
+
--- a/b2g/chrome/content/shell.js
+++ b/b2g/chrome/content/shell.js
@@ -523,62 +523,16 @@ function startDebugger() {
 }
 
 window.addEventListener('ContentStart', function(evt) {
   if (Services.prefs.getBoolPref('devtools.debugger.enabled')) {
     startDebugger();
   }
 });
 
-
-// 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
   let power = navigator.mozPower;
   let idleHandler = function idleHandler(subject, topic, time) {
     if (topic !== 'idle')
       return;
 
@@ -639,31 +593,8 @@ SettingsListener.observe('language.curre
   });
 
   window.addEventListener('unload', function removeIdleObjects() {
     Services.idle.removeIdleObserver(idleHandler, idleTimeout);
     power.removeWakeLockListener(wakeLockHandler);
   });
 })();
 
-
-(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);
-    });
-  });
-})();
-
--- a/b2g/chrome/content/shell.xul
+++ b/b2g/chrome/content/shell.xul
@@ -9,17 +9,19 @@
         windowtype="navigator:browser"
 #ifdef ANDROID
         sizemode="fullscreen"
 #endif
         style="background: black; overflow: hidden; width:480px; height:800px"
         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"/>
 #endif
   <browser id="homescreen"
            type="content-primary"
            flex="1"
            style="overflow: hidden;"
--- a/b2g/chrome/jar.mn
+++ b/b2g/chrome/jar.mn
@@ -4,16 +4,17 @@
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 
 chrome.jar:
 % content branding %content/branding/
 % 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
   content/screen.js                     (content/screen.js)
 #endif
   content/webapi.js                     (content/webapi.js)
   content/content.css                   (content/content.css)
   content/touchcontrols.css             (content/touchcontrols.css)