From 338ccab7dc1f14c4239e429df1743618a26c1755 Mon Sep 17 00:00:00 2001 From: Andrea Marchesini Date: Thu, 27 Aug 2015 09:12:21 +0100 Subject: [PATCH] Bug 1184058 - AudioChannelAgent should be muted when used without a proper window object, r=alwu --- dom/audiochannel/AudioChannelAgent.cpp | 31 +++++++++++++++++--------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/dom/audiochannel/AudioChannelAgent.cpp b/dom/audiochannel/AudioChannelAgent.cpp index 1338c9fb389a..9b221029acee 100644 --- a/dom/audiochannel/AudioChannelAgent.cpp +++ b/dom/audiochannel/AudioChannelAgent.cpp @@ -85,6 +85,8 @@ AudioChannelAgent::InitInternal(nsIDOMWindow* aWindow, int32_t aChannelType, nsIAudioChannelAgentCallback *aCallback, bool aUseWeakRef) { + MOZ_ASSERT(aWindow); + // We syncd the enum of channel type between nsIAudioChannelAgent.idl and // AudioChannelBinding.h the same. MOZ_ASSERT(int(AUDIO_AGENT_CHANNEL_NORMAL) == int(AudioChannel::Normal) && @@ -103,17 +105,19 @@ AudioChannelAgent::InitInternal(nsIDOMWindow* aWindow, int32_t aChannelType, return NS_ERROR_FAILURE; } - if (aWindow) { - nsCOMPtr pInnerWindow = do_QueryInterface(aWindow); - MOZ_ASSERT(pInnerWindow->IsInnerWindow()); - mInnerWindowID = pInnerWindow->WindowID(); + nsCOMPtr pInnerWindow = do_QueryInterface(aWindow); + MOZ_ASSERT(pInnerWindow->IsInnerWindow()); + mInnerWindowID = pInnerWindow->WindowID(); - nsCOMPtr topWindow; - aWindow->GetScriptableTop(getter_AddRefs(topWindow)); - mWindow = do_QueryInterface(topWindow); - if (mWindow) { - mWindow = mWindow->GetOuterWindow(); - } + nsCOMPtr topWindow; + aWindow->GetScriptableTop(getter_AddRefs(topWindow)); + mWindow = do_QueryInterface(topWindow); + if (mWindow) { + mWindow = mWindow->GetOuterWindow(); + } + + if (!mWindow) { + return NS_ERROR_FAILURE; } mAudioChannelType = aChannelType; @@ -134,6 +138,13 @@ NS_IMETHODIMP AudioChannelAgent::NotifyStartedPlaying(uint32_t aNotifyPlayback, MOZ_ASSERT(aVolume); MOZ_ASSERT(aMuted); + // Window-less AudioChannelAgents are muted by default. + if (!mWindow) { + *aVolume = 0; + *aMuted = true; + return NS_OK; + } + nsRefPtr service = AudioChannelService::GetOrCreate(); if (mAudioChannelType == AUDIO_AGENT_CHANNEL_ERROR || service == nullptr || mIsRegToService) {