mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 21:37:36 +00:00
LibWeb+LibWebView+WebContent: Add APIs to manage an autoplay allowlist
The spec defines a Permissions Policy to control some browser behaviors on a per-origin basis. Management of these permissions live in their own spec: https://w3c.github.io/webappsec-permissions-policy/ This implements a somewhat ad-hoc Permissions Policy for autoplaying media elements. We will need to implement the entire policy spec for this to be more general.
This commit is contained in:
parent
6131e621d6
commit
7966fc4780
12 changed files with 209 additions and 0 deletions
|
@ -72,6 +72,7 @@
|
|||
#include <LibWeb/Layout/Viewport.h>
|
||||
#include <LibWeb/Namespace.h>
|
||||
#include <LibWeb/Page/Page.h>
|
||||
#include <LibWeb/PermissionsPolicy/AutoplayAllowlist.h>
|
||||
#include <LibWeb/Platform/Timer.h>
|
||||
#include <LibWeb/SVG/TagNames.h>
|
||||
#include <LibWeb/Selection/Selection.h>
|
||||
|
@ -2398,6 +2399,31 @@ void Document::unload(bool recursive_flag, Optional<DocumentUnloadTimingInfo> un
|
|||
m_unload_counter -= 1;
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/iframe-embed-object.html#allowed-to-use
|
||||
bool Document::is_allowed_to_use_feature(PolicyControlledFeature feature) const
|
||||
{
|
||||
// 1. If document's browsing context is null, then return false.
|
||||
if (browsing_context() == nullptr)
|
||||
return false;
|
||||
|
||||
// 2. If document is not fully active, then return false.
|
||||
if (!is_fully_active())
|
||||
return false;
|
||||
|
||||
// 3. If the result of running is feature enabled in document for origin on feature, document, and document's origin
|
||||
// is "Enabled", then return true.
|
||||
// FIXME: This is ad-hoc. Implement the Permissions Policy specification.
|
||||
switch (feature) {
|
||||
case PolicyControlledFeature::Autoplay:
|
||||
if (PermissionsPolicy::AutoplayAllowlist::the().is_allowed_for_origin(*this, origin()) == PermissionsPolicy::Decision::Enabled)
|
||||
return true;
|
||||
break;
|
||||
}
|
||||
|
||||
// 4. Return false.
|
||||
return false;
|
||||
}
|
||||
|
||||
void Document::did_stop_being_active_document_in_browsing_context(Badge<HTML::BrowsingContext>)
|
||||
{
|
||||
tear_down_layout_tree();
|
||||
|
|
|
@ -74,6 +74,10 @@ struct ElementCreationOptions {
|
|||
DeprecatedString is;
|
||||
};
|
||||
|
||||
enum class PolicyControlledFeature {
|
||||
Autoplay,
|
||||
};
|
||||
|
||||
class Document
|
||||
: public ParentNode
|
||||
, public NonElementParentNode<Document>
|
||||
|
@ -456,6 +460,8 @@ public:
|
|||
DocumentUnloadTimingInfo const& previous_document_unload_timing() const { return m_previous_document_unload_timing; }
|
||||
void set_previous_document_unload_timing(DocumentUnloadTimingInfo const& previous_document_unload_timing) { m_previous_document_unload_timing = previous_document_unload_timing; }
|
||||
|
||||
bool is_allowed_to_use_feature(PolicyControlledFeature) const;
|
||||
|
||||
void did_stop_being_active_document_in_browsing_context(Badge<HTML::BrowsingContext>);
|
||||
|
||||
bool query_command_supported(DeprecatedString const&) const;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue