Bug 794011 - Add 'sessionEnded' to nsIDOMUSSDReceivedEvent. r=mounir

This commit is contained in:
Guillermo López 2012-10-17 12:17:19 +01:00
parent ffe77a0c82
commit 40ab2b91fe
8 changed files with 44 additions and 16 deletions

View File

@ -4,8 +4,9 @@
#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;
};

View File

@ -19,6 +19,8 @@
#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")
@ -157,13 +159,15 @@ MobileConnection::Observe(nsISupports* aSubject,
}
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;
}

View File

@ -14,13 +14,14 @@ 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();
}
@ -40,6 +41,13 @@ USSDReceivedEvent::GetMessage(nsAString& aMessage)
return NS_OK;
}
/* [infallible] */ NS_IMETHODIMP
USSDReceivedEvent::GetSessionEnded(bool* aSessionEnded)
{
*aSessionEnded = mSessionEnded;
return NS_OK;
}
}
}
}

View File

@ -16,6 +16,7 @@ class USSDReceivedEvent : public nsDOMEvent,
public nsIDOMUSSDReceivedEvent
{
nsString mMessage;
bool mSessionEnded;
public:
NS_DECL_ISUPPORTS_INHERITED
@ -23,7 +24,7 @@ public:
NS_DECL_NSIDOMUSSDRECEIVEDEVENT
static already_AddRefed<USSDReceivedEvent>
Create(nsAString& aMessage);
Create(nsAString& aMessage, bool aSessionEnded);
nsresult
Dispatch(nsIDOMEventTarget* aTarget, const nsAString& aEventType)

View File

@ -710,8 +710,9 @@ RILContentHelper.prototype = {
}
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":

View File

@ -4845,14 +4845,11 @@ RIL[UNSOLICITED_ON_USSD] = function UNSOLICITED_ON_USSD() {
debug("On USSD. Type Code: " + typeCode + " Message: " + message);
}
this._ussdSession = (typeCode != "0" || typeCode != "2");
this._ussdSession = (typeCode != "0" && typeCode != "2");
// Empty message should not be progressed to the DOM.
if (!message || message == "") {
return;
}
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();

View File

@ -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;
};

View File

@ -61,6 +61,12 @@ webidl_files += \
$(NULL)
endif
ifdef MOZ_B2G_RIL
webidl_files += \
USSDReceivedEvent.webidl \
$(NULL)
endif
ifdef ENABLE_TESTS
test_webidl_files := \
TestCodeGen.webidl \