Commit bf8458a6 authored by Charlie Hu's avatar Charlie Hu Committed by Commit Bot

Add document_policy_features.cc generation

This CL adds document_policy_features.h/.cc where all document policy
features can be retrieved. document_policy_features are in blink/common
directory because the serialization of document policy on browser side
needs feature to name mapping.

Change-Id: I850c6c9c008174ee39d89f60962cee5d30a639a1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2014149
Commit-Queue: Charlie Hu <chenleihu@google.com>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Reviewed-by: default avatarIan Clelland <iclelland@chromium.org>
Cr-Commit-Position: refs/heads/master@{#737172}
parent 9b92a6a2
......@@ -5,6 +5,28 @@
import("//build/config/jumbo.gni")
import("//testing/libfuzzer/fuzzer_test.gni")
import("//testing/test.gni")
import("//third_party/blink/renderer/build/scripts/scripts.gni")
blink_python_runner("make_generated_document_policy_features") {
script = "../renderer/build/scripts/make_document_policy_features.py"
inputs =
scripts_for_json5_files + [
"../renderer/build/scripts/make_document_policy_features.py",
"../renderer/core/feature_policy/document_policy_features.json5",
"../renderer/build/scripts/templates/document_policy_features.cc.tmpl",
]
outputs = [ "$root_gen_dir/third_party/blink/common/feature_policy/document_policy_features.cc" ]
args = [
rebase_path(
"../renderer/core/feature_policy/document_policy_features.json5",
root_build_dir),
"--output_dir",
rebase_path("$root_gen_dir/third_party/blink/common/feature_policy",
root_build_dir),
]
}
jumbo_source_set("common") {
# No target should directly depend on this target since this is just the
......@@ -99,7 +121,12 @@ jumbo_source_set("common") {
"web_package/signed_exchange_request_matcher.cc",
]
public_deps = [ "//third_party/blink/public/common:headers" ]
sources += get_target_outputs(":make_generated_document_policy_features")
public_deps = [
":make_generated_document_policy_features",
"//third_party/blink/public/common:headers",
]
deps = [
"//base",
......
......@@ -51,7 +51,6 @@ struct FeatureInfo {
using FeatureInfoMap = std::map<mojom::FeaturePolicyFeature, FeatureInfo>;
// TODO(iclelland): Generate this block
const FeatureInfoMap& GetDefaultFeatureInfoMap() {
static base::NoDestructor<FeatureInfoMap> feature_info_map(
{{mojom::FeaturePolicyFeature::kFontDisplay,
......
......@@ -63,6 +63,7 @@ source_set("headers") {
"dom_storage/session_storage_namespace_id.h",
"experiments/memory_ablation_experiment.h",
"feature_policy/document_policy.h",
"feature_policy/document_policy_features.h",
"feature_policy/feature_policy.h",
"feature_policy/policy_value.h",
"features.h",
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef THIRD_PARTY_BLINK_PUBLIC_COMMON_FEATURE_POLICY_DOCUMENT_POLICY_FEATURES_H_
#define THIRD_PARTY_BLINK_PUBLIC_COMMON_FEATURE_POLICY_DOCUMENT_POLICY_FEATURES_H_
#include "base/containers/flat_map.h"
#include "third_party/blink/public/common/common_export.h"
#include "third_party/blink/public/common/feature_policy/policy_value.h"
#include "third_party/blink/public/mojom/feature_policy/feature_policy_feature.mojom-forward.h"
namespace blink {
struct DocumentPolicyFeatureInfo {
std::string feature_name;
std::string feature_param_name;
PolicyValue default_value;
};
using DocumentPolicyFeatureInfoMap =
base::flat_map<mojom::FeaturePolicyFeature, DocumentPolicyFeatureInfo>;
using DocumentPolicyNameFeatureMap =
base::flat_map<std::string, mojom::FeaturePolicyFeature>;
BLINK_COMMON_EXPORT const DocumentPolicyFeatureInfoMap&
GetDocumentPolicyFeatureInfoMap();
BLINK_COMMON_EXPORT const DocumentPolicyNameFeatureMap&
GetDocumentPolicyNameFeatureMap();
} // namespace blink
#endif // THIRD_PARTY_BLINK_PUBLIC_COMMON_FEATURE_POLICY_DOCUMENT_POLICY_FEATURES_H_
# Copyright 2020 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import json5_generator
import template_expander
class DocumentPolicyFeatureWriter(json5_generator.Writer):
file_basename = 'document_policy_features'
def __init__(self, json5_file_path, output_dir):
super(DocumentPolicyFeatureWriter, self).__init__(json5_file_path, output_dir)
@template_expander.use_jinja('templates/' + self.file_basename + '.cc.tmpl')
def generate_implementation():
return {
'header_guard': self.make_header_guard(self._relative_output_dir + self.file_basename + '.h'),
'input_files': self._input_files,
'features': self.json5_file.name_dictionaries
}
self._outputs = {
self.file_basename + '.cc': generate_implementation,
}
if __name__ == '__main__':
json5_generator.Maker(DocumentPolicyFeatureWriter).main()
{% from 'templates/macros.tmpl' import license, source_files_for_generated_file %}
{{license()}}
{{ source_files_for_generated_file(template_file, input_files) }}
#include "base/no_destructor.h"
#include "third_party/blink/public/common/feature_policy/document_policy_features.h"
#include "third_party/blink/public/common/feature_policy/policy_value.h"
#include "third_party/blink/public/mojom/feature_policy/feature_policy_feature.mojom.h"
#include "third_party/blink/public/mojom/feature_policy/policy_value.mojom.h"
namespace blink {
const DocumentPolicyFeatureInfoMap& GetDocumentPolicyFeatureInfoMap() {
static const base::NoDestructor<DocumentPolicyFeatureInfoMap> feature_info_map({
{%- for feature in features %}
{
mojom::FeaturePolicyFeature::k{{feature.name}},
{
"{{feature.document_policy_name}}",
"{{feature.value_name}}",
PolicyValue({{feature.default_value}})
}
},
{%- endfor %}
});
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
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment