Bug 947100 - B2G NFC: Enable/disable NFC worker at runtime. r=yoshi, a=1.3+
authorDimi Lee <dlee@mozilla.com>
Wed, 11 Dec 2013 14:04:27 +0800
changeset 174384 90cf56c3fc35ce1866b9e49bcff039b657ec4d6e
parent 174383 8325c38a2f049ee93576f6c26b8e412c5ccca45e
child 174385 57157e39abea7b4ce3e33458acbaad2116b31253
push id3224
push userlsblakk@mozilla.com
push dateTue, 04 Feb 2014 01:06:49 +0000
treeherdermozilla-beta@60c04d0987f1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersyoshi, 1.3
bugs947100
milestone28.0a2
Bug 947100 - B2G NFC: Enable/disable NFC worker at runtime. r=yoshi, a=1.3+
dom/nfc/nsNfc.js
dom/system/gonk/Nfc.js
dom/system/gonk/NfcContentHelper.js
--- a/dom/nfc/nsNfc.js
+++ b/dom/nfc/nsNfc.js
@@ -133,18 +133,22 @@ MozNFCPeer.prototype = {
                                          Ci.nsIDOMGlobalPropertyInitializer]),
 };
 
 /**
  * Navigator NFC object
  */
 function mozNfc() {
   debug("In mozNfc Constructor");
-  this._nfcContentHelper = Cc["@mozilla.org/nfc/content-helper;1"]
-                             .getService(Ci.nsINfcContentHelper);
+  try {
+    this._nfcContentHelper = Cc["@mozilla.org/nfc/content-helper;1"]
+                               .getService(Ci.nsINfcContentHelper);
+  } catch(e) {
+    debug("No NFC support.")
+  }
 }
 mozNfc.prototype = {
   _nfcContentHelper: null,
   _window: null,
   _wrap: function _wrap(obj) {
     return ObjectWrapper.wrap(obj, this._window);
   },
 
--- a/dom/system/gonk/Nfc.js
+++ b/dom/system/gonk/Nfc.js
@@ -20,16 +20,19 @@
 const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
 
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 Cu.import("resource://gre/modules/Services.jsm");
 
 let NFC = {};
 Cu.import("resource://gre/modules/nfc_consts.js", NFC);
 
+Cu.import("resource://gre/modules/systemlibs.js");
+const NFC_ENABLED = libcutils.property_get("ro.moz.nfc.enabled", "false") === "true";
+
 // set to true in nfc_consts.js to see debug messages
 let DEBUG = NFC.DEBUG_NFC;
 
 let debug;
 if (DEBUG) {
   debug = function (s) {
     dump("-*- Nfc: " + s + "\n");
   };
@@ -622,9 +625,11 @@ Nfc.prototype = {
     }
   },
 
   setConfig: function setConfig(prop) {
     this.sendToWorker("config", prop);
   }
 };
 
-this.NSGetFactory = XPCOMUtils.generateNSGetFactory([Nfc]);
+if (NFC_ENABLED) {
+  this.NSGetFactory = XPCOMUtils.generateNSGetFactory([Nfc]);
+}
--- a/dom/system/gonk/NfcContentHelper.js
+++ b/dom/system/gonk/NfcContentHelper.js
@@ -21,16 +21,19 @@ const {classes: Cc, interfaces: Ci, util
 
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 Cu.import("resource://gre/modules/Services.jsm");
 Cu.import("resource://gre/modules/DOMRequestHelper.jsm");
 
 let NFC = {};
 Cu.import("resource://gre/modules/nfc_consts.js", NFC);
 
+Cu.import("resource://gre/modules/systemlibs.js");
+const NFC_ENABLED = libcutils.property_get("ro.moz.nfc.enabled", "false") === "true";
+
 // set to true to in nfc_consts.js to see debug messages
 let DEBUG = NFC.DEBUG_CONTENT_HELPER;
 
 let debug;
 if (DEBUG) {
   debug = function (s) {
     dump("-*- NfcContentHelper: " + s + "\n");
   };
@@ -379,9 +382,11 @@ NfcContentHelper.prototype = {
     if (message.status !== NFC.GECKO_NFC_ERROR_SUCCESS) {
       this.fireRequestError(requestId, result.status);
     } else {
       this.fireRequestSuccess(requestId, result);
     }
   },
 };
 
-this.NSGetFactory = XPCOMUtils.generateNSGetFactory([NfcContentHelper]);
+if (NFC_ENABLED) {
+  this.NSGetFactory = XPCOMUtils.generateNSGetFactory([NfcContentHelper]);
+}