Bug 1329179 - only display 'play tab' icon for background tab. draft
authorAlastor Wu <alwu@mozilla.com>
Tue, 17 Jan 2017 16:30:22 +0800
changeset 462375 fe52fe99a9037a1c66ef15748652e06c4ee8b659
parent 457446 d192a99be4b436f2dc839435319f7630d5d8f4b0
child 542365 d1b9bf4fa018ff62a9649634cb83d6759f7be4ed
push id41723
push useralwu@mozilla.com
push dateTue, 17 Jan 2017 08:29:59 +0000
bugs1329179
milestone53.0a1
Bug 1329179 - only display 'play tab' icon for background tab. When user open new tab and then go to the pasted URL (which has autoplaying media), the "play tab" icon would be displayed briefly, and then change to the "mute tab" icon. That is the media element starts before calling nsDocument::PageShow() which would resume all blocked media in the tab. Before that moment, even the tab is in the foreground, but we doesn't resume the media yet. Therefore, we need to check the document's visibility by ourself, and only show the "play tab" icon for the background blocked tab. MozReview-Commit-ID: Eg2SD5kpG0j
dom/audiochannel/AudioChannelService.cpp
--- a/dom/audiochannel/AudioChannelService.cpp
+++ b/dom/audiochannel/AudioChannelService.cpp
@@ -1398,17 +1398,28 @@ void
 AudioChannelService::AudioChannelWindow::MaybeNotifyMediaBlocked(AudioChannelAgent* aAgent)
 {
   nsCOMPtr<nsPIDOMWindowOuter> window = aAgent->Window();
   if (!window) {
     return;
   }
 
   MOZ_ASSERT(window->IsOuterWindow());
-  if (window->GetMediaSuspend() != nsISuspendedTypes::SUSPENDED_BLOCK) {
+  nsCOMPtr<nsPIDOMWindowInner> inner = window->GetCurrentInnerWindow();
+  if (!inner) {
+    return;
+  }
+
+  nsCOMPtr<nsIDocument> doc = inner->GetExtantDoc();
+  if (!doc) {
+    return;
+  }
+
+  if (window->GetMediaSuspend() != nsISuspendedTypes::SUSPENDED_BLOCK ||
+      !doc->Hidden()) {
     return;
   }
 
   NS_DispatchToCurrentThread(NS_NewRunnableFunction([window] () -> void {
       nsCOMPtr<nsIObserverService> observerService =
         services::GetObserverService();
       if (NS_WARN_IF(!observerService)) {
         return;