chromium/third_party/blink/renderer/build/scripts/templates/document_policy_features.cc.tmpl

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


#include "base/no_destructor.h"
#include "base/feature_list.h"
#include "third_party/blink/public/common/features.h"
#include "third_party/blink/public/common/permissions_policy/document_policy_features.h"
#include "third_party/blink/public/common/permissions_policy/policy_value.h"
#include "third_party/blink/public/mojom/permissions_policy/policy_value.mojom.h"
#include "third_party/blink/public/mojom/permissions_policy/document_policy_feature.mojom.h"


namespace blink {

const DocumentPolicyFeatureInfoMap& GetDocumentPolicyFeatureInfoMap() {
  static const base::NoDestructor<DocumentPolicyFeatureInfoMap> feature_info_map([] {
    DocumentPolicyFeatureInfoMap map({
      {%- for feature in features %}
        {
          mojom::DocumentPolicyFeature::k{{feature.name}},
          {
            "{{feature.document_policy_name}}",
            {{parse_default_value(feature.default_value, feature.value_type)}}
          }
        },
      {%- endfor %}
    });

    {%- for feature in features %}
    {%- if feature.default_value_behind_flag %}
      {%- for flag, default_value in feature.default_value_behind_flag %}
        {%- if not loop.first %} else {% endif %}
        if (base::FeatureList::IsEnabled(features::k{{flag}})) {
          map.find(mojom::DocumentPolicyFeature::k{{feature.name}})->second.default_value =
            {{parse_default_value(default_value, feature.value_type)}};
        }
      {%- endfor %}
    {%- endif %}
    {%- endfor %}

    return map;
  }());
  return *feature_info_map;
}

const DocumentPolicyNameFeatureMap& GetDocumentPolicyNameFeatureMap() {
  static const base::NoDestructor<DocumentPolicyNameFeatureMap> name_feature_map([] {
    DocumentPolicyNameFeatureMap map;
    for (const auto& entry : GetDocumentPolicyFeatureInfoMap())
      map.emplace(entry.second.feature_name, entry.first);
    return map;
  }());
  return *name_feature_map;
}

} // namespace blink