Bug 717462 - WebTelephony: notify errors. r=philikon

This commit is contained in:
Price Tseng 2012-05-14 21:13:06 -07:00
parent fd1f4fb93f
commit bac98d5c4b
3 changed files with 34 additions and 1 deletions

View File

@ -43,6 +43,7 @@
#include "CallEvent.h"
#include "Telephony.h"
#include "DOMError.h"
USING_TELEPHONY_NAMESPACE
@ -62,6 +63,7 @@ TelephonyCall::Create(Telephony* aTelephony, const nsAString& aNumber,
call->mTelephony = aTelephony;
call->mNumber = aNumber;
call->mCallIndex = aCallIndex;
call->mError = nsnull;
call->ChangeStateInternal(aCallState, false);
@ -153,8 +155,22 @@ TelephonyCall::ChangeStateInternal(PRUint16 aCallState, bool aFireEvents)
void
TelephonyCall::NotifyError(const nsAString& aError)
{
// Set the error string
NS_ASSERTION(!mError, "Already have an error?");
mError = DOMError::CreateWithName(aError);
// Do the state transitions
ChangeStateInternal(nsIRadioInterfaceLayer::CALL_STATE_DISCONNECTED, true);
// Notify the error event
nsRefPtr<CallEvent> event = CallEvent::Create(this);
NS_ASSERTION(event, "This should never fail!");
if (NS_FAILED(event->Dispatch(ToIDOMEventTarget(),
NS_LITERAL_STRING("error")))) {
NS_WARNING("Failed to dispatch error event!");
}
}
NS_IMPL_CYCLE_COLLECTION_CLASS(TelephonyCall)
@ -174,6 +190,7 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(TelephonyCall,
NS_CYCLE_COLLECTION_TRAVERSE_EVENT_HANDLER(holding)
NS_CYCLE_COLLECTION_TRAVERSE_EVENT_HANDLER(held)
NS_CYCLE_COLLECTION_TRAVERSE_EVENT_HANDLER(resuming)
NS_CYCLE_COLLECTION_TRAVERSE_EVENT_HANDLER(error)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(TelephonyCall,
@ -190,6 +207,7 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(TelephonyCall,
NS_CYCLE_COLLECTION_UNLINK_EVENT_HANDLER(holding)
NS_CYCLE_COLLECTION_UNLINK_EVENT_HANDLER(held)
NS_CYCLE_COLLECTION_UNLINK_EVENT_HANDLER(resuming)
NS_CYCLE_COLLECTION_UNLINK_EVENT_HANDLER(error)
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(TelephonyCall)
@ -216,6 +234,13 @@ TelephonyCall::GetState(nsAString& aState)
return NS_OK;
}
NS_IMETHODIMP
TelephonyCall::GetError(nsIDOMDOMError** aError)
{
NS_IF_ADDREF(*aError = mError);
return NS_OK;
}
NS_IMETHODIMP
TelephonyCall::Answer()
{
@ -296,3 +321,4 @@ NS_IMPL_EVENT_HANDLER(TelephonyCall, disconnected)
NS_IMPL_EVENT_HANDLER(TelephonyCall, holding)
NS_IMPL_EVENT_HANDLER(TelephonyCall, held)
NS_IMPL_EVENT_HANDLER(TelephonyCall, resuming)
NS_IMPL_EVENT_HANDLER(TelephonyCall, error)

View File

@ -63,11 +63,13 @@ class TelephonyCall : public nsDOMEventTargetHelper,
NS_DECL_EVENT_HANDLER(holding)
NS_DECL_EVENT_HANDLER(held)
NS_DECL_EVENT_HANDLER(resuming)
NS_DECL_EVENT_HANDLER(error)
nsRefPtr<Telephony> mTelephony;
nsString mNumber;
nsString mState;
nsCOMPtr<nsIDOMDOMError> mError;
PRUint32 mCallIndex;
PRUint16 mCallState;

View File

@ -38,16 +38,19 @@
* ***** END LICENSE BLOCK ***** */
#include "nsIDOMEventTarget.idl"
#include "nsIDOMDOMError.idl"
interface nsIDOMEventListener;
[scriptable, builtinclass, uuid(2fb9502b-2054-4eda-8db7-3726c39144f7)]
[scriptable, builtinclass, uuid(d902afb1-2e1d-412e-bfa3-cb6a9453a4db)]
interface nsIDOMTelephonyCall : nsIDOMEventTarget
{
readonly attribute DOMString number;
readonly attribute DOMString state;
readonly attribute nsIDOMDOMError error;
void answer();
void hangUp();
void hold();
@ -65,4 +68,6 @@ interface nsIDOMTelephonyCall : nsIDOMEventTarget
attribute nsIDOMEventListener onholding;
attribute nsIDOMEventListener onheld;
attribute nsIDOMEventListener onresuming;
attribute nsIDOMEventListener onerror;
};