Bug 1943650 - Command-line --help output misformatted after --dbus-service. r=emilio
[gecko.git] / dom / media / autoplay / AutoplayPolicy.h
blob5d884ac74e314e8238e004f6179a1becacd39151
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim:set ts=2 sw=2 sts=2 et cindent: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #if !defined(AutoplayPolicy_h_)
8 # define AutoplayPolicy_h_
10 # include "mozilla/NotNull.h"
12 class nsIPrincipal;
14 namespace mozilla::dom {
16 class HTMLMediaElement;
17 class AudioContext;
18 class Document;
19 enum class AutoplayPolicy : uint8_t;
20 enum class AutoplayPolicyMediaType : uint8_t;
22 } // namespace mozilla::dom
24 namespace mozilla::media {
25 /**
26 * AutoplayPolicy is used to manage autoplay logic for all kinds of media,
27 * including MediaElement, Web Audio and Web Speech.
29 * Autoplay could be disable by setting the pref "media.autoplay.default"
30 * to anything but nsIAutoplay::Allowed. Once user disables autoplay, media
31 * could only be played if one of following conditions is true.
32 * 1) Owner document is activated by user gestures
33 * We restrict user gestures to "mouse click", "keyboard press" and "touch".
34 * 2) Muted media content or video without audio content.
35 * 3) Document's origin has the "autoplay-media" permission.
37 class AutoplayPolicy {
38 public:
39 // Returns whether a given media element is allowed to play.
40 static bool IsAllowedToPlay(const dom::HTMLMediaElement& aElement);
42 // Returns whether a given AudioContext is allowed to play.
43 static bool IsAllowedToPlay(const dom::AudioContext& aContext);
45 // Return the value of the autoplay permission for given principal. The return
46 // value can be 0=unknown, 1=allow, 2=block audio, 5=block audio and video.
47 static uint32_t GetSiteAutoplayPermission(nsIPrincipal* aPrincipal);
49 // Following methods are used for the internal implementation for the Autoplay
50 // Policy Detection API, the public JS interfaces are in exposed on Navigator.
51 // https://w3c.github.io/autoplay/#autoplay-detection-methods
52 static dom::AutoplayPolicy GetAutoplayPolicy(
53 const dom::HTMLMediaElement& aElement);
55 static dom::AutoplayPolicy GetAutoplayPolicy(
56 const dom::AudioContext& aContext);
58 static dom::AutoplayPolicy GetAutoplayPolicy(
59 const dom::AutoplayPolicyMediaType& aType, const dom::Document& aDoc);
62 } // namespace mozilla::media
64 #endif