| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 '''python %prog [options] platform chromium_os_flag template | 6 '''python %prog [options] platform chromium_os_flag template |
| 7 | 7 |
| 8 platform specifies which platform source is being generated for | 8 platform specifies which platform source is being generated for |
| 9 and can be one of (win, mac, linux) | 9 and can be one of (win, mac, linux) |
| 10 chromium_os_flag should be 1 if this is a Chromium OS build | 10 chromium_os_flag should be 1 if this is a Chromium OS build |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 parser.add_option('--pch', '--policy-constants-header', dest='header_path', | 175 parser.add_option('--pch', '--policy-constants-header', dest='header_path', |
| 176 help='generate header file of policy constants', | 176 help='generate header file of policy constants', |
| 177 metavar='FILE') | 177 metavar='FILE') |
| 178 parser.add_option('--pcc', '--policy-constants-source', dest='source_path', | 178 parser.add_option('--pcc', '--policy-constants-source', dest='source_path', |
| 179 help='generate source file of policy constants', | 179 help='generate source file of policy constants', |
| 180 metavar='FILE') | 180 metavar='FILE') |
| 181 parser.add_option('--cpp', '--cloud-policy-protobuf', | 181 parser.add_option('--cpp', '--cloud-policy-protobuf', |
| 182 dest='cloud_policy_proto_path', | 182 dest='cloud_policy_proto_path', |
| 183 help='generate cloud policy protobuf file', | 183 help='generate cloud policy protobuf file', |
| 184 metavar='FILE') | 184 metavar='FILE') |
| 185 parser.add_option('--cpfrp', '--cloud-policy-full-runtime-protobuf', |
| 186 dest='cloud_policy_full_runtime_proto_path', |
| 187 help='generate cloud policy full runtime protobuf', |
| 188 metavar='FILE') |
| 185 parser.add_option('--csp', '--chrome-settings-protobuf', | 189 parser.add_option('--csp', '--chrome-settings-protobuf', |
| 186 dest='chrome_settings_proto_path', | 190 dest='chrome_settings_proto_path', |
| 187 help='generate chrome settings protobuf file', | 191 help='generate chrome settings protobuf file', |
| 188 metavar='FILE') | 192 metavar='FILE') |
| 189 parser.add_option('--cpd', '--cloud-policy-decoder', | 193 parser.add_option('--cpd', '--cloud-policy-decoder', |
| 190 dest='cloud_policy_decoder_path', | 194 dest='cloud_policy_decoder_path', |
| 191 help='generate C++ code decoding the cloud policy protobuf', | 195 help='generate C++ code decoding the cloud policy protobuf', |
| 192 metavar='FILE') | 196 metavar='FILE') |
| 193 parser.add_option('--ard', '--app-restrictions-definition', | 197 parser.add_option('--ard', '--app-restrictions-definition', |
| 194 dest='app_restrictions_path', | 198 dest='app_restrictions_path', |
| (...skipping 30 matching lines...) Expand all Loading... |
| 225 if path: | 229 if path: |
| 226 with open(path, 'w') as f: | 230 with open(path, 'w') as f: |
| 227 _OutputGeneratedWarningHeader(f, template_file_name, xml) | 231 _OutputGeneratedWarningHeader(f, template_file_name, xml) |
| 228 writer(sorted and sorted_policy_details or policy_details, | 232 writer(sorted and sorted_policy_details or policy_details, |
| 229 os, f, riskTags) | 233 os, f, riskTags) |
| 230 | 234 |
| 231 GenerateFile(opts.header_path, _WritePolicyConstantHeader, sorted=True) | 235 GenerateFile(opts.header_path, _WritePolicyConstantHeader, sorted=True) |
| 232 GenerateFile(opts.source_path, _WritePolicyConstantSource, sorted=True) | 236 GenerateFile(opts.source_path, _WritePolicyConstantSource, sorted=True) |
| 233 GenerateFile(opts.risk_header_path, _WritePolicyRiskTagHeader) | 237 GenerateFile(opts.risk_header_path, _WritePolicyRiskTagHeader) |
| 234 GenerateFile(opts.cloud_policy_proto_path, _WriteCloudPolicyProtobuf) | 238 GenerateFile(opts.cloud_policy_proto_path, _WriteCloudPolicyProtobuf) |
| 239 GenerateFile(opts.cloud_policy_full_runtime_proto_path, |
| 240 _WriteCloudPolicyFullRuntimeProtobuf) |
| 235 GenerateFile(opts.chrome_settings_proto_path, _WriteChromeSettingsProtobuf) | 241 GenerateFile(opts.chrome_settings_proto_path, _WriteChromeSettingsProtobuf) |
| 236 GenerateFile(opts.cloud_policy_decoder_path, _WriteCloudPolicyDecoder) | 242 GenerateFile(opts.cloud_policy_decoder_path, _WriteCloudPolicyDecoder) |
| 237 | 243 |
| 238 if os == 'android': | 244 if os == 'android': |
| 239 GenerateFile(opts.app_restrictions_path, _WriteAppRestrictions, xml=True) | 245 GenerateFile(opts.app_restrictions_path, _WriteAppRestrictions, xml=True) |
| 240 | 246 |
| 241 return 0 | 247 return 0 |
| 242 | 248 |
| 243 | 249 |
| 244 #------------------ shared helpers ---------------------------------# | 250 #------------------ shared helpers ---------------------------------# |
| (...skipping 693 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 938 } | 944 } |
| 939 | 945 |
| 940 message StringListPolicyProto { | 946 message StringListPolicyProto { |
| 941 optional PolicyOptions policy_options = 1; | 947 optional PolicyOptions policy_options = 1; |
| 942 optional StringList value = 2; | 948 optional StringList value = 2; |
| 943 } | 949 } |
| 944 | 950 |
| 945 ''' | 951 ''' |
| 946 | 952 |
| 947 | 953 |
| 954 CLOUD_POLICY_FULL_RUNTIME_PROTO_HEAD = ''' |
| 955 syntax = "proto2"; |
| 956 |
| 957 package enterprise_management; |
| 958 |
| 959 message StringList { |
| 960 repeated string entries = 1; |
| 961 } |
| 962 |
| 963 message PolicyOptions { |
| 964 enum PolicyMode { |
| 965 // The given settings are applied regardless of user choice. |
| 966 MANDATORY = 0; |
| 967 // The user may choose to override the given settings. |
| 968 RECOMMENDED = 1; |
| 969 // No policy value is present and the policy should be ignored. |
| 970 UNSET = 2; |
| 971 } |
| 972 optional PolicyMode mode = 1 [default = MANDATORY]; |
| 973 } |
| 974 |
| 975 message BooleanPolicyProto { |
| 976 optional PolicyOptions policy_options = 1; |
| 977 optional bool value = 2; |
| 978 } |
| 979 |
| 980 message IntegerPolicyProto { |
| 981 optional PolicyOptions policy_options = 1; |
| 982 optional int64 value = 2; |
| 983 } |
| 984 |
| 985 message StringPolicyProto { |
| 986 optional PolicyOptions policy_options = 1; |
| 987 optional string value = 2; |
| 988 } |
| 989 |
| 990 message StringListPolicyProto { |
| 991 optional PolicyOptions policy_options = 1; |
| 992 optional StringList value = 2; |
| 993 } |
| 994 |
| 995 ''' |
| 996 |
| 997 |
| 948 # Field IDs [1..RESERVED_IDS] will not be used in the wrapping protobuf. | 998 # Field IDs [1..RESERVED_IDS] will not be used in the wrapping protobuf. |
| 949 RESERVED_IDS = 2 | 999 RESERVED_IDS = 2 |
| 950 | 1000 |
| 951 | 1001 |
| 952 def _WritePolicyProto(f, policy, fields): | 1002 def _WritePolicyProto(f, policy, fields): |
| 953 _OutputComment(f, policy.caption + '\n\n' + policy.desc) | 1003 _OutputComment(f, policy.caption + '\n\n' + policy.desc) |
| 954 if policy.items is not None: | 1004 if policy.items is not None: |
| 955 _OutputComment(f, '\nValid values:') | 1005 _OutputComment(f, '\nValid values:') |
| 956 for item in policy.items: | 1006 for item in policy.items: |
| 957 _OutputComment(f, ' %s: %s' % (str(item.value), item.caption)) | 1007 _OutputComment(f, ' %s: %s' % (str(item.value), item.caption)) |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 993 f.write(CLOUD_POLICY_PROTO_HEAD) | 1043 f.write(CLOUD_POLICY_PROTO_HEAD) |
| 994 f.write('message CloudPolicySettings {\n') | 1044 f.write('message CloudPolicySettings {\n') |
| 995 for policy in policies: | 1045 for policy in policies: |
| 996 if policy.is_supported and not policy.is_device_only: | 1046 if policy.is_supported and not policy.is_device_only: |
| 997 f.write(' optional %sPolicyProto %s = %s;\n' % | 1047 f.write(' optional %sPolicyProto %s = %s;\n' % |
| 998 (policy.policy_protobuf_type, policy.name, | 1048 (policy.policy_protobuf_type, policy.name, |
| 999 policy.id + RESERVED_IDS)) | 1049 policy.id + RESERVED_IDS)) |
| 1000 f.write('}\n\n') | 1050 f.write('}\n\n') |
| 1001 | 1051 |
| 1002 | 1052 |
| 1053 def _WriteCloudPolicyFullRuntimeProtobuf(policies, os, f, riskTags): |
| 1054 f.write(CLOUD_POLICY_FULL_RUNTIME_PROTO_HEAD) |
| 1055 f.write('message CloudPolicySettings {\n') |
| 1056 for policy in policies: |
| 1057 if policy.is_supported and not policy.is_device_only: |
| 1058 f.write(' optional %sPolicyProto %s = %s;\n' % |
| 1059 (policy.policy_protobuf_type, policy.name, |
| 1060 policy.id + RESERVED_IDS)) |
| 1061 f.write('}\n\n') |
| 1062 |
| 1063 |
| 1003 #------------------ protobuf decoder -------------------------------# | 1064 #------------------ protobuf decoder -------------------------------# |
| 1004 | 1065 |
| 1005 CPP_HEAD = ''' | 1066 CPP_HEAD = ''' |
| 1006 #include <limits> | 1067 #include <limits> |
| 1007 #include <memory> | 1068 #include <memory> |
| 1008 #include <utility> | 1069 #include <utility> |
| 1009 #include <string> | 1070 #include <string> |
| 1010 | 1071 |
| 1011 #include "base/callback.h" | 1072 #include "base/callback.h" |
| 1012 #include "base/json/json_reader.h" | 1073 #include "base/json/json_reader.h" |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1172 f.write('<restrictions xmlns:android="' | 1233 f.write('<restrictions xmlns:android="' |
| 1173 'http://schemas.android.com/apk/res/android">\n\n') | 1234 'http://schemas.android.com/apk/res/android">\n\n') |
| 1174 for policy in policies: | 1235 for policy in policies: |
| 1175 if (policy.is_supported and policy.restriction_type != 'invalid' and | 1236 if (policy.is_supported and policy.restriction_type != 'invalid' and |
| 1176 not policy.is_deprecated and not policy.is_future): | 1237 not policy.is_deprecated and not policy.is_future): |
| 1177 WriteAppRestriction(policy) | 1238 WriteAppRestriction(policy) |
| 1178 f.write('</restrictions>') | 1239 f.write('</restrictions>') |
| 1179 | 1240 |
| 1180 if __name__ == '__main__': | 1241 if __name__ == '__main__': |
| 1181 sys.exit(main()) | 1242 sys.exit(main()) |
| OLD | NEW |