Bug 1319771 - part1 : only resume the window when there has active media components. r=baku
authorAlastor Wu <alwu@mozilla.com>
Fri, 03 Feb 2017 10:48:38 +0800
changeset 332387 7302c447d09afb58837338a023a31458d720a531
parent 332386 76a2444f8eabe37083ec4750d8f491719acb4d8c
child 332388 9d882c051d0043250bf4a196411abdba4ff5709c
push id86521
push usercbook@mozilla.com
push dateFri, 03 Feb 2017 12:32:52 +0000
treeherdermozilla-inbound@d3774f2ebaf2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku
bugs1319771
milestone54.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 1319771 - part1 : only resume the window when there has active media components. r=baku For the first pinned tab, it would be set to visible first and then set to invisible if there exists other tabs after restarting the whole browser. If the tab is set to visible, we would activate the media component (set the |mMediaSuspended| in outer window to none-suspend). In this case, the first pinned tab would be set to visible briefly, but it doesn't mean the tab is in the foreground, it's just how DOM manage the tab's visibility. In that moment, none of the media component has been created yet. Therefore, we would only activate the media component after the audio channel service exists. MozReview-Commit-ID: 1FgdMq84yWX
dom/audiochannel/AudioChannelAgent.cpp
dom/audiochannel/AudioChannelService.cpp
dom/audiochannel/AudioChannelService.h
dom/base/nsDocument.cpp
--- a/dom/audiochannel/AudioChannelAgent.cpp
+++ b/dom/audiochannel/AudioChannelAgent.cpp
@@ -36,16 +36,19 @@ NS_INTERFACE_MAP_END
 NS_IMPL_CYCLE_COLLECTING_ADDREF(AudioChannelAgent)
 NS_IMPL_CYCLE_COLLECTING_RELEASE(AudioChannelAgent)
 
 AudioChannelAgent::AudioChannelAgent()
   : mAudioChannelType(AUDIO_AGENT_CHANNEL_ERROR)
   , mInnerWindowID(0)
   , mIsRegToService(false)
 {
+  // Init service in the begining, it can help us to know whether there is any
+  // created media component via AudioChannelService::IsServiceStarted().
+  RefPtr<AudioChannelService> service = AudioChannelService::GetOrCreate();
 }
 
 AudioChannelAgent::~AudioChannelAgent()
 {
   Shutdown();
 }
 
 void
--- a/dom/audiochannel/AudioChannelService.cpp
+++ b/dom/audiochannel/AudioChannelService.cpp
@@ -196,16 +196,23 @@ AudioChannelService::CreateServiceIfNeed
 {
   MOZ_ASSERT(NS_IsMainThread());
 
   if (!gAudioChannelService) {
     gAudioChannelService = new AudioChannelService();
   }
 }
 
+/* static */ bool
+AudioChannelService::IsServiceStarted()
+{
+  // The service would start when the first AudioChannelAgent is created.
+  return !!gAudioChannelService;
+}
+
 /* static */ already_AddRefed<AudioChannelService>
 AudioChannelService::GetOrCreate()
 {
   if (sXPCOMShuttingDown) {
     return nullptr;
   }
 
   CreateServiceIfNeeded();
--- a/dom/audiochannel/AudioChannelService.h
+++ b/dom/audiochannel/AudioChannelService.h
@@ -95,16 +95,18 @@ public:
   static already_AddRefed<AudioChannelService> GetOrCreate();
 
   static bool IsAudioChannelMutedByDefault();
 
   static PRLogModuleInfo* GetAudioChannelLog();
 
   static bool IsEnableAudioCompeting();
 
+  static bool IsServiceStarted();
+
   /**
    * Any audio channel agent that starts playing should register itself to
    * this service, sharing the AudioChannel.
    */
   void RegisterAudioChannelAgent(AudioChannelAgent* aAgent,
                                  AudibleState aAudible);
 
   /**
--- a/dom/base/nsDocument.cpp
+++ b/dom/base/nsDocument.cpp
@@ -3,16 +3,17 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 /*
  * Base class for all our document implementations.
  */
 
+#include "AudioChannelService.h"
 #include "nsDocument.h"
 #include "nsIDocumentInlines.h"
 #include "mozilla/AnimationComparator.h"
 #include "mozilla/ArrayUtils.h"
 #include "mozilla/AutoRestore.h"
 #include "mozilla/BinarySearch.h"
 #include "mozilla/DebugOnly.h"
 #include "mozilla/EffectSet.h"
@@ -12079,17 +12080,18 @@ nsDocument::MaybeActiveMediaComponents()
     return;
   }
 
   if (!mWindow) {
     return;
   }
 
   mEverInForeground = true;
-  if (GetWindow()->GetMediaSuspend() == nsISuspendedTypes::SUSPENDED_BLOCK) {
+  if (GetWindow()->GetMediaSuspend() == nsISuspendedTypes::SUSPENDED_BLOCK &&
+      AudioChannelService::IsServiceStarted()) {
     GetWindow()->SetMediaSuspend(nsISuspendedTypes::NONE_SUSPENDED);
   }
 }
 
 NS_IMETHODIMP
 nsDocument::GetHidden(bool* aHidden)
 {
   *aHidden = Hidden();