Bug 1513039 - part13 : set 'mWasAllowedToStart' flag. r=karlt
authoralwu <alwu@mozilla.com>
Mon, 07 Jan 2019 18:43:31 +0000
changeset 509883 a06f5553f2cafd6915f650a82a379018c5fdfdc6
parent 509882 b67708aaec68b07ecc71c3a5cc7587b0b6dfe52b
child 509884 14ee7539fbc0fb33d4616d38dcbf225894dec9c8
push id10547
push userffxbld-merge
push dateMon, 21 Jan 2019 13:03:58 +0000
treeherdermozilla-beta@24ec1916bffe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskarlt
bugs1513039
milestone66.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 1513039 - part13 : set 'mWasAllowedToStart' flag. r=karlt 'mWasAllowedToStart' would be set to false if AudioContext is not allowed to start, and would be set to true if AudioContext has been allowed to start. Differential Revision: https://phabricator.services.mozilla.com/D14636
dom/media/webaudio/AudioContext.cpp
--- a/dom/media/webaudio/AudioContext.cpp
+++ b/dom/media/webaudio/AudioContext.cpp
@@ -166,17 +166,16 @@ AudioContext::AudioContext(nsPIDOMWindow
     Mute();
   }
 
   // If an AudioContext is not allowed to start, we would postpone its state
   // transition from `suspended` to `running` until sites explicitly call
   // AudioContext.resume() or AudioScheduledSourceNode.start().
   if (!allowedToStart) {
     AUTOPLAY_LOG("AudioContext %p is not allowed to start", this);
-    mWasAllowedToStart = false;
     SuspendInternal(nullptr);
     ReportBlocked();
   }
 
   FFTBlock::MainThreadInit();
 }
 
 void AudioContext::NotifyScheduledSourceNodeStarted() {
@@ -935,27 +934,28 @@ already_AddRefed<Promise> AudioContext::
   }
 
   mPendingResumePromises.AppendElement(promise);
 
   const bool isAllowedToPlay = AutoplayPolicy::IsAllowedToPlay(*this);
   AUTOPLAY_LOG("Trying to resume AudioContext %p, IsAllowedToPlay=%d", this,
                isAllowedToPlay);
   if (isAllowedToPlay) {
-    mWasAllowedToStart = true;
     ResumeInternal();
   } else {
     ReportBlocked();
   }
 
   return promise.forget();
 }
 
 void AudioContext::ResumeInternal() {
   AUTOPLAY_LOG("Allow to resume AudioContext %p", this);
+  mWasAllowedToStart = true;
+
   Destination()->Resume();
 
   nsTArray<MediaStream*> streams;
   // If mSuspendCalled is false then we already resumed all our streams,
   // so don't resume them again (since suspend(); resume(); resume(); should
   // be OK). But we still need to do ApplyAudioContextOperation
   // to ensure our new promise is resolved.
   if (mSuspendCalled) {
@@ -963,16 +963,17 @@ void AudioContext::ResumeInternal() {
   }
   Graph()->ApplyAudioContextOperation(DestinationStream(), streams,
                                       AudioContextOperation::Resume, nullptr);
   mSuspendCalled = false;
 }
 
 void AudioContext::ReportBlocked() {
   ReportToConsole(nsIScriptError::warningFlag, "BlockAutoplayError");
+  mWasAllowedToStart = false;
 
   if (!StaticPrefs::MediaBlockEventEnabled()) {
     return;
   }
 
   RefPtr<AudioContext> self = this;
   RefPtr<nsIRunnable> r =
       NS_NewRunnableFunction("AudioContext::AutoplayBlocked", [self]() {