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__
|
|
|
|
|
|
|
|
#include "TelephonyCommon.h"
|
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
|
|
|
|
|
|
|
#include "nsIDOMTelephony.h"
|
|
|
|
#include "nsIDOMTelephonyCall.h"
|
2013-03-06 01:53:23 -08:00
|
|
|
#include "nsITelephonyProvider.h"
|
2012-01-09 14:28:47 -08:00
|
|
|
|
|
|
|
class nsIScriptContext;
|
|
|
|
class nsPIDOMWindow;
|
|
|
|
|
|
|
|
BEGIN_TELEPHONY_NAMESPACE
|
|
|
|
|
2012-02-08 11:22:01 -08:00
|
|
|
class Telephony : public nsDOMEventTargetHelper,
|
2012-01-09 14:28:47 -08:00
|
|
|
public nsIDOMTelephony
|
|
|
|
{
|
2013-03-06 01:53:23 -08: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;
|
|
|
|
|
2013-05-09 03:44:13 -07:00
|
|
|
class EnumerationAck;
|
|
|
|
friend class EnumerationAck;
|
|
|
|
|
2013-03-06 01:53:23 -08:00
|
|
|
nsCOMPtr<nsITelephonyProvider> mProvider;
|
|
|
|
nsRefPtr<Listener> mListener;
|
2012-01-09 14:28:47 -08:00
|
|
|
|
|
|
|
TelephonyCall* mActiveCall;
|
|
|
|
nsTArray<nsRefPtr<TelephonyCall> > mCalls;
|
|
|
|
|
2012-02-23 07:09:11 -08:00
|
|
|
// Cached calls array object. Cleared whenever mCalls changes and then rebuilt
|
|
|
|
// once a page looks for the liveCalls attribute.
|
2013-06-18 03:00:38 -07:00
|
|
|
JS::Heap<JSObject*> mCallsArray;
|
2012-02-23 07:09:11 -08:00
|
|
|
|
|
|
|
bool mRooted;
|
2013-05-09 03:44:13 -07:00
|
|
|
bool mEnumerated;
|
2012-01-09 14:28:47 -08:00
|
|
|
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
NS_DECL_NSIDOMTELEPHONY
|
2013-03-06 01:53:23 -08:00
|
|
|
NS_DECL_NSITELEPHONYLISTENER
|
2013-05-24 10:22:20 -07:00
|
|
|
NS_REALLY_FORWARD_NSIDOMEVENTTARGET(nsDOMEventTargetHelper)
|
2012-02-23 07:09:11 -08:00
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(
|
|
|
|
Telephony,
|
|
|
|
nsDOMEventTargetHelper)
|
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);
|
|
|
|
|
|
|
|
static bool CheckPermission(nsPIDOMWindow* aOwner);
|
2012-01-09 14:28:47 -08:00
|
|
|
|
|
|
|
nsISupports*
|
2013-04-19 15:18:33 -07:00
|
|
|
ToISupports()
|
2012-01-09 14:28:47 -08:00
|
|
|
{
|
2013-04-19 15:18:33 -07:00
|
|
|
return static_cast<EventTarget*>(this);
|
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-07-30 07:20:58 -07:00
|
|
|
mCallsArray = nullptr;
|
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-07-30 07:20:58 -07:00
|
|
|
mCallsArray = nullptr;
|
2012-02-24 05:14:37 -08:00
|
|
|
NotifyCallsChanged(aCall);
|
2012-01-09 14:28:47 -08:00
|
|
|
}
|
|
|
|
|
2013-03-06 01:53:23 -08:00
|
|
|
nsITelephonyProvider*
|
|
|
|
Provider() const
|
2012-01-09 14:28:47 -08:00
|
|
|
{
|
2013-03-06 01:53:23 -08:00
|
|
|
return mProvider;
|
2012-01-09 14:28:47 -08:00
|
|
|
}
|
|
|
|
|
2013-05-24 10:22:20 -07:00
|
|
|
virtual void EventListenerAdded(nsIAtom* aType) MOZ_OVERRIDE;
|
|
|
|
|
2012-01-09 14:28:47 -08:00
|
|
|
private:
|
2012-02-24 05:14:37 -08:00
|
|
|
Telephony();
|
2012-01-09 14:28:47 -08:00
|
|
|
~Telephony();
|
|
|
|
|
2012-02-24 05:14:37 -08:00
|
|
|
already_AddRefed<TelephonyCall>
|
|
|
|
CreateNewDialingCall(const nsAString& aNumber);
|
|
|
|
|
2012-01-09 14:28:47 -08:00
|
|
|
void
|
2012-02-24 05:14:37 -08:00
|
|
|
NoteDialedCallFromOtherInstance(const nsAString& aNumber);
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
NotifyCallsChanged(TelephonyCall* aCall);
|
2012-01-09 14:28:47 -08:00
|
|
|
|
2012-07-20 05:08:24 -07:00
|
|
|
nsresult
|
|
|
|
DialInternal(bool isEmergency,
|
|
|
|
const nsAString& aNumber,
|
|
|
|
nsIDOMTelephonyCall** aResult);
|
|
|
|
|
2013-01-27 23:39:50 -08:00
|
|
|
nsresult
|
|
|
|
DispatchCallEvent(const nsAString& aType,
|
|
|
|
nsIDOMTelephonyCall* aCall);
|
2013-05-09 03:44:13 -07:00
|
|
|
|
|
|
|
void
|
|
|
|
EnqueueEnumerationAck();
|
2012-01-09 14:28:47 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
END_TELEPHONY_NAMESPACE
|
|
|
|
|
|
|
|
#endif // mozilla_dom_telephony_telephony_h__
|