2015-05-03 19:32:37 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 11:12:37 +00: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/. */
|
2012-01-09 22:28:47 +00:00
|
|
|
|
|
|
|
#include "TelephonyCall.h"
|
2014-06-11 01:23:34 +00:00
|
|
|
#include "mozilla/dom/CallEvent.h"
|
2013-07-15 08:27:19 +00:00
|
|
|
#include "mozilla/dom/TelephonyCallBinding.h"
|
2015-01-04 22:33:00 +00:00
|
|
|
#include "mozilla/dom/telephony/TelephonyCallback.h"
|
2012-01-09 22:28:47 +00:00
|
|
|
|
2013-05-18 17:52:06 +00:00
|
|
|
#include "mozilla/dom/DOMError.h"
|
2015-01-28 04:01:00 +00:00
|
|
|
#include "nsPrintfCString.h"
|
2013-07-15 08:27:19 +00:00
|
|
|
|
2013-01-28 07:39:50 +00:00
|
|
|
#include "Telephony.h"
|
2013-07-06 10:24:55 +00:00
|
|
|
#include "TelephonyCallGroup.h"
|
2012-01-09 22:28:47 +00:00
|
|
|
|
2015-03-26 08:39:39 +00:00
|
|
|
#ifdef CONVERT_STRING_TO_NULLABLE_ENUM
|
|
|
|
#undef CONVERT_STRING_TO_NULLABLE_ENUM
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define CONVERT_STRING_TO_NULLABLE_ENUM(_string, _enumType, _enum) \
|
|
|
|
{ \
|
|
|
|
_enum.SetNull(); \
|
|
|
|
\
|
|
|
|
uint32_t i = 0; \
|
|
|
|
for (const EnumEntry* entry = _enumType##Values::strings; \
|
|
|
|
entry->value; \
|
|
|
|
++entry, ++i) { \
|
|
|
|
if (_string.EqualsASCII(entry->value)) { \
|
|
|
|
_enum.SetValue(static_cast<_enumType>(i)); \
|
|
|
|
break; \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
|
2015-10-06 17:11:00 +00:00
|
|
|
#ifdef TELEPHONY_CALL_STATE
|
|
|
|
#undef TELEPHONY_CALL_STATE
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define TELEPHONY_CALL_STATE(_state) \
|
|
|
|
(TelephonyCallStateValues::strings[static_cast<int32_t>(_state)].value)
|
|
|
|
|
2013-07-15 08:27:19 +00:00
|
|
|
using namespace mozilla::dom;
|
2015-01-04 22:33:00 +00:00
|
|
|
using namespace mozilla::dom::telephony;
|
2013-09-07 06:19:53 +00:00
|
|
|
using mozilla::ErrorResult;
|
2012-01-09 22:28:47 +00:00
|
|
|
|
2015-10-06 17:11:00 +00:00
|
|
|
// static
|
|
|
|
TelephonyCallState
|
|
|
|
TelephonyCall::ConvertToTelephonyCallState(uint32_t aCallState)
|
|
|
|
{
|
|
|
|
switch (aCallState) {
|
|
|
|
case nsITelephonyService::CALL_STATE_DIALING:
|
|
|
|
return TelephonyCallState::Dialing;
|
|
|
|
case nsITelephonyService::CALL_STATE_ALERTING:
|
|
|
|
return TelephonyCallState::Alerting;
|
|
|
|
case nsITelephonyService::CALL_STATE_CONNECTED:
|
|
|
|
return TelephonyCallState::Connected;
|
|
|
|
case nsITelephonyService::CALL_STATE_HELD:
|
|
|
|
return TelephonyCallState::Held;
|
|
|
|
case nsITelephonyService::CALL_STATE_DISCONNECTED:
|
|
|
|
return TelephonyCallState::Disconnected;
|
|
|
|
case nsITelephonyService::CALL_STATE_INCOMING:
|
|
|
|
return TelephonyCallState::Incoming;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_NOTREACHED("Unknown state!");
|
|
|
|
return TelephonyCallState::Disconnected;
|
|
|
|
}
|
|
|
|
|
2012-01-09 22:28:47 +00:00
|
|
|
// static
|
|
|
|
already_AddRefed<TelephonyCall>
|
2015-10-06 17:11:00 +00:00
|
|
|
TelephonyCall::Create(Telephony* aTelephony,
|
|
|
|
TelephonyCallId* aId,
|
|
|
|
uint32_t aServiceId,
|
|
|
|
uint32_t aCallIndex,
|
|
|
|
TelephonyCallState aState,
|
|
|
|
bool aEmergency,
|
|
|
|
bool aConference,
|
|
|
|
bool aSwitchable,
|
|
|
|
bool aMergeable)
|
2012-01-09 22:28:47 +00:00
|
|
|
{
|
2014-06-24 10:52:00 +00:00
|
|
|
NS_ASSERTION(aTelephony, "Null aTelephony pointer!");
|
|
|
|
NS_ASSERTION(aId, "Null aId pointer!");
|
2012-01-09 22:28:47 +00:00
|
|
|
NS_ASSERTION(aCallIndex >= 1, "Invalid call index!");
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<TelephonyCall> call = new TelephonyCall(aTelephony->GetOwner());
|
2012-03-13 22:11:16 +00:00
|
|
|
|
2012-01-09 22:28:47 +00:00
|
|
|
call->mTelephony = aTelephony;
|
2014-06-24 10:52:00 +00:00
|
|
|
call->mId = aId;
|
2013-10-31 12:05:51 +00:00
|
|
|
call->mServiceId = aServiceId;
|
2012-01-09 22:28:47 +00:00
|
|
|
call->mCallIndex = aCallIndex;
|
2013-05-14 06:08:07 +00:00
|
|
|
call->mEmergency = aEmergency;
|
2014-06-24 10:52:00 +00:00
|
|
|
call->mGroup = aConference ? aTelephony->ConferenceGroup() : nullptr;
|
2014-02-21 09:52:13 +00:00
|
|
|
call->mSwitchable = aSwitchable;
|
|
|
|
call->mMergeable = aMergeable;
|
2014-06-24 10:52:00 +00:00
|
|
|
call->mError = nullptr;
|
2012-01-09 22:28:47 +00:00
|
|
|
|
2015-10-06 17:11:00 +00:00
|
|
|
call->ChangeStateInternal(aState, false);
|
2012-01-09 22:28:47 +00:00
|
|
|
return call.forget();
|
|
|
|
}
|
|
|
|
|
2014-01-07 02:53:23 +00:00
|
|
|
TelephonyCall::TelephonyCall(nsPIDOMWindow* aOwner)
|
2014-04-01 06:13:50 +00:00
|
|
|
: DOMEventTargetHelper(aOwner),
|
2014-01-29 06:27:22 +00:00
|
|
|
mLive(false)
|
2013-03-06 09:53:23 +00:00
|
|
|
{
|
2013-07-15 08:27:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TelephonyCall::~TelephonyCall()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
JSObject*
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 14:13:33 +00:00
|
|
|
TelephonyCall::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
2013-07-15 08:27:19 +00:00
|
|
|
{
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 14:13:33 +00:00
|
|
|
return TelephonyCallBinding::Wrap(aCx, this, aGivenProto);
|
2013-03-06 09:53:23 +00:00
|
|
|
}
|
|
|
|
|
2012-01-09 22:28:47 +00:00
|
|
|
void
|
2015-10-06 17:11:00 +00:00
|
|
|
TelephonyCall::ChangeStateInternal(TelephonyCallState aState, bool aFireEvents)
|
2012-01-09 22:28:47 +00:00
|
|
|
{
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<TelephonyCall> kungFuDeathGrip(this);
|
2012-01-09 22:28:47 +00:00
|
|
|
|
2015-10-06 17:11:00 +00:00
|
|
|
// Update current state
|
|
|
|
mState = aState;
|
2012-01-09 22:28:47 +00:00
|
|
|
|
2015-10-06 17:11:00 +00:00
|
|
|
// Handle disconnected calls
|
|
|
|
if (mState == TelephonyCallState::Disconnected) {
|
2012-01-09 22:28:47 +00:00
|
|
|
NS_ASSERTION(mLive, "Should be live!");
|
2014-04-04 12:18:49 +00:00
|
|
|
mLive = false;
|
2013-07-06 10:24:55 +00:00
|
|
|
if (mGroup) {
|
|
|
|
mGroup->RemoveCall(this);
|
|
|
|
} else {
|
|
|
|
mTelephony->RemoveCall(this);
|
|
|
|
}
|
2015-10-06 17:11:00 +00:00
|
|
|
} else if (!mLive) { // Handle newly added calls
|
2014-04-04 12:18:49 +00:00
|
|
|
mLive = true;
|
2013-07-06 10:24:55 +00:00
|
|
|
if (mGroup) {
|
|
|
|
mGroup->AddCall(this);
|
|
|
|
} else {
|
|
|
|
mTelephony->AddCall(this);
|
|
|
|
}
|
2012-01-09 22:28:47 +00:00
|
|
|
}
|
|
|
|
|
2015-10-06 17:11:00 +00:00
|
|
|
// Dispatch call state changed and call state event
|
2015-05-06 07:58:00 +00:00
|
|
|
if (aFireEvents) {
|
2015-10-06 17:11:00 +00:00
|
|
|
NotifyStateChanged();
|
|
|
|
}
|
|
|
|
}
|
2012-01-09 22:28:47 +00:00
|
|
|
|
2015-10-06 17:11:00 +00:00
|
|
|
nsresult
|
|
|
|
TelephonyCall::NotifyStateChanged()
|
|
|
|
{
|
|
|
|
// Since |mState| can be changed after statechange handler called back here,
|
|
|
|
// we must save current state. Maybe we should figure out something smarter.
|
|
|
|
TelephonyCallState prevState = mState;
|
|
|
|
|
|
|
|
nsresult res = DispatchCallEvent(NS_LITERAL_STRING("statechange"), this);
|
|
|
|
if (NS_FAILED(res)) {
|
|
|
|
NS_WARNING("Failed to dispatch specific event!");
|
2012-01-09 22:28:47 +00:00
|
|
|
}
|
2015-10-06 17:11:00 +00:00
|
|
|
|
|
|
|
// Check whether |mState| remains the same after the statechange handler.
|
|
|
|
if (mState != prevState) {
|
|
|
|
NS_WARNING("Call State has changed by statechange handler!");
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
res = DispatchCallEvent(NS_ConvertASCIItoUTF16(TELEPHONY_CALL_STATE(mState)),
|
|
|
|
this);
|
|
|
|
if (NS_FAILED(res)) {
|
|
|
|
NS_WARNING("Failed to dispatch a specific event!");
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
2012-01-09 22:28:47 +00:00
|
|
|
}
|
|
|
|
|
2013-01-28 07:39:50 +00:00
|
|
|
nsresult
|
|
|
|
TelephonyCall::DispatchCallEvent(const nsAString& aType,
|
2013-07-15 08:27:19 +00:00
|
|
|
TelephonyCall* aCall)
|
2013-01-28 07:39:50 +00:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(aCall);
|
|
|
|
|
2014-06-11 01:23:34 +00:00
|
|
|
CallEventInit init;
|
|
|
|
init.mBubbles = false;
|
|
|
|
init.mCancelable = false;
|
|
|
|
init.mCall = aCall;
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<CallEvent> event = CallEvent::Constructor(this, aType, init);
|
2013-01-28 07:39:50 +00:00
|
|
|
|
2013-07-15 08:27:19 +00:00
|
|
|
return DispatchTrustedEvent(event);
|
2013-01-28 07:39:50 +00:00
|
|
|
}
|
|
|
|
|
2015-01-28 04:01:00 +00:00
|
|
|
already_AddRefed<Promise>
|
|
|
|
TelephonyCall::CreatePromise(ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(GetOwner());
|
|
|
|
if (!global) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<Promise> promise = Promise::Create(global, aRv);
|
2015-01-28 04:01:00 +00:00
|
|
|
if (aRv.Failed()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return promise.forget();
|
|
|
|
}
|
|
|
|
|
2012-05-15 04:13:06 +00:00
|
|
|
void
|
|
|
|
TelephonyCall::NotifyError(const nsAString& aError)
|
|
|
|
{
|
2012-05-15 04:13:06 +00:00
|
|
|
// Set the error string
|
|
|
|
NS_ASSERTION(!mError, "Already have an error?");
|
|
|
|
|
2013-09-12 03:47:14 +00:00
|
|
|
mError = new DOMError(GetOwner(), aError);
|
2012-05-15 04:13:06 +00:00
|
|
|
|
2013-01-28 07:39:50 +00:00
|
|
|
nsresult rv = DispatchCallEvent(NS_LITERAL_STRING("error"), this);
|
|
|
|
if (NS_FAILED(rv)) {
|
2012-05-15 04:13:06 +00:00
|
|
|
NS_WARNING("Failed to dispatch error event!");
|
|
|
|
}
|
2012-05-15 04:13:06 +00:00
|
|
|
}
|
|
|
|
|
2015-03-26 08:39:39 +00:00
|
|
|
void
|
|
|
|
TelephonyCall::UpdateDisconnectedReason(const nsAString& aDisconnectedReason)
|
|
|
|
{
|
2015-04-28 03:28:00 +00:00
|
|
|
NS_ASSERTION(Substring(aDisconnectedReason,
|
|
|
|
aDisconnectedReason.Length() - 5).EqualsLiteral("Error"),
|
2015-03-26 08:39:39 +00:00
|
|
|
"Disconnected reason should end with 'Error'");
|
|
|
|
|
2015-04-28 03:28:00 +00:00
|
|
|
if (!mDisconnectedReason.IsNull()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// There is no 'Error' suffix in the corresponding enum. We should skip
|
|
|
|
// that part for comparison.
|
|
|
|
CONVERT_STRING_TO_NULLABLE_ENUM(
|
|
|
|
Substring(aDisconnectedReason, 0, aDisconnectedReason.Length() - 5),
|
|
|
|
TelephonyCallDisconnectedReason,
|
|
|
|
mDisconnectedReason);
|
|
|
|
|
|
|
|
if (!aDisconnectedReason.EqualsLiteral("NormalCallClearingError")) {
|
|
|
|
NotifyError(aDisconnectedReason);
|
2015-03-26 08:39:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-06 10:24:55 +00:00
|
|
|
void
|
|
|
|
TelephonyCall::ChangeGroup(TelephonyCallGroup* aGroup)
|
|
|
|
{
|
|
|
|
mGroup = aGroup;
|
|
|
|
|
|
|
|
nsresult rv = DispatchCallEvent(NS_LITERAL_STRING("groupchange"), this);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
NS_WARNING("Failed to dispatch error event!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-25 16:49:00 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_INHERITED(TelephonyCall,
|
|
|
|
DOMEventTargetHelper,
|
|
|
|
mTelephony,
|
|
|
|
mError,
|
2014-04-10 06:25:42 +00:00
|
|
|
mGroup,
|
|
|
|
mId,
|
|
|
|
mSecondId);
|
2012-01-09 22:28:47 +00:00
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(TelephonyCall)
|
2014-04-01 06:13:50 +00:00
|
|
|
NS_INTERFACE_MAP_END_INHERITING(DOMEventTargetHelper)
|
2012-01-09 22:28:47 +00:00
|
|
|
|
2014-04-01 06:13:50 +00:00
|
|
|
NS_IMPL_ADDREF_INHERITED(TelephonyCall, DOMEventTargetHelper)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(TelephonyCall, DOMEventTargetHelper)
|
2012-01-09 22:28:47 +00:00
|
|
|
|
2013-07-15 08:27:19 +00:00
|
|
|
// TelephonyCall WebIDL
|
2012-01-09 22:28:47 +00:00
|
|
|
|
2014-04-10 06:25:42 +00:00
|
|
|
already_AddRefed<TelephonyCallId>
|
|
|
|
TelephonyCall::Id() const
|
|
|
|
{
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<TelephonyCallId> id = mId;
|
2014-04-10 06:25:42 +00:00
|
|
|
return id.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<TelephonyCallId>
|
|
|
|
TelephonyCall::GetSecondId() const
|
|
|
|
{
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<TelephonyCallId> id = mSecondId;
|
2014-04-10 06:25:42 +00:00
|
|
|
return id.forget();
|
|
|
|
}
|
|
|
|
|
2013-07-15 08:27:19 +00:00
|
|
|
already_AddRefed<DOMError>
|
|
|
|
TelephonyCall::GetError() const
|
2013-05-14 06:08:07 +00:00
|
|
|
{
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<DOMError> error = mError;
|
2013-07-15 08:27:19 +00:00
|
|
|
return error.forget();
|
2013-05-14 06:08:07 +00:00
|
|
|
}
|
|
|
|
|
2013-07-06 10:24:55 +00:00
|
|
|
already_AddRefed<TelephonyCallGroup>
|
|
|
|
TelephonyCall::GetGroup() const
|
|
|
|
{
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<TelephonyCallGroup> group = mGroup;
|
2013-07-06 10:24:55 +00:00
|
|
|
return group.forget();
|
|
|
|
}
|
|
|
|
|
2015-01-04 22:33:00 +00:00
|
|
|
already_AddRefed<Promise>
|
2013-07-15 08:27:19 +00:00
|
|
|
TelephonyCall::Answer(ErrorResult& aRv)
|
2012-01-09 22:28:47 +00:00
|
|
|
{
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<Promise> promise = CreatePromise(aRv);
|
2015-01-28 04:01:00 +00:00
|
|
|
if (!promise) {
|
2015-01-04 22:33:00 +00:00
|
|
|
return nullptr;
|
2012-01-09 22:28:47 +00:00
|
|
|
}
|
|
|
|
|
2015-10-06 17:11:00 +00:00
|
|
|
if (mState != TelephonyCallState::Incoming) {
|
2015-01-28 04:01:00 +00:00
|
|
|
NS_WARNING(nsPrintfCString("Answer on non-incoming call is rejected!"
|
2015-10-06 17:11:00 +00:00
|
|
|
" (State: %s)",
|
|
|
|
TELEPHONY_CALL_STATE(mState)).get());
|
2015-01-04 22:33:00 +00:00
|
|
|
promise->MaybeReject(NS_ERROR_DOM_INVALID_STATE_ERR);
|
|
|
|
return promise.forget();
|
2013-07-15 08:27:19 +00:00
|
|
|
}
|
2012-01-09 22:28:47 +00:00
|
|
|
|
2015-01-04 22:33:00 +00:00
|
|
|
nsCOMPtr<nsITelephonyCallback> callback = new TelephonyCallback(promise);
|
|
|
|
aRv = mTelephony->Service()->AnswerCall(mServiceId, mCallIndex, callback);
|
|
|
|
NS_ENSURE_TRUE(!aRv.Failed(), nullptr);
|
|
|
|
|
|
|
|
return promise.forget();
|
2012-01-09 22:28:47 +00:00
|
|
|
}
|
|
|
|
|
2015-01-04 22:33:00 +00:00
|
|
|
already_AddRefed<Promise>
|
2013-07-15 08:27:19 +00:00
|
|
|
TelephonyCall::HangUp(ErrorResult& aRv)
|
2012-01-09 22:28:47 +00:00
|
|
|
{
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<Promise> promise = CreatePromise(aRv);
|
2015-01-28 04:01:00 +00:00
|
|
|
if (!promise) {
|
2015-01-04 22:33:00 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2015-10-06 17:11:00 +00:00
|
|
|
if (mState == TelephonyCallState::Disconnected) {
|
|
|
|
NS_WARNING(nsPrintfCString("HangUp on a disconnected call is rejected!"
|
|
|
|
" (State: %s)",
|
|
|
|
TELEPHONY_CALL_STATE(mState)).get());
|
2015-01-04 22:33:00 +00:00
|
|
|
promise->MaybeReject(NS_ERROR_DOM_INVALID_STATE_ERR);
|
|
|
|
return promise.forget();
|
2012-01-09 22:28:47 +00:00
|
|
|
}
|
|
|
|
|
2015-01-04 22:33:00 +00:00
|
|
|
nsCOMPtr<nsITelephonyCallback> callback = new TelephonyCallback(promise);
|
2015-10-06 17:11:00 +00:00
|
|
|
aRv = mState == TelephonyCallState::Incoming ?
|
2015-01-04 22:33:00 +00:00
|
|
|
mTelephony->Service()->RejectCall(mServiceId, mCallIndex, callback) :
|
|
|
|
mTelephony->Service()->HangUpCall(mServiceId, mCallIndex, callback);
|
|
|
|
NS_ENSURE_TRUE(!aRv.Failed(), nullptr);
|
2012-01-09 22:28:47 +00:00
|
|
|
|
2015-01-04 22:33:00 +00:00
|
|
|
return promise.forget();
|
2012-01-09 22:28:47 +00:00
|
|
|
}
|
|
|
|
|
2015-01-04 22:33:00 +00:00
|
|
|
already_AddRefed<Promise>
|
2013-07-15 08:27:19 +00:00
|
|
|
TelephonyCall::Hold(ErrorResult& aRv)
|
2012-04-05 08:12:42 +00:00
|
|
|
{
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<Promise> promise = CreatePromise(aRv);
|
2015-01-28 04:01:00 +00:00
|
|
|
if (!promise) {
|
2015-01-04 22:33:00 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2015-03-26 08:27:25 +00:00
|
|
|
nsCOMPtr<nsITelephonyCallback> callback = new TelephonyCallback(promise);
|
|
|
|
aRv = Hold(callback);
|
|
|
|
if (NS_WARN_IF(aRv.Failed() &&
|
|
|
|
!aRv.ErrorCodeIs(NS_ERROR_DOM_INVALID_STATE_ERR))) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return promise.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
TelephonyCall::Hold(nsITelephonyCallback* aCallback)
|
|
|
|
{
|
2015-10-06 17:11:00 +00:00
|
|
|
if (mState != TelephonyCallState::Connected) {
|
2015-01-28 04:01:00 +00:00
|
|
|
NS_WARNING(nsPrintfCString("Hold non-connected call is rejected!"
|
2015-10-06 17:11:00 +00:00
|
|
|
" (State: %s)",
|
|
|
|
TELEPHONY_CALL_STATE(mState)).get());
|
2015-03-26 08:27:25 +00:00
|
|
|
aCallback->NotifyError(NS_LITERAL_STRING("InvalidStateError"));
|
|
|
|
return NS_ERROR_DOM_INVALID_STATE_ERR;
|
2012-04-05 08:12:42 +00:00
|
|
|
}
|
2013-01-28 07:39:50 +00:00
|
|
|
|
2013-07-06 10:24:55 +00:00
|
|
|
if (mGroup) {
|
2015-01-04 22:33:00 +00:00
|
|
|
NS_WARNING("Hold a call in conference is rejected!");
|
2015-03-26 08:27:25 +00:00
|
|
|
aCallback->NotifyError(NS_LITERAL_STRING("InvalidStateError"));
|
|
|
|
return NS_ERROR_DOM_INVALID_STATE_ERR;
|
2013-07-06 10:24:55 +00:00
|
|
|
}
|
|
|
|
|
2014-02-21 09:52:13 +00:00
|
|
|
if (!mSwitchable) {
|
2015-01-04 22:33:00 +00:00
|
|
|
NS_WARNING("Hold a non-switchable call is rejected!");
|
2015-03-26 08:27:25 +00:00
|
|
|
aCallback->NotifyError(NS_LITERAL_STRING("InvalidStateError"));
|
|
|
|
return NS_ERROR_DOM_INVALID_STATE_ERR;
|
2014-02-21 09:52:13 +00:00
|
|
|
}
|
|
|
|
|
2015-03-26 08:27:25 +00:00
|
|
|
nsresult rv = mTelephony->Service()->HoldCall(mServiceId, mCallIndex, aCallback);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2013-01-28 07:39:50 +00:00
|
|
|
|
2014-04-10 06:25:42 +00:00
|
|
|
if (mSecondId) {
|
2013-08-16 09:01:41 +00:00
|
|
|
// No state transition when we switch two numbers within one TelephonyCall
|
|
|
|
// object. Otherwise, the state here will be inconsistent with the backend
|
|
|
|
// RIL and will never be right.
|
2015-03-26 08:27:25 +00:00
|
|
|
return NS_OK;
|
2013-08-16 09:01:41 +00:00
|
|
|
}
|
|
|
|
|
2015-03-26 08:27:25 +00:00
|
|
|
return NS_OK;
|
2012-04-05 08:12:42 +00:00
|
|
|
}
|
|
|
|
|
2015-10-06 17:11:00 +00:00
|
|
|
already_AddRefed<Promise>
|
|
|
|
TelephonyCall::Resume(ErrorResult& aRv)
|
|
|
|
{
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<Promise> promise = CreatePromise(aRv);
|
2015-10-06 17:11:00 +00:00
|
|
|
if (!promise) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsITelephonyCallback> callback = new TelephonyCallback(promise);
|
|
|
|
aRv = Resume(callback);
|
|
|
|
if (NS_WARN_IF(aRv.Failed() &&
|
|
|
|
!aRv.ErrorCodeIs(NS_ERROR_DOM_INVALID_STATE_ERR))) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return promise.forget();
|
|
|
|
}
|
|
|
|
|
2015-03-26 08:27:25 +00:00
|
|
|
nsresult
|
|
|
|
TelephonyCall::Resume(nsITelephonyCallback* aCallback)
|
2012-04-05 08:12:42 +00:00
|
|
|
{
|
2015-10-06 17:11:00 +00:00
|
|
|
if (mState != TelephonyCallState::Held) {
|
|
|
|
NS_WARNING(nsPrintfCString("Resume non-held call is rejected!"
|
|
|
|
" (State: %s)",
|
|
|
|
TELEPHONY_CALL_STATE(mState)).get());
|
2015-03-26 08:27:25 +00:00
|
|
|
aCallback->NotifyError(NS_LITERAL_STRING("InvalidStateError"));
|
|
|
|
return NS_ERROR_DOM_INVALID_STATE_ERR;
|
2012-04-05 08:12:42 +00:00
|
|
|
}
|
2013-01-28 07:39:50 +00:00
|
|
|
|
2013-07-06 10:24:55 +00:00
|
|
|
if (mGroup) {
|
2015-01-04 22:33:00 +00:00
|
|
|
NS_WARNING("Resume a call in conference is rejected!");
|
2015-03-26 08:27:25 +00:00
|
|
|
aCallback->NotifyError(NS_LITERAL_STRING("InvalidStateError"));
|
|
|
|
return NS_ERROR_DOM_INVALID_STATE_ERR;
|
2013-07-06 10:24:55 +00:00
|
|
|
}
|
|
|
|
|
2014-02-21 09:52:13 +00:00
|
|
|
if (!mSwitchable) {
|
2015-01-04 22:33:00 +00:00
|
|
|
NS_WARNING("Resume a non-switchable call is rejected!");
|
2015-03-26 08:27:25 +00:00
|
|
|
aCallback->NotifyError(NS_LITERAL_STRING("InvalidStateError"));
|
|
|
|
return NS_ERROR_DOM_INVALID_STATE_ERR;
|
2014-02-21 09:52:13 +00:00
|
|
|
}
|
|
|
|
|
2015-03-26 08:27:25 +00:00
|
|
|
nsresult rv = mTelephony->Service()->ResumeCall(mServiceId, mCallIndex, aCallback);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2013-01-28 07:39:50 +00:00
|
|
|
|
2015-03-26 08:27:25 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|