Bug 1466926 - part1 : always allow extension background script to autoplay. draft
authoralwu <alwu@mozilla.com>
Tue, 10 Jul 2018 10:37:33 -0700
changeset 825453 29f18aa2758b8d757fcf1cace12b7b79016f02df
parent 824607 0d72c7996d60a7c07e35c5f90d78b02a47d17460
child 825454 bc85cbe1be278ba76700f9905eda6348924882a0
push id118119
push userbmo:alwu@mozilla.com
push dateWed, 01 Aug 2018 21:08:21 +0000
bugs1466926
milestone63.0a1
Bug 1466926 - part1 : always allow extension background script to autoplay. In present web extension design (both Firefox and Chrome), background script can autoplay. We don't want to break this design, so we would always allow it to autoplay. MozReview-Commit-ID: 9BfWgll7PNx
dom/base/nsDocument.cpp
dom/base/nsIDocument.h
dom/media/AutoplayPolicy.cpp
--- a/dom/base/nsDocument.cpp
+++ b/dom/base/nsDocument.cpp
@@ -12612,16 +12612,22 @@ nsIDocument::HasBeenUserGestureActivated
       break;
     }
     doc = doc->GetSameTypeParentDocument();
   }
 
   return mUserGestureActivated;
 }
 
+bool
+nsIDocument::IsExtensionPage() const
+{
+  return BasePrincipal::Cast(NodePrincipal())->AddonPolicy();
+}
+
 nsIDocument*
 nsIDocument::GetSameTypeParentDocument()
 {
   nsCOMPtr<nsIDocShellTreeItem> current = GetDocShell();
   if (!current) {
     return nullptr;
   }
 
--- a/dom/base/nsIDocument.h
+++ b/dom/base/nsIDocument.h
@@ -3434,16 +3434,20 @@ public:
   // permit autoplay audible media. This also gesture activates all other
   // content documents in this tab.
   void NotifyUserGestureActivation();
 
   // Return true if NotifyUserGestureActivation() has been called on any
   // document in the document tree.
   bool HasBeenUserGestureActivated();
 
+  // This document is a WebExtension page, it might be a background page, a
+  // popup, a visible tab, a visible iframe ...e.t.c.
+  bool IsExtensionPage() const;
+
   bool HasScriptsBlockedBySandbox();
 
   bool InlineScriptAllowedByCSP();
 
   void ReportHasScrollLinkedEffect();
   bool HasScrollLinkedEffect() const
   {
     return mHasScrollLinkedEffect;
--- a/dom/media/AutoplayPolicy.cpp
+++ b/dom/media/AutoplayPolicy.cpp
@@ -66,16 +66,21 @@ IsWindowAllowedToPlay(nsPIDOMWindowInner
     return true;
   }
 
   if (approver->HasBeenUserGestureActivated()) {
     // Document has been activated by user gesture.
     return true;
   }
 
+  if (approver->IsExtensionPage()) {
+    // Always allow extension page to autoplay.
+    return true;
+  }
+
   return false;
 }
 
 /* static */
 already_AddRefed<AutoplayPermissionManager>
 AutoplayPolicy::RequestFor(const nsIDocument& aDocument)
 {
   nsIDocument* document = ApproverDocOf(aDocument);