Bug 1129882 - add mozInterrupt in telephony object. r=baku

This commit is contained in:
Alastor Wu 2015-09-03 10:14:17 +08:00
parent b5daced1c2
commit cbdade4ed8
2 changed files with 21 additions and 1 deletions

View File

@ -64,7 +64,9 @@ public:
Telephony::Telephony(nsPIDOMWindow* aOwner)
: DOMEventTargetHelper(aOwner),
mAudioAgentNotify(nsIAudioChannelAgent::AUDIO_AGENT_NOTIFY),
mIsAudioStartPlaying(false)
mIsAudioStartPlaying(false),
mHaveDispatchedInterruptBeginEvent(false),
mMuted(AudioChannelService::IsAudioChannelMutedByDefault())
{
MOZ_ASSERT(aOwner);
nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(aOwner);
@ -690,6 +692,22 @@ Telephony::WindowVolumeChanged(float aVolume, bool aMuted)
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;
}

View File

@ -61,6 +61,8 @@ class Telephony final : public DOMEventTargetHelper,
uint32_t mAudioAgentNotify;
bool mIsAudioStartPlaying;
bool mHaveDispatchedInterruptBeginEvent;
bool mMuted;
public:
NS_DECL_ISUPPORTS_INHERITED