The autoplay setting was binary and its default blocked all media, including muted video, leaving sites that rely on muted autoplay visibly broken. Replace it with a tri-state user-agent autoplay policy (allow audio and video, block audio, or block audio and video) defaulting to allowing only inaudible media to autoplay. This is enforced through the media element's "allowed to play" check, so unmuting a muted autoplay or calling `play()` cannot slip audio past the policy; audible playback is permitted once the document has been activated by the user. The policy lives in a dedicated AutoplaySettings consulted from HTMLMediaElement instead of the Permissions Policy "allowed to use feature" check it was previously conflated with.
41 lines
989 B
C++
41 lines
989 B
C++
/*
|
|
* Copyright (c) 2023-2025, Tim Flynn <trflynn89@ladybird.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <AK/Vector.h>
|
|
#include <LibURL/Forward.h>
|
|
#include <LibWeb/Export.h>
|
|
#include <LibWeb/Forward.h>
|
|
#include <LibWeb/HTML/AutoplayPolicy.h>
|
|
|
|
namespace Web::HTML {
|
|
|
|
enum class AutoplayDecision : u8 {
|
|
Allowed,
|
|
AllowedIfInaudible,
|
|
Blocked,
|
|
};
|
|
|
|
// Holds the user agent's autoplay configuration for this process: the global policy plus the set of
|
|
// origins that may always autoplay regardless of that policy. Populated from the browser process.
|
|
class WEB_API AutoplaySettings {
|
|
public:
|
|
static AutoplaySettings& the();
|
|
|
|
AutoplayDecision decision_for_origin(DOM::Document const&, URL::Origin const&) const;
|
|
|
|
void set_policy(AutoplayPolicy, ReadonlySpan<String> allowlist);
|
|
|
|
private:
|
|
AutoplaySettings();
|
|
~AutoplaySettings();
|
|
|
|
AutoplayPolicy m_policy { AutoplayPolicy::BlockAudio };
|
|
Vector<URL::Origin> m_allowlist;
|
|
};
|
|
|
|
}
|