Bug 959437 - Part 2: Add NotifySendFileStatus to Chrome process. r=allstars.chh
authorSiddartha Pothapragada <Siddartha.Pothapragada@telekom.com>
Wed, 15 Jan 2014 15:42:49 -0800
changeset 181944 1d4c70a7296ede71f9adeee8291af9c50625f285
parent 181943 a504dfc43d3fc1874bede56cf4d78c61a3fa24db
child 181945 464a1e7fb0d96a29e8486902fca71aaf876049a4
push id3343
push userffxbld
push dateMon, 17 Mar 2014 21:55:32 +0000
treeherdermozilla-beta@2f7d3415f79f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersallstars
bugs959437
milestone29.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 959437 - Part 2: Add NotifySendFileStatus to Chrome process. r=allstars.chh
dom/system/gonk/Nfc.js
dom/system/gonk/NfcContentHelper.js
dom/system/gonk/nsINfcContentHelper.idl
--- a/dom/system/gonk/Nfc.js
+++ b/dom/system/gonk/Nfc.js
@@ -54,17 +54,18 @@ const NFC_IPC_MSG_NAMES = [
   "NFC:Close",
   "NFC:SendFile"
 ];
 
 const NFC_IPC_PEER_MSG_NAMES = [
   "NFC:RegisterPeerTarget",
   "NFC:UnregisterPeerTarget",
   "NFC:CheckP2PRegistration",
-  "NFC:NotifyUserAcceptedP2P"
+  "NFC:NotifyUserAcceptedP2P",
+  "NFC:NotifySendFileStatus"
 ];
 
 XPCOMUtils.defineLazyServiceGetter(this, "ppmm",
                                    "@mozilla.org/parentprocessmessagemanager;1",
                                    "nsIMessageBroadcaster");
 XPCOMUtils.defineLazyServiceGetter(this, "gSystemMessenger",
                                    "@mozilla.org/system-message-internal;1",
                                    "nsISystemMessagesInternal");
@@ -304,20 +305,22 @@ XPCOMUtils.defineLazyGetter(this, "gMess
         }
       } else if (NFC_IPC_PEER_MSG_NAMES.indexOf(msg.name) != -1) {
         if (!msg.target.assertPermission("nfc-write")) {
           debug("Nfc Peer message  " + msg.name +
                 " from a content process with no 'nfc-write' privileges.");
           return null;
         }
 
-        // Add extra permission check for below IPC Peer events:
-        // 'NFC:CheckP2PRegistration' , 'NFC:NotifyUserAcceptedP2P'
+        // Add extra permission check for below events:
+        // 'NFC:CheckP2PRegistration' , 'NFC:NotifyUserAcceptedP2P',
+        // 'NFC:NotifySendFileStatus'
         if ((msg.name == "NFC:CheckP2PRegistration") ||
-            (msg.name == "NFC:NotifyUserAcceptedP2P")) {
+            (msg.name == "NFC:NotifyUserAcceptedP2P") ||
+            (msg.name == "NFC:NotifySendFileStatus")) {
           // 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.");
             return null;
           }
         }
       } else {
@@ -351,16 +354,21 @@ XPCOMUtils.defineLazyGetter(this, "gMess
             status: status,
             requestId: msg.json.requestId
           });
           break;
         case "NFC:NotifyUserAcceptedP2P":
           // Notify the 'NFC_PEER_EVENT_READY' since user has acknowledged
           this.notifyPeerEvent(msg.json.appId, NFC.NFC_PEER_EVENT_READY);
           break;
+        case "NFC:NotifySendFileStatus":
+          // Upon receiving the status of sendFile operation, send the response
+          // to appropriate content process.
+          this.sendNfcResponseMessage(msg.name + "Response", msg.json);
+          break;
       }
       return null;
     },
 
     /**
      * nsIObserver interface methods.
      */
 
