Bug 1014903 - Get active call by query. r=hsinyi

This commit is contained in:
Szu-Yu Chen [:aknow] 2014-06-12 19:34:00 -04:00
Родитель adec138b52
Коммит b3b134d636
2 изменённых файлов: 11 добавлений и 38 удалений

Просмотреть файл

@ -111,7 +111,7 @@ public:
};
Telephony::Telephony(nsPIDOMWindow* aOwner)
: DOMEventTargetHelper(aOwner), mActiveCall(nullptr), mEnumerated(false)
: DOMEventTargetHelper(aOwner), mEnumerated(false)
{
}
@ -207,6 +207,8 @@ bool
Telephony::IsActiveState(uint16_t aCallState) {
return aCallState == nsITelephonyService::CALL_STATE_DIALING ||
aCallState == nsITelephonyService::CALL_STATE_ALERTING ||
aCallState == nsITelephonyService::CALL_STATE_HOLDING ||
aCallState == nsITelephonyService::CALL_STATE_DISCONNECTING ||
aCallState == nsITelephonyService::CALL_STATE_CONNECTED;
}
@ -236,14 +238,6 @@ Telephony::HasDialingCall()
return false;
}
bool
Telephony::MatchActiveCall(TelephonyCall* aCall)
{
return (mActiveCall &&
mActiveCall->CallIndex() == aCall->CallIndex() &&
mActiveCall->ServiceId() == aCall->ServiceId());
}
already_AddRefed<Promise>
Telephony::DialInternal(uint32_t aServiceId, const nsAString& aNumber,
bool aIsEmergency)
@ -300,16 +294,6 @@ Telephony::NotifyCallsChanged(TelephonyCall* aCall)
return DispatchCallEvent(NS_LITERAL_STRING("callschanged"), aCall);
}
void
Telephony::UpdateActiveCall(TelephonyCall* aCall, bool aIsActive)
{
if (aIsActive) {
mActiveCall = aCall;
} else if (MatchActiveCall(aCall)) {
mActiveCall = nullptr;
}
}
already_AddRefed<TelephonyCall>
Telephony::GetCall(uint32_t aServiceId, uint32_t aCallIndex)
{
@ -351,7 +335,6 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(Telephony,
DOMEventTargetHelper)
tmp->Shutdown();
tmp->mActiveCall = nullptr;
NS_IMPL_CYCLE_COLLECTION_UNLINK(mCalls)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mCallsList)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mGroup)
@ -451,11 +434,16 @@ Telephony::SetSpeakerEnabled(bool aEnabled, ErrorResult& aRv)
void
Telephony::GetActive(Nullable<OwningTelephonyCallOrTelephonyCallGroup>& aValue)
{
if (mActiveCall) {
aValue.SetValue().SetAsTelephonyCall() = mActiveCall;
} else if (mGroup->CallState() == nsITelephonyService::CALL_STATE_CONNECTED) {
if (mGroup->CallState() == nsITelephonyService::CALL_STATE_CONNECTED) {
aValue.SetValue().SetAsTelephonyCallGroup() = mGroup;
} else {
// Search the first active call.
for (uint32_t i = 0; i < mCalls.Length(); i++) {
if (IsActiveState(mCalls[i]->CallState())) {
aValue.SetValue().SetAsTelephonyCall() = mCalls[i];
return;
}
}
aValue.SetNull();
}
}
@ -503,10 +491,6 @@ Telephony::CallStateChanged(uint32_t aServiceId, uint32_t aCallIndex,
modifiedCall->UpdateSwitchable(aIsSwitchable);
modifiedCall->UpdateMergeable(aIsMergeable);
if (!aIsConference) {
UpdateActiveCall(modifiedCall, IsActiveState(aCallState));
}
if (modifiedCall->CallState() != aCallState) {
// We don't fire the statechange event on a call in conference here.
// Instead, the event will be fired later in
@ -661,8 +645,6 @@ Telephony::NotifyError(uint32_t aServiceId,
return NS_ERROR_UNEXPECTED;
}
UpdateActiveCall(callToNotify, false);
// Set the call state to 'disconnected' and remove it from the calls list.
callToNotify->NotifyError(aError);

Просмотреть файл

@ -44,7 +44,6 @@ class Telephony MOZ_FINAL : public DOMEventTargetHelper
nsCOMPtr<nsITelephonyService> mService;
nsRefPtr<Listener> mListener;
TelephonyCall* mActiveCall;
nsTArray<nsRefPtr<TelephonyCall> > mCalls;
nsRefPtr<CallsList> mCallsList;
@ -117,7 +116,6 @@ public:
{
NS_ASSERTION(!mCalls.Contains(aCall), "Already know about this one!");
mCalls.AppendElement(aCall);
UpdateActiveCall(aCall, IsActiveState(aCall->CallState()));
NotifyCallsChanged(aCall);
}
@ -126,7 +124,6 @@ public:
{
NS_ASSERTION(mCalls.Contains(aCall), "Didn't know about this one!");
mCalls.RemoveElement(aCall);
UpdateActiveCall(aCall, false);
NotifyCallsChanged(aCall);
}
@ -169,9 +166,6 @@ private:
bool
HasDialingCall();
bool
MatchActiveCall(TelephonyCall* aCall);
already_AddRefed<Promise>
DialInternal(uint32_t aServiceId, const nsAString& aNumber, bool isEmergency);
@ -188,9 +182,6 @@ private:
void
EnqueueEnumerationAck();
void
UpdateActiveCall(TelephonyCall* aCall, bool aIsActive);
already_AddRefed<TelephonyCall>
GetCall(uint32_t aServiceId, uint32_t aCallIndex);