Bug 765684 - WebTelephony: invalid argument in Telephony::NotifyError. r=bent

This commit is contained in:
Hsinyi Tsai 2012-06-21 11:00:52 +08:00
parent f694bf793c
commit 0a3800a656

View File

@ -478,26 +478,33 @@ Telephony::EnumerateCallState(PRUint32 aCallIndex, PRUint16 aCallState,
NS_IMETHODIMP
Telephony::NotifyError(PRInt32 aCallIndex,
const nsAString& aError)
const nsAString& aError)
{
PRInt32 index = -1;
PRInt32 length = mCalls.Length();
nsRefPtr<TelephonyCall> callToNotify;
if (!mCalls.IsEmpty()) {
// The connection is not established yet. Get the latest call object.
if (aCallIndex == -1) {
callToNotify = mCalls[mCalls.Length() - 1];
} else {
// The connection has been established. Get the failed call.
for (PRUint32 index = 0; index < mCalls.Length(); index++) {
nsRefPtr<TelephonyCall>& call = mCalls[index];
if (call->CallIndex() == aCallIndex) {
callToNotify = call;
break;
}
}
}
}
// The connection is not established yet, remove the latest call object
if (aCallIndex == -1) {
if (length > 0) {
index = length - 1;
}
} else {
if (aCallIndex < 0 || aCallIndex >= length) {
return NS_ERROR_INVALID_ARG;
}
index = aCallIndex;
}
if (index != -1) {
mCalls[index]->NotifyError(aError);
if (!callToNotify) {
NS_ERROR("Don't call me with a bad call index!");
return NS_ERROR_UNEXPECTED;
}
// Set the call state to 'disconnected' and remove it from the calls list.
callToNotify->NotifyError(aError);
return NS_OK;
}