Bug 1513039 - part4 : remove permission request logic in AudioContext. r=karlt
authoralwu <alwu@mozilla.com>
Mon, 07 Jan 2019 18:33:36 +0000
changeset 452771 dba8b9714294f04b19675a10c972bdd72ab7f9ef
parent 452770 5d5121ecc18102123d5b84f388313a10a535e2dd
child 452772 0e229bbdaae5c8fa9f83796c628a4fdf88f057ba
push id35330
push useropoprus@mozilla.com
push dateTue, 08 Jan 2019 09:41:12 +0000
treeherdermozilla-central@4ad5b70956ab [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 - part4 : remove permission request logic in AudioContext. r=karlt AudioContext won't need to ask permission request anymore, and we will report error message in patch5. Differential Revision: https://phabricator.services.mozilla.com/D14329
dom/media/webaudio/AudioContext.cpp
dom/media/webaudio/AudioContext.h
--- a/dom/media/webaudio/AudioContext.cpp
+++ b/dom/media/webaudio/AudioContext.cpp
@@ -3,17 +3,16 @@
 /* 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/. */
 
 #include "AudioContext.h"
 
 #include "blink/PeriodicWave.h"
 
-#include "mozilla/AutoplayPermissionManager.h"
 #include "mozilla/ErrorResult.h"
 #include "mozilla/NotNull.h"
 #include "mozilla/OwningNonNull.h"
 #include "mozilla/RefPtr.h"
 #include "mozilla/Preferences.h"
 #include "mozilla/StaticPrefs.h"
 
 #include "mozilla/dom/AnalyserNode.h"
@@ -188,55 +187,18 @@ void AudioContext::NotifyScheduledSource
   }
 
   const bool isAllowedToPlay = AutoplayPolicy::IsAllowedToPlay(*this);
   AUTOPLAY_LOG("Trying to start AudioContext %p, IsAllowedToPlay=%d", this,
                isAllowedToPlay);
   if (isAllowedToPlay) {
     ResumeInternal();
   } else {
-    EnsureAutoplayRequested();
-  }
-}
-
-void AudioContext::EnsureAutoplayRequested() {
-  nsPIDOMWindowInner* parent = GetParentObject();
-  if (!parent || !parent->AsGlobal()) {
-    return;
-  }
-
-  RefPtr<AutoplayPermissionManager> request =
-      AutoplayPolicy::RequestFor(*(parent->GetExtantDoc()));
-  if (!request) {
-    return;
+    DispatchBlockedEvent();
   }
-
-  AUTOPLAY_LOG("AudioContext %p EnsureAutoplayRequested %p", this,
-               request.get());
-  RefPtr<AudioContext> self = this;
-  request->RequestWithPrompt()->Then(
-      parent->AsGlobal()->AbstractMainThreadFor(TaskCategory::Other), __func__,
-      [self, request](bool aApproved) {
-        AUTOPLAY_LOG("%p Autoplay request approved request=%p", self.get(),
-                     request.get());
-        self->mWasAllowedToStart = true;
-        self->ResumeInternal();
-      },
-      [self, request](nsresult aError) {
-        AUTOPLAY_LOG("%p Autoplay request denied request=%p", self.get(),
-                     request.get());
-        self->mWasAllowedToStart = false;
-        self->DispatchBlockedEvent();
-        Document* doc = self->GetParentObject()
-                            ? self->GetParentObject()->GetExtantDoc()
-                            : nullptr;
-        nsContentUtils::ReportToConsole(
-            nsIScriptError::warningFlag, NS_LITERAL_CSTRING("Media"), doc,
-            nsContentUtils::eDOM_PROPERTIES, "BlockAutoplayError");
-      });
 }
 
 nsresult AudioContext::Init() {
   if (!mIsOffline) {
     nsresult rv = mDestination->CreateAudioChannelAgent();
     if (NS_WARN_IF(NS_FAILED(rv))) {
       return rv;
     }
@@ -975,18 +937,18 @@ 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 if (!isAllowedToPlay && !mWasAllowedToStart) {
-    EnsureAutoplayRequested();
+  } else {
+    DispatchBlockedEvent();
   }
 
   return promise.forget();
 }
 
 void AudioContext::ResumeInternal() {
   AUTOPLAY_LOG("Allow to resume AudioContext %p", this);
   Destination()->Resume();
--- a/dom/media/webaudio/AudioContext.h
+++ b/dom/media/webaudio/AudioContext.h
@@ -314,19 +314,16 @@ class AudioContext final : public DOMEve
 
   size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
   NS_DECL_NSIMEMORYREPORTER
 
   friend struct ::mozilla::WebAudioDecodeJob;
 
   nsTArray<MediaStream*> GetAllStreams() const;
 
-  // Request the prompt to ask for user's approval for autoplay.
-  void EnsureAutoplayRequested();
-
   void ResumeInternal();
   void SuspendInternal(void* aPromise);
 
   // This event is used for testing only.
   void DispatchBlockedEvent();
 
  private:
   // Each AudioContext has an id, that is passed down the MediaStreams that