Bug 1339930 - Don't crash in AudioChannelService when dealing with Windows without a parent. r=baku, a=lizzard
authorEhsan Akhgari <ehsan@mozilla.com>
Thu, 16 Feb 2017 10:56:00 -0500
changeset 376289 391c8637750f29cabf0ca3922de7af096001dd46
parent 376288 4dce664e6046b3dd002efcbd287834da242d10e9
child 376290 f68de4ebb25abf057ce57a620a9347571d6cff6c
push id6996
push userjlorenzo@mozilla.com
push dateMon, 06 Mar 2017 20:48:21 +0000
treeherdermozilla-beta@d89512dab048 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku, lizzard
bugs1339930
milestone53.0a2
Bug 1339930 - Don't crash in AudioChannelService when dealing with Windows without a parent. r=baku, a=lizzard
dom/audiochannel/AudioChannelService.cpp
dom/audiochannel/crashtests/1339930.html
dom/audiochannel/crashtests/crashtests.list
--- a/dom/audiochannel/AudioChannelService.cpp
+++ b/dom/audiochannel/AudioChannelService.cpp
@@ -803,16 +803,20 @@ AudioChannelService::GetAudioChannelVolu
 NS_IMETHODIMP
 AudioChannelService::GetAudioChannelVolume(mozIDOMWindowProxy* aWindow,
                                            unsigned short aAudioChannel,
                                            float* aVolume)
 {
   MOZ_ASSERT(NS_IsMainThread());
 
   auto* window = nsPIDOMWindowOuter::From(aWindow)->GetScriptableTop();
+  if (!window) {
+    *aVolume = 0.f;
+    return NS_ERROR_FAILURE;
+  }
   *aVolume = GetAudioChannelVolume(window, (AudioChannel)aAudioChannel);
   return NS_OK;
 }
 
 void
 AudioChannelService::SetAudioChannelVolume(nsPIDOMWindowOuter* aWindow,
                                            AudioChannel aAudioChannel,
                                            float aVolume)
@@ -833,16 +837,19 @@ AudioChannelService::SetAudioChannelVolu
 NS_IMETHODIMP
 AudioChannelService::SetAudioChannelVolume(mozIDOMWindowProxy* aWindow,
                                            unsigned short aAudioChannel,
                                            float aVolume)
 {
   MOZ_ASSERT(NS_IsMainThread());
 
   auto* window = nsPIDOMWindowOuter::From(aWindow)->GetScriptableTop();
+  if (!window) {
+    return NS_ERROR_FAILURE;
+  }
   SetAudioChannelVolume(window, (AudioChannel)aAudioChannel, aVolume);
   return NS_OK;
 }
 
 bool
 AudioChannelService::GetAudioChannelMuted(nsPIDOMWindowOuter* aWindow,
                                           AudioChannel aAudioChannel)
 {
@@ -857,16 +864,20 @@ AudioChannelService::GetAudioChannelMute
 NS_IMETHODIMP
 AudioChannelService::GetAudioChannelMuted(mozIDOMWindowProxy* aWindow,
                                           unsigned short aAudioChannel,
                                           bool* aMuted)
 {
   MOZ_ASSERT(NS_IsMainThread());
 
   auto* window = nsPIDOMWindowOuter::From(aWindow)->GetScriptableTop();
+  if (!window) {
+    *aMuted = false;
+    return NS_ERROR_FAILURE;
+  }
   *aMuted = GetAudioChannelMuted(window, (AudioChannel)aAudioChannel);
   return NS_OK;
 }
 
 void
 AudioChannelService::SetAudioChannelMuted(nsPIDOMWindowOuter* aWindow,
                                           AudioChannel aAudioChannel,
                                           bool aMuted)
@@ -892,16 +903,19 @@ AudioChannelService::SetAudioChannelMute
 NS_IMETHODIMP
 AudioChannelService::SetAudioChannelMuted(mozIDOMWindowProxy* aWindow,
                                           unsigned short aAudioChannel,
                                           bool aMuted)
 {
   MOZ_ASSERT(NS_IsMainThread());
 
   auto* window = nsPIDOMWindowOuter::From(aWindow)->GetScriptableTop();
+  if (!window) {
+    return NS_ERROR_FAILURE;
+  }
   SetAudioChannelMuted(window, (AudioChannel)aAudioChannel, aMuted);
   return NS_OK;
 }
 
 bool
 AudioChannelService::IsAudioChannelActive(nsPIDOMWindowOuter* aWindow,
                                           AudioChannel aAudioChannel)
 {
@@ -916,26 +930,33 @@ AudioChannelService::IsAudioChannelActiv
 NS_IMETHODIMP
 AudioChannelService::IsAudioChannelActive(mozIDOMWindowProxy* aWindow,
                                           unsigned short aAudioChannel,
                                           bool* aActive)
 {
   MOZ_ASSERT(NS_IsMainThread());
 
   auto* window = nsPIDOMWindowOuter::From(aWindow)->GetScriptableTop();
+  if (!window) {
+    *aActive = false;
+    return NS_ERROR_FAILURE;
+  }
   *aActive = IsAudioChannelActive(window, (AudioChannel)aAudioChannel);
   return NS_OK;
 }
 
 bool
 AudioChannelService::IsWindowActive(nsPIDOMWindowOuter* aWindow)
 {
   MOZ_ASSERT(NS_IsMainThread());
 
   auto* window = nsPIDOMWindowOuter::From(aWindow)->GetScriptableTop();
+  if (!window) {
+    return false;
+  }
   AudioChannelWindow* winData = GetOrCreateWindowData(window);
   return !winData->mAudibleAgents.IsEmpty();
 }
 
 void
 AudioChannelService::SetDefaultVolumeControlChannel(int32_t aChannel,
                                                     bool aVisible)
 {
new file mode 100644
--- /dev/null
+++ b/dom/audiochannel/crashtests/1339930.html
@@ -0,0 +1,19 @@
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset="UTF-8">
+<script>
+window.onload = function(){
+  let x = document.getElementsByTagName("iframe")[0];
+  let w = window.open();
+  let o = window.frames[0];
+  x.remove();
+  o.requestIdleCallback(function(){});
+  w.close();
+};
+</script>
+</head>
+<body>
+<iframe></iframe>
+</body>
+</html>
--- a/dom/audiochannel/crashtests/crashtests.list
+++ b/dom/audiochannel/crashtests/crashtests.list
@@ -1,1 +1,2 @@
 load 1223734.html
+load 1339930.html