2013-07-06 14:24:55 +04: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: */
|
|
|
|
/* 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 "TelephonyCallGroup.h"
|
|
|
|
|
|
|
|
#include "CallsList.h"
|
2014-10-22 11:07:00 +04:00
|
|
|
#include "Telephony.h"
|
2014-06-11 05:23:34 +04:00
|
|
|
#include "mozilla/dom/CallEvent.h"
|
2013-10-28 10:43:14 +04:00
|
|
|
#include "mozilla/dom/CallGroupErrorEvent.h"
|
2014-10-22 11:07:00 +04:00
|
|
|
#include "mozilla/dom/telephony/TelephonyCallback.h"
|
2013-07-06 14:24:55 +04:00
|
|
|
|
2015-10-06 20:11:00 +03:00
|
|
|
#include "nsPrintfCString.h"
|
|
|
|
|
|
|
|
#ifdef TELEPHONY_GROUP_STATE
|
|
|
|
#undef TELEPHONY_GROUP_STATE
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define TELEPHONY_GROUP_STATE(_state) \
|
|
|
|
(TelephonyCallGroupStateValues::strings[static_cast<int32_t>(_state)].value)
|
|
|
|
|
2013-07-06 14:24:55 +04:00
|
|
|
using namespace mozilla::dom;
|
2014-10-22 11:07:00 +04:00
|
|
|
using namespace mozilla::dom::telephony;
|
2013-09-07 10:19:53 +04:00
|
|
|
using mozilla::ErrorResult;
|
2013-07-06 14:24:55 +04:00
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
TelephonyCallGroup::TelephonyCallGroup(nsPIDOMWindowInner* aOwner)
|
2014-04-01 10:13:50 +04:00
|
|
|
: DOMEventTargetHelper(aOwner)
|
2013-07-06 14:24:55 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
TelephonyCallGroup::~TelephonyCallGroup()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
already_AddRefed<TelephonyCallGroup>
|
|
|
|
TelephonyCallGroup::Create(Telephony* aTelephony)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aTelephony, "Null telephony!");
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<TelephonyCallGroup> group =
|
2014-01-07 06:53:23 +04:00
|
|
|
new TelephonyCallGroup(aTelephony->GetOwner());
|
2013-07-06 14:24:55 +04:00
|
|
|
|
|
|
|
group->mTelephony = aTelephony;
|
2015-10-06 20:11:00 +03:00
|
|
|
group->mState = TelephonyCallGroupState::_empty;
|
2013-07-06 14:24:55 +04:00
|
|
|
group->mCallsList = new CallsList(aTelephony, group);
|
|
|
|
|
|
|
|
return group.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
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 17:13:33 +03:00
|
|
|
TelephonyCallGroup::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
2013-07-06 14:24:55 +04: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 17:13:33 +03:00
|
|
|
return TelephonyCallGroupBinding::Wrap(aCx, this, aGivenProto);
|
2013-07-06 14:24:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TelephonyCallGroup::AddCall(TelephonyCall* aCall)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(!mCalls.Contains(aCall), "Already know about this one!");
|
|
|
|
mCalls.AppendElement(aCall);
|
|
|
|
aCall->ChangeGroup(this);
|
|
|
|
NotifyCallsChanged(aCall);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TelephonyCallGroup::RemoveCall(TelephonyCall* aCall)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(mCalls.Contains(aCall), "Didn't know about this one!");
|
|
|
|
mCalls.RemoveElement(aCall);
|
|
|
|
aCall->ChangeGroup(nullptr);
|
|
|
|
NotifyCallsChanged(aCall);
|
|
|
|
}
|
|
|
|
|
2013-10-28 10:43:14 +04:00
|
|
|
nsresult
|
|
|
|
TelephonyCallGroup::NotifyError(const nsAString& aName, const nsAString& aMessage)
|
|
|
|
{
|
|
|
|
CallGroupErrorEventInit init;
|
|
|
|
init.mBubbles = false;
|
|
|
|
init.mCancelable = false;
|
|
|
|
init.mName = aName;
|
|
|
|
init.mMessage = aMessage;
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<CallGroupErrorEvent> event =
|
2013-10-28 10:43:14 +04:00
|
|
|
CallGroupErrorEvent::Constructor(this, NS_LITERAL_STRING("error"), init);
|
|
|
|
|
|
|
|
return DispatchTrustedEvent(event);
|
|
|
|
}
|
|
|
|
|
2013-07-06 14:24:55 +04:00
|
|
|
void
|
2015-10-06 20:11:00 +03:00
|
|
|
TelephonyCallGroup::ChangeState()
|
2013-07-06 14:24:55 +04:00
|
|
|
{
|
2015-10-06 20:11:00 +03:00
|
|
|
MOZ_ASSERT(mCalls.Length() != 1);
|
|
|
|
if (mCalls.Length() == 0) {
|
|
|
|
ChangeStateInternal(TelephonyCallGroupState::_empty);
|
2013-07-06 14:24:55 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-10-06 20:11:00 +03:00
|
|
|
TelephonyCallState state = mCalls[0]->State();
|
|
|
|
for (uint32_t i = 1; i < mCalls.Length(); i++) {
|
|
|
|
if (mCalls[i]->State() != state) {
|
|
|
|
MOZ_ASSERT(false, "Various call states are found in a call group!");
|
|
|
|
ChangeStateInternal(TelephonyCallGroupState::_empty);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TelephonyCallGroupState groupState = TelephonyCallGroupState::_empty;
|
|
|
|
switch (state) {
|
|
|
|
case TelephonyCallState::Connected:
|
|
|
|
groupState = TelephonyCallGroupState::Connected;
|
2013-07-06 14:24:55 +04:00
|
|
|
break;
|
2015-10-06 20:11:00 +03:00
|
|
|
case TelephonyCallState::Held:
|
|
|
|
groupState = TelephonyCallGroupState::Held;
|
2013-07-06 14:24:55 +04:00
|
|
|
break;
|
|
|
|
default:
|
2015-10-06 20:11:00 +03:00
|
|
|
NS_NOTREACHED(nsPrintfCString("Invavild call state for a call group(%s)!",
|
|
|
|
TELEPHONY_CALL_STATE(state)).get());
|
2013-07-06 14:24:55 +04:00
|
|
|
}
|
|
|
|
|
2015-10-06 20:11:00 +03:00
|
|
|
ChangeStateInternal(groupState);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TelephonyCallGroup::ChangeStateInternal(TelephonyCallGroupState aState)
|
|
|
|
{
|
|
|
|
if (mState == aState) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update Current State
|
|
|
|
mState = aState;
|
|
|
|
|
|
|
|
// Dispatch related events
|
|
|
|
NotifyStateChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
TelephonyCallGroup::NotifyStateChanged()
|
|
|
|
{
|
|
|
|
// Since |mState| can be changed after statechange handler called back here,
|
|
|
|
// we must save current state. Maybe we should figure out something smarter.
|
|
|
|
TelephonyCallGroupState prevState = mState;
|
|
|
|
|
|
|
|
nsresult res = DispatchCallEvent(NS_LITERAL_STRING("statechange"), nullptr);
|
|
|
|
if (NS_FAILED(res)) {
|
2015-05-06 10:58:00 +03:00
|
|
|
NS_WARNING("Failed to dispatch specific event!");
|
|
|
|
}
|
2015-10-06 20:11:00 +03:00
|
|
|
|
|
|
|
// Check whether |mState| remains the same after the statechange handler.
|
|
|
|
// Besides, If there is no conference call at all, then we dont't have to
|
|
|
|
// dispatch the state evnet.
|
|
|
|
if (mState == prevState) {
|
|
|
|
res = DispatchCallEvent(NS_ConvertASCIItoUTF16(TELEPHONY_GROUP_STATE(mState)),
|
|
|
|
nullptr);
|
|
|
|
if (NS_FAILED(res)) {
|
|
|
|
NS_WARNING("Failed to dispatch specific event!");
|
2013-07-06 14:24:55 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-06 20:11:00 +03:00
|
|
|
// Notify each call within to dispatch call state change event
|
2013-07-06 14:24:55 +04:00
|
|
|
for (uint32_t index = 0; index < mCalls.Length(); index++) {
|
2015-10-06 20:11:00 +03:00
|
|
|
if (NS_FAILED(mCalls[index]->NotifyStateChanged())){
|
|
|
|
res = NS_ERROR_FAILURE;
|
|
|
|
}
|
2013-07-06 14:24:55 +04:00
|
|
|
}
|
2015-10-06 20:11:00 +03:00
|
|
|
|
|
|
|
return res;
|
2013-07-06 14:24:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
TelephonyCallGroup::NotifyCallsChanged(TelephonyCall* aCall)
|
|
|
|
{
|
|
|
|
return DispatchCallEvent(NS_LITERAL_STRING("callschanged"), aCall);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
TelephonyCallGroup::DispatchCallEvent(const nsAString& aType,
|
|
|
|
TelephonyCall* aCall)
|
|
|
|
{
|
2014-06-11 05:23:34 +04:00
|
|
|
CallEventInit init;
|
|
|
|
init.mBubbles = false;
|
|
|
|
init.mCancelable = false;
|
|
|
|
init.mCall = aCall;
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<CallEvent> event = CallEvent::Constructor(this, aType, init);
|
2013-07-06 14:24:55 +04:00
|
|
|
return DispatchTrustedEvent(event);
|
|
|
|
}
|
|
|
|
|
2015-01-09 10:52:00 +03:00
|
|
|
already_AddRefed<Promise>
|
|
|
|
TelephonyCallGroup::CreatePromise(ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(GetOwner());
|
|
|
|
if (!global) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<Promise> promise = Promise::Create(global, aRv);
|
2015-01-09 10:52:00 +03:00
|
|
|
if (aRv.Failed()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return promise.forget();
|
|
|
|
}
|
|
|
|
|
2013-07-06 14:24:55 +04:00
|
|
|
bool
|
|
|
|
TelephonyCallGroup::CanConference(const TelephonyCall& aCall,
|
2015-01-09 10:52:00 +03:00
|
|
|
const TelephonyCall* aSecondCall)
|
2013-07-06 14:24:55 +04:00
|
|
|
{
|
2014-02-21 13:52:13 +04:00
|
|
|
if (!aCall.Mergeable()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-07-06 14:24:55 +04:00
|
|
|
if (!aSecondCall) {
|
|
|
|
MOZ_ASSERT(!mCalls.IsEmpty());
|
2015-10-06 20:11:00 +03:00
|
|
|
return (mState == TelephonyCallGroupState::Connected &&
|
|
|
|
aCall.State() == TelephonyCallState::Held) ||
|
|
|
|
(mState == TelephonyCallGroupState::Held &&
|
|
|
|
aCall.State() == TelephonyCallState::Connected);
|
2013-07-06 14:24:55 +04:00
|
|
|
}
|
|
|
|
|
2015-10-06 20:11:00 +03:00
|
|
|
MOZ_ASSERT(mState != TelephonyCallGroupState::_empty);
|
2013-07-06 14:24:55 +04:00
|
|
|
|
2013-10-31 16:05:51 +04:00
|
|
|
if (aCall.ServiceId() != aSecondCall->ServiceId()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-02-21 13:52:13 +04:00
|
|
|
if (!aSecondCall->Mergeable()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-10-06 20:11:00 +03:00
|
|
|
return (aCall.State() == TelephonyCallState::Connected &&
|
|
|
|
aSecondCall->State() == TelephonyCallState::Held) ||
|
|
|
|
(aCall.State() == TelephonyCallState::Held &&
|
|
|
|
aSecondCall->State() == TelephonyCallState::Connected);
|
2013-07-06 14:24:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<TelephonyCall>
|
2013-10-31 16:05:51 +04:00
|
|
|
TelephonyCallGroup::GetCall(uint32_t aServiceId, uint32_t aCallIndex)
|
2013-07-06 14:24:55 +04:00
|
|
|
{
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<TelephonyCall> call;
|
2013-07-06 14:24:55 +04:00
|
|
|
|
|
|
|
for (uint32_t index = 0; index < mCalls.Length(); index++) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<TelephonyCall>& tempCall = mCalls[index];
|
2013-10-31 16:05:51 +04:00
|
|
|
if (tempCall->ServiceId() == aServiceId &&
|
|
|
|
tempCall->CallIndex() == aCallIndex) {
|
2013-07-06 14:24:55 +04:00
|
|
|
call = tempCall;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return call.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(TelephonyCallGroup)
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(TelephonyCallGroup,
|
2014-04-01 10:13:50 +04:00
|
|
|
DOMEventTargetHelper)
|
2013-07-06 14:24:55 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mCalls)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mCallsList)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mTelephony)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(TelephonyCallGroup,
|
2014-04-01 10:13:50 +04:00
|
|
|
DOMEventTargetHelper)
|
2013-07-06 14:24:55 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mCalls)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mCallsList)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mTelephony)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(TelephonyCallGroup)
|
2014-04-01 10:13:50 +04:00
|
|
|
NS_INTERFACE_MAP_END_INHERITING(DOMEventTargetHelper)
|
2013-07-06 14:24:55 +04:00
|
|
|
|
2014-04-01 10:13:50 +04:00
|
|
|
NS_IMPL_ADDREF_INHERITED(TelephonyCallGroup, DOMEventTargetHelper)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(TelephonyCallGroup, DOMEventTargetHelper)
|
2013-07-06 14:24:55 +04:00
|
|
|
|
|
|
|
// WebIDL
|
|
|
|
already_AddRefed<CallsList>
|
|
|
|
TelephonyCallGroup::Calls() const
|
|
|
|
{
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<CallsList> list = mCallsList;
|
2013-07-06 14:24:55 +04:00
|
|
|
return list.forget();
|
|
|
|
}
|
|
|
|
|
2015-01-09 10:52:00 +03:00
|
|
|
already_AddRefed<Promise>
|
2013-07-06 14:24:55 +04:00
|
|
|
TelephonyCallGroup::Add(TelephonyCall& aCall,
|
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
2015-01-09 10:52:00 +03:00
|
|
|
MOZ_ASSERT(!mCalls.IsEmpty());
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<Promise> promise = CreatePromise(aRv);
|
2015-01-09 10:52:00 +03:00
|
|
|
if (!promise) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2013-07-06 14:24:55 +04:00
|
|
|
if (!CanConference(aCall, nullptr)) {
|
2015-01-09 10:52:00 +03:00
|
|
|
promise->MaybeReject(NS_ERROR_NOT_AVAILABLE);
|
|
|
|
return promise.forget();
|
2013-07-06 14:24:55 +04:00
|
|
|
}
|
|
|
|
|
2015-01-09 10:52:00 +03:00
|
|
|
nsCOMPtr<nsITelephonyCallback> callback = new TelephonyCallback(promise);
|
|
|
|
aRv = mTelephony->Service()->ConferenceCall(aCall.ServiceId(), callback);
|
|
|
|
NS_ENSURE_TRUE(!aRv.Failed(), nullptr);
|
|
|
|
|
|
|
|
return promise.forget();
|
2013-07-06 14:24:55 +04:00
|
|
|
}
|
|
|
|
|
2015-01-09 10:52:00 +03:00
|
|
|
already_AddRefed<Promise>
|
2013-07-06 14:24:55 +04:00
|
|
|
TelephonyCallGroup::Add(TelephonyCall& aCall,
|
|
|
|
TelephonyCall& aSecondCall,
|
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<Promise> promise = CreatePromise(aRv);
|
2015-01-09 10:52:00 +03:00
|
|
|
if (!promise) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2013-07-06 14:24:55 +04:00
|
|
|
if (!CanConference(aCall, &aSecondCall)) {
|
2015-01-09 10:52:00 +03:00
|
|
|
promise->MaybeReject(NS_ERROR_NOT_AVAILABLE);
|
|
|
|
return promise.forget();
|
2013-07-06 14:24:55 +04:00
|
|
|
}
|
|
|
|
|
2015-01-09 10:52:00 +03:00
|
|
|
nsCOMPtr<nsITelephonyCallback> callback = new TelephonyCallback(promise);
|
|
|
|
aRv = mTelephony->Service()->ConferenceCall(aCall.ServiceId(), callback);
|
|
|
|
NS_ENSURE_TRUE(!aRv.Failed(), nullptr);
|
|
|
|
|
|
|
|
return promise.forget();
|
2013-07-06 14:24:55 +04:00
|
|
|
}
|
|
|
|
|
2015-01-09 10:52:00 +03:00
|
|
|
already_AddRefed<Promise>
|
2013-07-06 14:24:55 +04:00
|
|
|
TelephonyCallGroup::Remove(TelephonyCall& aCall, ErrorResult& aRv)
|
|
|
|
{
|
2015-01-09 10:52:00 +03:00
|
|
|
MOZ_ASSERT(!mCalls.IsEmpty());
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<Promise> promise = CreatePromise(aRv);
|
2015-01-09 10:52:00 +03:00
|
|
|
if (!promise) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2015-10-06 20:11:00 +03:00
|
|
|
if (mState != TelephonyCallGroupState::Connected) {
|
2013-07-06 14:24:55 +04:00
|
|
|
NS_WARNING("Remove call from a non-connected call group. Ignore!");
|
2015-01-09 10:52:00 +03:00
|
|
|
promise->MaybeReject(NS_ERROR_DOM_INVALID_STATE_ERR);
|
|
|
|
return promise.forget();
|
2013-07-06 14:24:55 +04:00
|
|
|
}
|
|
|
|
|
2013-10-31 16:05:51 +04:00
|
|
|
uint32_t serviceId = aCall.ServiceId();
|
2013-07-06 14:24:55 +04:00
|
|
|
uint32_t callIndex = aCall.CallIndex();
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<TelephonyCall> call = GetCall(serviceId, callIndex);
|
2015-01-09 10:52:00 +03:00
|
|
|
if (!call) {
|
2013-07-06 14:24:55 +04:00
|
|
|
NS_WARNING("Didn't have this call. Ignore!");
|
2015-01-09 10:52:00 +03:00
|
|
|
promise->MaybeReject(NS_ERROR_NOT_AVAILABLE);
|
|
|
|
return promise.forget();
|
2013-07-06 14:24:55 +04:00
|
|
|
}
|
2015-01-09 10:52:00 +03:00
|
|
|
|
|
|
|
nsCOMPtr<nsITelephonyCallback> callback = new TelephonyCallback(promise);
|
|
|
|
aRv = mTelephony->Service()->SeparateCall(serviceId, callIndex, callback);
|
|
|
|
NS_ENSURE_TRUE(!aRv.Failed(), nullptr);
|
|
|
|
|
|
|
|
return promise.forget();
|
2013-07-06 14:24:55 +04:00
|
|
|
}
|
|
|
|
|
2014-10-22 11:07:00 +04:00
|
|
|
already_AddRefed<Promise>
|
|
|
|
TelephonyCallGroup::HangUp(ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(!mCalls.IsEmpty());
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<Promise> promise = CreatePromise(aRv);
|
2015-01-09 10:52:00 +03:00
|
|
|
if (!promise) {
|
2014-10-22 11:07:00 +04:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2015-10-06 20:11:00 +03:00
|
|
|
if (mState == TelephonyCallGroupState::_empty) {
|
|
|
|
NS_WARNING(nsPrintfCString("We don't have a call group now!"
|
|
|
|
" (State: %s)",
|
|
|
|
TELEPHONY_GROUP_STATE(mState)).get());
|
|
|
|
promise->MaybeReject(NS_ERROR_DOM_INVALID_STATE_ERR);
|
|
|
|
return promise.forget();
|
|
|
|
}
|
|
|
|
|
2014-10-22 11:07:00 +04:00
|
|
|
nsCOMPtr<nsITelephonyCallback> callback = new TelephonyCallback(promise);
|
|
|
|
aRv = mTelephony->Service()->HangUpConference(mCalls[0]->ServiceId(),
|
|
|
|
callback);
|
|
|
|
NS_ENSURE_TRUE(!aRv.Failed(), nullptr);
|
|
|
|
return promise.forget();
|
|
|
|
}
|
|
|
|
|
2015-01-09 10:52:00 +03:00
|
|
|
already_AddRefed<Promise>
|
2013-07-06 14:24:55 +04:00
|
|
|
TelephonyCallGroup::Hold(ErrorResult& aRv)
|
|
|
|
{
|
2013-10-31 16:05:51 +04:00
|
|
|
MOZ_ASSERT(!mCalls.IsEmpty());
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<Promise> promise = CreatePromise(aRv);
|
2015-01-09 10:52:00 +03:00
|
|
|
if (!promise) {
|
|
|
|
return nullptr;
|
2013-07-06 14:24:55 +04:00
|
|
|
}
|
|
|
|
|
2015-03-26 11:27:25 +03: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;
|
2015-01-09 10:52:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return promise.forget();
|
2013-07-06 14:24:55 +04:00
|
|
|
}
|
|
|
|
|
2015-10-06 20:11:00 +03:00
|
|
|
nsresult
|
|
|
|
TelephonyCallGroup::Hold(nsITelephonyCallback* aCallback)
|
|
|
|
{
|
|
|
|
if (mState != TelephonyCallGroupState::Connected) {
|
|
|
|
NS_WARNING(nsPrintfCString("Resume non-connected call group is rejected!"
|
|
|
|
" (State: %s)",
|
|
|
|
TELEPHONY_GROUP_STATE(mState)).get());
|
|
|
|
aCallback->NotifyError(NS_LITERAL_STRING("InvalidStateError"));
|
|
|
|
return NS_ERROR_DOM_INVALID_STATE_ERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult rv = mTelephony->Service()->HoldConference(mCalls[0]->ServiceId(),
|
|
|
|
aCallback);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-01-09 10:52:00 +03:00
|
|
|
already_AddRefed<Promise>
|
2013-07-06 14:24:55 +04:00
|
|
|
TelephonyCallGroup::Resume(ErrorResult& aRv)
|
|
|
|
{
|
2013-10-31 16:05:51 +04:00
|
|
|
MOZ_ASSERT(!mCalls.IsEmpty());
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<Promise> promise = CreatePromise(aRv);
|
2015-01-09 10:52:00 +03:00
|
|
|
if (!promise) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2015-03-26 11:27:25 +03:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
TelephonyCallGroup::Resume(nsITelephonyCallback* aCallback)
|
|
|
|
{
|
2015-10-06 20:11:00 +03:00
|
|
|
if (mState != TelephonyCallGroupState::Held) {
|
|
|
|
NS_WARNING(nsPrintfCString("Resume non-held call group is rejected!"
|
|
|
|
" (State: %s)",
|
|
|
|
TELEPHONY_GROUP_STATE(mState)).get());
|
2015-03-26 11:27:25 +03:00
|
|
|
aCallback->NotifyError(NS_LITERAL_STRING("InvalidStateError"));
|
|
|
|
return NS_ERROR_DOM_INVALID_STATE_ERR;
|
2015-03-26 11:27:25 +03:00
|
|
|
}
|
|
|
|
|
2015-03-26 11:27:25 +03:00
|
|
|
nsresult rv = mTelephony->Service()->ResumeConference(mCalls[0]->ServiceId(),
|
|
|
|
aCallback);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
2013-07-06 14:24:55 +04:00
|
|
|
}
|