gecko-dev/dom/media/AutoplayPolicy.h
Chris Pearce ea95e39bc9 Bug 1463919 - Move ask autoplay permission check into AutoplayPolicy. r=jya
MozReview-Commit-ID: KJcVI6gtGXw

--HG--
extra : rebase_source : a2ccd2da32d77708fdeb6ea6361975a7759cb18d
extra : source : 9b1c40f3e61ab351707f2d320ce8f87951e4868e
2018-06-26 14:16:13 +12:00

61 lines
1.7 KiB
C++

/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 et cindent: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#if !defined(AutoplayPolicy_h_)
#define AutoplayPolicy_h_
#include "mozilla/NotNull.h"
class nsIDocument;
namespace mozilla {
class AutoplayRequest;
namespace dom {
class HTMLMediaElement;
class AudioContext;
enum class Authorization
{
Allowed,
Blocked,
Prompt
};
/**
* AutoplayPolicy is used to manage autoplay logic for all kinds of media,
* including MediaElement, Web Audio and Web Speech.
*
* Autoplay could be disable by turn off the pref "media.autoplay.enabled".
* Once user disable autoplay, media could only be played if one of following
* 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.
* 3) Document's origin has the "autoplay-media" permission.
*/
class AutoplayPolicy
{
public:
// Returns whether a given media element is allowed to play.
static Authorization IsAllowedToPlay(const HTMLMediaElement& aElement);
// Returns whether a given AudioContext is allowed to play.
static bool IsAudioContextAllowedToPlay(NotNull<AudioContext*> aContext);
// Returns the AutoplayRequest that a given document must request on
// for autoplay permission.
static already_AddRefed<AutoplayRequest> RequestFor(
const nsIDocument& aDocument);
};
} // namespace dom
} // namespace mozilla
#endif