Bug 933093 - Part 2: Add 'sendFile' implementation to Chrome process. r=yoshi

The chrome process is the arbitrator / mediator between the content process that issued the nfc 'sendFile' operation and the system-process (content) that is responsible for performing handover to an alternate carrier(AC).

The chrome process notifies the system process through a 'nfc-manager-send-file' system-message to initiate the handover process.

The system-process subsequently handovers the data to alternate carrier's (AC's : BT / WiFi) 'sendFile' interface.
This commit is contained in:
Siddartha Pothapragada 2013-12-14 00:57:11 -08:00
parent 08f0a3df68
commit 73c0d4b415
3 changed files with 55 additions and 5 deletions

View File

@ -51,7 +51,8 @@ const NFC_IPC_MSG_NAMES = [
"NFC:GetDetailsNDEF",
"NFC:MakeReadOnlyNDEF",
"NFC:Connect",
"NFC:Close"
"NFC:Close",
"NFC:SendFile"
];
const NFC_IPC_PEER_MSG_NAMES = [
@ -296,11 +297,11 @@ XPCOMUtils.defineLazyGetter(this, "gMessageManager", function () {
return null;
}
// Add extra permission check for two IPC Peer events:
// Add extra permission check for below IPC Peer events:
// 'NFC:CheckP2PRegistration' , 'NFC:NotifyUserAcceptedP2P'
if ((msg.name == "NFC:CheckP2PRegistration") ||
(msg.name == "NFC:NotifyUserAcceptedP2P")) {
// ONLY privileged Content can send these two events
// ONLY privileged Content can send these events
if (!msg.target.assertPermission("nfc-manager")) {
debug("NFC message " + message.name +
" from a content process with no 'nfc-manager' privileges.");
@ -532,6 +533,7 @@ Nfc.prototype = {
break;
case "NFC:WriteNDEF": // Fall through
case "NFC:MakeReadOnlyNDEF":
case "NFC:SendFile":
if (!message.target.assertPermission("nfc-write")) {
debug("NFC message " + message.name +
" from a content process with no 'nfc-write' privileges.");
@ -574,6 +576,17 @@ Nfc.prototype = {
case "NFC:Close":
this.sendToWorker("close", message.json);
break;
case "NFC:SendFile":
// Chrome process is the arbitrator / mediator between
// system app (content process) that issued nfc 'sendFile' operation
// and system app that handles the system message :
// 'nfc-manager-send-file'. System app subsequently handover's
// the data to alternate carrier's (BT / WiFi) 'sendFile' interface.
// Notify system app to initiate BT send file operation
gSystemMessenger.broadcastMessage("nfc-manager-send-file",
message.json);
break;
default:
debug("UnSupported : Message Name " + message.name);
return null;

View File

@ -218,6 +218,23 @@ NfcContentHelper.prototype = {
return request;
},
sendFile: function sendFile(window, data, sessionToken) {
if (window == null) {
throw Components.Exception("Can't get window object",
Cr.NS_ERROR_UNEXPECTED);
}
let request = Services.DOMRequest.createRequest(window);
let requestId = btoa(this.getRequestId(request));
this._requestMap[requestId] = window;
cpmm.sendAsyncMessage("NFC:SendFile", {
requestId: requestId,
sessionToken: sessionToken,
blob: data.blob
});
return request;
},
registerTargetForPeerEvent: function registerTargetForPeerEvent(window,
appId, event, callback) {
if (window == null) {
@ -276,7 +293,6 @@ NfcContentHelper.prototype = {
},
// nsIObserver
observe: function observe(subject, topic, data) {
if (topic == "xpcom-shutdown") {
this.removeMessageListener();

View File

@ -7,7 +7,7 @@
interface nsIVariant;
[scriptable, function, uuid(271f48b0-c884-4f0b-a348-e29824c95168)]
[scriptable, function, uuid(26673d1a-4af4-470a-ba96-f1f54b1f2052)]
interface nsINfcPeerCallback : nsISupports
{
/**
@ -40,6 +40,27 @@ interface nsINfcContentHelper : nsISupports
nsIDOMDOMRequest connect(in nsIDOMWindow window, in unsigned long techType, in DOMString sessionToken);
nsIDOMDOMRequest close(in nsIDOMWindow window, in DOMString sessionToken);
/**
* Initiate Send file operation
*
* @param window
* Current window
*
* @param blob
* Raw data of the file to be sent. This object represents a file-like
* (nsIDOMFile) object of immutable, raw data. The blob data needs
* to be 'object wrapped' before calling this interface.
*
* @param sessionToken
* Current token
*
* Returns DOMRequest, if initiation of send file operation is successful
* then 'onsuccess' is called else 'onerror'
*/
nsIDOMDOMRequest sendFile(in nsIDOMWindow window,
in jsval blob,
in DOMString sessionToken);
/**
* Register the given application id with Chrome process
*