From 73c0d4b41509008090816715a16a20e949efab61 Mon Sep 17 00:00:00 2001 From: Siddartha Pothapragada Date: Sat, 14 Dec 2013 00:57:11 -0800 Subject: [PATCH] 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. --- dom/system/gonk/Nfc.js | 19 ++++++++++++++++--- dom/system/gonk/NfcContentHelper.js | 18 +++++++++++++++++- dom/system/gonk/nsINfcContentHelper.idl | 23 ++++++++++++++++++++++- 3 files changed, 55 insertions(+), 5 deletions(-) diff --git a/dom/system/gonk/Nfc.js b/dom/system/gonk/Nfc.js index c2a489ef426..e7d71ddc3ae 100644 --- a/dom/system/gonk/Nfc.js +++ b/dom/system/gonk/Nfc.js @@ -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; diff --git a/dom/system/gonk/NfcContentHelper.js b/dom/system/gonk/NfcContentHelper.js index 2ed5b17670a..5da34c2506a 100644 --- a/dom/system/gonk/NfcContentHelper.js +++ b/dom/system/gonk/NfcContentHelper.js @@ -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(); diff --git a/dom/system/gonk/nsINfcContentHelper.idl b/dom/system/gonk/nsINfcContentHelper.idl index 30f703bbbf6..62130652261 100644 --- a/dom/system/gonk/nsINfcContentHelper.idl +++ b/dom/system/gonk/nsINfcContentHelper.idl @@ -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 *