Bug 794011 - Add 'sessionEnded' to nsIDOMUSSDReceivedEvent. r=mounir, a=akeybl
authorGuillermo López <willyaranda@gmail.com>
Wed, 17 Oct 2012 12:17:19 +0100
changeset 113663 a1f5eec912256b98f3e7ac91649cd6e4b91ebeb5
parent 113662 85293aa3815ed30364ea4e032afc013a82a80298
child 113664 3985eab2ddecbd589e8f99d0407cb951952bdcfd
push id2453
push userryanvm@gmail.com
push dateFri, 26 Oct 2012 01:49:42 +0000
treeherdermozilla-aurora@15d6d97a9b5d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmounir, akeybl
bugs794011
milestone18.0a2
Bug 794011 - Add 'sessionEnded' to nsIDOMUSSDReceivedEvent. r=mounir, a=akeybl
dom/network/interfaces/nsIDOMUSSDReceivedEvent.idl
dom/network/src/MobileConnection.cpp
dom/network/src/USSDReceivedEvent.cpp
dom/network/src/USSDReceivedEvent.h
dom/system/gonk/RILContentHelper.js
dom/system/gonk/ril_worker.js
dom/webidl/USSDReceivedEvent.webidl
dom/webidl/WebIDL.mk
--- a/dom/network/interfaces/nsIDOMUSSDReceivedEvent.idl
+++ b/dom/network/interfaces/nsIDOMUSSDReceivedEvent.idl
@@ -1,11 +1,12 @@
 /* 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/. */
 
 #include "nsIDOMEvent.idl"
 
-[scriptable, builtinclass, uuid(1b8ea6e4-8142-4aba-b174-4d580b5bc294)]
+[scriptable, builtinclass, uuid(c0de7fba-725f-4180-b1f1-83163014d1e2)]
 interface nsIDOMUSSDReceivedEvent : nsIDOMEvent
 {
   readonly attribute DOMString message;
+  [infallible] readonly attribute boolean sessionEnded;
 };
--- a/dom/network/src/MobileConnection.cpp
+++ b/dom/network/src/MobileConnection.cpp
@@ -14,16 +14,18 @@
 #include "GeneratedEvents.h"
 #include "nsIDOMICCCardLockErrorEvent.h"
 
 #include "nsContentUtils.h"
 #include "nsJSUtils.h"
 #include "nsJSON.h"
 #include "jsapi.h"
 
+#include "mozilla/dom/USSDReceivedEventBinding.h"
+
 #define NS_RILCONTENTHELPER_CONTRACTID "@mozilla.org/ril/content-helper;1"
 
 #define VOICECHANGE_EVENTNAME      NS_LITERAL_STRING("voicechange")
 #define DATACHANGE_EVENTNAME       NS_LITERAL_STRING("datachange")
 #define CARDSTATECHANGE_EVENTNAME  NS_LITERAL_STRING("cardstatechange")
 #define ICCINFOCHANGE_EVENTNAME    NS_LITERAL_STRING("iccinfochange")
 #define USSDRECEIVED_EVENTNAME     NS_LITERAL_STRING("ussdreceived")
 #define DATAERROR_EVENTNAME        NS_LITERAL_STRING("dataerror")
