Bug 1058397 - Part 4: Wrap system message. r=hsinyi
authorSzu-Yu Chen [:aknow] <szchen@mozilla.com>
Wed, 15 Oct 2014 02:51:00 -0400
changeset 210717 1b5f60a8cbac6583f796915cd442f7e2ec94e28e
parent 210716 b93c5e78c526d4d1caa93fb9664adeb1a96f33bf
child 210718 2c9e31c7739d7b25acd07d283f1b2b940cbac3ed
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewershsinyi
bugs1058397
milestone36.0a1
Bug 1058397 - Part 4: Wrap system message. r=hsinyi
dom/mobileconnection/gonk/MobileConnectionService.js
dom/system/gonk/RadioInterfaceLayer.js
dom/telephony/gonk/TelephonyService.js
dom/telephony/gonk/TelephonyService.manifest
dom/telephony/nsIGonkTelephonyService.idl
--- a/dom/mobileconnection/gonk/MobileConnectionService.js
+++ b/dom/mobileconnection/gonk/MobileConnectionService.js
@@ -995,24 +995,16 @@ MobileConnectionService.prototype = {
   notifyUssdReceived: function(aClientId, aMessage, aSessionEnded) {
     if (DEBUG) {
       debug("notifyUssdReceived for " + aClientId + ": " +
             aMessage + " (sessionEnded : " + aSessionEnded + ")");
     }
 
     this.getItemByServiceId(aClientId)
         .deliverListenerEvent("notifyUssdReceived", [aMessage, aSessionEnded]);
-
-    let info = {
-      message: aMessage,
-      sessionEnded: aSessionEnded,
-      serviceId: aClientId
-    };
-
-    gSystemMessenger.broadcastMessage("ussd-received", info);
   },
 
   notifyDataError: function(aClientId, aMessage) {
     if (DEBUG) {
       debug("notifyDataError for " + aClientId + ": " + aMessage);
     }
 
     this.getItemByServiceId(aClientId)
--- a/dom/system/gonk/RadioInterfaceLayer.js
+++ b/dom/system/gonk/RadioInterfaceLayer.js
@@ -1980,23 +1980,28 @@ RadioInterface.prototype = {
         break;
       case "callDisconnected":
         gTelephonyService.notifyCallDisconnected(this.clientId, message.call);
         break;
       case "conferenceCallStateChanged":
         gTelephonyService.notifyConferenceCallStateChanged(message.state);
         break;
       case "cdmaCallWaiting":
-        gTelephonyService.notifyCdmaCallWaiting(this.clientId, message.waitingCall);
+        gTelephonyService.notifyCdmaCallWaiting(this.clientId,
+                                                message.waitingCall);
         break;
       case "suppSvcNotification":
         gTelephonyService.notifySupplementaryService(this.clientId,
                                                      message.callIndex,
                                                      message.notification);
         break;
+      case "ussdreceived":
+        gTelephonyService.notifyUssdReceived(this.clientId, message.message,
+                                             message.sessionEnded);
+        break;
       case "datacallerror":
         connHandler.handleDataCallError(message);
         break;
       case "datacallstatechange":
         let addresses = [];
         for (let i = 0; i < message.addresses.length; i++) {
           let [address, prefixLength] = message.addresses[i].split("/");
           // From AOSP hardware/ril/include/telephony/ril.h, that address prefix
@@ -2040,21 +2045,16 @@ RadioInterface.prototype = {
         gMobileConnectionService.notifyOtaStatusChanged(this.clientId, message.status);
         break;
       case "radiostatechange":
         // gRadioEnabledController should know the radio state for each client,
         // so notify gRadioEnabledController here.
         gRadioEnabledController.notifyRadioStateChanged(this.clientId,
                                                         message.radioState);
         break;
-      case "ussdreceived":
-        gMobileConnectionService.notifyUssdReceived(this.clientId,
-                                                    message.message,
-                                                    message.sessionEnded);
-        break;
       case "cardstatechange":
         this.rilContext.cardState = message.cardState;
         gRadioEnabledController.receiveCardState(this.clientId);
         gMessageManager.sendIccMessage("RIL:CardStateChanged",
                                        this.clientId, message);
         break;
       case "sms-received":
         this.handleSmsMultipart(message);
--- a/dom/telephony/gonk/TelephonyService.js
+++ b/dom/telephony/gonk/TelephonyService.js
@@ -1281,16 +1281,34 @@ TelephonyService.prototype = {
   },
 
   notifyConferenceCallStateChanged: function(aState) {
     if (DEBUG) debug("handleConferenceCallStateChanged: " + aState);
     aState = this._convertRILCallState(aState);
     this._notifyAllListeners("conferenceCallStateChanged", [aState]);
   },
 
+  notifyUssdReceived: function(aClientId, aMessage, aSessionEnded) {
+    if (DEBUG) {
+      debug("notifyUssdReceived for " + aClientId + ": " +
+            aMessage + " (sessionEnded : " + aSessionEnded + ")");
+    }
+
+    let info = {
+      serviceId: aClientId,
+      message: aMessage,
+      sessionEnded: aSessionEnded
+    };
+
+    gSystemMessenger.broadcastMessage("ussd-received", info);
+
+    gGonkMobileConnectionService.notifyUssdReceived(aClientId, aMessage,
+                                                    aSessionEnded);
+  },
+
   dialMMI: function(aClientId, aMmiString, aCallback) {
     let mmi = this._parseMMI(aMmiString, this._hasCalls(aClientId));
     this._dialMMI(aClientId, mmi, aCallback, false);
   },
 
   /**
    * nsIObserver interface.
    */
@@ -1310,9 +1328,43 @@ TelephonyService.prototype = {
         this._releaseCallRingWakeLock();
 
         Services.obs.removeObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID);
         break;
     }
   }
 };
 
-this.NSGetFactory = XPCOMUtils.generateNSGetFactory([TelephonyService]);
+/**
+ * This implements nsISystemMessagesWrapper.wrapMessage(), which provides a
+ * plugable way to wrap a "ussd-received" type system message.
+ *
+ * Please see SystemMessageManager.js to know how it customizes the wrapper.
+ */
+function USSDReceivedWrapper() {
+  if (DEBUG) debug("USSDReceivedWrapper()");
+}
+USSDReceivedWrapper.prototype = {
+  // nsISystemMessagesWrapper implementation.
+  wrapMessage: function(aMessage, aWindow) {
+    if (DEBUG) debug("wrapMessage: " + JSON.stringify(aMessage));
+
+    let session = aMessage.sessionEnded ? null :
+      new aWindow.USSDSession(aMessage.serviceId);
+
+    let event = new aWindow.USSDReceivedEvent("ussdreceived", {
+      serviceId: aMessage.serviceId,
+      message: aMessage.message,
+      sessionEnded: aMessage.sessionEnded,
+      session: session
+    });
+
+    return event;
+  },
+
+  classDescription: "USSDReceivedWrapper",
+  classID: Components.ID("{d03684ed-ede4-4210-8206-f4f32772d9f5}"),
+  contractID: "@mozilla.org/dom/system-messages/wrapper/ussd-received;1",
+  QueryInterface: XPCOMUtils.generateQI([Ci.nsISystemMessagesWrapper])
+};
+
+this.NSGetFactory = XPCOMUtils.generateNSGetFactory([TelephonyService,
+                                                    USSDReceivedWrapper]);
--- a/dom/telephony/gonk/TelephonyService.manifest
+++ b/dom/telephony/gonk/TelephonyService.manifest
@@ -1,2 +1,5 @@
 component {67d26434-d063-4d28-9f48-5b3189788155} TelephonyService.js
 contract @mozilla.org/telephony/gonktelephonyservice;1 {67d26434-d063-4d28-9f48-5b3189788155}
+
+component {d03684ed-ede4-4210-8206-f4f32772d9f5} TelephonyService.js
+contract @mozilla.org/dom/system-messages/wrapper/ussd-received;1 {d03684ed-ede4-4210-8206-f4f32772d9f5}
--- a/dom/telephony/nsIGonkTelephonyService.idl
+++ b/dom/telephony/nsIGonkTelephonyService.idl
@@ -5,28 +5,31 @@
 
 #include "nsITelephonyService.idl"
 
 %{C++
 #define GONK_TELEPHONY_SERVICE_CONTRACTID \
         "@mozilla.org/telephony/gonktelephonyservice;1"
 %}
 
-[scriptable, uuid(518165dc-2d55-4db3-9549-60dc4062d1c5)]
+[scriptable, uuid(79eec3c3-2dfc-4bbf-b106-af5457651ae0)]
 interface nsIGonkTelephonyService : nsITelephonyService
 {
   void notifyCallDisconnected(in unsigned long clientId, in jsval call);
 
   void notifyCallRing();
 
   void notifyCallStateChanged(in unsigned long clientId, in jsval call,
                               [optional] in boolean skipStateConversion);
 
   void notifyCdmaCallWaiting(in unsigned long clientId, in jsval waitingCall);
 
   void notifySupplementaryService(in unsigned long clientId, in long callIndex,
                                   in AString notification);
 
   void notifyConferenceCallStateChanged(in short state);
 
+  void notifyUssdReceived(in unsigned long clientId, in DOMString message,
+                          in boolean sessionEnded);
+
   void dialMMI(in unsigned long clientId, in AString mmiString,
                in nsITelephonyDialCallback callback);
 };