From 81ae6fd494b3ddda32a641b0054c81e57aa8b007 Mon Sep 17 00:00:00 2001 From: alwu Date: Tue, 10 Jul 2018 10:37:33 -0700 Subject: [PATCH] Bug 1466926 - part1 : always allow extension background script to autoplay. r=cpearce 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 --HG-- extra : rebase_source : 7996daa06c31a84a2aea9008daa9bddfcde98c74 --- dom/base/nsDocument.cpp | 6 ++++++ dom/base/nsIDocument.h | 4 ++++ dom/media/AutoplayPolicy.cpp | 5 +++++ 3 files changed, 15 insertions(+) diff --git a/dom/base/nsDocument.cpp b/dom/base/nsDocument.cpp index a6de74531215..a420e7feb372 100644 --- a/dom/base/nsDocument.cpp +++ b/dom/base/nsDocument.cpp @@ -12638,6 +12638,12 @@ nsIDocument::HasBeenUserGestureActivated() return mUserGestureActivated; } +bool +nsIDocument::IsExtensionPage() const +{ + return BasePrincipal::Cast(NodePrincipal())->AddonPolicy(); +} + nsIDocument* nsIDocument::GetSameTypeParentDocument() { diff --git a/dom/base/nsIDocument.h b/dom/base/nsIDocument.h index e7af1c6118d2..9e7412d9705f 100644 --- a/dom/base/nsIDocument.h +++ b/dom/base/nsIDocument.h @@ -3439,6 +3439,10 @@ public: // 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(); diff --git a/dom/media/AutoplayPolicy.cpp b/dom/media/AutoplayPolicy.cpp index 0b8bd819daf7..5a9766c69b44 100644 --- a/dom/media/AutoplayPolicy.cpp +++ b/dom/media/AutoplayPolicy.cpp @@ -71,6 +71,11 @@ IsWindowAllowedToPlay(nsPIDOMWindowInner* aWindow) return true; } + if (approver->IsExtensionPage()) { + // Always allow extension page to autoplay. + return true; + } + return false; }