chromium/third_party/blink/renderer/core/permissions_policy/policy_helper.h

// Copyright 2019 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef THIRD_PARTY_BLINK_RENDERER_CORE_PERMISSIONS_POLICY_POLICY_HELPER_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_PERMISSIONS_POLICY_POLICY_HELPER_H_

#include "third_party/blink/public/common/permissions_policy/permissions_policy.h"
#include "third_party/blink/public/mojom/devtools/console_message.mojom-blink.h"
#include "third_party/blink/public/mojom/permissions_policy/document_policy_feature.mojom-blink.h"
#include "third_party/blink/public/mojom/permissions_policy/permissions_policy.mojom-blink-forward.h"
#include "third_party/blink/public/mojom/permissions_policy/permissions_policy_feature.mojom-blink-forward.h"
#include "third_party/blink/renderer/core/core_export.h"
#include "third_party/blink/renderer/platform/wtf/hash_map.h"
#include "third_party/blink/renderer/platform/wtf/hash_set.h"
#include "third_party/blink/renderer/platform/wtf/hash_traits.h"
#include "third_party/blink/renderer/platform/wtf/text/wtf_string.h"
#include "third_party/blink/renderer/platform/wtf/vector.h"

namespace blink {
class PolicyParserMessageBuffer {};

struct FeatureNameMapCacheKey {};
FeatureNameMap;
FeatureNameMapCache;

DocumentPolicyFeatureSet;

class ExecutionContext;
class FeatureContext;

// This method defines the feature names which will be recognized by the parser
// for the Permissions-Policy HTTP header and the <iframe> "allow" attribute, as
// well as the features which will be recognized by the document or iframe
// policy object.
CORE_EXPORT const FeatureNameMap
GetDefaultFeatureNameMap(bool is_isolated_context);

// This method defines the feature names which will be recognized by the parser
// for the Document-Policy HTTP header and the <iframe> "policy" attribute, as
// well as the features which will be recognized by the document or iframe
// policy object.
const DocumentPolicyFeatureSet& GetAvailableDocumentPolicyFeatures();

// Refresh the set content based on current RuntimeFeatures environment.
CORE_EXPORT void ResetAvailableDocumentPolicyFeaturesForTest();

// Returns true if this PermissionsPolicyFeature is currently disabled by an
// origin trial (it is origin trial controlled, and the origin trial is not
// enabled). The first String param should be a name of
// PermissionsPolicyFeature.
bool DisabledByOriginTrial(const String&, FeatureContext*);

// Returns true if this DocumentPolicyFeature is currently disabled by an origin
// trial (it is origin trial controlled, and the origin trial is not enabled).
bool DisabledByOriginTrial(mojom::blink::DocumentPolicyFeature,
                           FeatureContext*);

// Converts |mojom::blink::PermissionsPolicyFeature| to enum used in devtools
// protocol.
String PermissionsPolicyFeatureToProtocol(
    mojom::blink::PermissionsPolicyFeature,
    ExecutionContext*);

}  // namespace blink

namespace WTF {

// A helper that defines the hash function and the invalid 'empty value' that
// HashMap should use internally.
template <>
struct HashTraits<blink::FeatureNameMapCacheKey>
    : SimpleClassHashTraits<blink::FeatureNameMapCacheKey> {};

}  // namespace WTF

#endif  // THIRD_PARTY_BLINK_RENDERER_CORE_PERMISSIONS_POLICY_POLICY_HELPER_H_