2013-06-01 10:53:06 +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: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* 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/. */
|
2012-01-10 02:28:47 +04:00
|
|
|
|
|
|
|
#ifndef mozilla_dom_telephony_telephony_h__
|
|
|
|
#define mozilla_dom_telephony_telephony_h__
|
|
|
|
|
2013-10-31 16:05:51 +04:00
|
|
|
#include "mozilla/dom/BindingDeclarations.h"
|
2014-02-27 10:12:30 +04:00
|
|
|
#include "mozilla/dom/Promise.h"
|
2013-09-12 07:47:14 +04:00
|
|
|
#include "mozilla/dom/telephony/TelephonyCommon.h"
|
2013-07-06 14:24:55 +04:00
|
|
|
|
|
|
|
#include "nsITelephonyProvider.h"
|
|
|
|
|
2013-07-12 18:36:13 +04:00
|
|
|
// Need to include TelephonyCall.h because we have inline methods that
|
|
|
|
// assume they see the definition of TelephonyCall.
|
|
|
|
#include "TelephonyCall.h"
|
2012-01-10 02:28:47 +04:00
|
|
|
|
|
|
|
class nsPIDOMWindow;
|
|
|
|
|
2013-07-06 14:24:55 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2013-09-17 19:16:02 +04:00
|
|
|
class OwningTelephonyCallOrTelephonyCallGroup;
|
2012-01-10 02:28:47 +04:00
|
|
|
|
2014-04-01 10:13:50 +04:00
|
|
|
class Telephony MOZ_FINAL : public DOMEventTargetHelper
|
2012-01-10 02:28:47 +04:00
|
|
|
{
|
2013-03-06 13:53:23 +04:00
|
|
|
/**
|
|
|
|
* Class Telephony doesn't actually inherit nsITelephonyListener.
|
|
|
|
* Instead, it owns an nsITelephonyListener derived instance mListener
|
|
|
|
* and passes it to nsITelephonyProvider. The onreceived events are first
|
|
|
|
* delivered to mListener and then forwarded to its owner, Telephony. See
|
|
|
|
* also bug 775997 comment #51.
|
|
|
|
*/
|
|
|
|
class Listener;
|
|
|
|
|
2014-02-27 10:12:30 +04:00
|
|
|
class Callback;
|
|
|
|
friend class Callback;
|
|
|
|
|
2013-05-09 14:44:13 +04:00
|
|
|
class EnumerationAck;
|
|
|
|
friend class EnumerationAck;
|
|
|
|
|
2013-03-06 13:53:23 +04:00
|
|
|
nsCOMPtr<nsITelephonyProvider> mProvider;
|
|
|
|
nsRefPtr<Listener> mListener;
|
2012-01-10 02:28:47 +04:00
|
|
|
|
|
|
|
TelephonyCall* mActiveCall;
|
|
|
|
nsTArray<nsRefPtr<TelephonyCall> > mCalls;
|
2013-07-15 12:27:19 +04:00
|
|
|
nsRefPtr<CallsList> mCallsList;
|
2012-01-10 02:28:47 +04:00
|
|
|
|
2013-07-06 14:24:55 +04:00
|
|
|
nsRefPtr<TelephonyCallGroup> mGroup;
|
|
|
|
|
2013-05-09 14:44:13 +04:00
|
|
|
bool mEnumerated;
|
2012-01-10 02:28:47 +04:00
|
|
|
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
2013-03-06 13:53:23 +04:00
|
|
|
NS_DECL_NSITELEPHONYLISTENER
|
2014-04-01 10:13:50 +04:00
|
|
|
NS_REALLY_FORWARD_NSIDOMEVENTTARGET(DOMEventTargetHelper)
|
2013-07-15 12:27:19 +04:00
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(Telephony,
|
2014-04-01 10:13:50 +04:00
|
|
|
DOMEventTargetHelper)
|
2013-07-15 12:27:19 +04:00
|
|
|
|
|
|
|
nsPIDOMWindow*
|
|
|
|
GetParentObject() const
|
|
|
|
{
|
|
|
|
return GetOwner();
|
|
|
|
}
|
|
|
|
|
|
|
|
// WrapperCache
|
|
|
|
virtual JSObject*
|
2014-04-09 02:27:18 +04:00
|
|
|
WrapObject(JSContext* aCx) MOZ_OVERRIDE;
|
2013-07-15 12:27:19 +04:00
|
|
|
|
|
|
|
// WebIDL
|
2014-02-27 10:12:30 +04:00
|
|
|
already_AddRefed<Promise>
|
|
|
|
Dial(const nsAString& aNumber, const Optional<uint32_t>& aServiceId);
|
2013-07-15 12:27:19 +04:00
|
|
|
|
2014-02-27 10:12:30 +04:00
|
|
|
already_AddRefed<Promise>
|
|
|
|
DialEmergency(const nsAString& aNumber, const Optional<uint32_t>& aServiceId);
|
2013-10-30 23:06:41 +04:00
|
|
|
|
2013-10-31 16:05:51 +04:00
|
|
|
void
|
2013-10-31 16:05:51 +04:00
|
|
|
StartTone(const nsAString& aDTMFChar, const Optional<uint32_t>& aServiceId,
|
|
|
|
ErrorResult& aRv);
|
2013-10-31 16:05:51 +04:00
|
|
|
|
|
|
|
void
|
2013-10-31 16:05:51 +04:00
|
|
|
StopTone(const Optional<uint32_t>& aServiceId, ErrorResult& aRv);
|
2013-10-31 16:05:51 +04:00
|
|
|
|
2013-07-15 12:27:19 +04:00
|
|
|
bool
|
|
|
|
GetMuted(ErrorResult& aRv) const;
|
|
|
|
|
|
|
|
void
|
|
|
|
SetMuted(bool aMuted, ErrorResult& aRv);
|
|
|
|
|
|
|
|
bool
|
|
|
|
GetSpeakerEnabled(ErrorResult& aRv) const;
|
|
|
|
|
|
|
|
void
|
|
|
|
SetSpeakerEnabled(bool aEnabled, ErrorResult& aRv);
|
|
|
|
|
2013-07-06 14:24:55 +04:00
|
|
|
void
|
2013-09-17 19:16:02 +04:00
|
|
|
GetActive(Nullable<OwningTelephonyCallOrTelephonyCallGroup>& aValue);
|
2013-07-15 12:27:19 +04:00
|
|
|
|
|
|
|
already_AddRefed<CallsList>
|
|
|
|
Calls() const;
|
|
|
|
|
2013-07-06 14:24:55 +04:00
|
|
|
already_AddRefed<TelephonyCallGroup>
|
|
|
|
ConferenceGroup() const;
|
|
|
|
|
2013-07-15 12:27:19 +04:00
|
|
|
IMPL_EVENT_HANDLER(incoming)
|
|
|
|
IMPL_EVENT_HANDLER(callschanged)
|
|
|
|
IMPL_EVENT_HANDLER(remoteheld)
|
|
|
|
IMPL_EVENT_HANDLER(remoteresumed)
|
2012-01-10 02:28:47 +04:00
|
|
|
|
|
|
|
static already_AddRefed<Telephony>
|
2013-07-12 18:36:13 +04:00
|
|
|
Create(nsPIDOMWindow* aOwner, ErrorResult& aRv);
|
|
|
|
|
2012-01-10 02:28:47 +04:00
|
|
|
void
|
|
|
|
AddCall(TelephonyCall* aCall)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(!mCalls.Contains(aCall), "Already know about this one!");
|
|
|
|
mCalls.AppendElement(aCall);
|
2013-10-31 16:05:51 +04:00
|
|
|
UpdateActiveCall(aCall, IsActiveState(aCall->CallState()));
|
2012-02-24 17:14:37 +04:00
|
|
|
NotifyCallsChanged(aCall);
|
2012-01-10 02:28:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
RemoveCall(TelephonyCall* aCall)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(mCalls.Contains(aCall), "Didn't know about this one!");
|
|
|
|
mCalls.RemoveElement(aCall);
|
2013-07-06 14:24:55 +04:00
|
|
|
UpdateActiveCall(aCall, false);
|
2012-02-24 17:14:37 +04:00
|
|
|
NotifyCallsChanged(aCall);
|
2012-01-10 02:28:47 +04:00
|
|
|
}
|
|
|
|
|
2013-03-06 13:53:23 +04:00
|
|
|
nsITelephonyProvider*
|
|
|
|
Provider() const
|
2012-01-10 02:28:47 +04:00
|
|
|
{
|
2013-03-06 13:53:23 +04:00
|
|
|
return mProvider;
|
2012-01-10 02:28:47 +04:00
|
|
|
}
|
|
|
|
|
2013-07-15 12:27:19 +04:00
|
|
|
const nsTArray<nsRefPtr<TelephonyCall> >&
|
|
|
|
CallsArray() const
|
|
|
|
{
|
|
|
|
return mCalls;
|
|
|
|
}
|
|
|
|
|
2013-05-24 21:22:20 +04:00
|
|
|
virtual void EventListenerAdded(nsIAtom* aType) MOZ_OVERRIDE;
|
|
|
|
|
2012-01-10 02:28:47 +04:00
|
|
|
private:
|
2014-01-07 06:53:23 +04:00
|
|
|
Telephony(nsPIDOMWindow* aOwner);
|
2012-01-10 02:28:47 +04:00
|
|
|
~Telephony();
|
|
|
|
|
2013-10-31 16:05:51 +04:00
|
|
|
void
|
|
|
|
Shutdown();
|
|
|
|
|
2013-10-31 16:05:51 +04:00
|
|
|
static bool
|
|
|
|
IsValidNumber(const nsAString& aNumber);
|
|
|
|
|
2013-10-31 16:05:51 +04:00
|
|
|
static uint32_t
|
|
|
|
GetNumServices();
|
|
|
|
|
|
|
|
static bool
|
|
|
|
IsValidServiceId(uint32_t aServiceId);
|
|
|
|
|
2013-10-31 16:05:51 +04:00
|
|
|
static bool
|
|
|
|
IsActiveState(uint16_t aCallState);
|
|
|
|
|
2013-10-31 16:05:51 +04:00
|
|
|
uint32_t
|
|
|
|
ProvidedOrDefaultServiceId(const Optional<uint32_t>& aServiceId);
|
|
|
|
|
2013-10-31 16:05:51 +04:00
|
|
|
bool
|
|
|
|
HasDialingCall();
|
|
|
|
|
|
|
|
bool
|
|
|
|
MatchActiveCall(TelephonyCall* aCall);
|
|
|
|
|
2014-02-27 10:12:30 +04:00
|
|
|
already_AddRefed<Promise>
|
|
|
|
DialInternal(uint32_t aServiceId, const nsAString& aNumber, bool isEmergency);
|
2013-10-31 16:05:51 +04:00
|
|
|
|
2012-02-24 17:14:37 +04:00
|
|
|
already_AddRefed<TelephonyCall>
|
2014-05-26 21:08:00 +04:00
|
|
|
CreateNewDialingCall(uint32_t aServiceId, const nsAString& aNumber,
|
|
|
|
uint32_t aCallIndex);
|
2012-02-24 17:14:37 +04:00
|
|
|
|
|
|
|
nsresult
|
|
|
|
NotifyCallsChanged(TelephonyCall* aCall);
|
2012-01-10 02:28:47 +04:00
|
|
|
|
2013-01-28 11:39:50 +04:00
|
|
|
nsresult
|
2013-10-31 16:05:51 +04:00
|
|
|
DispatchCallEvent(const nsAString& aType, TelephonyCall* aCall);
|
2013-05-09 14:44:13 +04:00
|
|
|
|
|
|
|
void
|
|
|
|
EnqueueEnumerationAck();
|
2013-07-06 14:24:55 +04:00
|
|
|
|
|
|
|
void
|
2013-10-31 16:05:51 +04:00
|
|
|
UpdateActiveCall(TelephonyCall* aCall, bool aIsActive);
|
2013-07-06 14:24:55 +04:00
|
|
|
|
|
|
|
already_AddRefed<TelephonyCall>
|
2013-10-31 16:05:51 +04:00
|
|
|
GetCall(uint32_t aServiceId, uint32_t aCallIndex);
|
2013-07-06 14:24:55 +04:00
|
|
|
|
2013-10-31 16:05:51 +04:00
|
|
|
already_AddRefed<TelephonyCall>
|
|
|
|
GetOutgoingCall();
|
|
|
|
|
|
|
|
already_AddRefed<TelephonyCall>
|
2013-10-31 16:05:51 +04:00
|
|
|
GetCallFromEverywhere(uint32_t aServiceId, uint32_t aCallIndex);
|
2012-01-10 02:28:47 +04:00
|
|
|
};
|
|
|
|
|
2013-09-12 07:47:14 +04:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
2012-01-10 02:28:47 +04:00
|
|
|
|
|
|
|
#endif // mozilla_dom_telephony_telephony_h__
|