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
--- 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);