mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1129882 - backout 9c6fde246f6e and 847b57aaeff7 for causing 1193840 on a CLOSED TREE r=szchen, r=htsai
This commit is contained in:
parent
cf9125daad
commit
2ee84dff73
@ -7,7 +7,6 @@
|
||||
#include "Telephony.h"
|
||||
|
||||
#include "mozilla/Preferences.h"
|
||||
#include "mozilla/dom/AudioChannelBinding.h"
|
||||
#include "mozilla/dom/CallEvent.h"
|
||||
#include "mozilla/dom/MozMobileConnectionBinding.h"
|
||||
#include "mozilla/dom/Promise.h"
|
||||
@ -21,7 +20,6 @@
|
||||
#include "nsServiceManagerUtils.h"
|
||||
#include "nsThreadUtils.h"
|
||||
|
||||
#include "AudioChannelService.h"
|
||||
#include "CallsList.h"
|
||||
#include "TelephonyCall.h"
|
||||
#include "TelephonyCallGroup.h"
|
||||
@ -64,12 +62,8 @@ public:
|
||||
};
|
||||
|
||||
Telephony::Telephony(nsPIDOMWindow* aOwner)
|
||||
: DOMEventTargetHelper(aOwner),
|
||||
mIsAudioStartPlaying(false),
|
||||
mAudioAgentNotify(nsIAudioChannelAgent::AUDIO_AGENT_NOTIFY),
|
||||
mHaveDispatchedInterruptBeginEvent(false)
|
||||
: DOMEventTargetHelper(aOwner)
|
||||
{
|
||||
MOZ_ASSERT(aOwner);
|
||||
nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(aOwner);
|
||||
MOZ_ASSERT(global);
|
||||
|
||||
@ -78,7 +72,6 @@ Telephony::Telephony(nsPIDOMWindow* aOwner)
|
||||
MOZ_ASSERT(!rv.Failed());
|
||||
|
||||
mReadyPromise = promise;
|
||||
mMuted = AudioChannelService::IsAudioChannelMutedByDefault();
|
||||
}
|
||||
|
||||
Telephony::~Telephony()
|
||||
@ -525,61 +518,6 @@ Telephony::StopTone(const Optional<uint32_t>& aServiceId, ErrorResult& aRv)
|
||||
aRv = mService->StopTone(serviceId);
|
||||
}
|
||||
|
||||
void
|
||||
Telephony::OwnAudioChannel(ErrorResult& aRv)
|
||||
{
|
||||
if (mAudioAgent) {
|
||||
return;
|
||||
}
|
||||
|
||||
mAudioAgent = do_CreateInstance("@mozilla.org/audiochannelagent;1");
|
||||
MOZ_ASSERT(mAudioAgent);
|
||||
aRv = mAudioAgent->Init(GetParentObject(),
|
||||
(int32_t)AudioChannel::Telephony, this);
|
||||
if (NS_WARN_IF(aRv.Failed())) {
|
||||
return;
|
||||
}
|
||||
aRv = HandleAudioAgentState();
|
||||
if (NS_WARN_IF(aRv.Failed())) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
nsresult
|
||||
Telephony::HandleAudioAgentState()
|
||||
{
|
||||
if (!mAudioAgent) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
Nullable<OwningTelephonyCallOrTelephonyCallGroup> activeCall;
|
||||
GetActive(activeCall);
|
||||
nsresult rv;
|
||||
// Only stop agent when the call is disconnected.
|
||||
if ((!mCalls.Length() && !mGroup->CallsArray().Length()) &&
|
||||
mIsAudioStartPlaying) {
|
||||
mIsAudioStartPlaying = false;
|
||||
rv = mAudioAgent->NotifyStoppedPlaying(mAudioAgentNotify);
|
||||
mAudioAgent = nullptr;
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
} else if (!activeCall.IsNull() && !mIsAudioStartPlaying) {
|
||||
mIsAudioStartPlaying = true;
|
||||
float volume = 1.0;
|
||||
bool muted = false;
|
||||
rv = mAudioAgent->NotifyStartedPlaying(mAudioAgentNotify, &volume, &muted);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
rv = WindowVolumeChanged(volume, muted);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
bool
|
||||
Telephony::GetMuted(ErrorResult& aRv) const
|
||||
{
|
||||
@ -653,78 +591,13 @@ Telephony::GetReady(ErrorResult& aRv) const
|
||||
return promise.forget();
|
||||
}
|
||||
|
||||
// nsIAudioChannelAgentCallback
|
||||
|
||||
NS_IMETHODIMP
|
||||
Telephony::WindowVolumeChanged(float aVolume, bool aMuted)
|
||||
{
|
||||
// Check the limitation of the network connection
|
||||
if (mCalls.Length() > 1 ||
|
||||
(mCalls.Length() == 1 && mGroup->CallsArray().Length())) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
ErrorResult rv;
|
||||
nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(GetOwner());
|
||||
nsRefPtr<Promise> promise = Promise::Create(global, rv);
|
||||
if (NS_WARN_IF(rv.Failed())) {
|
||||
return rv.StealNSResult();
|
||||
}
|
||||
|
||||
// Check the single call or conference call
|
||||
bool isSingleCall = mCalls.Length();
|
||||
nsCOMPtr<nsITelephonyCallback> callback = new TelephonyCallback(promise);
|
||||
if (isSingleCall) {
|
||||
rv = aMuted ? mCalls[0]->Hold(callback) : mCalls[0]->Resume(callback);
|
||||
} else {
|
||||
rv = aMuted ? mGroup->Hold(callback) : mGroup->Resume(callback);
|
||||
}
|
||||
if (NS_WARN_IF(rv.Failed())) {
|
||||
return rv.StealNSResult();
|
||||
}
|
||||
|
||||
// These events will be triggered when the telephony is interrupted by other
|
||||
// audio channel.
|
||||
if (mMuted != aMuted) {
|
||||
mMuted = aMuted;
|
||||
// We should not dispatch "mozinterruptend" when the system app initializes
|
||||
// the telephony audio from muted to unmuted at the first time. The event
|
||||
// "mozinterruptend" must be dispatched after the "mozinterruptbegin".
|
||||
if (!mHaveDispatchedInterruptBeginEvent && mMuted) {
|
||||
DispatchTrustedEvent(NS_LITERAL_STRING("mozinterruptbegin"));
|
||||
mHaveDispatchedInterruptBeginEvent = mMuted;
|
||||
} else if (mHaveDispatchedInterruptBeginEvent && !mMuted) {
|
||||
DispatchTrustedEvent(NS_LITERAL_STRING("mozinterruptend"));
|
||||
mHaveDispatchedInterruptBeginEvent = mMuted;
|
||||
}
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
Telephony::WindowAudioCaptureChanged()
|
||||
{
|
||||
// Do nothing
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// nsITelephonyListener
|
||||
|
||||
NS_IMETHODIMP
|
||||
Telephony::CallStateChanged(uint32_t aLength, nsITelephonyCallInfo** aAllInfo)
|
||||
{
|
||||
nsresult rv;
|
||||
for (uint32_t i = 0; i < aLength; ++i) {
|
||||
rv = HandleCallInfo(aAllInfo[i]);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
|
||||
rv = HandleAudioAgentState();
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
HandleCallInfo(aAllInfo[i]);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
@ -732,8 +605,7 @@ Telephony::CallStateChanged(uint32_t aLength, nsITelephonyCallInfo** aAllInfo)
|
||||
NS_IMETHODIMP
|
||||
Telephony::EnumerateCallState(nsITelephonyCallInfo* aInfo)
|
||||
{
|
||||
uint32_t currentCallNum = 1;
|
||||
return CallStateChanged(currentCallNum, &aInfo);
|
||||
return HandleCallInfo(aInfo);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
@ -11,7 +11,6 @@
|
||||
#include "mozilla/dom/Promise.h"
|
||||
#include "mozilla/dom/telephony/TelephonyCommon.h"
|
||||
|
||||
#include "nsIAudioChannelAgent.h"
|
||||
#include "nsITelephonyCallInfo.h"
|
||||
#include "nsITelephonyService.h"
|
||||
|
||||
@ -32,7 +31,6 @@ class TelephonyDialCallback;
|
||||
class OwningTelephonyCallOrTelephonyCallGroup;
|
||||
|
||||
class Telephony final : public DOMEventTargetHelper,
|
||||
public nsIAudioChannelAgentCallback,
|
||||
private nsITelephonyListener
|
||||
{
|
||||
/**
|
||||
@ -46,8 +44,6 @@ class Telephony final : public DOMEventTargetHelper,
|
||||
|
||||
friend class telephony::TelephonyDialCallback;
|
||||
|
||||
// The audio agent is needed to communicate with the audio channel service.
|
||||
nsCOMPtr<nsIAudioChannelAgent> mAudioAgent;
|
||||
nsCOMPtr<nsITelephonyService> mService;
|
||||
nsRefPtr<Listener> mListener;
|
||||
|
||||
@ -58,15 +54,8 @@ class Telephony final : public DOMEventTargetHelper,
|
||||
|
||||
nsRefPtr<Promise> mReadyPromise;
|
||||
|
||||
bool mIsAudioStartPlaying;
|
||||
|
||||
uint32_t mAudioAgentNotify;
|
||||
bool mHaveDispatchedInterruptBeginEvent;
|
||||
bool mMuted;
|
||||
|
||||
public:
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
NS_DECL_NSIAUDIOCHANNELAGENTCALLBACK
|
||||
NS_DECL_NSITELEPHONYLISTENER
|
||||
NS_REALLY_FORWARD_NSIDOMEVENTTARGET(DOMEventTargetHelper)
|
||||
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(Telephony,
|
||||
@ -105,15 +94,6 @@ public:
|
||||
void
|
||||
StopTone(const Optional<uint32_t>& aServiceId, ErrorResult& aRv);
|
||||
|
||||
// In the audio channel architecture, the system app needs to know the state
|
||||
// of every audio channel, including the telephony. Therefore, when a
|
||||
// telephony call is activated , the audio channel service would notify the
|
||||
// system app about that. And we need a agent to communicate with the audio
|
||||
// channel service. We would follow the call states to make a correct
|
||||
// notification.
|
||||
void
|
||||
OwnAudioChannel(ErrorResult& aRv);
|
||||
|
||||
bool
|
||||
GetMuted(ErrorResult& aRv) const;
|
||||
|
||||
@ -233,10 +213,6 @@ private:
|
||||
|
||||
nsresult
|
||||
HandleCallInfo(nsITelephonyCallInfo* aInfo);
|
||||
|
||||
// Check the call states to decide whether need to send the notificaiton.
|
||||
nsresult
|
||||
HandleAudioAgentState();
|
||||
};
|
||||
|
||||
} // namespace dom
|
||||
|
@ -324,10 +324,34 @@ TelephonyCall::Hold(ErrorResult& aRv)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (mCallState != nsITelephonyService::CALL_STATE_CONNECTED) {
|
||||
NS_WARNING(nsPrintfCString("Hold non-connected call is rejected!"
|
||||
" (State: %u)", mCallState).get());
|
||||
promise->MaybeReject(NS_ERROR_DOM_INVALID_STATE_ERR);
|
||||
return promise.forget();
|
||||
}
|
||||
|
||||
if (mGroup) {
|
||||
NS_WARNING("Hold a call in conference is rejected!");
|
||||
promise->MaybeReject(NS_ERROR_DOM_INVALID_STATE_ERR);
|
||||
return promise.forget();
|
||||
}
|
||||
|
||||
if (!mSwitchable) {
|
||||
NS_WARNING("Hold a non-switchable call is rejected!");
|
||||
promise->MaybeReject(NS_ERROR_DOM_INVALID_STATE_ERR);
|
||||
return promise.forget();
|
||||
}
|
||||
|
||||
nsCOMPtr<nsITelephonyCallback> callback = new TelephonyCallback(promise);
|
||||
aRv = Hold(callback);
|
||||
if (NS_WARN_IF(aRv.Failed())) {
|
||||
return nullptr;
|
||||
aRv = mTelephony->Service()->HoldCall(mServiceId, mCallIndex, callback);
|
||||
NS_ENSURE_TRUE(!aRv.Failed(), nullptr);
|
||||
|
||||
if (mSecondId) {
|
||||
// No state transition when we switch two numbers within one TelephonyCall
|
||||
// object. Otherwise, the state here will be inconsistent with the backend
|
||||
// RIL and will never be right.
|
||||
return promise.forget();
|
||||
}
|
||||
|
||||
return promise.forget();
|
||||
@ -341,77 +365,28 @@ TelephonyCall::Resume(ErrorResult& aRv)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsITelephonyCallback> callback = new TelephonyCallback(promise);
|
||||
aRv = Resume(callback);
|
||||
if (NS_WARN_IF(aRv.Failed())) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return promise.forget();
|
||||
}
|
||||
|
||||
nsresult
|
||||
TelephonyCall::Hold(nsITelephonyCallback* aCallback)
|
||||
{
|
||||
if (mCallState != nsITelephonyService::CALL_STATE_CONNECTED) {
|
||||
NS_WARNING(nsPrintfCString("Hold non-connected call is rejected!"
|
||||
" (State: %u)", mCallState).get());
|
||||
aCallback->NotifyError(NS_LITERAL_STRING("InvalidStateError"));
|
||||
return NS_ERROR_DOM_INVALID_STATE_ERR;
|
||||
}
|
||||
|
||||
if (mGroup) {
|
||||
NS_WARNING("Hold a call in conference is rejected!");
|
||||
aCallback->NotifyError(NS_LITERAL_STRING("InvalidStateError"));
|
||||
return NS_ERROR_DOM_INVALID_STATE_ERR;
|
||||
}
|
||||
|
||||
if (!mSwitchable) {
|
||||
NS_WARNING("Hold a non-switchable call is rejected!");
|
||||
aCallback->NotifyError(NS_LITERAL_STRING("InvalidStateError"));
|
||||
return NS_ERROR_DOM_INVALID_STATE_ERR;
|
||||
}
|
||||
|
||||
nsresult rv = mTelephony->Service()->HoldCall(mServiceId, mCallIndex, aCallback);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
if (mSecondId) {
|
||||
// No state transition when we switch two numbers within one TelephonyCall
|
||||
// object. Otherwise, the state here will be inconsistent with the backend
|
||||
// RIL and will never be right.
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
TelephonyCall::Resume(nsITelephonyCallback* aCallback)
|
||||
{
|
||||
if (mCallState != nsITelephonyService::CALL_STATE_HELD) {
|
||||
NS_WARNING("Resume non-held call is rejected!");
|
||||
aCallback->NotifyError(NS_LITERAL_STRING("InvalidStateError"));
|
||||
return NS_ERROR_DOM_INVALID_STATE_ERR;
|
||||
NS_WARNING(nsPrintfCString("Resume non-held call is rejected!"
|
||||
" (State: %u)", mCallState).get());
|
||||
promise->MaybeReject(NS_ERROR_DOM_INVALID_STATE_ERR);
|
||||
return promise.forget();
|
||||
}
|
||||
|
||||
if (mGroup) {
|
||||
NS_WARNING("Resume a call in conference is rejected!");
|
||||
aCallback->NotifyError(NS_LITERAL_STRING("InvalidStateError"));
|
||||
return NS_ERROR_DOM_INVALID_STATE_ERR;
|
||||
promise->MaybeReject(NS_ERROR_DOM_INVALID_STATE_ERR);
|
||||
return promise.forget();
|
||||
}
|
||||
|
||||
if (!mSwitchable) {
|
||||
NS_WARNING("Resume a non-switchable call is rejected!");
|
||||
aCallback->NotifyError(NS_LITERAL_STRING("InvalidStateError"));
|
||||
return NS_ERROR_DOM_INVALID_STATE_ERR;
|
||||
promise->MaybeReject(NS_ERROR_DOM_INVALID_STATE_ERR);
|
||||
return promise.forget();
|
||||
}
|
||||
|
||||
nsresult rv = mTelephony->Service()->ResumeCall(mServiceId, mCallIndex, aCallback);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
nsCOMPtr<nsITelephonyCallback> callback = new TelephonyCallback(promise);
|
||||
aRv = mTelephony->Service()->ResumeCall(mServiceId, mCallIndex, callback);
|
||||
NS_ENSURE_TRUE(!aRv.Failed(), nullptr);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
return promise.forget();
|
||||
}
|
||||
|
@ -12,7 +12,6 @@
|
||||
#include "mozilla/dom/TelephonyCallBinding.h"
|
||||
#include "mozilla/dom/TelephonyCallId.h"
|
||||
#include "mozilla/dom/telephony/TelephonyCommon.h"
|
||||
#include "nsITelephonyService.h"
|
||||
|
||||
class nsPIDOMWindow;
|
||||
|
||||
@ -186,12 +185,6 @@ private:
|
||||
|
||||
~TelephonyCall();
|
||||
|
||||
nsresult
|
||||
Hold(nsITelephonyCallback* aCallback);
|
||||
|
||||
nsresult
|
||||
Resume(nsITelephonyCallback* aCallback);
|
||||
|
||||
void
|
||||
ChangeStateInternal(uint16_t aCallState, bool aFireEvents);
|
||||
|
||||
|
@ -347,12 +347,16 @@ TelephonyCallGroup::Hold(ErrorResult& aRv)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsITelephonyCallback> callback = new TelephonyCallback(promise);
|
||||
aRv = Hold(callback);
|
||||
if (NS_WARN_IF(aRv.Failed())) {
|
||||
return nullptr;
|
||||
if (mCallState != nsITelephonyService::CALL_STATE_CONNECTED) {
|
||||
NS_WARNING("Holding a non-connected call is rejected!");
|
||||
promise->MaybeReject(NS_ERROR_DOM_INVALID_STATE_ERR);
|
||||
return promise.forget();
|
||||
}
|
||||
|
||||
nsCOMPtr<nsITelephonyCallback> callback = new TelephonyCallback(promise);
|
||||
aRv = mTelephony->Service()->HoldConference(mCalls[0]->ServiceId(),
|
||||
callback);
|
||||
NS_ENSURE_TRUE(!aRv.Failed(), nullptr);
|
||||
return promise.forget();
|
||||
}
|
||||
|
||||
@ -366,47 +370,15 @@ TelephonyCallGroup::Resume(ErrorResult& aRv)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsITelephonyCallback> callback = new TelephonyCallback(promise);
|
||||
aRv = Resume(callback);
|
||||
if (NS_WARN_IF(aRv.Failed())) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return promise.forget();
|
||||
}
|
||||
|
||||
nsresult
|
||||
TelephonyCallGroup::Hold(nsITelephonyCallback* aCallback)
|
||||
{
|
||||
if (mCallState != nsITelephonyService::CALL_STATE_CONNECTED) {
|
||||
NS_WARNING("Holding a non-connected call is rejected!");
|
||||
aCallback->NotifyError(NS_LITERAL_STRING("InvalidStateError"));
|
||||
return NS_ERROR_DOM_INVALID_STATE_ERR;
|
||||
}
|
||||
|
||||
nsresult rv = mTelephony->Service()->HoldConference(mCalls[0]->ServiceId(),
|
||||
aCallback);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
TelephonyCallGroup::Resume(nsITelephonyCallback* aCallback)
|
||||
{
|
||||
if (mCallState != nsITelephonyService::CALL_STATE_HELD) {
|
||||
NS_WARNING("Resuming a non-held call is rejected!");
|
||||
aCallback->NotifyError(NS_LITERAL_STRING("InvalidStateError"));
|
||||
return NS_ERROR_DOM_INVALID_STATE_ERR;
|
||||
promise->MaybeReject(NS_ERROR_DOM_INVALID_STATE_ERR);
|
||||
return promise.forget();
|
||||
}
|
||||
|
||||
nsresult rv = mTelephony->Service()->ResumeConference(mCalls[0]->ServiceId(),
|
||||
aCallback);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
nsCOMPtr<nsITelephonyCallback> callback = new TelephonyCallback(promise);
|
||||
aRv = mTelephony->Service()->ResumeConference(mCalls[0]->ServiceId(),
|
||||
callback);
|
||||
NS_ENSURE_TRUE(!aRv.Failed(), nullptr);
|
||||
return promise.forget();
|
||||
}
|
||||
|
@ -30,8 +30,6 @@ public:
|
||||
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(TelephonyCallGroup,
|
||||
DOMEventTargetHelper)
|
||||
|
||||
friend class Telephony;
|
||||
|
||||
nsPIDOMWindow*
|
||||
GetParentObject() const
|
||||
{
|
||||
@ -110,12 +108,6 @@ private:
|
||||
explicit TelephonyCallGroup(nsPIDOMWindow* aOwner);
|
||||
~TelephonyCallGroup();
|
||||
|
||||
nsresult
|
||||
Hold(nsITelephonyCallback* aCallback);
|
||||
|
||||
nsresult
|
||||
Resume(nsITelephonyCallback* aCallback);
|
||||
|
||||
nsresult
|
||||
NotifyCallsChanged(TelephonyCall* aCall);
|
||||
|
||||
|
@ -49,12 +49,6 @@ interface Telephony : EventTarget {
|
||||
[Throws]
|
||||
void stopTone(optional unsigned long serviceId);
|
||||
|
||||
// Calling this method, the app will be treated as owner of the telephony
|
||||
// calls from the AudioChannel policy.
|
||||
[Throws,
|
||||
CheckAllPermissions="audio-channel-telephony"]
|
||||
void ownAudioChannel();
|
||||
|
||||
[Throws]
|
||||
attribute boolean muted;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user