2012-01-09 14:28:47 -08:00
|
|
|
/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
|
|
|
|
/* vim: set ts=2 et sw=2 tw=40: */
|
2012-05-21 04:12:37 -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/. */
|
2012-01-09 14:28:47 -08:00
|
|
|
|
|
|
|
#include "TelephonyCall.h"
|
2014-06-10 18:23:34 -07:00
|
|
|
#include "mozilla/dom/CallEvent.h"
|
2013-07-15 01:27:19 -07:00
|
|
|
#include "mozilla/dom/TelephonyCallBinding.h"
|
2012-01-09 14:28:47 -08:00
|
|
|
|
2013-05-18 10:52:06 -07:00
|
|
|
#include "mozilla/dom/DOMError.h"
|
2013-07-15 01:27:19 -07:00
|
|
|
|
2013-01-27 23:39:50 -08:00
|
|
|
#include "Telephony.h"
|
2013-07-06 03:24:55 -07:00
|
|
|
#include "TelephonyCallGroup.h"
|
2012-01-09 14:28:47 -08:00
|
|
|
|
2013-07-15 01:27:19 -07:00
|
|
|
using namespace mozilla::dom;
|
2013-09-06 23:19:53 -07:00
|
|
|
using mozilla::ErrorResult;
|
2012-01-09 14:28:47 -08:00
|
|
|
|
|
|
|
// static
|
|
|
|
already_AddRefed<TelephonyCall>
|
2014-06-24 03:52:00 -07:00
|
|
|
TelephonyCall::Create(Telephony* aTelephony, TelephonyCallId* aId,
|
|
|
|
uint32_t aServiceId, uint32_t aCallIndex,
|
|
|
|
uint16_t aCallState, bool aEmergency, bool aConference,
|
|
|
|
bool aSwitchable, bool aMergeable)
|
2012-01-09 14:28:47 -08:00
|
|
|
{
|
2014-06-24 03:52:00 -07:00
|
|
|
NS_ASSERTION(aTelephony, "Null aTelephony pointer!");
|
|
|
|
NS_ASSERTION(aId, "Null aId pointer!");
|
2012-01-09 14:28:47 -08:00
|
|
|
NS_ASSERTION(aCallIndex >= 1, "Invalid call index!");
|
|
|
|
|
2014-01-06 18:53:23 -08:00
|
|
|
nsRefPtr<TelephonyCall> call = new TelephonyCall(aTelephony->GetOwner());
|
2012-03-13 15:11:16 -07:00
|
|
|
|
2012-01-09 14:28:47 -08:00
|
|
|
call->mTelephony = aTelephony;
|
2014-06-24 03:52:00 -07:00
|
|
|
call->mId = aId;
|
2013-10-31 05:05:51 -07:00
|
|
|
call->mServiceId = aServiceId;
|
2012-01-09 14:28:47 -08:00
|
|
|
call->mCallIndex = aCallIndex;
|
2013-05-13 23:08:07 -07:00
|
|
|
call->mEmergency = aEmergency;
|
2014-06-24 03:52:00 -07:00
|
|
|
call->mGroup = aConference ? aTelephony->ConferenceGroup() : nullptr;
|
2014-02-21 01:52:13 -08:00
|
|
|
call->mSwitchable = aSwitchable;
|
|
|
|
call->mMergeable = aMergeable;
|
2014-06-24 03:52:00 -07:00
|
|
|
call->mError = nullptr;
|
2012-01-09 14:28:47 -08:00
|
|
|
|
|
|
|
call->ChangeStateInternal(aCallState, false);
|
|
|
|
|
|
|
|
return call.forget();
|
|
|
|
}
|
|
|
|
|
2014-01-06 18:53:23 -08:00
|
|
|
TelephonyCall::TelephonyCall(nsPIDOMWindow* aOwner)
|
2014-03-31 23:13:50 -07:00
|
|
|
: DOMEventTargetHelper(aOwner),
|
2014-01-28 22:27:22 -08:00
|
|
|
mLive(false)
|
2013-03-06 01:53:23 -08:00
|
|
|
{
|
2013-07-15 01:27:19 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
TelephonyCall::~TelephonyCall()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
JSObject*
|
2014-04-08 15:27:18 -07:00
|
|
|
TelephonyCall::WrapObject(JSContext* aCx)
|
2013-07-15 01:27:19 -07:00
|
|
|
{
|
Bug 991742 part 6. Remove the "aScope" argument of binding Wrap() methods. r=bholley
This patch was mostly generated with this command:
find . -name "*.h" -o -name "*.cpp" | xargs sed -e 's/Binding::Wrap(aCx, aScope, this/Binding::Wrap(aCx, this/' -e 's/Binding_workers::Wrap(aCx, aScope, this/Binding_workers::Wrap(aCx, this/' -e 's/Binding::Wrap(cx, scope, this/Binding::Wrap(cx, this/' -i ""
plus a few manual fixes to dom/bindings/Codegen.py, js/xpconnect/src/event_impl_gen.py, and a few C++ files that were not caught in the search-and-replace above.
2014-04-08 15:27:17 -07:00
|
|
|
return TelephonyCallBinding::Wrap(aCx, this);
|
2013-03-06 01:53:23 -08:00
|
|
|
}
|
|
|
|
|
2012-01-09 14:28:47 -08:00
|
|
|
void
|
2012-08-22 08:56:38 -07:00
|
|
|
TelephonyCall::ChangeStateInternal(uint16_t aCallState, bool aFireEvents)
|
2012-01-09 14:28:47 -08:00
|
|
|
{
|
|
|
|
nsRefPtr<TelephonyCall> kungFuDeathGrip(this);
|
|
|
|
|
|
|
|
nsString stateString;
|
|
|
|
switch (aCallState) {
|
2014-06-03 07:15:25 -07:00
|
|
|
case nsITelephonyService::CALL_STATE_DIALING:
|
2012-01-09 14:28:47 -08:00
|
|
|
stateString.AssignLiteral("dialing");
|
|
|
|
break;
|
2014-06-03 07:15:25 -07:00
|
|
|
case nsITelephonyService::CALL_STATE_ALERTING:
|
2012-03-15 20:13:42 -07:00
|
|
|
stateString.AssignLiteral("alerting");
|
2012-01-09 14:28:47 -08:00
|
|
|
break;
|
2014-06-03 07:15:25 -07:00
|
|
|
case nsITelephonyService::CALL_STATE_CONNECTING:
|
2012-01-09 14:28:47 -08:00
|
|
|
stateString.AssignLiteral("connecting");
|
|
|
|
break;
|
2014-06-03 07:15:25 -07:00
|
|
|
case nsITelephonyService::CALL_STATE_CONNECTED:
|
2012-01-09 14:28:47 -08:00
|
|
|
stateString.AssignLiteral("connected");
|
|
|
|
break;
|
2014-06-03 07:15:25 -07:00
|
|
|
case nsITelephonyService::CALL_STATE_HOLDING:
|
2012-01-09 14:28:47 -08:00
|
|
|
stateString.AssignLiteral("holding");
|
|
|
|
break;
|
2014-06-03 07:15:25 -07:00
|
|
|
case nsITelephonyService::CALL_STATE_HELD:
|
2012-01-09 14:28:47 -08:00
|
|
|
stateString.AssignLiteral("held");
|
|
|
|
break;
|
2014-06-03 07:15:25 -07:00
|
|
|
case nsITelephonyService::CALL_STATE_RESUMING:
|
2012-01-09 14:28:47 -08:00
|
|
|
stateString.AssignLiteral("resuming");
|
|
|
|
break;
|
2014-06-03 07:15:25 -07:00
|
|
|
case nsITelephonyService::CALL_STATE_DISCONNECTING:
|
2012-01-09 14:28:47 -08:00
|
|
|
stateString.AssignLiteral("disconnecting");
|
|
|
|
break;
|
2014-06-03 07:15:25 -07:00
|
|
|
case nsITelephonyService::CALL_STATE_DISCONNECTED:
|
2012-01-09 14:28:47 -08:00
|
|
|
stateString.AssignLiteral("disconnected");
|
|
|
|
break;
|
2014-06-03 07:15:25 -07:00
|
|
|
case nsITelephonyService::CALL_STATE_INCOMING:
|
2012-01-09 14:28:47 -08:00
|
|
|
stateString.AssignLiteral("incoming");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
NS_NOTREACHED("Unknown state!");
|
|
|
|
}
|
|
|
|
|
|
|
|
mState = stateString;
|
|
|
|
mCallState = aCallState;
|
|
|
|
|
2014-06-03 07:15:25 -07:00
|
|
|
if (aCallState == nsITelephonyService::CALL_STATE_DISCONNECTED) {
|
2012-01-09 14:28:47 -08:00
|
|
|
NS_ASSERTION(mLive, "Should be live!");
|
2014-04-04 05:18:49 -07:00
|
|
|
mLive = false;
|
2013-07-06 03:24:55 -07:00
|
|
|
if (mGroup) {
|
|
|
|
mGroup->RemoveCall(this);
|
|
|
|
} else {
|
|
|
|
mTelephony->RemoveCall(this);
|
|
|
|
}
|
2012-01-09 14:28:47 -08:00
|
|
|
} else if (!mLive) {
|
2014-04-04 05:18:49 -07:00
|
|
|
mLive = true;
|
2013-07-06 03:24:55 -07:00
|
|
|
if (mGroup) {
|
|
|
|
mGroup->AddCall(this);
|
|
|
|
} else {
|
|
|
|
mTelephony->AddCall(this);
|
|
|
|
}
|
2012-01-09 14:28:47 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (aFireEvents) {
|
2013-01-27 23:39:50 -08:00
|
|
|
nsresult rv = DispatchCallEvent(NS_LITERAL_STRING("statechange"), this);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
NS_WARNING("Failed to dispatch specific event!");
|
2012-01-09 14:28:47 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// This can change if the statechange handler called back here... Need to
|
|
|
|
// figure out something smarter.
|
|
|
|
if (mCallState == aCallState) {
|
2013-01-27 23:39:50 -08:00
|
|
|
rv = DispatchCallEvent(stateString, this);
|
|
|
|
if (NS_FAILED(rv)) {
|
2012-01-09 14:28:47 -08:00
|
|
|
NS_WARNING("Failed to dispatch specific event!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-27 23:39:50 -08:00
|
|
|
nsresult
|
|
|
|
TelephonyCall::DispatchCallEvent(const nsAString& aType,
|
2013-07-15 01:27:19 -07:00
|
|
|
TelephonyCall* aCall)
|
2013-01-27 23:39:50 -08:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(aCall);
|
|
|
|
|
2014-06-10 18:23:34 -07:00
|
|
|
CallEventInit init;
|
|
|
|
init.mBubbles = false;
|
|
|
|
init.mCancelable = false;
|
|
|
|
init.mCall = aCall;
|
|
|
|
|
|
|
|
nsRefPtr<CallEvent> event = CallEvent::Constructor(this, aType, init);
|
2013-01-27 23:39:50 -08:00
|
|
|
|
2013-07-15 01:27:19 -07:00
|
|
|
return DispatchTrustedEvent(event);
|
2013-01-27 23:39:50 -08:00
|
|
|
}
|
|
|
|
|
2012-05-14 21:13:06 -07:00
|
|
|
void
|
|
|
|
TelephonyCall::NotifyError(const nsAString& aError)
|
|
|
|
{
|
2012-05-14 21:13:06 -07:00
|
|
|
// Set the error string
|
|
|
|
NS_ASSERTION(!mError, "Already have an error?");
|
|
|
|
|
2013-09-11 20:47:14 -07:00
|
|
|
mError = new DOMError(GetOwner(), aError);
|
2012-05-14 21:13:06 -07:00
|
|
|
|
2012-05-14 21:13:06 -07:00
|
|
|
// Do the state transitions
|
2014-06-03 07:15:25 -07:00
|
|
|
ChangeStateInternal(nsITelephonyService::CALL_STATE_DISCONNECTED, true);
|
2012-05-14 21:13:06 -07:00
|
|
|
|
2013-01-27 23:39:50 -08:00
|
|
|
nsresult rv = DispatchCallEvent(NS_LITERAL_STRING("error"), this);
|
|
|
|
if (NS_FAILED(rv)) {
|
2012-05-14 21:13:06 -07:00
|
|
|
NS_WARNING("Failed to dispatch error event!");
|
|
|
|
}
|
2012-05-14 21:13:06 -07:00
|
|
|
}
|
|
|
|
|
2013-07-06 03:24:55 -07: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 09:49:00 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_INHERITED(TelephonyCall,
|
|
|
|
DOMEventTargetHelper,
|
|
|
|
mTelephony,
|
|
|
|
mError,
|
2014-04-09 23:25:42 -07:00
|
|
|
mGroup,
|
|
|
|
mId,
|
|
|
|
mSecondId);
|
2012-01-09 14:28:47 -08:00
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(TelephonyCall)
|
2014-03-31 23:13:50 -07:00
|
|
|
NS_INTERFACE_MAP_END_INHERITING(DOMEventTargetHelper)
|
2012-01-09 14:28:47 -08:00
|
|
|
|
2014-03-31 23:13:50 -07:00
|
|
|
NS_IMPL_ADDREF_INHERITED(TelephonyCall, DOMEventTargetHelper)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(TelephonyCall, DOMEventTargetHelper)
|
2012-01-09 14:28:47 -08:00
|
|
|
|
2013-07-15 01:27:19 -07:00
|
|
|
// TelephonyCall WebIDL
|
2012-01-09 14:28:47 -08:00
|
|
|
|
2014-04-09 23:25:42 -07:00
|
|
|
already_AddRefed<TelephonyCallId>
|
|
|
|
TelephonyCall::Id() const
|
|
|
|
{
|
|
|
|
nsRefPtr<TelephonyCallId> id = mId;
|
|
|
|
return id.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<TelephonyCallId>
|
|
|
|
TelephonyCall::GetSecondId() const
|
|
|
|
{
|
|
|
|
nsRefPtr<TelephonyCallId> id = mSecondId;
|
|
|
|
return id.forget();
|
|
|
|
}
|
|
|
|
|
2013-07-15 01:27:19 -07:00
|
|
|
already_AddRefed<DOMError>
|
|
|
|
TelephonyCall::GetError() const
|
2013-05-13 23:08:07 -07:00
|
|
|
{
|
2013-07-15 01:27:19 -07:00
|
|
|
nsRefPtr<DOMError> error = mError;
|
|
|
|
return error.forget();
|
2013-05-13 23:08:07 -07:00
|
|
|
}
|
|
|
|
|
2013-07-06 03:24:55 -07:00
|
|
|
already_AddRefed<TelephonyCallGroup>
|
|
|
|
TelephonyCall::GetGroup() const
|
|
|
|
{
|
|
|
|
nsRefPtr<TelephonyCallGroup> group = mGroup;
|
|
|
|
return group.forget();
|
|
|
|
}
|
|
|
|
|
2013-07-15 01:27:19 -07:00
|
|
|
void
|
|
|
|
TelephonyCall::Answer(ErrorResult& aRv)
|
2012-01-09 14:28:47 -08:00
|
|
|
{
|
2014-06-03 07:15:25 -07:00
|
|
|
if (mCallState != nsITelephonyService::CALL_STATE_INCOMING) {
|
2012-01-09 14:28:47 -08:00
|
|
|
NS_WARNING("Answer on non-incoming call ignored!");
|
2013-07-15 01:27:19 -07:00
|
|
|
return;
|
2012-01-09 14:28:47 -08:00
|
|
|
}
|
|
|
|
|
2014-06-03 07:15:30 -07:00
|
|
|
nsresult rv = mTelephony->Service()->AnswerCall(mServiceId, mCallIndex);
|
2013-07-15 01:27:19 -07:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
return;
|
|
|
|
}
|
2012-01-09 14:28:47 -08:00
|
|
|
|
2014-06-03 07:15:25 -07:00
|
|
|
ChangeStateInternal(nsITelephonyService::CALL_STATE_CONNECTING, true);
|
2012-01-09 14:28:47 -08:00
|
|
|
}
|
|
|
|
|
2013-07-15 01:27:19 -07:00
|
|
|
void
|
|
|
|
TelephonyCall::HangUp(ErrorResult& aRv)
|
2012-01-09 14:28:47 -08:00
|
|
|
{
|
2014-06-03 07:15:25 -07:00
|
|
|
if (mCallState == nsITelephonyService::CALL_STATE_DISCONNECTING ||
|
|
|
|
mCallState == nsITelephonyService::CALL_STATE_DISCONNECTED) {
|
2012-01-09 14:28:47 -08:00
|
|
|
NS_WARNING("HangUp on previously disconnected call ignored!");
|
2013-07-15 01:27:19 -07:00
|
|
|
return;
|
2012-01-09 14:28:47 -08:00
|
|
|
}
|
|
|
|
|
2014-06-03 07:15:25 -07:00
|
|
|
nsresult rv = mCallState == nsITelephonyService::CALL_STATE_INCOMING ?
|
2014-06-03 07:15:30 -07:00
|
|
|
mTelephony->Service()->RejectCall(mServiceId, mCallIndex) :
|
|
|
|
mTelephony->Service()->HangUp(mServiceId, mCallIndex);
|
2013-07-15 01:27:19 -07:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
return;
|
|
|
|
}
|
2012-01-09 14:28:47 -08:00
|
|
|
|
2014-06-03 07:15:25 -07:00
|
|
|
ChangeStateInternal(nsITelephonyService::CALL_STATE_DISCONNECTING, true);
|
2012-01-09 14:28:47 -08:00
|
|
|
}
|
|
|
|
|
2013-07-15 01:27:19 -07:00
|
|
|
void
|
|
|
|
TelephonyCall::Hold(ErrorResult& aRv)
|
2012-04-05 01:12:42 -07:00
|
|
|
{
|
2014-06-03 07:15:25 -07:00
|
|
|
if (mCallState != nsITelephonyService::CALL_STATE_CONNECTED) {
|
2012-04-05 01:12:42 -07:00
|
|
|
NS_WARNING("Hold non-connected call ignored!");
|
2013-07-15 01:27:19 -07:00
|
|
|
return;
|
2012-04-05 01:12:42 -07:00
|
|
|
}
|
2013-01-27 23:39:50 -08:00
|
|
|
|
2013-07-06 03:24:55 -07:00
|
|
|
if (mGroup) {
|
|
|
|
NS_WARNING("Hold a call in conference ignored!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-02-21 01:52:13 -08:00
|
|
|
if (!mSwitchable) {
|
|
|
|
NS_WARNING("Hold a non-switchable call ignored!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-06-03 07:15:30 -07:00
|
|
|
nsresult rv = mTelephony->Service()->HoldCall(mServiceId, mCallIndex);
|
2013-07-15 01:27:19 -07:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
return;
|
|
|
|
}
|
2013-01-27 23:39:50 -08:00
|
|
|
|
2014-04-09 23:25:42 -07:00
|
|
|
if (mSecondId) {
|
2013-08-16 02:01:41 -07: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.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-06-03 07:15:25 -07:00
|
|
|
ChangeStateInternal(nsITelephonyService::CALL_STATE_HOLDING, true);
|
2012-04-05 01:12:42 -07:00
|
|
|
}
|
|
|
|
|
2013-07-15 01:27:19 -07:00
|
|
|
void
|
|
|
|
TelephonyCall::Resume(ErrorResult& aRv)
|
2012-04-05 01:12:42 -07:00
|
|
|
{
|
2014-06-03 07:15:25 -07:00
|
|
|
if (mCallState != nsITelephonyService::CALL_STATE_HELD) {
|
2012-04-05 01:12:42 -07:00
|
|
|
NS_WARNING("Resume non-held call ignored!");
|
2013-07-15 01:27:19 -07:00
|
|
|
return;
|
2012-04-05 01:12:42 -07:00
|
|
|
}
|
2013-01-27 23:39:50 -08:00
|
|
|
|
2013-07-06 03:24:55 -07:00
|
|
|
if (mGroup) {
|
|
|
|
NS_WARNING("Resume a call in conference ignored!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-02-21 01:52:13 -08:00
|
|
|
if (!mSwitchable) {
|
|
|
|
NS_WARNING("Resume a non-switchable call ignored!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-06-03 07:15:30 -07:00
|
|
|
nsresult rv = mTelephony->Service()->ResumeCall(mServiceId, mCallIndex);
|
2013-07-15 01:27:19 -07:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
return;
|
|
|
|
}
|
2013-01-27 23:39:50 -08:00
|
|
|
|
2014-06-03 07:15:25 -07:00
|
|
|
ChangeStateInternal(nsITelephonyService::CALL_STATE_RESUMING, true);
|
2012-04-05 01:12:42 -07:00
|
|
|
}
|