Bug 979767 - Part 1: Messages and Permissions. Supporting web application triggering based on HCI event EVT_TRANSACTION. r=fabrice
authorGarner Lee <garner.lee@telekom.com>
Wed, 27 Aug 2014 14:41:00 +0200
changeset 223773 0f8132707c4672c219b69c5a6ea7c7c1d1021ca3
parent 223772 d5a0230a2ed709dc28a0750e5bd7911a94ea7da1
child 223774 98d9bdb538a84ccad2f0804c32ca86d94be60479
push id3979
push userraliiev@mozilla.com
push dateMon, 13 Oct 2014 16:35:44 +0000
treeherdermozilla-beta@30f2cc610691 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfabrice
bugs979767
milestone34.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 979767 - Part 1: Messages and Permissions. Supporting web application triggering based on HCI event EVT_TRANSACTION. r=fabrice
b2g/installer/package-manifest.in
dom/apps/src/PermissionsTable.jsm
dom/messages/SystemMessagePermissionsChecker.jsm
dom/nfc/messages/HCIEventTransactionSystemMessage.manifest
dom/nfc/messages/HCIEventTransactionSystemMessageConfigurator.js
dom/nfc/moz.build
--- a/b2g/installer/package-manifest.in
+++ b/b2g/installer/package-manifest.in
@@ -558,16 +558,18 @@
 
 @BINPATH@/components/nsDOMIdentity.js
 @BINPATH@/components/nsIDService.js
 @BINPATH@/components/Identity.manifest
 
 @BINPATH@/components/SystemMessageInternal.js
 @BINPATH@/components/SystemMessageManager.js
 @BINPATH@/components/SystemMessageManager.manifest
+@BINPATH@/components/HCIEventTransactionSystemMessage.manifest
+@BINPATH@/components/HCIEventTransactionSystemMessageConfigurator.js
 
 @BINPATH@/components/Activities.manifest
 @BINPATH@/components/ActivityProxy.js
 @BINPATH@/components/ActivityRequestHandler.js
 @BINPATH@/components/ActivityWrapper.js
 @BINPATH@/components/ActivityMessageConfigurator.js
 
 @BINPATH@/components/TCPSocket.js
--- a/dom/apps/src/PermissionsTable.jsm
+++ b/dom/apps/src/PermissionsTable.jsm
@@ -349,16 +349,21 @@ this.PermissionsTable =  { geolocation: 
                              certified: ALLOW_ACTION,
                              access: ["read", "write"]
                            },
                            "nfc-manager": {
                              app: DENY_ACTION,
                              privileged: DENY_ACTION,
                              certified: ALLOW_ACTION
                            },
