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