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