Skip to content

Commit

Permalink
Wrap USSDSession object in the promise solver
Browse files Browse the repository at this point in the history
  • Loading branch information
bchabod committed Aug 28, 2015
1 parent 54b1341 commit 8bf12ad
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 5 deletions.
30 changes: 29 additions & 1 deletion dom/telephony/TelephonyDialCallback.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "TelephonyDialCallback.h"

#include "mozilla/dom/USSDSession.h"
#include "mozilla/dom/MozMobileConnectionBinding.h"
#include "nsIMobileCallForwardingOptions.h"
#include "nsIMobileConnectionService.h"
Expand Down Expand Up @@ -102,6 +102,34 @@ TelephonyDialCallback::NotifyDialMMISuccessWithInteger(const nsAString& aStatusM
return NotifyDialMMISuccess(cx, result);
}

NS_IMETHODIMP
TelephonyDialCallback::NotifyDialMMISuccessWithSession(const nsAString& aStatusMessage, uint32_t aServiceId)
{
AutoJSAPI jsapi;
if (NS_WARN_IF(!jsapi.Init(mWindow))) {
return NS_ERROR_FAILURE;
}

JSContext* cx = jsapi.cx();

RootedDictionary<MozMMIResult> result(cx);
result.mSuccess = true;
result.mServiceCode.Assign(mServiceCode);
result.mStatusMessage.Assign(aStatusMessage);

nsCOMPtr<nsITelephonyService> service = do_GetService(TELEPHONY_SERVICE_CONTRACTID);
nsRefPtr<USSDSession> session = new USSDSession(mWindow, service, aServiceId);

JS::Rooted<JS::Value> jsAdditionalInformation(cx);
if (!ToJSValue(cx, session, &jsAdditionalInformation)) {
JS_ClearPendingException(cx);
return NS_ERROR_TYPE_ERR;
}

result.mAdditionalInformation.Construct().SetAsObject() = &jsAdditionalInformation.toObject();
return NotifyDialMMISuccess(cx, result);
}

NS_IMETHODIMP
TelephonyDialCallback::NotifyDialMMISuccessWithStrings(const nsAString& aStatusMessage,
uint32_t aCount,
Expand Down
12 changes: 8 additions & 4 deletions dom/telephony/gonk/TelephonyService.js
Original file line number Diff line number Diff line change
Expand Up @@ -1689,11 +1689,15 @@ TelephonyService.prototype = {
}
},

_defaultMMICallbackHandler: function(aCallback, aResponse) {
_defaultMMICallbackHandler: function(aCallback, aResponse, aClientId, aSessionEnded) {
if (aResponse && aResponse.errorMsg) {
aCallback.notifyDialMMIError(aResponse.errorMsg);
} else {
aCallback.notifyDialMMISuccess(aResponse);
if (aSessionEnded) {
aCallback.notifyDialMMISuccessWithSession(aResponse, aClientId);
} else {
aCallback.notifyDialMMISuccess(aResponse);
}
}
},

Expand Down Expand Up @@ -2430,7 +2434,7 @@ TelephonyService.prototype = {
this._notifyAllListeners("conferenceCallStateChanged", [aState]);
},

notifyUssdReceived: function(aClientId, aMessage, aSessionEnded) {
notifyUssdReceived: function(aClientId, aMessage, aSessionEnded) {g
if (DEBUG) {
debug("notifyUssdReceived for " + aClientId + ": " +
aMessage + " (sessionEnded : " + aSessionEnded + ")");
Expand All @@ -2445,7 +2449,7 @@ TelephonyService.prototype = {

// If there is a callback registered, call it
if (this._ussdCallbacks[aClientId]) {
this._ussdCallbacks[aClientId](aMessage);
this._ussdCallbacks[aClientId](aMessage, aClientId, aSessionEnded);
this._ussdCallbacks[aClientId] = null;
} else {
gTelephonyMessenger.notifyUssdReceived(aClientId, aMessage, aSessionEnded);
Expand Down
3 changes: 3 additions & 0 deletions dom/telephony/ipc/TelephonyChild.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,9 @@ TelephonyRequestChild::DoResponse(const DialResponseMMISuccess& aResponse)
case AdditionalInformation::Tvoid_t:
callback->NotifyDialMMISuccess(statusMessage);
break;
case AdditionalInformation::Tuint32_t:
callback->NotifyDialMMISuccessWithSession(statusMessage, info.get_uint32_t());
break;
case AdditionalInformation::Tuint16_t:
callback->NotifyDialMMISuccessWithInteger(statusMessage, info.get_uint16_t());
break;
Expand Down
8 changes: 8 additions & 0 deletions dom/telephony/ipc/TelephonyParent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,14 @@ TelephonyRequestParent::DialCallback::NotifyDialMMISuccess(const nsAString& aSta
AdditionalInformation(mozilla::void_t())));
}

NS_IMETHODIMP
TelephonyRequestParent::DialCallback::NotifyDialMMISuccessWithSession(const nsAString& aStatusMessage,
uint32_t aAdditionalInformation)
{
return SendResponse(DialResponseMMISuccess(nsAutoString(aStatusMessage),
AdditionalInformation(aAdditionalInformation)));
}

NS_IMETHODIMP
TelephonyRequestParent::DialCallback::NotifyDialMMISuccessWithInteger(const nsAString& aStatusMessage,
uint16_t aAdditionalInformation)
Expand Down
1 change: 1 addition & 0 deletions dom/telephony/ipc/TelephonyTypes.ipdlh
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ struct IPCCdmaWaitingCallData
union AdditionalInformation {
void_t;
uint16_t;
uint32_t;
nsString[];
nsMobileCallForwardingOptions[];
};
Expand Down
1 change: 1 addition & 0 deletions dom/telephony/nsITelephonyService.idl
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ interface nsITelephonyDialCallback : nsITelephonyCallback
void notifyDialMMISuccess(in AString statusMessage);
void notifyDialMMISuccessWithInteger(in AString statusMessage,
in unsigned short aAdditionalInformation);
void notifyDialMMISuccessWithSession(in AString statusMessage, in unsigned long aAdditionalInformation);
void notifyDialMMISuccessWithStrings(in AString statusMessage,
in unsigned long aLength,
[array, size_is(aLength)] in wstring aAdditionalInformation);
Expand Down

0 comments on commit 8bf12ad

Please sign in to comment.