mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-14 13:55:43 +00:00
Bug 1457048 - Ensure origins with autoplay-media exact permission can autoplay. r=bryce,johannh
Sites which are whitelisted should be allowed to autoplay audible media. So check whether a HTMLMediaElement's owner doc's principal has an exact "autoplay-media" permission. This ensures whitelisted origins can autoplay, but sub-origins of whitelisted origins need their own permission. MozReview-Commit-ID: 2IO5KIyplEa --HG-- extra : rebase_source : 4d9afdec0caa4a82b53bedfd645f259a5c760e4d
This commit is contained in:
parent
bf5b9dea2d
commit
d7eacf6ae5
@ -600,6 +600,16 @@ var gPermissionObject = {
|
||||
* don't want to expose a "Hide Prompt" button to the user through pageinfo.
|
||||
*/
|
||||
|
||||
"autoplay-media": {
|
||||
exactHostMatch: true,
|
||||
getDefault() {
|
||||
if (Services.prefs.getBoolPref("media.autoplay.enabled")) {
|
||||
return SitePermissions.ALLOW;
|
||||
}
|
||||
return SitePermissions.BLOCK;
|
||||
}
|
||||
},
|
||||
|
||||
"image": {
|
||||
states: [ SitePermissions.ALLOW, SitePermissions.BLOCK ],
|
||||
},
|
||||
|
@ -10,18 +10,13 @@
|
||||
#include "mozilla/Preferences.h"
|
||||
#include "mozilla/dom/HTMLMediaElement.h"
|
||||
#include "mozilla/dom/HTMLMediaElementBinding.h"
|
||||
#include "nsContentUtils.h"
|
||||
#include "nsIDocument.h"
|
||||
#include "MediaManager.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
/* static */ bool
|
||||
AutoplayPolicy::IsDocumentAllowedToPlay(nsIDocument* aDoc)
|
||||
{
|
||||
return aDoc ? aDoc->HasBeenUserActivated() : false;
|
||||
}
|
||||
|
||||
/* static */ bool
|
||||
AutoplayPolicy::IsMediaElementAllowedToPlay(NotNull<HTMLMediaElement*> aElement)
|
||||
{
|
||||
@ -45,7 +40,7 @@ AutoplayPolicy::IsMediaElementAllowedToPlay(NotNull<HTMLMediaElement*> aElement)
|
||||
// If elelement is blessed, it would always be allowed to play().
|
||||
return aElement->IsBlessed() ||
|
||||
EventStateManager::IsHandlingUserInput();
|
||||
}
|
||||
}
|
||||
|
||||
// Muted content
|
||||
if (aElement->Volume() == 0.0 || aElement->Muted()) {
|
||||
@ -59,7 +54,18 @@ AutoplayPolicy::IsMediaElementAllowedToPlay(NotNull<HTMLMediaElement*> aElement)
|
||||
return true;
|
||||
}
|
||||
|
||||
return AutoplayPolicy::IsDocumentAllowedToPlay(aElement->OwnerDoc());
|
||||
// Whitelisted.
|
||||
if (nsContentUtils::IsExactSitePermAllow(
|
||||
aElement->NodePrincipal(), "autoplay-media")) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Activated by user gesture.
|
||||
if (aElement->OwnerDoc()->HasBeenUserActivated()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace dom
|
||||
|
@ -25,14 +25,13 @@ class HTMLMediaElement;
|
||||
* conditions is true.
|
||||
* 1) Owner document is activated by user gestures
|
||||
* We restrict user gestures to "mouse click", "keyboard press" and "touch".
|
||||
* 2) Muted media content or video without audio content
|
||||
* 2) Muted media content or video without audio content.
|
||||
* 3) Document's origin has the "autoplay-media" permission.
|
||||
*/
|
||||
class AutoplayPolicy
|
||||
{
|
||||
public:
|
||||
static bool IsMediaElementAllowedToPlay(NotNull<HTMLMediaElement*> aElement);
|
||||
private:
|
||||
static bool IsDocumentAllowedToPlay(nsIDocument* aDoc);
|
||||
};
|
||||
|
||||
} // namespace dom
|
||||
|
Loading…
Reference in New Issue
Block a user