michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim: set ts=8 sts=2 et sw=2 tw=80: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef mozilla_dom_telephony_telephony_h__ michael@0: #define mozilla_dom_telephony_telephony_h__ michael@0: michael@0: #include "mozilla/dom/BindingDeclarations.h" michael@0: #include "mozilla/dom/Promise.h" michael@0: #include "mozilla/dom/telephony/TelephonyCommon.h" michael@0: michael@0: #include "nsITelephonyProvider.h" michael@0: michael@0: // Need to include TelephonyCall.h because we have inline methods that michael@0: // assume they see the definition of TelephonyCall. michael@0: #include "TelephonyCall.h" michael@0: michael@0: class nsPIDOMWindow; michael@0: michael@0: namespace mozilla { michael@0: namespace dom { michael@0: michael@0: class OwningTelephonyCallOrTelephonyCallGroup; michael@0: michael@0: class Telephony MOZ_FINAL : public DOMEventTargetHelper michael@0: { michael@0: /** michael@0: * Class Telephony doesn't actually inherit nsITelephonyListener. michael@0: * Instead, it owns an nsITelephonyListener derived instance mListener michael@0: * and passes it to nsITelephonyProvider. The onreceived events are first michael@0: * delivered to mListener and then forwarded to its owner, Telephony. See michael@0: * also bug 775997 comment #51. michael@0: */ michael@0: class Listener; michael@0: michael@0: class Callback; michael@0: friend class Callback; michael@0: michael@0: class EnumerationAck; michael@0: friend class EnumerationAck; michael@0: michael@0: nsCOMPtr mProvider; michael@0: nsRefPtr mListener; michael@0: michael@0: TelephonyCall* mActiveCall; michael@0: nsTArray > mCalls; michael@0: nsRefPtr mCallsList; michael@0: michael@0: nsRefPtr mGroup; michael@0: michael@0: bool mEnumerated; michael@0: michael@0: public: michael@0: NS_DECL_ISUPPORTS_INHERITED michael@0: NS_DECL_NSITELEPHONYLISTENER michael@0: NS_REALLY_FORWARD_NSIDOMEVENTTARGET(DOMEventTargetHelper) michael@0: NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(Telephony, michael@0: DOMEventTargetHelper) michael@0: michael@0: nsPIDOMWindow* michael@0: GetParentObject() const michael@0: { michael@0: return GetOwner(); michael@0: } michael@0: michael@0: // WrapperCache michael@0: virtual JSObject* michael@0: WrapObject(JSContext* aCx) MOZ_OVERRIDE; michael@0: michael@0: // WebIDL michael@0: already_AddRefed michael@0: Dial(const nsAString& aNumber, const Optional& aServiceId); michael@0: michael@0: already_AddRefed michael@0: DialEmergency(const nsAString& aNumber, const Optional& aServiceId); michael@0: michael@0: void michael@0: StartTone(const nsAString& aDTMFChar, const Optional& aServiceId, michael@0: ErrorResult& aRv); michael@0: michael@0: void michael@0: StopTone(const Optional& aServiceId, ErrorResult& aRv); michael@0: michael@0: bool michael@0: GetMuted(ErrorResult& aRv) const; michael@0: michael@0: void michael@0: SetMuted(bool aMuted, ErrorResult& aRv); michael@0: michael@0: bool michael@0: GetSpeakerEnabled(ErrorResult& aRv) const; michael@0: michael@0: void michael@0: SetSpeakerEnabled(bool aEnabled, ErrorResult& aRv); michael@0: michael@0: void michael@0: GetActive(Nullable& aValue); michael@0: michael@0: already_AddRefed michael@0: Calls() const; michael@0: michael@0: already_AddRefed michael@0: ConferenceGroup() const; michael@0: michael@0: IMPL_EVENT_HANDLER(incoming) michael@0: IMPL_EVENT_HANDLER(callschanged) michael@0: IMPL_EVENT_HANDLER(remoteheld) michael@0: IMPL_EVENT_HANDLER(remoteresumed) michael@0: michael@0: static already_AddRefed michael@0: Create(nsPIDOMWindow* aOwner, ErrorResult& aRv); michael@0: michael@0: void michael@0: AddCall(TelephonyCall* aCall) michael@0: { michael@0: NS_ASSERTION(!mCalls.Contains(aCall), "Already know about this one!"); michael@0: mCalls.AppendElement(aCall); michael@0: UpdateActiveCall(aCall, IsActiveState(aCall->CallState())); michael@0: NotifyCallsChanged(aCall); michael@0: } michael@0: michael@0: void michael@0: RemoveCall(TelephonyCall* aCall) michael@0: { michael@0: NS_ASSERTION(mCalls.Contains(aCall), "Didn't know about this one!"); michael@0: mCalls.RemoveElement(aCall); michael@0: UpdateActiveCall(aCall, false); michael@0: NotifyCallsChanged(aCall); michael@0: } michael@0: michael@0: nsITelephonyProvider* michael@0: Provider() const michael@0: { michael@0: return mProvider; michael@0: } michael@0: michael@0: const nsTArray >& michael@0: CallsArray() const michael@0: { michael@0: return mCalls; michael@0: } michael@0: michael@0: virtual void EventListenerAdded(nsIAtom* aType) MOZ_OVERRIDE; michael@0: michael@0: private: michael@0: Telephony(nsPIDOMWindow* aOwner); michael@0: ~Telephony(); michael@0: michael@0: void michael@0: Shutdown(); michael@0: michael@0: static bool michael@0: IsValidNumber(const nsAString& aNumber); michael@0: michael@0: static uint32_t michael@0: GetNumServices(); michael@0: michael@0: static bool michael@0: IsValidServiceId(uint32_t aServiceId); michael@0: michael@0: static bool michael@0: IsActiveState(uint16_t aCallState); michael@0: michael@0: uint32_t michael@0: ProvidedOrDefaultServiceId(const Optional& aServiceId); michael@0: michael@0: bool michael@0: HasDialingCall(); michael@0: michael@0: bool michael@0: MatchActiveCall(TelephonyCall* aCall); michael@0: michael@0: already_AddRefed michael@0: DialInternal(uint32_t aServiceId, const nsAString& aNumber, bool isEmergency); michael@0: michael@0: already_AddRefed michael@0: CreateNewDialingCall(uint32_t aServiceId, const nsAString& aNumber); michael@0: michael@0: nsresult michael@0: NotifyCallsChanged(TelephonyCall* aCall); michael@0: michael@0: nsresult michael@0: DispatchCallEvent(const nsAString& aType, TelephonyCall* aCall); michael@0: michael@0: void michael@0: EnqueueEnumerationAck(); michael@0: michael@0: void michael@0: UpdateActiveCall(TelephonyCall* aCall, bool aIsActive); michael@0: michael@0: already_AddRefed michael@0: GetCall(uint32_t aServiceId, uint32_t aCallIndex); michael@0: michael@0: already_AddRefed michael@0: GetOutgoingCall(); michael@0: michael@0: already_AddRefed michael@0: GetCallFromEverywhere(uint32_t aServiceId, uint32_t aCallIndex); michael@0: }; michael@0: michael@0: } // namespace dom michael@0: } // namespace mozilla michael@0: michael@0: #endif // mozilla_dom_telephony_telephony_h__