#include "third_party/blink/renderer/core/permissions_policy/permissions_policy_parser.h"
#include <bitset>
#include <utility>
#include "base/containers/contains.h"
#include "base/feature_list.h"
#include "base/metrics/histogram_macros.h"
#include "net/http/structured_headers.h"
#include "third_party/blink/public/common/features.h"
#include "third_party/blink/public/common/permissions_policy/origin_with_possible_wildcards.h"
#include "third_party/blink/public/mojom/permissions_policy/permissions_policy.mojom-blink.h"
#include "third_party/blink/renderer/core/execution_context/execution_context.h"
#include "third_party/blink/renderer/core/frame/deprecation/deprecation.h"
#include "third_party/blink/renderer/core/frame/local_dom_window.h"
#include "third_party/blink/renderer/core/frame/web_feature.h"
#include "third_party/blink/renderer/core/html/parser/html_parser_idioms.h"
#include "third_party/blink/renderer/core/origin_trials/origin_trial_context.h"
#include "third_party/blink/renderer/platform/allow_discouraged_type.h"
#include "third_party/blink/renderer/platform/instrumentation/use_counter.h"
#include "third_party/blink/renderer/platform/json/json_values.h"
#include "third_party/blink/renderer/platform/network/http_parsers.h"
#include "third_party/blink/renderer/platform/weborigin/security_origin.h"
#include "third_party/blink/renderer/platform/wtf/casting.h"
#include "third_party/blink/renderer/platform/wtf/hash_set.h"
#include "third_party/blink/renderer/platform/wtf/text/string_utf8_adaptor.h"
#include "url/origin.h"
namespace blink {
namespace {
class ParsedFeaturePolicies final
: public GarbageCollected<ParsedFeaturePolicies>,
public Supplement<ExecutionContext> { … };
const char ParsedFeaturePolicies::kSupplementName[] = …;
class FeatureObserver { … };
class ParsingContext { … };
bool FeatureObserver::FeatureObserved(
mojom::blink::PermissionsPolicyFeature feature) { … }
void ParsingContext::ReportFeatureUsageLegacy(
mojom::blink::PermissionsPolicyFeature feature) { … }
void ParsingContext::ReportFeatureUsage(
mojom::blink::PermissionsPolicyFeature feature) { … }
std::optional<mojom::blink::PermissionsPolicyFeature>
ParsingContext::ParseFeatureName(const String& feature_name) { … }
ParsingContext::ParsedAllowlist ParsingContext::ParseAllowlist(
const Vector<String>& origin_strings,
const OriginWithPossibleWildcards::NodeType type) { … }
std::optional<ParsedPermissionsPolicyDeclaration> ParsingContext::ParseFeature(
const PermissionsPolicyParser::Declaration& declaration_node,
const OriginWithPossibleWildcards::NodeType type) { … }
ParsedPermissionsPolicy ParsingContext::ParseFeaturePolicy(
const String& policy) { … }
ParsedPermissionsPolicy ParsingContext::ParsePermissionsPolicy(
const String& policy) { … }
ParsedPermissionsPolicy ParsingContext::ParsePolicyFromNode(
const PermissionsPolicyParser::Node& root) { … }
PermissionsPolicyParser::Node ParsingContext::ParseFeaturePolicyToIR(
const String& policy) { … }
PermissionsPolicyParser::Node ParsingContext::ParsePermissionsPolicyToIR(
const String& policy) { … }
}
ParsedPermissionsPolicy PermissionsPolicyParser::ParseHeader(
const String& feature_policy_header,
const String& permissions_policy_header,
scoped_refptr<const SecurityOrigin> origin,
PolicyParserMessageBuffer& feature_policy_logger,
PolicyParserMessageBuffer& permissions_policy_logger,
ExecutionContext* execution_context) { … }
ParsedPermissionsPolicy PermissionsPolicyParser::ParseAttribute(
const String& policy,
scoped_refptr<const SecurityOrigin> self_origin,
scoped_refptr<const SecurityOrigin> src_origin,
PolicyParserMessageBuffer& logger,
ExecutionContext* execution_context) { … }
ParsedPermissionsPolicy PermissionsPolicyParser::ParsePolicyFromNode(
PermissionsPolicyParser::Node& policy,
scoped_refptr<const SecurityOrigin> origin,
PolicyParserMessageBuffer& logger,
ExecutionContext* execution_context) { … }
ParsedPermissionsPolicy PermissionsPolicyParser::ParseFeaturePolicyForTest(
const String& policy,
scoped_refptr<const SecurityOrigin> self_origin,
scoped_refptr<const SecurityOrigin> src_origin,
PolicyParserMessageBuffer& logger,
const FeatureNameMap& feature_names,
ExecutionContext* execution_context) { … }
ParsedPermissionsPolicy PermissionsPolicyParser::ParsePermissionsPolicyForTest(
const String& policy,
scoped_refptr<const SecurityOrigin> self_origin,
scoped_refptr<const SecurityOrigin> src_origin,
PolicyParserMessageBuffer& logger,
const FeatureNameMap& feature_names,
ExecutionContext* execution_context) { … }
bool IsFeatureDeclared(mojom::blink::PermissionsPolicyFeature feature,
const ParsedPermissionsPolicy& policy) { … }
bool RemoveFeatureIfPresent(mojom::blink::PermissionsPolicyFeature feature,
ParsedPermissionsPolicy& policy) { … }
bool DisallowFeatureIfNotPresent(mojom::blink::PermissionsPolicyFeature feature,
ParsedPermissionsPolicy& policy) { … }
bool AllowFeatureEverywhereIfNotPresent(
mojom::blink::PermissionsPolicyFeature feature,
ParsedPermissionsPolicy& policy) { … }
void DisallowFeature(mojom::blink::PermissionsPolicyFeature feature,
ParsedPermissionsPolicy& policy) { … }
bool IsFeatureForMeasurementOnly(
mojom::blink::PermissionsPolicyFeature feature) { … }
void AllowFeatureEverywhere(mojom::blink::PermissionsPolicyFeature feature,
ParsedPermissionsPolicy& policy) { … }
const Vector<String> GetAvailableFeatures(ExecutionContext* execution_context) { … }
const String GetNameForFeature(mojom::blink::PermissionsPolicyFeature feature,
bool is_isolated_context) { … }
}