dymokomi/luce-browser-engine
Source of release 0.6.1
0.6.1 / src / web / content_security_policy / directives / style_source_attribute_directive.lucb
#==============================================================================================
#
# style_source_attribute_directive - ContentSecurityPolicy::Directives::StyleSourceAttributeDirective
# (the style-src-attr directive): the inline check of its source list
#
# DESCRIPTION:
# Port of Libraries/LibWeb/ContentSecurityPolicy/Directives/StyleSourceAttributeDirective.cpp
# (lines 1-41).
#
# Copyright (c) 2024, Luke Wilde <luke@ladybird.org>
# SPDX-License-Identifier: BSD-2-Clause
#
#==============================================================================================
## Ported from Libraries/LibWeb/ContentSecurityPolicy/Directives/StyleSourceAttributeDirective.cpp:16 Web::ContentSecurityPolicy::Directives::StyleSourceAttributeDirective::StyleSourceAttributeDirective.
func content_security_policy_style_source_attribute_directive_construct(this: ContentSecurityPolicyStyleSourceAttributeDirective*, name: ak.String, value: ak.Vector[ak.String]):
content_security_policy_directive_construct(this.content_security_policy_directive(), name, value)
## Ported from Libraries/LibWeb/ContentSecurityPolicy/Directives/StyleSourceAttributeDirective.cpp:22 Web::ContentSecurityPolicy::Directives::StyleSourceAttributeDirective::inline_check (override).
# https://w3c.github.io/webappsec-csp/#style-src-attr-inline
pub func content_security_policy_style_source_attribute_directive_inline_check_impl(base: ContentSecurityPolicyDirective*, arg0: gc.Heap*, element: DomElement*?, type_: ContentSecurityPolicyInlineType, policy: ContentSecurityPolicyPolicy*, source: ak.String) -> ContentSecurityPolicyResult:
# 1. Let name be the result of executing § 6.8.2 Get the effective directive for inline checks on type.
let name = content_security_policy_directives_get_the_effective_directive_for_inline_checks(type_)
# 2. If the result of executing § 6.8.4 Should fetch directive execute on name, style-src-attr and policy is "No",
# return "Allowed".
if content_security_policy_directives_should_fetch_directive_execute(name, content_security_policy_directives_names_style_src_attr, policy) == ContentSecurityPolicyShouldExecute.no:
return ContentSecurityPolicyResult.allowed
# 3. If the result of executing § 6.7.3.3 Does element match source list for type and source? on element, this
# directive’s value, type, and source, is "Does Not Match", return "Blocked".
if content_security_policy_directives_does_element_match_source_list_for_type_and_source(element, &base.m_value, type_, source) == ContentSecurityPolicyDirectivesMatchResult.does_not_match:
return ContentSecurityPolicyResult.blocked
# 4. Return "Allowed".
return ContentSecurityPolicyResult.allowed