--- a/dom/system/gonk/NfcContentHelper.js
+++ b/dom/system/gonk/NfcContentHelper.js
@@ -47,17 +47,19 @@ const NFCCONTENTHELPER_CID =
 const NFC_IPC_MSG_NAMES = [
   "NFC:ReadNDEFResponse",
   "NFC:WriteNDEFResponse",
   "NFC:GetDetailsNDEFResponse",
   "NFC:MakeReadOnlyNDEFResponse",
   "NFC:ConnectResponse",
   "NFC:CloseResponse",
   "NFC:CheckP2PRegistrationResponse",
-  "NFC:PeerEvent"
+  "NFC:PeerEvent",
+  "NFC:NotifySendFileStatusResponse",
+  "NFC:SendFileResponse"
 ];
 
 XPCOMUtils.defineLazyServiceGetter(this, "cpmm",
                                    "@mozilla.org/childprocessmessagemanager;1",
                                    "nsISyncMessageSender");
 
 function NfcContentHelper() {
   this.initDOMRequestHelper(/* aWindow */ null, NFC_IPC_MSG_NAMES);
@@ -230,16 +232,29 @@ NfcContentHelper.prototype = {
     cpmm.sendAsyncMessage("NFC:SendFile", {
       requestId: requestId,
       sessionToken: sessionToken,
       blob: data.blob
     });
     return request;
   },
 
+  notifySendFileStatus: function notifySendFileStatus(window, status,
+                                                      requestId) {
+    if (window == null) {
+      throw Components.Exception("Can't get window object",
+                                  Cr.NS_ERROR_UNEXPECTED);
+    }
+
+    cpmm.sendAsyncMessage("NFC:NotifySendFileStatus", {
+      status: status,
+      requestId: requestId
+    });
+  },
+
   registerTargetForPeerEvent: function registerTargetForPeerEvent(window,
                                                   appId, event, callback) {
     if (window == null) {
       throw Components.Exception("Can't get window object",
                                   Cr.NS_ERROR_UNEXPECTED);
     }
     this.peerEventsCallbackMap[event] = callback;
     cpmm.sendAsyncMessage("NFC:RegisterPeerTarget", {
@@ -336,16 +351,17 @@ NfcContentHelper.prototype = {
         this.handleReadNDEFResponse(message.json);
         break;
       case "NFC:ConnectResponse": // Fall through.
       case "NFC:CloseResponse":
       case "NFC:WriteNDEFResponse":
       case "NFC:MakeReadOnlyNDEFResponse":
       case "NFC:GetDetailsNDEFResponse":
       case "NFC:CheckP2PRegistrationResponse":
+      case "NFC:NotifySendFileStatusResponse":
         this.handleResponse(message.json);
         break;
       case "NFC:PeerEvent":
         let callback = this.peerEventsCallbackMap[message.json.event];
         if (callback) {
           callback.peerNotification(message.json.event,
                                     message.json.sessionToken);
         } else {
--- a/dom/system/gonk/nsINfcContentHelper.idl
+++ b/dom/system/gonk/nsINfcContentHelper.idl
@@ -19,17 +19,17 @@ interface nsINfcPeerCallback : nsISuppor
    *
    * @param sessionToken
    *        SessionToken received from Chrome process
    */
    void peerNotification(in unsigned long event,
                          in DOMString sessionToken);
 };
 
-[scriptable, uuid(91c2760a-f41c-4174-ad68-614840d4e201)]
+[scriptable, uuid(70cac000-7e3c-11e3-baa7-0800200c9a66)]
 interface nsINfcContentHelper : nsISupports
 {
   const long NFC_EVENT_PEER_READY = 0x01;
   const long NFC_EVENT_PEER_LOST  = 0x02;
 
   void setSessionToken(in DOMString sessionToken);
 
   nsIDOMDOMRequest getDetailsNDEF(in nsIDOMWindow window, in DOMString sessionToken);
@@ -113,9 +113,26 @@ interface nsINfcContentHelper : nsISuppo
   *
   * @param window
   *        Current window
   *
   * @param appId
   *        Application ID that is capable of handling NFC_EVENT_PEER_READY event
   */
   void notifyUserAcceptedP2P(in nsIDOMWindow window, in unsigned long appId);
+
+ /**
+  * Notify the status of sendFile operation to Chrome process
+  *
+  * @param window
+  *        Current window
+  *
+  * @param status
+  *        Status of sendFile operation
+  *        (GECKO_NFC_ERROR_SUCCESS, GECKO_NFC_ERROR_GENERIC_FAILURE)
+  *
+  * @param requestId
+  *        Request ID of SendFile DOM Request
+  */
+  void notifySendFileStatus(in nsIDOMWindow window,
+                            in octet status,
+                            in DOMString requestId);
 };