+                           "nfc-hci-events": {
+                             app: DENY_ACTION,
+                             privileged: DENY_ACTION,
+                             certified: ALLOW_ACTION
+                           },
                            "speaker-control": {
                              app: DENY_ACTION,
                              privileged: ALLOW_ACTION,
                              certified: ALLOW_ACTION
                            },
                            "downloads": {
                              app: DENY_ACTION,
                              privileged: DENY_ACTION,
--- a/dom/messages/SystemMessagePermissionsChecker.jsm
+++ b/dom/messages/SystemMessagePermissionsChecker.jsm
@@ -103,16 +103,19 @@ this.SystemMessagePermissionsTable = {
     "mobileconnection": []
   },
   "wappush-received": {
     "wappush": []
   },
   "cdma-info-rec-received": {
     "mobileconnection": []
   },
+  "nfc-hci-event-transaction": {
+    "nfc-hci-events": []
+  },
   "nfc-manager-tech-discovered": {
     "nfc-manager": []
   },
   "nfc-manager-tech-lost": {
     "nfc-manager": []
   },
   "nfc-manager-send-file": {
     "nfc-manager": []
new file mode 100644
--- /dev/null
+++ b/dom/nfc/messages/HCIEventTransactionSystemMessage.manifest
@@ -0,0 +1,2 @@
+component {b501edd0-28bd-11e4-8c21-0800200c9a66} HCIEventTransactionSystemMessageConfigurator.js
+contract @mozilla.org/dom/system-messages/configurator/nfc-hci-event-transaction;1 {b501edd0-28bd-11e4-8c21-0800200c9a66}
new file mode 100644
--- /dev/null
+++ b/dom/nfc/messages/HCIEventTransactionSystemMessageConfigurator.js
@@ -0,0 +1,114 @@
+/* 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";
+
+const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
+
+Cu.import("resource://gre/modules/XPCOMUtils.jsm");
+Cu.import("resource://gre/modules/Promise.jsm");
+
+XPCOMUtils.defineLazyServiceGetter(this, "appsService",
+                                   "@mozilla.org/AppsService;1",
+                                   "nsIAppsService");
+
+let DEBUG = false;
+function debug(aMsg) {
+  if (DEBUG) {
+    dump("-- HCIEventTransactionSystemMessageConfigurator.js " + Date.now() + " : " + aMsg + "\n");
+  }
+}
+
+/**
+  * nsISystemMessagesConfigurator implementation.
+  */
+function HCIEventTransactionSystemMessageConfigurator() {
+  debug("HCIEventTransactionSystemMessageConfigurator");
+}
+
+HCIEventTransactionSystemMessageConfigurator.prototype = {
+  get mustShowRunningApp() {
+    debug("mustShowRunningApp returning true");
+    return true;
+  },
+
+  shouldDispatch: function shouldDispatch(aManifestURL, aPageURL, aType, aMessage, aExtra) {
+    let deferred = Promise.defer();
+    debug("message to dispatch: " + JSON.stringify(aMessage));
+    debug("aManifest url: " + aManifestURL);
+    if(!aMessage) {
+      return deferred.resolve(false);
+    }
+    let aid = this._byteAIDToHex(aMessage.aid);
+    let seName = aMessage.seName;
+
+    appsService.getManifestFor(aManifestURL)
+    .then((aManifest) => this._checkAppManifest(seName, aid, aManifest))
+    .then(() => {
+      // FIXME: Bug 884594: Access Control Enforcer
+      // Here we will call ace.isAllowed function which will also return
+      // a Promise, for now we're just resolving shouldDispatch promise
+      debug("dispatching message");
+      deferred.resolve(true);
+    })
+    .catch(() => {
+      // if the Promise chain was broken we don't dispatch the message
+      debug("not dispatching");
+      deferred.resolve(false);
+    });
+
+    return deferred.promise;
+  },
+
+  // we might be doing some async hash computations here, returning
+  // a resolved/rejected promise for now so we can easily fit the method
+  // into a Promise chain
+  _checkAppManifest: function _checkAppManifest(aSeName, aAid, aManifest) {
+    debug("aManifest " + JSON.stringify(aManifest));
+
+    let hciRules = aManifest["secure_element_access"] || [];
+    let matchingRule = hciRules.find((rule) => {
+      rule = rule.toUpperCase();
+      if(rule === "*" || rule === (aSeName + "/" + aAid)) {
+        return true;
+      }
+
+      let isMatching = (match, element) => {
+        if(match === "*") {
+          return true;
+        }
+        if(match.charAt(match.length - 1) === '*') {
+          return element.indexOf(match.substr(0,match.length - 1)) === 0;
+        }
+
+        return match === element;
+      };
+
+      return isMatching(rule.split('/')[0], aSeName) &&
+             isMatching(rule.split('/')[1], aAid);
+    });
+
+    return (matchingRule) ? Promise.resolve() : Promise.reject();
+  },
+
+  // FIXME: there is probably something which does this
+  _byteAIDToHex: function _byteAIDToHex(uint8arr) {
+    if (!uint8arr) {
+      return "";
+    }
+
+    var hexStr = "";
+    for (var i = 0; i < uint8arr.length; i++) {
+      var hex = (uint8arr[i] & 0xff).toString(16);
+      hex = (hex.length === 1) ? '0' + hex : hex;
+      hexStr += hex;
+    }
+    return hexStr.toUpperCase();
+  },
+
+  classID: Components.ID("{b501edd0-28bd-11e4-8c21-0800200c9a66}"),
+  QueryInterface: XPCOMUtils.generateQI([Ci.nsISystemMessagesConfigurator])
+}
+
+this.NSGetFactory = XPCOMUtils.generateNSGetFactory([HCIEventTransactionSystemMessageConfigurator]);
--- a/dom/nfc/moz.build
+++ b/dom/nfc/moz.build
@@ -29,16 +29,18 @@ if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'gonk
         'gonk/NfcService.cpp',
     ]
     XPIDL_SOURCES += [
         'gonk/nsINfcService.idl',
     ]
     EXTRA_COMPONENTS += [
         'gonk/Nfc.js',
         'gonk/Nfc.manifest',
+        'messages/HCIEventTransactionSystemMessage.manifest',
+        'messages/HCIEventTransactionSystemMessageConfigurator.js',
     ]
     EXTRA_JS_MODULES += [
         'gonk/nfc_consts.js',
     ]
 
 FAIL_ON_WARNINGS = True
 include('/ipc/chromium/chromium-config.mozbuild')