Bug 1184058 - AudioChannelAgent should be muted when used without a proper window object. r=alwu
authorAndrea Marchesini <amarchesini@mozilla.com>
Tue, 01 Sep 2015 12:05:59 -0400
changeset 260349 7cf7a64736eeb428853c3b0821ec705149058235
parent 260348 fd0134809e69e2402ca9359b15e47f2d9e22f32b
child 260350 aadbd9ccc0d3fc3edf22168943743735ca9c36e9
push id29307
push userryanvm@gmail.com
push dateWed, 02 Sep 2015 01:01:53 +0000
treeherdermozilla-central@e2eb0442ece9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersalwu
bugs1184058
milestone43.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1184058 - AudioChannelAgent should be muted when used without a proper window object. r=alwu CLOSED TREE
dom/audiochannel/AudioChannelAgent.cpp
--- a/dom/audiochannel/AudioChannelAgent.cpp
+++ b/dom/audiochannel/AudioChannelAgent.cpp
@@ -98,27 +98,33 @@ AudioChannelAgent::InitInternal(nsIDOMWi
              "Enum of channel on nsIAudioChannelAgent.idl should be the same with AudioChannelBinding.h");
 
   if (mAudioChannelType != AUDIO_AGENT_CHANNEL_ERROR ||
       aChannelType > AUDIO_AGENT_CHANNEL_PUBLICNOTIFICATION ||
       aChannelType < AUDIO_AGENT_CHANNEL_NORMAL) {
     return NS_ERROR_FAILURE;
   }
 
-  if (aWindow) {
-    nsCOMPtr<nsPIDOMWindow> pInnerWindow = do_QueryInterface(aWindow);
-    MOZ_ASSERT(pInnerWindow->IsInnerWindow());
-    mInnerWindowID = pInnerWindow->WindowID();
+  if (NS_WARN_IF(!aWindow)) {
+    return NS_ERROR_FAILURE;
+  }
+
+  nsCOMPtr<nsPIDOMWindow> pInnerWindow = do_QueryInterface(aWindow);
+  MOZ_ASSERT(pInnerWindow->IsInnerWindow());
+  mInnerWindowID = pInnerWindow->WindowID();
 
-    nsCOMPtr<nsIDOMWindow> topWindow;
-    aWindow->GetScriptableTop(getter_AddRefs(topWindow));
-    mWindow = do_QueryInterface(topWindow);
-    if (mWindow) {
-      mWindow = mWindow->GetOuterWindow();
-    }
+  nsCOMPtr<nsIDOMWindow> topWindow;
+  aWindow->GetScriptableTop(getter_AddRefs(topWindow));
+  mWindow = do_QueryInterface(topWindow);
+  if (mWindow) {
+    mWindow = mWindow->GetOuterWindow();
+  }
+
+  if (!mWindow) {
+    return NS_ERROR_FAILURE;
   }
 
   mAudioChannelType = aChannelType;
 
   if (aUseWeakRef) {
     mWeakCallback = do_GetWeakReference(aCallback);
   } else {
     mCallback = aCallback;
@@ -129,16 +135,23 @@ AudioChannelAgent::InitInternal(nsIDOMWi
 
 NS_IMETHODIMP AudioChannelAgent::NotifyStartedPlaying(uint32_t aNotifyPlayback,
                                                       float *aVolume,
                                                       bool* aMuted)
 {
   MOZ_ASSERT(aVolume);
   MOZ_ASSERT(aMuted);
 
+  // Window-less AudioChannelAgents are muted by default.
+  if (!mWindow) {
+    *aVolume = 0;
+    *aMuted = true;
+    return NS_OK;
+  }
+
   nsRefPtr<AudioChannelService> service = AudioChannelService::GetOrCreate();
   if (mAudioChannelType == AUDIO_AGENT_CHANNEL_ERROR ||
       service == nullptr || mIsRegToService) {
     return NS_ERROR_FAILURE;
   }
 
   service->RegisterAudioChannelAgent(this, aNotifyPlayback,
     static_cast<AudioChannel>(mAudioChannelType));