mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-29 15:52:07 +00:00
Bug 1047196 - Part 2: Avoid the use of 'jsval' in interfaces (dom). f=echen, r=smaug
This commit is contained in:
parent
d2bc712fe4
commit
7fe1bc112c
72
dom/mobileconnection/MobileCallForwardingOptions.cpp
Normal file
72
dom/mobileconnection/MobileCallForwardingOptions.cpp
Normal file
@ -0,0 +1,72 @@
|
||||
/* 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 "mozilla/dom/mobileconnection/MobileCallForwardingOptions.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
namespace mobileconnection {
|
||||
|
||||
NS_IMPL_ISUPPORTS(MobileCallForwardingOptions, nsIMobileCallForwardingOptions)
|
||||
|
||||
MobileCallForwardingOptions::MobileCallForwardingOptions(bool aActive,
|
||||
int16_t aAction,
|
||||
int16_t aReason,
|
||||
const nsAString& aNumber,
|
||||
int16_t aTimeSeconds,
|
||||
int16_t aServiceClass)
|
||||
: mActive(aActive)
|
||||
, mAction(aAction)
|
||||
, mReason(aReason)
|
||||
, mNumber(aNumber)
|
||||
, mTimeSeconds(aTimeSeconds)
|
||||
, mServiceClass(aServiceClass)
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
MobileCallForwardingOptions::GetActive(bool* aActive)
|
||||
{
|
||||
*aActive = mActive;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
MobileCallForwardingOptions::GetAction(int16_t* aAction)
|
||||
{
|
||||
*aAction = mAction;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
MobileCallForwardingOptions::GetReason(int16_t* aReason)
|
||||
{
|
||||
*aReason = mReason;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
MobileCallForwardingOptions::GetNumber(nsAString& aNumber)
|
||||
{
|
||||
aNumber = mNumber;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
MobileCallForwardingOptions::GetTimeSeconds(int16_t* aTimeSeconds)
|
||||
{
|
||||
*aTimeSeconds = mTimeSeconds;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
MobileCallForwardingOptions::GetServiceClass(int16_t *aServiceClass)
|
||||
{
|
||||
*aServiceClass = mServiceClass;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
} // namespace mobileconnection
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
44
dom/mobileconnection/MobileCallForwardingOptions.h
Normal file
44
dom/mobileconnection/MobileCallForwardingOptions.h
Normal file
@ -0,0 +1,44 @@
|
||||
/* 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/. */
|
||||
|
||||
#ifndef mozilla_dom_MobileCallForwardingOptions_h
|
||||
#define mozilla_dom_MobileCallForwardingOptions_h
|
||||
|
||||
#include "nsIMobileCallForwardingOptions.h"
|
||||
#include "nsString.h"
|
||||
#include "mozilla/Attributes.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
namespace mobileconnection {
|
||||
|
||||
class MobileCallForwardingOptions MOZ_FINAL : public nsIMobileCallForwardingOptions
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIMOBILECALLFORWARDINGOPTIONS
|
||||
|
||||
MobileCallForwardingOptions(bool aActive, int16_t aAction,
|
||||
int16_t aReason, const nsAString& aNumber,
|
||||
int16_t aTimeSeconds, int16_t aServiceClass);
|
||||
|
||||
private:
|
||||
// Don't try to use the default constructor.
|
||||
MobileCallForwardingOptions() {}
|
||||
|
||||
~MobileCallForwardingOptions() {}
|
||||
|
||||
bool mActive;
|
||||
int16_t mAction;
|
||||
int16_t mReason;
|
||||
nsString mNumber;
|
||||
int16_t mTimeSeconds;
|
||||
int16_t mServiceClass;
|
||||
};
|
||||
|
||||
} // namespace mobileconnection
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
||||
#endif // mozilla_dom_MobileCallForwardingOptions_h
|
@ -21,6 +21,9 @@
|
||||
#include "nsJSUtils.h"
|
||||
#include "nsServiceManagerUtils.h"
|
||||
|
||||
#define MOBILECONN_ERROR_INVALID_PARAMETER NS_LITERAL_STRING("InvalidParameter")
|
||||
#define MOBILECONN_ERROR_INVALID_PASSWORD NS_LITERAL_STRING("InvalidPassword")
|
||||
|
||||
#ifdef CONVERT_STRING_TO_NULLABLE_ENUM
|
||||
#undef CONVERT_STRING_TO_NULLABLE_ENUM
|
||||
#endif
|
||||
@ -206,6 +209,84 @@ MobileConnection::UpdateData()
|
||||
mData->Update(info);
|
||||
}
|
||||
|
||||
nsresult
|
||||
MobileConnection::NotifyError(nsIDOMDOMRequest* aRequest, const nsAString& aMessage)
|
||||
{
|
||||
nsCOMPtr<nsIDOMRequestService> rs = do_GetService(DOMREQUEST_SERVICE_CONTRACTID);
|
||||
NS_ENSURE_TRUE(rs, NS_ERROR_FAILURE);
|
||||
|
||||
return rs->FireErrorAsync(aRequest, aMessage);
|
||||
}
|
||||
|
||||
bool
|
||||
MobileConnection::IsValidPassword(const nsAString& aPassword)
|
||||
{
|
||||
// Check valid PIN for supplementary services. See TS.22.004 clause 5.2.
|
||||
if (aPassword.IsEmpty() || aPassword.Length() != 4) {
|
||||
return false;
|
||||
}
|
||||
|
||||
nsresult rv;
|
||||
int32_t password = nsString(aPassword).ToInteger(&rv);
|
||||
return NS_SUCCEEDED(rv) && password >= 0 && password <= 9999;
|
||||
}
|
||||
|
||||
bool
|
||||
MobileConnection::IsValidCallForwardingReason(int32_t aReason)
|
||||
{
|
||||
return aReason >= nsIMobileConnection::CALL_FORWARD_REASON_UNCONDITIONAL &&
|
||||
aReason <= nsIMobileConnection::CALL_FORWARD_REASON_ALL_CONDITIONAL_CALL_FORWARDING;
|
||||
}
|
||||
|
||||
bool
|
||||
MobileConnection::IsValidCallForwardingAction(int32_t aAction)
|
||||
{
|
||||
return aAction >= nsIMobileConnection::CALL_FORWARD_ACTION_DISABLE &&
|
||||
aAction <= nsIMobileConnection::CALL_FORWARD_ACTION_ERASURE &&
|
||||
// Set operation doesn't allow "query" action.
|
||||
aAction != nsIMobileConnection::CALL_FORWARD_ACTION_QUERY_STATUS;
|
||||
}
|
||||
|
||||
bool
|
||||
MobileConnection::IsValidCallBarringProgram(int32_t aProgram)
|
||||
{
|
||||
return aProgram >= nsIMobileConnection::CALL_BARRING_PROGRAM_ALL_OUTGOING &&
|
||||
aProgram <= nsIMobileConnection::CALL_BARRING_PROGRAM_INCOMING_ROAMING;
|
||||
}
|
||||
|
||||
bool
|
||||
MobileConnection::IsValidCallBarringOptions(const MozCallBarringOptions& aOptions,
|
||||
bool isSetting)
|
||||
{
|
||||
if (!aOptions.mServiceClass.WasPassed() || aOptions.mServiceClass.Value().IsNull() ||
|
||||
!aOptions.mProgram.WasPassed() || aOptions.mProgram.Value().IsNull() ||
|
||||
!IsValidCallBarringProgram(aOptions.mProgram.Value().Value())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// For setting callbarring options, |enabled| and |password| are required.
|
||||
if (isSetting &&
|
||||
(!aOptions.mEnabled.WasPassed() || aOptions.mEnabled.Value().IsNull() ||
|
||||
!aOptions.mPassword.WasPassed() || aOptions.mPassword.Value().IsVoid())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
MobileConnection::IsValidCallForwardingOptions(const MozCallForwardingOptions& aOptions)
|
||||
{
|
||||
if (!aOptions.mReason.WasPassed() || aOptions.mReason.Value().IsNull() ||
|
||||
!aOptions.mAction.WasPassed() || aOptions.mAction.Value().IsNull() ||
|
||||
!IsValidCallForwardingReason(aOptions.mReason.Value().Value()) ||
|
||||
!IsValidCallForwardingAction(aOptions.mAction.Value().Value())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// WebIDL interface
|
||||
|
||||
void
|
||||
@ -568,6 +649,16 @@ MobileConnection::GetCallForwardingOption(uint16_t aReason, ErrorResult& aRv)
|
||||
}
|
||||
|
||||
nsRefPtr<DOMRequest> request = new DOMRequest(GetOwner());
|
||||
|
||||
if (!IsValidCallForwardingReason(aReason)) {
|
||||
nsresult rv = NotifyError(request, MOBILECONN_ERROR_INVALID_PARAMETER);
|
||||
if (NS_FAILED(rv)) {
|
||||
aRv.Throw(rv);
|
||||
return nullptr;
|
||||
}
|
||||
return request.forget();
|
||||
}
|
||||
|
||||
nsRefPtr<MobileConnectionCallback> requestCallback =
|
||||
new MobileConnectionCallback(GetOwner(), request);
|
||||
|
||||
@ -589,24 +680,42 @@ MobileConnection::SetCallForwardingOption(const MozCallForwardingOptions& aOptio
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
AutoJSAPI jsapi;
|
||||
if (!NS_WARN_IF(jsapi.Init(GetOwner()))) {
|
||||
aRv.Throw(NS_ERROR_FAILURE);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
JSContext *cx = jsapi.cx();
|
||||
JS::Rooted<JS::Value> options(cx);
|
||||
if (!ToJSValue(cx, aOptions, &options)) {
|
||||
aRv.Throw(NS_ERROR_TYPE_ERR);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
nsRefPtr<DOMRequest> request = new DOMRequest(GetOwner());
|
||||
|
||||
if (!IsValidCallForwardingOptions(aOptions)) {
|
||||
nsresult rv = NotifyError(request, MOBILECONN_ERROR_INVALID_PARAMETER);
|
||||
if (NS_FAILED(rv)) {
|
||||
aRv.Throw(rv);
|
||||
return nullptr;
|
||||
}
|
||||
return request.forget();
|
||||
}
|
||||
|
||||
// Fill in optional attributes.
|
||||
uint16_t timeSeconds = 0;
|
||||
if (aOptions.mTimeSeconds.WasPassed() && !aOptions.mTimeSeconds.Value().IsNull()) {
|
||||
timeSeconds = aOptions.mTimeSeconds.Value().Value();
|
||||
}
|
||||
uint16_t serviceClass = nsIMobileConnection::ICC_SERVICE_CLASS_NONE;
|
||||
if (aOptions.mServiceClass.WasPassed() && !aOptions.mServiceClass.Value().IsNull()) {
|
||||
serviceClass = aOptions.mServiceClass.Value().Value();
|
||||
}
|
||||
nsAutoString number;
|
||||
if (aOptions.mNumber.WasPassed()) {
|
||||
number = aOptions.mNumber.Value();
|
||||
} else {
|
||||
number.SetIsVoid(true);
|
||||
}
|
||||
|
||||
nsRefPtr<MobileConnectionCallback> requestCallback =
|
||||
new MobileConnectionCallback(GetOwner(), request);
|
||||
|
||||
nsresult rv = mMobileConnection->SetCallForwarding(options, requestCallback);
|
||||
nsresult rv = mMobileConnection->SetCallForwarding(aOptions.mAction.Value().Value(),
|
||||
aOptions.mReason.Value().Value(),
|
||||
number,
|
||||
timeSeconds,
|
||||
serviceClass,
|
||||
requestCallback);
|
||||
if (NS_FAILED(rv)) {
|
||||
aRv.Throw(rv);
|
||||
return nullptr;
|
||||
@ -624,24 +733,32 @@ MobileConnection::GetCallBarringOption(const MozCallBarringOptions& aOptions,
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
AutoJSAPI jsapi;
|
||||
if (!NS_WARN_IF(jsapi.Init(GetOwner()))) {
|
||||
aRv.Throw(NS_ERROR_FAILURE);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
JSContext *cx = jsapi.cx();
|
||||
JS::Rooted<JS::Value> options(cx);
|
||||
if (!ToJSValue(cx, aOptions, &options)) {
|
||||
aRv.Throw(NS_ERROR_TYPE_ERR);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
nsRefPtr<DOMRequest> request = new DOMRequest(GetOwner());
|
||||
|
||||
if (!IsValidCallBarringOptions(aOptions, false)) {
|
||||
nsresult rv = NotifyError(request, MOBILECONN_ERROR_INVALID_PARAMETER);
|
||||
if (NS_FAILED(rv)) {
|
||||
aRv.Throw(rv);
|
||||
return nullptr;
|
||||
}
|
||||
return request.forget();
|
||||
}
|
||||
|
||||
// Fill in optional attributes.
|
||||
nsAutoString password;
|
||||
if (aOptions.mPassword.WasPassed()) {
|
||||
password = aOptions.mPassword.Value();
|
||||
} else {
|
||||
password.SetIsVoid(true);
|
||||
}
|
||||
|
||||
nsRefPtr<MobileConnectionCallback> requestCallback =
|
||||
new MobileConnectionCallback(GetOwner(), request);
|
||||
|
||||
nsresult rv = mMobileConnection->GetCallBarring(options, requestCallback);
|
||||
nsresult rv = mMobileConnection->GetCallBarring(aOptions.mProgram.Value().Value(),
|
||||
password,
|
||||
aOptions.mServiceClass.Value().Value(),
|
||||
requestCallback);
|
||||
if (NS_FAILED(rv)) {
|
||||
aRv.Throw(rv);
|
||||
return nullptr;
|
||||
@ -659,24 +776,25 @@ MobileConnection::SetCallBarringOption(const MozCallBarringOptions& aOptions,
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
AutoJSAPI jsapi;
|
||||
if (!NS_WARN_IF(jsapi.Init(GetOwner()))) {
|
||||
aRv.Throw(NS_ERROR_FAILURE);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
JSContext *cx = jsapi.cx();
|
||||
JS::Rooted<JS::Value> options(cx);
|
||||
if (!ToJSValue(cx, aOptions, &options)) {
|
||||
aRv.Throw(NS_ERROR_TYPE_ERR);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
nsRefPtr<DOMRequest> request = new DOMRequest(GetOwner());
|
||||
|
||||
if (!IsValidCallBarringOptions(aOptions, true)) {
|
||||
nsresult rv = NotifyError(request, MOBILECONN_ERROR_INVALID_PARAMETER);
|
||||
if (NS_FAILED(rv)) {
|
||||
aRv.Throw(rv);
|
||||
return nullptr;
|
||||
}
|
||||
return request.forget();
|
||||
}
|
||||
|
||||
nsRefPtr<MobileConnectionCallback> requestCallback =
|
||||
new MobileConnectionCallback(GetOwner(), request);
|
||||
|
||||
nsresult rv = mMobileConnection->SetCallBarring(options, requestCallback);
|
||||
nsresult rv = mMobileConnection->SetCallBarring(aOptions.mProgram.Value().Value(),
|
||||
aOptions.mEnabled.Value().Value(),
|
||||
aOptions.mPassword.Value(),
|
||||
aOptions.mServiceClass.Value().Value(),
|
||||
requestCallback);
|
||||
if (NS_FAILED(rv)) {
|
||||
aRv.Throw(rv);
|
||||
return nullptr;
|
||||
@ -694,25 +812,27 @@ MobileConnection::ChangeCallBarringPassword(const MozCallBarringOptions& aOption
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
AutoJSAPI jsapi;
|
||||
if (!NS_WARN_IF(jsapi.Init(GetOwner()))) {
|
||||
aRv.Throw(NS_ERROR_FAILURE);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
JSContext *cx = jsapi.cx();
|
||||
JS::Rooted<JS::Value> options(cx);
|
||||
if (!ToJSValue(cx, aOptions, &options)) {
|
||||
aRv.Throw(NS_ERROR_TYPE_ERR);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
nsRefPtr<DOMRequest> request = new DOMRequest(GetOwner());
|
||||
|
||||
if (!aOptions.mPin.WasPassed() || aOptions.mPin.Value().IsVoid() ||
|
||||
!aOptions.mNewPin.WasPassed() || aOptions.mNewPin.Value().IsVoid() ||
|
||||
!IsValidPassword(aOptions.mPin.Value()) ||
|
||||
!IsValidPassword(aOptions.mNewPin.Value())) {
|
||||
nsresult rv = NotifyError(request, MOBILECONN_ERROR_INVALID_PASSWORD);
|
||||
if (NS_FAILED(rv)) {
|
||||
aRv.Throw(rv);
|
||||
return nullptr;
|
||||
}
|
||||
return request.forget();
|
||||
}
|
||||
|
||||
nsRefPtr<MobileConnectionCallback> requestCallback =
|
||||
new MobileConnectionCallback(GetOwner(), request);
|
||||
|
||||
nsresult rv =
|
||||
mMobileConnection->ChangeCallBarringPassword(options, requestCallback);
|
||||
mMobileConnection->ChangeCallBarringPassword(aOptions.mPin.Value(),
|
||||
aOptions.mNewPin.Value(),
|
||||
requestCallback);
|
||||
if (NS_FAILED(rv)) {
|
||||
aRv.Throw(rv);
|
||||
return nullptr;
|
||||
|
@ -176,6 +176,27 @@ private:
|
||||
|
||||
void
|
||||
UpdateData();
|
||||
|
||||
nsresult
|
||||
NotifyError(nsIDOMDOMRequest* aRequest, const nsAString& aMessage);
|
||||
|
||||
bool
|
||||
IsValidPassword(const nsAString& aPassword);
|
||||
|
||||
bool
|
||||
IsValidCallBarringOptions(const MozCallBarringOptions& aOptions, bool isSetting);
|
||||
|
||||
bool
|
||||
IsValidCallForwardingOptions(const MozCallForwardingOptions& aOptions);
|
||||
|
||||
bool
|
||||
IsValidCallForwardingReason(int32_t aReason);
|
||||
|
||||
bool
|
||||
IsValidCallForwardingAction(int32_t aAction);
|
||||
|
||||
bool
|
||||
IsValidCallBarringProgram(int32_t aProgram);
|
||||
};
|
||||
|
||||
} // namespace dom
|
||||
|
@ -27,94 +27,6 @@ MobileConnectionCallback::MobileConnectionCallback(nsPIDOMWindow* aWindow,
|
||||
/**
|
||||
* Notify Success for Send/CancelMmi.
|
||||
*/
|
||||
nsresult
|
||||
MobileConnectionCallback::NotifySendCancelMmiSuccess(const nsAString& aServiceCode,
|
||||
const nsAString& aStatusMessage)
|
||||
{
|
||||
MozMMIResult result;
|
||||
result.mServiceCode.Assign(aServiceCode);
|
||||
result.mStatusMessage.Assign(aStatusMessage);
|
||||
|
||||
return NotifySendCancelMmiSuccess(result);
|
||||
}
|
||||
|
||||
nsresult
|
||||
MobileConnectionCallback::NotifySendCancelMmiSuccess(const nsAString& aServiceCode,
|
||||
const nsAString& aStatusMessage,
|
||||
JS::Handle<JS::Value> aAdditionalInformation)
|
||||
{
|
||||
AutoJSAPI jsapi;
|
||||
if (!NS_WARN_IF(jsapi.Init(mWindow))) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
JSContext* cx = jsapi.cx();
|
||||
RootedDictionary<MozMMIResult> result(cx);
|
||||
|
||||
result.mServiceCode.Assign(aServiceCode);
|
||||
result.mStatusMessage.Assign(aStatusMessage);
|
||||
result.mAdditionalInformation.Construct().SetAsObject() = &aAdditionalInformation.toObject();
|
||||
|
||||
return NotifySendCancelMmiSuccess(result);
|
||||
}
|
||||
|
||||
nsresult
|
||||
MobileConnectionCallback::NotifySendCancelMmiSuccess(const nsAString& aServiceCode,
|
||||
const nsAString& aStatusMessage,
|
||||
uint16_t aAdditionalInformation)
|
||||
{
|
||||
MozMMIResult result;
|
||||
result.mServiceCode.Assign(aServiceCode);
|
||||
result.mStatusMessage.Assign(aStatusMessage);
|
||||
result.mAdditionalInformation.Construct().SetAsUnsignedShort() = aAdditionalInformation;
|
||||
|
||||
return NotifySendCancelMmiSuccess(result);
|
||||
}
|
||||
|
||||
nsresult
|
||||
MobileConnectionCallback::NotifySendCancelMmiSuccess(const nsAString& aServiceCode,
|
||||
const nsAString& aStatusMessage,
|
||||
const nsTArray<nsString>& aAdditionalInformation)
|
||||
{
|
||||
AutoJSAPI jsapi;
|
||||
if (!NS_WARN_IF(jsapi.Init(mWindow))) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
JSContext* cx = jsapi.cx();
|
||||
JS::Rooted<JS::Value> additionalInformation(cx);
|
||||
|
||||
if (!ToJSValue(cx, aAdditionalInformation, &additionalInformation)) {
|
||||
JS_ClearPendingException(cx);
|
||||
return NS_ERROR_TYPE_ERR;
|
||||
}
|
||||
|
||||
return NotifySendCancelMmiSuccess(aServiceCode, aStatusMessage,
|
||||
additionalInformation);
|
||||
}
|
||||
|
||||
nsresult
|
||||
MobileConnectionCallback::NotifySendCancelMmiSuccess(const nsAString& aServiceCode,
|
||||
const nsAString& aStatusMessage,
|
||||
const nsTArray<IPC::MozCallForwardingOptions>& aAdditionalInformation)
|
||||
{
|
||||
AutoJSAPI jsapi;
|
||||
if (!NS_WARN_IF(jsapi.Init(mWindow))) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
JSContext* cx = jsapi.cx();
|
||||
JS::Rooted<JS::Value> additionalInformation(cx);
|
||||
|
||||
if (!ToJSValue(cx, aAdditionalInformation, &additionalInformation)) {
|
||||
JS_ClearPendingException(cx);
|
||||
return NS_ERROR_TYPE_ERR;
|
||||
}
|
||||
|
||||
return NotifySendCancelMmiSuccess(aServiceCode, aStatusMessage,
|
||||
additionalInformation);
|
||||
}
|
||||
|
||||
nsresult
|
||||
MobileConnectionCallback::NotifySendCancelMmiSuccess(const MozMMIResult& aResult)
|
||||
{
|
||||
@ -134,28 +46,6 @@ MobileConnectionCallback::NotifySendCancelMmiSuccess(const MozMMIResult& aResult
|
||||
return NotifySuccess(jsResult);
|
||||
}
|
||||
|
||||
/**
|
||||
* Notify Success for GetCallForwarding.
|
||||
*/
|
||||
nsresult
|
||||
MobileConnectionCallback::NotifyGetCallForwardingSuccess(const nsTArray<IPC::MozCallForwardingOptions>& aResults)
|
||||
{
|
||||
AutoJSAPI jsapi;
|
||||
if (!NS_WARN_IF(jsapi.Init(mWindow))) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
JSContext* cx = jsapi.cx();
|
||||
JS::Rooted<JS::Value> jsResult(cx);
|
||||
|
||||
if (!ToJSValue(cx, aResults, &jsResult)) {
|
||||
JS_ClearPendingException(cx);
|
||||
return NS_ERROR_TYPE_ERR;
|
||||
}
|
||||
|
||||
return NotifySuccess(jsResult);
|
||||
}
|
||||
|
||||
/**
|
||||
* Notify Success.
|
||||
*/
|
||||
@ -230,18 +120,186 @@ MobileConnectionCallback::NotifyGetNetworksSuccess(uint32_t aCount,
|
||||
return NotifySuccess(jsResult);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
MobileConnectionCallback::NotifySendCancelMmiSuccess(JS::Handle<JS::Value> aResult,
|
||||
JSContext* aCx)
|
||||
nsresult
|
||||
MobileConnectionCallback::NotifySendCancelMmiSuccess(const nsAString& aServiceCode,
|
||||
const nsAString& aStatusMessage)
|
||||
{
|
||||
return NotifySuccess(aResult);
|
||||
MozMMIResult result;
|
||||
result.mServiceCode.Assign(aServiceCode);
|
||||
result.mStatusMessage.Assign(aStatusMessage);
|
||||
|
||||
return NotifySendCancelMmiSuccess(result);
|
||||
}
|
||||
|
||||
nsresult
|
||||
MobileConnectionCallback::NotifySendCancelMmiSuccessWithInteger(const nsAString& aServiceCode,
|
||||
const nsAString& aStatusMessage,
|
||||
uint16_t aAdditionalInformation)
|
||||
{
|
||||
MozMMIResult result;
|
||||
result.mServiceCode.Assign(aServiceCode);
|
||||
result.mStatusMessage.Assign(aStatusMessage);
|
||||
result.mAdditionalInformation.Construct().SetAsUnsignedShort() = aAdditionalInformation;
|
||||
|
||||
return NotifySendCancelMmiSuccess(result);
|
||||
}
|
||||
|
||||
nsresult
|
||||
MobileConnectionCallback::NotifySendCancelMmiSuccessWithStrings(const nsAString& aServiceCode,
|
||||
const nsAString& aStatusMessage,
|
||||
uint32_t aCount,
|
||||
const char16_t** aAdditionalInformation)
|
||||
{
|
||||
AutoJSAPI jsapi;
|
||||
if (!NS_WARN_IF(jsapi.Init(mWindow))) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
JSContext* cx = jsapi.cx();
|
||||
RootedDictionary<MozMMIResult> result(cx);
|
||||
|
||||
result.mServiceCode.Assign(aServiceCode);
|
||||
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 NotifySendCancelMmiSuccess(result);
|
||||
}
|
||||
|
||||
nsresult
|
||||
MobileConnectionCallback::NotifySendCancelMmiSuccessWithCallForwardingOptions(
|
||||
const nsAString& aServiceCode,
|
||||
const nsAString& aStatusMessage,
|
||||
uint32_t aCount,
|
||||
nsIMobileCallForwardingOptions** aResults)
|
||||
{
|
||||
AutoJSAPI jsapi;
|
||||
if (!NS_WARN_IF(jsapi.Init(mWindow))) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
JSContext* cx = jsapi.cx();
|
||||
RootedDictionary<MozMMIResult> result(cx);
|
||||
|
||||
result.mServiceCode.Assign(aServiceCode);
|
||||
result.mStatusMessage.Assign(aStatusMessage);
|
||||
|
||||
nsTArray<MozCallForwardingOptions> additionalInformation;
|
||||
for (uint32_t i = 0; i < aCount; i++)
|
||||
{
|
||||
MozCallForwardingOptions options;
|
||||
int16_t pShort;
|
||||
nsString pString;
|
||||
bool pBool;
|
||||
|
||||
aResults[i]->GetActive(&pBool);
|
||||
options.mActive.Construct(pBool);
|
||||
|
||||
aResults[i]->GetAction(&pShort);
|
||||
if (pShort != nsIMobileConnection::CALL_FORWARD_ACTION_UNKNOWN) {
|
||||
options.mAction.Construct(pShort);
|
||||
}
|
||||
|
||||
aResults[i]->GetReason(&pShort);
|
||||
if (pShort != nsIMobileConnection::CALL_FORWARD_REASON_UNKNOWN) {
|
||||
options.mReason.Construct(pShort);
|
||||
}
|
||||
|
||||
aResults[i]->GetNumber(pString);
|
||||
options.mNumber.Construct(pString.get());
|
||||
|
||||
aResults[i]->GetTimeSeconds(&pShort);
|
||||
if (pShort >= 0) {
|
||||
options.mTimeSeconds.Construct(pShort);
|
||||
}
|
||||
|
||||
aResults[i]->GetServiceClass(&pShort);
|
||||
if (pShort != nsIMobileConnection::ICC_SERVICE_CLASS_NONE) {
|
||||
options.mServiceClass.Construct(pShort);
|
||||
}
|
||||
|
||||
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 NotifySendCancelMmiSuccess(result);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
MobileConnectionCallback::NotifyGetCallForwardingSuccess(JS::Handle<JS::Value> aResults,
|
||||
JSContext* aCx)
|
||||
MobileConnectionCallback::NotifyGetCallForwardingSuccess(uint32_t aCount,
|
||||
nsIMobileCallForwardingOptions** aResults)
|
||||
{
|
||||
return NotifySuccess(aResults);
|
||||
nsTArray<MozCallForwardingOptions> results;
|
||||
for (uint32_t i = 0; i < aCount; i++)
|
||||
{
|
||||
MozCallForwardingOptions result;
|
||||
int16_t pShort;
|
||||
nsString pString;
|
||||
bool pBool;
|
||||
|
||||
aResults[i]->GetActive(&pBool);
|
||||
result.mActive.Construct(pBool);
|
||||
|
||||
aResults[i]->GetAction(&pShort);
|
||||
if (pShort != nsIMobileConnection::CALL_FORWARD_ACTION_UNKNOWN) {
|
||||
result.mAction.Construct(pShort);
|
||||
}
|
||||
|
||||
aResults[i]->GetReason(&pShort);
|
||||
if (pShort != nsIMobileConnection::CALL_FORWARD_REASON_UNKNOWN) {
|
||||
result.mReason.Construct(pShort);
|
||||
}
|
||||
|
||||
aResults[i]->GetNumber(pString);
|
||||
result.mNumber.Construct(pString.get());
|
||||
|
||||
aResults[i]->GetTimeSeconds(&pShort);
|
||||
if (pShort >= 0) {
|
||||
result.mTimeSeconds.Construct(pShort);
|
||||
}
|
||||
|
||||
aResults[i]->GetServiceClass(&pShort);
|
||||
if (pShort != nsIMobileConnection::ICC_SERVICE_CLASS_NONE) {
|
||||
result.mServiceClass.Construct(pShort);
|
||||
}
|
||||
|
||||
results.AppendElement(result);
|
||||
}
|
||||
|
||||
AutoJSAPI jsapi;
|
||||
if (!NS_WARN_IF(jsapi.Init(mWindow))) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
JSContext* cx = jsapi.cx();
|
||||
JS::Rooted<JS::Value> jsResult(cx);
|
||||
|
||||
if (!ToJSValue(cx, results, &jsResult)) {
|
||||
JS_ClearPendingException(cx);
|
||||
return NS_ERROR_TYPE_ERR;
|
||||
}
|
||||
|
||||
return NotifySuccess(jsResult);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
@ -32,43 +32,15 @@ public:
|
||||
|
||||
MobileConnectionCallback(nsPIDOMWindow* aWindow, DOMRequest* aRequest);
|
||||
|
||||
/**
|
||||
* Notify Success for Send/CancelMmi.
|
||||
*/
|
||||
nsresult
|
||||
NotifySendCancelMmiSuccess(const nsAString& aServiceCode,
|
||||
const nsAString& aStatusMessage);
|
||||
nsresult
|
||||
NotifySendCancelMmiSuccess(const nsAString& aServiceCode,
|
||||
const nsAString& aStatusMessage,
|
||||
JS::Handle<JS::Value> aAdditionalInformation);
|
||||
nsresult
|
||||
NotifySendCancelMmiSuccess(const nsAString& aServiceCode,
|
||||
const nsAString& aStatusMessage,
|
||||
uint16_t aAdditionalInformation);
|
||||
nsresult
|
||||
NotifySendCancelMmiSuccess(const nsAString& aServiceCode,
|
||||
const nsAString& aStatusMessage,
|
||||
const nsTArray<nsString>& aAdditionalInformation);
|
||||
nsresult
|
||||
NotifySendCancelMmiSuccess(const nsAString& aServiceCode,
|
||||
const nsAString& aStatusMessage,
|
||||
const nsTArray<IPC::MozCallForwardingOptions>& aAdditionalInformation);
|
||||
nsresult
|
||||
NotifySendCancelMmiSuccess(const MozMMIResult& aResult);
|
||||
|
||||
/**
|
||||
* Notify Success for GetCallForwarding.
|
||||
*/
|
||||
nsresult
|
||||
NotifyGetCallForwardingSuccess(const nsTArray<IPC::MozCallForwardingOptions>& aResults);
|
||||
|
||||
private:
|
||||
~MobileConnectionCallback() {}
|
||||
|
||||
nsresult
|
||||
NotifySuccess(JS::Handle<JS::Value> aResult);
|
||||
|
||||
nsresult
|
||||
NotifySendCancelMmiSuccess(const MozMMIResult& aResult);
|
||||
|
||||
nsCOMPtr<nsPIDOMWindow> mWindow;
|
||||
nsRefPtr<DOMRequest> mRequest;
|
||||
};
|
||||
|
@ -19,6 +19,7 @@ EXPORTS.mozilla.dom.mobileconnection += [
|
||||
'ipc/MobileConnectionChild.h',
|
||||
'ipc/MobileConnectionIPCSerializer.h',
|
||||
'ipc/MobileConnectionParent.h',
|
||||
'MobileCallForwardingOptions.h',
|
||||
]
|
||||
|
||||
XPIDL_SOURCES += [
|
||||
@ -36,6 +37,7 @@ UNIFIED_SOURCES += [
|
||||
'ipc/MobileConnectionChild.cpp',
|
||||
'ipc/MobileConnectionIPCService.cpp',
|
||||
'ipc/MobileConnectionParent.cpp',
|
||||
'MobileCallForwardingOptions.cpp',
|
||||
'MobileCellInfo.cpp',
|
||||
'MobileConnection.cpp',
|
||||
'MobileConnectionArray.cpp',
|
||||
|
Loading…
Reference in New Issue
Block a user