@@ -155,23 +157,25 @@ MobileConnection::Observe(nsISupports* a
   }
 
   if (!strcmp(aTopic, kIccInfoChangedTopic)) {
     DispatchTrustedEvent(ICCINFOCHANGE_EVENTNAME);
     return NS_OK;
   }
 
   if (!strcmp(aTopic, kUssdReceivedTopic)) {
-    nsString ussd;
-    ussd.Assign(aData);
-    nsRefPtr<USSDReceivedEvent> event = USSDReceivedEvent::Create(ussd);
+    mozilla::dom::USSDReceivedEventDict dict;
+    bool ok = dict.Init(nsDependentString(aData));
+    NS_ENSURE_TRUE(ok, NS_ERROR_FAILURE);
+
+    nsRefPtr<USSDReceivedEvent> event =
+      USSDReceivedEvent::Create(dict.message, dict.sessionEnded);
     NS_ASSERTION(event, "This should never fail!");
 
-    nsresult rv =
-      event->Dispatch(ToIDOMEventTarget(), USSDRECEIVED_EVENTNAME);
+    nsresult rv = event->Dispatch(ToIDOMEventTarget(), USSDRECEIVED_EVENTNAME);
     NS_ENSURE_SUCCESS(rv, rv);
     return NS_OK;
   }
 
   if (!strcmp(aTopic, kDataErrorTopic)) {
     nsString dataerror;
     dataerror.Assign(aData);
     nsRefPtr<DataErrorEvent> event = DataErrorEvent::Create(dataerror);
--- a/dom/network/src/USSDReceivedEvent.cpp
+++ b/dom/network/src/USSDReceivedEvent.cpp
@@ -9,23 +9,24 @@
 
 DOMCI_DATA(USSDReceivedEvent, mozilla::dom::network::USSDReceivedEvent)
 
 namespace mozilla {
 namespace dom {
 namespace network {
 
 already_AddRefed<USSDReceivedEvent>
-USSDReceivedEvent::Create(nsAString& aMessage)
+USSDReceivedEvent::Create(nsAString& aMessage, bool aSessionEnded)
 {
   NS_ASSERTION(!aMessage.IsEmpty(), "Empty message!");
 
   nsRefPtr<USSDReceivedEvent> event = new USSDReceivedEvent();
 
   event->mMessage = aMessage;
+  event->mSessionEnded = aSessionEnded;
 
   return event.forget();
 }
 
 NS_IMPL_ADDREF_INHERITED(USSDReceivedEvent, nsDOMEvent)
 NS_IMPL_RELEASE_INHERITED(USSDReceivedEvent, nsDOMEvent)
 
 NS_INTERFACE_MAP_BEGIN(USSDReceivedEvent)
@@ -35,11 +36,18 @@ NS_INTERFACE_MAP_END_INHERITING(nsDOMEve
 
 NS_IMETHODIMP
 USSDReceivedEvent::GetMessage(nsAString& aMessage)
 {
   aMessage.Assign(mMessage);
   return NS_OK;
 }
 
+/* [infallible] */ NS_IMETHODIMP
+USSDReceivedEvent::GetSessionEnded(bool* aSessionEnded)
+{
+  *aSessionEnded = mSessionEnded;
+  return NS_OK;
+}
+
 }
 }
 }
--- a/dom/network/src/USSDReceivedEvent.h
+++ b/dom/network/src/USSDReceivedEvent.h
@@ -11,24 +11,25 @@
 namespace mozilla {
 namespace dom {
 namespace network {
 
 class USSDReceivedEvent : public nsDOMEvent,
                           public nsIDOMUSSDReceivedEvent
 {
   nsString mMessage;
+  bool mSessionEnded;
 
 public:
   NS_DECL_ISUPPORTS_INHERITED
   NS_FORWARD_TO_NSDOMEVENT
   NS_DECL_NSIDOMUSSDRECEIVEDEVENT
 
   static already_AddRefed<USSDReceivedEvent>
-  Create(nsAString& aMessage);
+  Create(nsAString& aMessage, bool aSessionEnded);
 
   nsresult
   Dispatch(nsIDOMEventTarget* aTarget, const nsAString& aEventType)
   {
     NS_ASSERTION(aTarget, "Null pointer!");
     NS_ASSERTION(!aEventType.IsEmpty(), "Empty event type!");
 
     nsresult rv = InitEvent(aEventType, false, false);
--- a/dom/system/gonk/RILContentHelper.js
+++ b/dom/system/gonk/RILContentHelper.js
@@ -722,18 +722,19 @@ RILContentHelper.prototype = {
                                          retryCount: msg.json.retryCount});
             Services.obs.notifyObservers(null, kIccCardLockErrorTopic,
                                          result);
           }
           this.fireRequestError(msg.json.requestId, msg.json.errorMsg);
         }
         break;
       case "RIL:USSDReceived":
-        Services.obs.notifyObservers(null, kUssdReceivedTopic,
-                                     msg.json.message);
+        let res = JSON.stringify({message: msg.json.message,
+                                  sessionEnded: msg.json.sessionEnded});
+        Services.obs.notifyObservers(null, kUssdReceivedTopic, res);
         break;
       case "RIL:SendMMI:Return:OK":
       case "RIL:CancelMMI:Return:OK":
         request = this.takeRequest(msg.json.requestId);
         if (request) {
           Services.DOMRequest.fireSuccess(request, msg.json.result);
         }
         break;
--- a/dom/system/gonk/ril_worker.js
+++ b/dom/system/gonk/ril_worker.js
@@ -4917,24 +4917,21 @@ RIL[UNSOLICITED_RESPONSE_NEW_SMS_ON_SIM]
   //TODO
 };
 RIL[UNSOLICITED_ON_USSD] = function UNSOLICITED_ON_USSD() {
   let [typeCode, message] = Buf.readStringList();
   if (DEBUG) {
     debug("On USSD. Type Code: " + typeCode + " Message: " + message);
   }
 
-  this._ussdSession = (typeCode != "0" || typeCode != "2");
-
-  // Empty message should not be progressed to the DOM.
-  if (!message || message == "") {
-    return;
-  }
+  this._ussdSession = (typeCode != "0" && typeCode != "2");
+
   this.sendDOMMessage({rilMessageType: "USSDReceived",
-                       message: message});
+                       message: message,
+                       sessionEnded: !this._ussdSession});
 };
 RIL[UNSOLICITED_NITZ_TIME_RECEIVED] = function UNSOLICITED_NITZ_TIME_RECEIVED() {
   let dateString = Buf.readString();
 
   // The data contained in the NITZ message is
   // in the form "yy/mm/dd,hh:mm:ss(+/-)tz,dt"
   // for example: 12/02/16,03:36:08-20,00,310410
 
new file mode 100644
--- /dev/null
+++ b/dom/webidl/USSDReceivedEvent.webidl
@@ -0,0 +1,10 @@
+/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* 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/.
+ */
+
+dictionary USSDReceivedEventDict {
+  DOMString message = "";
+  boolean sessionEnded = false;
+};
\ No newline at end of file
--- a/dom/webidl/WebIDL.mk
+++ b/dom/webidl/WebIDL.mk
@@ -48,16 +48,22 @@ webidl_files = \
   $(NULL)
 
 ifdef MOZ_WEBGL
 webidl_files += \
   WebGLRenderingContext.webidl \
   $(NULL)
 endif
 
+ifdef MOZ_B2G_RIL
+webidl_files += \
+  USSDReceivedEvent.webidl \
+  $(NULL)
+endif
+
 ifdef ENABLE_TESTS
 test_webidl_files := \
   TestCodeGen.webidl \
   TestDictionary.webidl \
   TestTypedef.webidl \
   $(NULL)
 else
 test_webidl_files := $(NULL)