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
|
|
|
|
2014-06-03 18:15:25 +04:00
|
|
|
#include "nsITelephonyService.h"
|
2013-07-06 14:24:55 +04:00
|
|
|
|
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-08-20 05:01:49 +04:00
|
|
|
class Telephony MOZ_FINAL : public DOMEventTargetHelper,
|
|
|
|
private nsITelephonyListener
|
2012-01-10 02:28:47 +04:00
|
|
|
{
|
2013-03-06 13:53:23 +04:00
|
|
|
/**
|
2014-08-20 05:01:49 +04:00
|
|
|
* Class Telephony doesn't actually expose nsITelephonyListener.
|
2013-03-06 13:53:23 +04:00
|
|
|
* Instead, it owns an nsITelephonyListener derived instance mListener
|
2014-06-03 18:15:25 +04:00
|
|
|
* and passes it to nsITelephonyService. The onreceived events are first
|
2013-03-06 13:53:23 +04:00
|
|
|
* 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;
|
|
|
|
|
2014-06-03 18:15:30 +04:00
|
|
|
nsCOMPtr<nsITelephonyService> mService;
|
2013-03-06 13:53:23 +04:00
|
|
|
nsRefPtr<Listener> mListener;
|
2012-01-10 02:28:47 +04:00
|
|
|
|
|
|
|
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>
|
2014-07-19 05:31:11 +04:00
|
|
|
Dial(const nsAString& aNumber, const Optional<uint32_t>& aServiceId,
|
|
|
|
ErrorResult& aRv);
|
2013-07-15 12:27:19 +04:00
|
|
|
|
2014-02-27 10:12:30 +04:00
|
|
|
already_AddRefed<Promise>
|
2014-07-19 05:31:11 +04:00
|
|
|
DialEmergency(const nsAString& aNumber, const Optional<uint32_t>& aServiceId,
|
|
|
|
ErrorResult& aRv);
|
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;
|
|
|
|
|
2014-07-21 21:17:00 +04:00
|
|
|
IMPL_EVENT_HANDLER(ready)
|
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);
|
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);
|
2012-02-24 17:14:37 +04:00
|
|
|
NotifyCallsChanged(aCall);
|
2012-01-10 02:28:47 +04:00
|
|
|
}
|
|
|
|
|
2014-06-03 18:15:25 +04:00
|
|
|
nsITelephonyService*
|
2014-06-03 18:15:30 +04:00
|
|
|
Service() const
|
2012-01-10 02:28:47 +04:00
|
|
|
{
|
2014-06-03 18:15:30 +04:00
|
|
|
return mService;
|
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-09-02 04:49:25 +04:00
|
|
|
explicit 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();
|
|
|
|
|
2014-02-27 10:12:30 +04:00
|
|
|
already_AddRefed<Promise>
|
2014-07-19 05:31:11 +04:00
|
|
|
DialInternal(uint32_t aServiceId, const nsAString& aNumber, bool aEmergency,
|
|
|
|
ErrorResult& aRv);
|
2014-06-24 14:52:00 +04: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 16:05:51 +04:00
|
|
|
|
2012-02-24 17:14:37 +04:00
|
|
|
already_AddRefed<TelephonyCall>
|
2014-06-24 14:52:00 +04: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 17:14:37 +04:00
|
|
|
|
2014-07-21 21:17:00 +04:00
|
|
|
nsresult
|
|
|
|
NotifyEvent(const nsAString& aType);
|
|
|
|
|
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
|
2014-07-21 21:17:00 +04:00
|
|
|
EnqueueEnumerationAck(const nsAString& aType);
|
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>
|
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__
|