Bug 979767 - Part 1: Messages and Permissions. Supporting web application triggering based on HCI event EVT_TRANSACTION. r=fabrice

This commit is contained in:
Garner Lee 2014-08-27 14:41:00 +02:00
parent b53939d9f3
commit ddbbc6e53d
6 changed files with 128 additions and 0 deletions

View File

@ -563,6 +563,8 @@
@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

View File

@ -354,6 +354,11 @@ this.PermissionsTable = { geolocation: {
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,

View File

@ -108,6 +108,9 @@ this.SystemMessagePermissionsTable = {
"cdma-info-rec-received": {
"mobileconnection": []
},
"nfc-hci-event-transaction": {
"nfc-hci-events": []
},
"nfc-manager-tech-discovered": {
"nfc-manager": []
},

View File

@ -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}

View File

@ -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]);

View File

@ -34,6 +34,8 @@ if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'gonk' and CONFIG['MOZ_NFC']:
EXTRA_COMPONENTS += [
'gonk/Nfc.js',
'gonk/Nfc.manifest',
'messages/HCIEventTransactionSystemMessage.manifest',
'messages/HCIEventTransactionSystemMessageConfigurator.js',
]
EXTRA_JS_MODULES += [
'gonk/nfc_consts.js',