mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 889737 - Part 07: Dial MMI (callback). r=vicamo
This commit is contained in:
parent
3f09af694e
commit
f3772f7cb2
@ -236,7 +236,7 @@ Telephony::DialInternal(uint32_t aServiceId, const nsAString& aNumber,
|
||||
}
|
||||
|
||||
nsCOMPtr<nsITelephonyCallback> callback =
|
||||
new TelephonyCallback(this, promise, aServiceId);
|
||||
new TelephonyCallback(GetOwner(), this, promise, aServiceId);
|
||||
|
||||
nsresult rv = mService->Dial(aServiceId, aNumber, aEmergency, callback);
|
||||
if (NS_FAILED(rv)) {
|
||||
|
@ -4,24 +4,82 @@
|
||||
|
||||
#include "TelephonyCallback.h"
|
||||
|
||||
#include "mozilla/dom/Promise.h"
|
||||
#include "Telephony.h"
|
||||
#include "mozilla/dom/DOMMMIError.h"
|
||||
#include "nsServiceManagerUtils.h"
|
||||
|
||||
using namespace mozilla::dom;
|
||||
using namespace mozilla::dom::telephony;
|
||||
|
||||
NS_IMPL_ISUPPORTS(TelephonyCallback, nsITelephonyCallback)
|
||||
|
||||
TelephonyCallback::TelephonyCallback(Telephony* aTelephony,
|
||||
TelephonyCallback::TelephonyCallback(nsPIDOMWindow* aWindow,
|
||||
Telephony* aTelephony,
|
||||
Promise* aPromise,
|
||||
uint32_t aServiceId)
|
||||
: mTelephony(aTelephony), mPromise(aPromise), mServiceId(aServiceId)
|
||||
: mWindow(aWindow), mTelephony(aTelephony), mPromise(aPromise),
|
||||
mServiceId(aServiceId)
|
||||
{
|
||||
MOZ_ASSERT(mTelephony);
|
||||
}
|
||||
|
||||
nsresult
|
||||
TelephonyCallback::NotifyDialMMISuccess(const nsAString& aStatusMessage)
|
||||
{
|
||||
AutoJSAPI jsapi;
|
||||
if (!NS_WARN_IF(jsapi.Init(mWindow))) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
JSContext* cx = jsapi.cx();
|
||||
|
||||
MozMMIResult result;
|
||||
|
||||
result.mServiceCode.Assign(mServiceCode);
|
||||
result.mStatusMessage.Assign(aStatusMessage);
|
||||
|
||||
return NotifyDialMMISuccess(cx, result);
|
||||
}
|
||||
|
||||
nsresult
|
||||
TelephonyCallback::NotifyDialMMISuccess(JSContext* aCx,
|
||||
const nsAString& aStatusMessage,
|
||||
JS::Handle<JS::Value> aInfo)
|
||||
{
|
||||
RootedDictionary<MozMMIResult> result(aCx);
|
||||
|
||||
result.mServiceCode.Assign(mServiceCode);
|
||||
result.mStatusMessage.Assign(aStatusMessage);
|
||||
result.mAdditionalInformation.Construct().SetAsObject() = &aInfo.toObject();
|
||||
|
||||
return NotifyDialMMISuccess(aCx, result);
|
||||
}
|
||||
|
||||
nsresult
|
||||
TelephonyCallback::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;
|
||||
}
|
||||
|
||||
return NotifyDialMMISuccess(jsResult);
|
||||
}
|
||||
|
||||
// nsITelephonyCallback
|
||||
|
||||
NS_IMETHODIMP
|
||||
TelephonyCallback::NotifyDialMMI(const nsAString& aServiceCode)
|
||||
{
|
||||
mMMIRequest = new DOMRequest(mWindow);
|
||||
mServiceCode.Assign(aServiceCode);
|
||||
|
||||
mPromise->MaybeResolve(mMMIRequest);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
TelephonyCallback::NotifyDialError(const nsAString& aError)
|
||||
{
|
||||
@ -41,3 +99,41 @@ TelephonyCallback::NotifyDialCallSuccess(uint32_t aCallIndex,
|
||||
mPromise->MaybeResolve(call);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
TelephonyCallback::NotifyDialMMISuccess(JS::Handle<JS::Value> aResult)
|
||||
{
|
||||
nsCOMPtr<nsIDOMRequestService> rs = do_GetService(DOMREQUEST_SERVICE_CONTRACTID);
|
||||
NS_ENSURE_TRUE(rs, NS_ERROR_FAILURE);
|
||||
|
||||
return rs->FireSuccessAsync(mMMIRequest, aResult);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
TelephonyCallback::NotifyDialMMIError(const nsAString& aError)
|
||||
{
|
||||
Nullable<int16_t> info;
|
||||
|
||||
nsRefPtr<DOMError> error =
|
||||
new DOMMMIError(mWindow, aError, EmptyString(), mServiceCode, info);
|
||||
|
||||
nsCOMPtr<nsIDOMRequestService> rs = do_GetService(DOMREQUEST_SERVICE_CONTRACTID);
|
||||
NS_ENSURE_TRUE(rs, NS_ERROR_FAILURE);
|
||||
|
||||
return rs->FireDetailedError(mMMIRequest, error);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
TelephonyCallback::NotifyDialMMIErrorWithInfo(const nsAString& aError,
|
||||
uint16_t aInfo)
|
||||
{
|
||||
Nullable<int16_t> info(aInfo);
|
||||
|
||||
nsRefPtr<DOMError> error =
|
||||
new DOMMMIError(mWindow, aError, EmptyString(), mServiceCode, info);
|
||||
|
||||
nsCOMPtr<nsIDOMRequestService> rs = do_GetService(DOMREQUEST_SERVICE_CONTRACTID);
|
||||
NS_ENSURE_TRUE(rs, NS_ERROR_FAILURE);
|
||||
|
||||
return rs->FireDetailedError(mMMIRequest, error);
|
||||
}
|
||||
|
@ -5,15 +5,21 @@
|
||||
#ifndef mozilla_dom_TelephonyCallback_h
|
||||
#define mozilla_dom_TelephonyCallback_h
|
||||
|
||||
#include "Telephony.h"
|
||||
#include "mozilla/dom/DOMRequest.h"
|
||||
#include "mozilla/dom/MozMobileConnectionBinding.h"
|
||||
#include "mozilla/dom/Promise.h"
|
||||
#include "mozilla/dom/ToJSValue.h"
|
||||
#include "nsAutoPtr.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsITelephonyService.h"
|
||||
#include "nsJSUtils.h"
|
||||
#include "nsString.h"
|
||||
|
||||
class nsPIDOMWindow;
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
class Promise;
|
||||
class Telephony;
|
||||
|
||||
namespace telephony {
|
||||
|
||||
class TelephonyCallback MOZ_FINAL : public nsITelephonyCallback
|
||||
@ -22,15 +28,50 @@ public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSITELEPHONYCALLBACK
|
||||
|
||||
TelephonyCallback(Telephony* aTelephony, Promise* aPromise,
|
||||
uint32_t aServiceId);
|
||||
TelephonyCallback(nsPIDOMWindow* aWindow, Telephony* aTelephony,
|
||||
Promise* aPromise, uint32_t aServiceId);
|
||||
|
||||
nsresult
|
||||
NotifyDialMMISuccess(const nsAString& aStatusMessage);
|
||||
|
||||
template<typename T>
|
||||
nsresult
|
||||
NotifyDialMMISuccess(const nsAString& aStatusMessage, const T& aInfo)
|
||||
{
|
||||
AutoJSAPI jsapi;
|
||||
if (!NS_WARN_IF(jsapi.Init(mWindow))) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
JSContext* cx = jsapi.cx();
|
||||
JS::Rooted<JS::Value> info(cx);
|
||||
|
||||
if (!ToJSValue(cx, aInfo, &info)) {
|
||||
JS_ClearPendingException(cx);
|
||||
return NS_ERROR_TYPE_ERR;
|
||||
}
|
||||
|
||||
return NotifyDialMMISuccess(cx, aStatusMessage, info);
|
||||
}
|
||||
|
||||
private:
|
||||
~TelephonyCallback() {}
|
||||
|
||||
nsresult
|
||||
NotifyDialMMISuccess(JSContext* aCx, const nsAString& aStatusMessage,
|
||||
JS::Handle<JS::Value> aInfo);
|
||||
|
||||
nsresult
|
||||
NotifyDialMMISuccess(JSContext* aCx, const MozMMIResult& aResult);
|
||||
|
||||
|
||||
nsCOMPtr<nsPIDOMWindow> mWindow;
|
||||
nsRefPtr<Telephony> mTelephony;
|
||||
nsRefPtr<Promise> mPromise;
|
||||
uint32_t mServiceId;
|
||||
|
||||
nsRefPtr<DOMRequest> mMMIRequest;
|
||||
nsString mServiceCode;
|
||||
};
|
||||
|
||||
} // namespace telephony
|
||||
|
@ -21,6 +21,7 @@ EXPORTS.mozilla.dom += [
|
||||
EXPORTS.mozilla.dom.telephony += [
|
||||
'ipc/TelephonyChild.h',
|
||||
'ipc/TelephonyParent.h',
|
||||
'TelephonyCallback.h',
|
||||
'TelephonyCommon.h',
|
||||
]
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user