Bug 1590864 - part1 : get the user activation state from top-level browsing context. r=edgar
authorAlastor Wu <alwu@mozilla.com>
Tue, 05 Nov 2019 16:41:16 +0000
changeset 500647 f66335a878bac85230b456372eddc4fd191c1473
parent 500646 5d1f3e0160fa7af5fcf2539ca63bec2a9cc4ede1
child 500648 31158d1ccce83ed74dc825ebfc57a2c3b9548a0e
push id114166
push userapavel@mozilla.com
push dateThu, 07 Nov 2019 10:04:01 +0000
treeherdermozilla-inbound@d271c572a9bc [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersedgar
bugs1590864
milestone72.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 1590864 - part1 : get the user activation state from top-level browsing context. r=edgar As `ApproverDocOf()` uses `docshell::GetInProcessSameTypeRootTreeItem()`, which is not compatible in Fission because we are not able to get the top document if we are in the remote process. Therefore, we should check browsering content directly instead, because the user activation state would be sync automatically for each top-level browsing context among different processes. Differential Revision: https://phabricator.services.mozilla.com/D51427
dom/media/AutoplayPolicy.cpp
--- a/dom/media/AutoplayPolicy.cpp
+++ b/dom/media/AutoplayPolicy.cpp
@@ -88,30 +88,33 @@ static bool IsWindowAllowedToPlay(nsPIDO
 
   if (IsActivelyCapturingOrHasAPermission(aWindow)) {
     AUTOPLAY_LOG(
         "Allow autoplay as document has camera or microphone or screen"
         " permission.");
     return true;
   }
 
+  RefPtr<BrowsingContext> topLevelBC = aWindow->GetBrowsingContext()->Top();
+  if (topLevelBC->HasBeenUserGestureActivated()) {
+    AUTOPLAY_LOG(
+        "Allow autoplay as top-level context has been activated by user "
+        "gesture.");
+    return true;
+  }
+
   if (!aWindow->GetExtantDoc()) {
     return false;
   }
 
   Document* approver = ApproverDocOf(*aWindow->GetExtantDoc());
   if (!approver) {
     return false;
   }
 
-  if (approver->HasBeenUserGestureActivated()) {
-    AUTOPLAY_LOG("Allow autoplay as document activated by user gesture.");
-    return true;
-  }
-
   if (approver->IsExtensionPage()) {
     AUTOPLAY_LOG("Allow autoplay as in extension document.");
     return true;
   }
 
   if (approver->MediaDocumentKind() == Document::MediaDocumentKind::Video) {
     AUTOPLAY_LOG("Allow video document to autoplay.");
     return true;