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
--- 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;