2014-10-14 23:50:00 -07:00
|
|
|
/* 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 "TelephonyDialCallback.h"
|
|
|
|
|
2014-11-05 18:20:51 -08:00
|
|
|
#include "mozilla/dom/MozMobileConnectionBinding.h"
|
|
|
|
#include "nsIMobileCallForwardingOptions.h"
|
|
|
|
#include "nsIMobileConnectionService.h"
|
2014-10-14 23:50:00 -07:00
|
|
|
|
|
|
|
using namespace mozilla::dom;
|
|
|
|
using namespace mozilla::dom::telephony;
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS_INHERITED(TelephonyDialCallback, TelephonyCallback,
|
|
|
|
nsITelephonyDialCallback)
|
|
|
|
|
|
|
|
TelephonyDialCallback::TelephonyDialCallback(nsPIDOMWindow* aWindow,
|
|
|
|
Telephony* aTelephony,
|
|
|
|
Promise* aPromise,
|
|
|
|
uint32_t aServiceId)
|
|
|
|
: TelephonyCallback(aPromise), mWindow(aWindow), mTelephony(aTelephony),
|
|
|
|
mServiceId(aServiceId)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mTelephony);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
TelephonyDialCallback::NotifyDialMMISuccess(JSContext* aCx,
|
|
|
|
const MozMMIResult& aResult)
|
|
|
|
{
|
|
|
|
JS::Rooted<JS::Value> jsResult(aCx);
|
|
|
|
|
|
|
|
if (!ToJSValue(aCx, aResult, &jsResult)) {
|
|
|
|
JS_ClearPendingException(aCx);
|
|
|
|
return NS_ERROR_TYPE_ERR;
|
|
|
|
}
|
|
|
|
|
2014-11-11 01:15:31 -08:00
|
|
|
mMMICall->NotifyResult(jsResult);
|
|
|
|
return NS_OK;
|
2014-10-14 23:50:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// nsITelephonyDialCallback
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
TelephonyDialCallback::NotifyDialMMI(const nsAString& aServiceCode)
|
|
|
|
{
|
|
|
|
mServiceCode.Assign(aServiceCode);
|
|
|
|
|
2014-11-11 01:15:31 -08:00
|
|
|
mMMICall = new MMICall(mWindow, aServiceCode);
|
|
|
|
mPromise->MaybeResolve(mMMICall);
|
2014-10-14 23:50:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
TelephonyDialCallback::NotifyDialCallSuccess(uint32_t aCallIndex,
|
|
|
|
const nsAString& aNumber)
|
|
|
|
{
|
|
|
|
nsRefPtr<TelephonyCallId> id = mTelephony->CreateCallId(aNumber);
|
|
|
|
nsRefPtr<TelephonyCall> call =
|
|
|
|
mTelephony->CreateCall(id, mServiceId, aCallIndex,
|
|
|
|
nsITelephonyService::CALL_STATE_DIALING);
|
|
|
|
|
|
|
|
mPromise->MaybeResolve(call);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-11-05 18:20:51 -08:00
|
|
|
TelephonyDialCallback::NotifyDialMMISuccess(const nsAString& aStatusMessage)
|
2014-10-14 23:50:00 -07:00
|
|
|
{
|
2014-11-05 18:20:51 -08:00
|
|
|
AutoJSAPI jsapi;
|
2014-11-06 20:56:00 -08:00
|
|
|
if (NS_WARN_IF(!jsapi.Init(mWindow))) {
|
2014-11-05 18:20:51 -08:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2014-10-14 23:50:00 -07:00
|
|
|
|
2014-11-05 18:20:51 -08:00
|
|
|
JSContext* cx = jsapi.cx();
|
|
|
|
|
|
|
|
MozMMIResult result;
|
2014-11-11 01:15:31 -08:00
|
|
|
result.mSuccess = true;
|
2014-11-05 18:20:51 -08:00
|
|
|
result.mServiceCode.Assign(mServiceCode);
|
|
|
|
result.mStatusMessage.Assign(aStatusMessage);
|
|
|
|
|
|
|
|
return NotifyDialMMISuccess(cx, result);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
TelephonyDialCallback::NotifyDialMMISuccessWithInteger(const nsAString& aStatusMessage,
|
|
|
|
uint16_t aAdditionalInformation)
|
|
|
|
{
|
|
|
|
AutoJSAPI jsapi;
|
2014-11-06 20:56:00 -08:00
|
|
|
if (NS_WARN_IF(!jsapi.Init(mWindow))) {
|
2014-11-05 18:20:51 -08:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
JSContext* cx = jsapi.cx();
|
|
|
|
|
|
|
|
MozMMIResult result;
|
2014-11-11 01:15:31 -08:00
|
|
|
result.mSuccess = true;
|
2014-11-05 18:20:51 -08:00
|
|
|
result.mServiceCode.Assign(mServiceCode);
|
|
|
|
result.mStatusMessage.Assign(aStatusMessage);
|
|
|
|
result.mAdditionalInformation.Construct().SetAsUnsignedShort() = aAdditionalInformation;
|
|
|
|
|
|
|
|
return NotifyDialMMISuccess(cx, result);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
TelephonyDialCallback::NotifyDialMMISuccessWithStrings(const nsAString& aStatusMessage,
|
|
|
|
uint32_t aCount,
|
|
|
|
const char16_t** aAdditionalInformation)
|
|
|
|
{
|
|
|
|
AutoJSAPI jsapi;
|
2014-11-06 20:56:00 -08:00
|
|
|
if (NS_WARN_IF(!jsapi.Init(mWindow))) {
|
2014-11-05 18:20:51 -08:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
JSContext* cx = jsapi.cx();
|
|
|
|
|
|
|
|
RootedDictionary<MozMMIResult> result(cx);
|
2014-11-11 01:15:31 -08:00
|
|
|
result.mSuccess = true;
|
2014-11-05 18:20:51 -08:00
|
|
|
result.mServiceCode.Assign(mServiceCode);
|
|
|
|
result.mStatusMessage.Assign(aStatusMessage);
|
|
|
|
|
|
|
|
nsTArray<nsString> additionalInformation;
|
|
|
|
for (uint32_t i = 0; i < aCount; i++) {
|
|
|
|
additionalInformation.AppendElement(nsDependentString(aAdditionalInformation[i]));
|
|
|
|
}
|
|
|
|
|
|
|
|
JS::Rooted<JS::Value> jsAdditionalInformation(cx);
|
|
|
|
if (!ToJSValue(cx, additionalInformation, &jsAdditionalInformation)) {
|
|
|
|
JS_ClearPendingException(cx);
|
|
|
|
return NS_ERROR_TYPE_ERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
result.mAdditionalInformation.Construct().SetAsObject() =
|
|
|
|
&jsAdditionalInformation.toObject();
|
|
|
|
|
|
|
|
return NotifyDialMMISuccess(cx, result);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
TelephonyDialCallback::NotifyDialMMISuccessWithCallForwardingOptions(const nsAString& aStatusMessage,
|
|
|
|
uint32_t aCount,
|
|
|
|
nsIMobileCallForwardingOptions** aResults)
|
|
|
|
{
|
|
|
|
AutoJSAPI jsapi;
|
2014-11-06 20:56:00 -08:00
|
|
|
if (NS_WARN_IF(!jsapi.Init(mWindow))) {
|
2014-11-05 18:20:51 -08:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
JSContext* cx = jsapi.cx();
|
|
|
|
|
|
|
|
RootedDictionary<MozMMIResult> result(cx);
|
2014-11-11 01:15:31 -08:00
|
|
|
result.mSuccess = true;
|
2014-11-05 18:20:51 -08:00
|
|
|
result.mServiceCode.Assign(mServiceCode);
|
|
|
|
result.mStatusMessage.Assign(aStatusMessage);
|
|
|
|
|
|
|
|
nsTArray<MozCallForwardingOptions> additionalInformation;
|
|
|
|
for (uint32_t i = 0; i < aCount; i++) {
|
|
|
|
MozCallForwardingOptions options;
|
|
|
|
|
|
|
|
bool active = false;
|
|
|
|
aResults[i]->GetActive(&active);
|
|
|
|
options.mActive.Construct(active);
|
|
|
|
|
|
|
|
int16_t action = nsIMobileConnection::CALL_FORWARD_ACTION_UNKNOWN;
|
|
|
|
aResults[i]->GetAction(&action);
|
|
|
|
if (action != nsIMobileConnection::CALL_FORWARD_ACTION_UNKNOWN) {
|
|
|
|
options.mAction.Construct(action);
|
|
|
|
}
|
|
|
|
|
|
|
|
int16_t reason = nsIMobileConnection::CALL_FORWARD_REASON_UNKNOWN;
|
|
|
|
aResults[i]->GetReason(&reason);
|
|
|
|
if (reason != nsIMobileConnection::CALL_FORWARD_REASON_UNKNOWN) {
|
|
|
|
options.mReason.Construct(reason);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoString number;
|
|
|
|
aResults[i]->GetNumber(number);
|
|
|
|
options.mNumber.Construct(number.get());
|
|
|
|
|
|
|
|
int16_t timeSeconds = -1;
|
|
|
|
aResults[i]->GetTimeSeconds(&timeSeconds);
|
|
|
|
if (timeSeconds >= 0) {
|
|
|
|
options.mTimeSeconds.Construct(timeSeconds);
|
|
|
|
}
|
|
|
|
|
|
|
|
int16_t serviceClass = nsIMobileConnection::ICC_SERVICE_CLASS_NONE;
|
|
|
|
aResults[i]->GetServiceClass(&serviceClass);
|
|
|
|
if (serviceClass != nsIMobileConnection::ICC_SERVICE_CLASS_NONE) {
|
|
|
|
options.mServiceClass.Construct(serviceClass);
|
|
|
|
}
|
|
|
|
|
|
|
|
additionalInformation.AppendElement(options);
|
|
|
|
}
|
|
|
|
|
|
|
|
JS::Rooted<JS::Value> jsAdditionalInformation(cx);
|
|
|
|
if (!ToJSValue(cx, additionalInformation, &jsAdditionalInformation)) {
|
|
|
|
JS_ClearPendingException(cx);
|
|
|
|
return NS_ERROR_TYPE_ERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
result.mAdditionalInformation.Construct().SetAsObject() =
|
|
|
|
&jsAdditionalInformation.toObject();
|
|
|
|
|
|
|
|
return NotifyDialMMISuccess(cx, result);
|
2014-10-14 23:50:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
TelephonyDialCallback::NotifyDialMMIError(const nsAString& aError)
|
|
|
|
{
|
2014-11-11 01:15:31 -08:00
|
|
|
AutoJSAPI jsapi;
|
|
|
|
if (NS_WARN_IF(!jsapi.Init(mWindow))) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2014-10-14 23:50:00 -07:00
|
|
|
|
2014-11-11 01:15:31 -08:00
|
|
|
JSContext* cx = jsapi.cx();
|
2014-10-14 23:50:00 -07:00
|
|
|
|
2014-11-11 01:15:31 -08:00
|
|
|
MozMMIResult result;
|
|
|
|
result.mSuccess = false;
|
|
|
|
result.mServiceCode.Assign(mServiceCode);
|
|
|
|
result.mStatusMessage.Assign(aError);
|
2014-10-14 23:50:00 -07:00
|
|
|
|
2014-11-11 01:15:31 -08:00
|
|
|
return NotifyDialMMISuccess(cx, result);
|
2014-10-14 23:50:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
TelephonyDialCallback::NotifyDialMMIErrorWithInfo(const nsAString& aError,
|
|
|
|
uint16_t aInfo)
|
|
|
|
{
|
2014-11-11 01:15:31 -08:00
|
|
|
AutoJSAPI jsapi;
|
|
|
|
if (NS_WARN_IF(!jsapi.Init(mWindow))) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2014-10-14 23:50:00 -07:00
|
|
|
|
2014-11-11 01:15:31 -08:00
|
|
|
JSContext* cx = jsapi.cx();
|
2014-10-14 23:50:00 -07:00
|
|
|
|
2014-11-11 01:15:31 -08:00
|
|
|
MozMMIResult result;
|
|
|
|
result.mSuccess = false;
|
|
|
|
result.mServiceCode.Assign(mServiceCode);
|
|
|
|
result.mStatusMessage.Assign(aError);
|
|
|
|
result.mAdditionalInformation.Construct().SetAsUnsignedShort() = aInfo;
|
2014-10-14 23:50:00 -07:00
|
|
|
|
2014-11-11 01:15:31 -08:00
|
|
|
return NotifyDialMMISuccess(cx, result);
|
2014-10-14 23:50:00 -07:00
|
|
|
}
|