mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 10:18:11 +00:00
LibWeb: Convert SandboxingFlagSet into a enum class
Instead of having a nested enum within a struct, use the macro AK_ENUM_BITWISE_OPERATORS to add all the convienent has_flag free functions and such for ease of use.
This commit is contained in:
parent
967cb86c5b
commit
d97b09693e
9 changed files with 39 additions and 41 deletions
|
@ -52,7 +52,7 @@ static bool url_matches_about_blank(AK::URL const& url)
|
|||
HTML::Origin determine_the_origin(BrowsingContext const& browsing_context, Optional<AK::URL> url, SandboxingFlagSet sandbox_flags, Optional<HTML::Origin> invocation_origin)
|
||||
{
|
||||
// 1. If sandboxFlags has its sandboxed origin browsing context flag set, then return a new opaque origin.
|
||||
if (sandbox_flags.flags & SandboxingFlagSet::SandboxedOrigin) {
|
||||
if (has_flag(sandbox_flags, SandboxingFlagSet::SandboxedOrigin)) {
|
||||
return HTML::Origin {};
|
||||
}
|
||||
|
||||
|
@ -80,7 +80,7 @@ HTML::Origin determine_the_origin(BrowsingContext const& browsing_context, Optio
|
|||
HTML::Origin determine_the_origin(AK::URL const& url, SandboxingFlagSet sandbox_flags, Optional<HTML::Origin> source_origin, Optional<HTML::Origin> container_origin)
|
||||
{
|
||||
// 1. If sandboxFlags has its sandboxed origin browsing context flag set, then return a new opaque origin.
|
||||
if (sandbox_flags.flags & SandboxingFlagSet::SandboxedOrigin) {
|
||||
if (has_flag(sandbox_flags, SandboxingFlagSet::SandboxedOrigin)) {
|
||||
return HTML::Origin {};
|
||||
}
|
||||
|
||||
|
@ -135,7 +135,7 @@ JS::NonnullGCPtr<BrowsingContext> BrowsingContext::create_a_new_browsing_context
|
|||
}
|
||||
|
||||
// FIXME: 4. Let sandboxFlags be the result of determining the creation sandboxing flags given browsingContext and embedded.
|
||||
SandboxingFlagSet sandbox_flags;
|
||||
SandboxingFlagSet sandbox_flags = {};
|
||||
|
||||
// 5. Let origin be the result of determining the origin given browsingContext, about:blank, sandboxFlags, and browsingContext's creator origin.
|
||||
auto origin = determine_the_origin(*browsing_context, AK::URL("about:blank"), sandbox_flags, browsing_context->m_creator_origin);
|
||||
|
@ -311,7 +311,7 @@ WebIDL::ExceptionOr<BrowsingContext::BrowsingContextAndDocument> BrowsingContext
|
|||
}
|
||||
|
||||
// FIXME: 5. Let sandboxFlags be the result of determining the creation sandboxing flags given browsingContext and embedder.
|
||||
SandboxingFlagSet sandbox_flags;
|
||||
SandboxingFlagSet sandbox_flags = {};
|
||||
|
||||
// 6. Let origin be the result of determining the origin given about:blank, sandboxFlags, creatorOrigin, and null.
|
||||
auto origin = determine_the_origin(AK::URL("about:blank"sv), sandbox_flags, creator_origin, {});
|
||||
|
@ -890,7 +890,7 @@ BrowsingContext::ChosenBrowsingContext BrowsingContext::choose_a_browsing_contex
|
|||
}
|
||||
|
||||
// --> If sandboxingFlagSet has the sandboxed auxiliary navigation browsing context flag set
|
||||
else if (sandboxing_flag_set.flags & SandboxingFlagSet::SandboxedAuxiliaryNavigation) {
|
||||
else if (has_flag(sandboxing_flag_set, SandboxingFlagSet::SandboxedAuxiliaryNavigation)) {
|
||||
// FIXME: The user agent may report to a developer console that a popup has been blocked.
|
||||
dbgln("Pop-up blocked!");
|
||||
}
|
||||
|
@ -1445,7 +1445,7 @@ bool BrowsingContext::is_allowed_to_navigate(BrowsingContext const& other) const
|
|||
// and A's active document's active sandboxing flag set has its sandboxed top-level navigation with user activation browsing context flag set,
|
||||
// then return false.
|
||||
if (active_window()->has_transient_activation()
|
||||
&& active_document()->active_sandboxing_flag_set().flags & SandboxingFlagSet::SandboxedTopLevelNavigationWithUserActivation) {
|
||||
&& has_flag(active_document()->active_sandboxing_flag_set(), SandboxingFlagSet::SandboxedTopLevelNavigationWithUserActivation)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -1453,7 +1453,7 @@ bool BrowsingContext::is_allowed_to_navigate(BrowsingContext const& other) const
|
|||
// and A's active document's active sandboxing flag set has its sandboxed top-level navigation without user activation browsing context flag set,
|
||||
// then return false.
|
||||
if (!active_window()->has_transient_activation()
|
||||
&& active_document()->active_sandboxing_flag_set().flags & SandboxingFlagSet::SandboxedTopLevelNavigationWithoutUserActivation) {
|
||||
&& has_flag(active_document()->active_sandboxing_flag_set(), SandboxingFlagSet::SandboxedTopLevelNavigationWithoutUserActivation)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -1466,7 +1466,7 @@ bool BrowsingContext::is_allowed_to_navigate(BrowsingContext const& other) const
|
|||
if (other.is_top_level()
|
||||
&& &other != this
|
||||
&& !other.is_ancestor_of(*this)
|
||||
&& active_document()->active_sandboxing_flag_set().flags & SandboxingFlagSet::SandboxedNavigation
|
||||
&& has_flag(active_document()->active_sandboxing_flag_set(), SandboxingFlagSet::SandboxedNavigation)
|
||||
&& this != other.the_one_permitted_sandboxed_navigator()) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -74,7 +74,7 @@ WebIDL::ExceptionOr<void> HTMLFormElement::submit_form(JS::NonnullGCPtr<HTMLElem
|
|||
auto* form_browsing_context = form_document->browsing_context();
|
||||
|
||||
// 4. If form document's active sandboxing flag set has its sandboxed forms browsing context flag set, then return.
|
||||
if (form_document->active_sandboxing_flag_set().flags & HTML::SandboxingFlagSet::Flag::SandboxedForms)
|
||||
if (has_flag(form_document->active_sandboxing_flag_set(), HTML::SandboxingFlagSet::SandboxedForms))
|
||||
return {};
|
||||
|
||||
// 5. If the submitted from submit() method flag is not set, then:
|
||||
|
|
|
@ -1655,7 +1655,7 @@ bool HTMLMediaElement::is_eligible_for_autoplay() const
|
|||
has_attribute(HTML::AttributeNames::autoplay) &&
|
||||
|
||||
// Its node document's active sandboxing flag set does not have the sandboxed automatic features browsing context flag set.
|
||||
(document().active_sandboxing_flag_set().flags & SandboxingFlagSet::SandboxedAutomaticFeatures) == 0 &&
|
||||
!has_flag(document().active_sandboxing_flag_set(), SandboxingFlagSet::SandboxedAutomaticFeatures) &&
|
||||
|
||||
// Its node document is allowed to use the "autoplay" feature.
|
||||
document().is_allowed_to_use_feature(DOM::PolicyControlledFeature::Autoplay));
|
||||
|
|
|
@ -490,7 +490,7 @@ static WebIDL::ExceptionOr<Optional<NavigationParams>> create_navigation_params_
|
|||
JS::GCPtr<Fetch::Infrastructure::FetchController> fetch_controller = nullptr;
|
||||
|
||||
// 13. Let finalSandboxFlags be an empty sandboxing flag set.
|
||||
SandboxingFlagSet final_sandbox_flags;
|
||||
SandboxingFlagSet final_sandbox_flags = {};
|
||||
|
||||
// 16. Let locationURL be null.
|
||||
ErrorOr<Optional<AK::URL>> location_url { OptionalNone {} };
|
||||
|
|
|
@ -36,7 +36,7 @@ struct NavigationParams {
|
|||
PolicyContainer policy_container;
|
||||
|
||||
// a sandboxing flag set to impose on the new Document
|
||||
SandboxingFlagSet final_sandboxing_flag_set;
|
||||
SandboxingFlagSet final_sandboxing_flag_set = {};
|
||||
|
||||
// a cross-origin opener policy to use for the new Document
|
||||
CrossOriginOpenerPolicy cross_origin_opener_policy;
|
||||
|
|
|
@ -6,35 +6,33 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <AK/EnumBits.h>
|
||||
#include <AK/Types.h>
|
||||
|
||||
namespace Web::HTML {
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/origin.html#sandboxing-flag-set
|
||||
struct SandboxingFlagSet {
|
||||
enum Flag {
|
||||
SandboxedNavigation = 1u << 0u,
|
||||
SandboxedAuxiliaryNavigation = 1u << 1u,
|
||||
SandboxedTopLevelNavigationWithoutUserActivation = 1u << 2u,
|
||||
SandboxedTopLevelNavigationWithUserActivation = 1u << 3u,
|
||||
SandboxedPlugins = 1u << 4u,
|
||||
SandboxedOrigin = 1u << 5u,
|
||||
SandboxedForms = 1u << 6u,
|
||||
SandboxedPointerLock = 1u << 7u,
|
||||
SandboxedScripts = 1u << 8u,
|
||||
SandboxedAutomaticFeatures = 1u << 9u,
|
||||
SandboxedDocumentDomain = 1u << 10u,
|
||||
SandboxPropagatesToAuxiliaryBrowsingContexts = 1u << 11u,
|
||||
SandboxedModals = 1u << 12u,
|
||||
SandboxedOrientationLock = 1u << 13u,
|
||||
SandboxedPresentation = 1u << 14u,
|
||||
SandboxedDownloads = 1u << 15u,
|
||||
SandboxedCustomProtocols = 1u << 16u,
|
||||
};
|
||||
|
||||
bool is_empty() const { return flags == 0; }
|
||||
|
||||
u32 flags { 0 };
|
||||
enum class SandboxingFlagSet {
|
||||
SandboxedNavigation = 1u << 0u,
|
||||
SandboxedAuxiliaryNavigation = 1u << 1u,
|
||||
SandboxedTopLevelNavigationWithoutUserActivation = 1u << 2u,
|
||||
SandboxedTopLevelNavigationWithUserActivation = 1u << 3u,
|
||||
SandboxedPlugins = 1u << 4u,
|
||||
SandboxedOrigin = 1u << 5u,
|
||||
SandboxedForms = 1u << 6u,
|
||||
SandboxedPointerLock = 1u << 7u,
|
||||
SandboxedScripts = 1u << 8u,
|
||||
SandboxedAutomaticFeatures = 1u << 9u,
|
||||
SandboxedDocumentDomain = 1u << 10u,
|
||||
SandboxPropagatesToAuxiliaryBrowsingContexts = 1u << 11u,
|
||||
SandboxedModals = 1u << 12u,
|
||||
SandboxedOrientationLock = 1u << 13u,
|
||||
SandboxedPresentation = 1u << 14u,
|
||||
SandboxedDownloads = 1u << 15u,
|
||||
SandboxedCustomProtocols = 1u << 16u,
|
||||
};
|
||||
|
||||
AK_ENUM_BITWISE_OPERATORS(SandboxingFlagSet);
|
||||
inline bool is_empty(SandboxingFlagSet s) { return (to_underlying(s) & 0x1FFU) == 0; }
|
||||
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ struct SourceSnapshotParams {
|
|||
bool has_transient_activation;
|
||||
|
||||
// a sandboxing flag set
|
||||
SandboxingFlagSet sandboxing_flags;
|
||||
SandboxingFlagSet sandboxing_flags = {};
|
||||
|
||||
// a boolean
|
||||
bool allows_downloading;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue