|
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */ |
|
3 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
4 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
6 |
|
7 #ifndef mozilla_dom_telephony_telephony_h__ |
|
8 #define mozilla_dom_telephony_telephony_h__ |
|
9 |
|
10 #include "mozilla/dom/BindingDeclarations.h" |
|
11 #include "mozilla/dom/Promise.h" |
|
12 #include "mozilla/dom/telephony/TelephonyCommon.h" |
|
13 |
|
14 #include "nsITelephonyProvider.h" |
|
15 |
|
16 // Need to include TelephonyCall.h because we have inline methods that |
|
17 // assume they see the definition of TelephonyCall. |
|
18 #include "TelephonyCall.h" |
|
19 |
|
20 class nsPIDOMWindow; |
|
21 |
|
22 namespace mozilla { |
|
23 namespace dom { |
|
24 |
|
25 class OwningTelephonyCallOrTelephonyCallGroup; |
|
26 |
|
27 class Telephony MOZ_FINAL : public DOMEventTargetHelper |
|
28 { |
|
29 /** |
|
30 * Class Telephony doesn't actually inherit nsITelephonyListener. |
|
31 * Instead, it owns an nsITelephonyListener derived instance mListener |
|
32 * and passes it to nsITelephonyProvider. The onreceived events are first |
|
33 * delivered to mListener and then forwarded to its owner, Telephony. See |
|
34 * also bug 775997 comment #51. |
|
35 */ |
|
36 class Listener; |
|
37 |
|
38 class Callback; |
|
39 friend class Callback; |
|
40 |
|
41 class EnumerationAck; |
|
42 friend class EnumerationAck; |
|
43 |
|
44 nsCOMPtr<nsITelephonyProvider> mProvider; |
|
45 nsRefPtr<Listener> mListener; |
|
46 |
|
47 TelephonyCall* mActiveCall; |
|
48 nsTArray<nsRefPtr<TelephonyCall> > mCalls; |
|
49 nsRefPtr<CallsList> mCallsList; |
|
50 |
|
51 nsRefPtr<TelephonyCallGroup> mGroup; |
|
52 |
|
53 bool mEnumerated; |
|
54 |
|
55 public: |
|
56 NS_DECL_ISUPPORTS_INHERITED |
|
57 NS_DECL_NSITELEPHONYLISTENER |
|
58 NS_REALLY_FORWARD_NSIDOMEVENTTARGET(DOMEventTargetHelper) |
|
59 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(Telephony, |
|
60 DOMEventTargetHelper) |
|
61 |
|
62 nsPIDOMWindow* |
|
63 GetParentObject() const |
|
64 { |
|
65 return GetOwner(); |
|
66 } |
|
67 |
|
68 // WrapperCache |
|
69 virtual JSObject* |
|
70 WrapObject(JSContext* aCx) MOZ_OVERRIDE; |
|
71 |
|
72 // WebIDL |
|
73 already_AddRefed<Promise> |
|
74 Dial(const nsAString& aNumber, const Optional<uint32_t>& aServiceId); |
|
75 |
|
76 already_AddRefed<Promise> |
|
77 DialEmergency(const nsAString& aNumber, const Optional<uint32_t>& aServiceId); |
|
78 |
|
79 void |
|
80 StartTone(const nsAString& aDTMFChar, const Optional<uint32_t>& aServiceId, |
|
81 ErrorResult& aRv); |
|
82 |
|
83 void |
|
84 StopTone(const Optional<uint32_t>& aServiceId, ErrorResult& aRv); |
|
85 |
|
86 bool |
|
87 GetMuted(ErrorResult& aRv) const; |
|
88 |
|
89 void |
|
90 SetMuted(bool aMuted, ErrorResult& aRv); |
|
91 |
|
92 bool |
|
93 GetSpeakerEnabled(ErrorResult& aRv) const; |
|
94 |
|
95 void |
|
96 SetSpeakerEnabled(bool aEnabled, ErrorResult& aRv); |
|
97 |
|
98 void |
|
99 GetActive(Nullable<OwningTelephonyCallOrTelephonyCallGroup>& aValue); |
|
100 |
|
101 already_AddRefed<CallsList> |
|
102 Calls() const; |
|
103 |
|
104 already_AddRefed<TelephonyCallGroup> |
|
105 ConferenceGroup() const; |
|
106 |
|
107 IMPL_EVENT_HANDLER(incoming) |
|
108 IMPL_EVENT_HANDLER(callschanged) |
|
109 IMPL_EVENT_HANDLER(remoteheld) |
|
110 IMPL_EVENT_HANDLER(remoteresumed) |
|
111 |
|
112 static already_AddRefed<Telephony> |
|
113 Create(nsPIDOMWindow* aOwner, ErrorResult& aRv); |
|
114 |
|
115 void |
|
116 AddCall(TelephonyCall* aCall) |
|
117 { |
|
118 NS_ASSERTION(!mCalls.Contains(aCall), "Already know about this one!"); |
|
119 mCalls.AppendElement(aCall); |
|
120 UpdateActiveCall(aCall, IsActiveState(aCall->CallState())); |
|
121 NotifyCallsChanged(aCall); |
|
122 } |
|
123 |
|
124 void |
|
125 RemoveCall(TelephonyCall* aCall) |
|
126 { |
|
127 NS_ASSERTION(mCalls.Contains(aCall), "Didn't know about this one!"); |
|
128 mCalls.RemoveElement(aCall); |
|
129 UpdateActiveCall(aCall, false); |
|
130 NotifyCallsChanged(aCall); |
|
131 } |
|
132 |
|
133 nsITelephonyProvider* |
|
134 Provider() const |
|
135 { |
|
136 return mProvider; |
|
137 } |
|
138 |
|
139 const nsTArray<nsRefPtr<TelephonyCall> >& |
|
140 CallsArray() const |
|
141 { |
|
142 return mCalls; |
|
143 } |
|
144 |
|
145 virtual void EventListenerAdded(nsIAtom* aType) MOZ_OVERRIDE; |
|
146 |
|
147 private: |
|
148 Telephony(nsPIDOMWindow* aOwner); |
|
149 ~Telephony(); |
|
150 |
|
151 void |
|
152 Shutdown(); |
|
153 |
|
154 static bool |
|
155 IsValidNumber(const nsAString& aNumber); |
|
156 |
|
157 static uint32_t |
|
158 GetNumServices(); |
|
159 |
|
160 static bool |
|
161 IsValidServiceId(uint32_t aServiceId); |
|
162 |
|
163 static bool |
|
164 IsActiveState(uint16_t aCallState); |
|
165 |
|
166 uint32_t |
|
167 ProvidedOrDefaultServiceId(const Optional<uint32_t>& aServiceId); |
|
168 |
|
169 bool |
|
170 HasDialingCall(); |
|
171 |
|
172 bool |
|
173 MatchActiveCall(TelephonyCall* aCall); |
|
174 |
|
175 already_AddRefed<Promise> |
|
176 DialInternal(uint32_t aServiceId, const nsAString& aNumber, bool isEmergency); |
|
177 |
|
178 already_AddRefed<TelephonyCall> |
|
179 CreateNewDialingCall(uint32_t aServiceId, const nsAString& aNumber); |
|
180 |
|
181 nsresult |
|
182 NotifyCallsChanged(TelephonyCall* aCall); |
|
183 |
|
184 nsresult |
|
185 DispatchCallEvent(const nsAString& aType, TelephonyCall* aCall); |
|
186 |
|
187 void |
|
188 EnqueueEnumerationAck(); |
|
189 |
|
190 void |
|
191 UpdateActiveCall(TelephonyCall* aCall, bool aIsActive); |
|
192 |
|
193 already_AddRefed<TelephonyCall> |
|
194 GetCall(uint32_t aServiceId, uint32_t aCallIndex); |
|
195 |
|
196 already_AddRefed<TelephonyCall> |
|
197 GetOutgoingCall(); |
|
198 |
|
199 already_AddRefed<TelephonyCall> |
|
200 GetCallFromEverywhere(uint32_t aServiceId, uint32_t aCallIndex); |
|
201 }; |
|
202 |
|
203 } // namespace dom |
|
204 } // namespace mozilla |
|
205 |
|
206 #endif // mozilla_dom_telephony_telephony_h__ |