2012-01-09 14:28:47 -08:00
|
|
|
/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
|
|
|
|
/* vim: set ts=2 et sw=2 tw=40: */
|
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"
|
|
|
|
|
|
|
|
#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;
|
|
|
|
|
|
|
|
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.
|
|
|
|
JSObject* mCallsArray;
|
|
|
|
|
|
|
|
bool mRooted;
|
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-04-16 14:16:08 -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-03-06 01:53:23 -08:00
|
|
|
Create(nsPIDOMWindow* aOwner, nsITelephonyProvider* aProvider);
|
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
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2012-01-09 14:28:47 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
END_TELEPHONY_NAMESPACE
|
|
|
|
|
|
|
|
#endif // mozilla_dom_telephony_telephony_h__
|