| 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 |
| 11 template is the path to a .json policy template file.''' | 11 template is the path to a .json policy template file.''' |
| 12 | 12 |
| 13 from __future__ import with_statement | 13 from __future__ import with_statement |
| 14 from optparse import OptionParser | 14 from optparse import OptionParser |
| 15 import re | 15 import re |
| 16 import sys | 16 import sys |
| 17 import textwrap | 17 import textwrap |
| 18 | 18 |
| 19 | 19 |
| 20 CHROME_MANDATORY_SUBKEY = 'SOFTWARE\\\\Policies\\\\Google\\\\Chrome' | 20 CHROME_POLICY_KEY = 'SOFTWARE\\\\Policies\\\\Google\\\\Chrome' |
| 21 CHROME_RECOMMENDED_SUBKEY = CHROME_MANDATORY_SUBKEY + '\\\\Recommended' | 21 CHROMIUM_POLICY_KEY = 'SOFTWARE\\\\Policies\\\\Chromium' |
| 22 CHROMIUM_MANDATORY_SUBKEY = 'SOFTWARE\\\\Policies\\\\Chromium' | |
| 23 CHROMIUM_RECOMMENDED_SUBKEY = CHROMIUM_MANDATORY_SUBKEY + '\\\\Recommended' | |
| 24 | 22 |
| 25 | 23 |
| 26 class PolicyDetails: | 24 class PolicyDetails: |
| 27 """Parses a policy template and caches all its details.""" | 25 """Parses a policy template and caches all its details.""" |
| 28 | 26 |
| 29 # Maps policy types to a tuple with 3 other types: | 27 # Maps policy types to a tuple with 3 other types: |
| 30 # - the equivalent base::Value::Type | 28 # - the equivalent base::Value::Type |
| 31 # - the equivalent Protobuf field type | 29 # - the equivalent Protobuf field type |
| 32 # - the name of one of the protobufs for shared policy types | 30 # - the name of one of the protobufs for shared policy types |
| 33 # TODO(joaodasilva): introduce a message to represent dictionary values. | 31 # TODO(joaodasilva): introduce a message to represent dictionary values. |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 f.write('#ifndef CHROME_COMMON_POLICY_CONSTANTS_H_\n' | 184 f.write('#ifndef CHROME_COMMON_POLICY_CONSTANTS_H_\n' |
| 187 '#define CHROME_COMMON_POLICY_CONSTANTS_H_\n' | 185 '#define CHROME_COMMON_POLICY_CONSTANTS_H_\n' |
| 188 '\n' | 186 '\n' |
| 189 '#include <string>\n' | 187 '#include <string>\n' |
| 190 '\n' | 188 '\n' |
| 191 '#include "base/values.h"\n' | 189 '#include "base/values.h"\n' |
| 192 '\n' | 190 '\n' |
| 193 'namespace policy {\n\n') | 191 'namespace policy {\n\n') |
| 194 | 192 |
| 195 if os == 'win': | 193 if os == 'win': |
| 196 f.write('// The windows registry path where mandatory policy ' | 194 f.write('// The windows registry path where Chrome policy ' |
| 197 'configuration resides.\n' | 195 'configuration resides.\n' |
| 198 'extern const wchar_t kRegistryMandatorySubKey[];\n' | 196 'extern const wchar_t kRegistryChromePolicyKey[];\n') |
| 199 '// The windows registry path where recommended policy ' | |
| 200 'configuration resides.\n' | |
| 201 'extern const wchar_t kRegistryRecommendedSubKey[];\n\n') | |
| 202 | 197 |
| 203 f.write('// Lists policy types mapped to their names and expected types.\n' | 198 f.write('// Lists policy types mapped to their names and expected types.\n' |
| 204 '// Used to initialize ConfigurationPolicyProviders.\n' | 199 '// Used to initialize ConfigurationPolicyProviders.\n' |
| 205 'struct PolicyDefinitionList {\n' | 200 'struct PolicyDefinitionList {\n' |
| 206 ' struct Entry {\n' | 201 ' struct Entry {\n' |
| 207 ' const char* name;\n' | 202 ' const char* name;\n' |
| 208 ' base::Value::Type value_type;\n' | 203 ' base::Value::Type value_type;\n' |
| 209 ' bool device_policy;\n' | 204 ' bool device_policy;\n' |
| 210 ' int id;\n' | 205 ' int id;\n' |
| 211 ' };\n' | 206 ' };\n' |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 'const char* kDeprecatedPolicyList[] = {\n') | 255 'const char* kDeprecatedPolicyList[] = {\n') |
| 261 for policy in policies: | 256 for policy in policies: |
| 262 if policy.is_supported and policy.is_deprecated: | 257 if policy.is_supported and policy.is_deprecated: |
| 263 f.write(' key::k%s,\n' % policy.name) | 258 f.write(' key::k%s,\n' % policy.name) |
| 264 f.write('};\n\n') | 259 f.write('};\n\n') |
| 265 | 260 |
| 266 f.write('} // namespace\n\n') | 261 f.write('} // namespace\n\n') |
| 267 | 262 |
| 268 if os == 'win': | 263 if os == 'win': |
| 269 f.write('#if defined(GOOGLE_CHROME_BUILD)\n' | 264 f.write('#if defined(GOOGLE_CHROME_BUILD)\n' |
| 270 'const wchar_t kRegistryMandatorySubKey[] = ' | 265 'const wchar_t kRegistryChromePolicyKey[] = ' |
| 271 'L"' + CHROME_MANDATORY_SUBKEY + '";\n' | 266 'L"' + CHROME_POLICY_KEY + '";\n' |
| 272 'const wchar_t kRegistryRecommendedSubKey[] = ' | |
| 273 'L"' + CHROME_RECOMMENDED_SUBKEY + '";\n' | |
| 274 '#else\n' | 267 '#else\n' |
| 275 'const wchar_t kRegistryMandatorySubKey[] = ' | 268 'const wchar_t kRegistryChromePolicyKey[] = ' |
| 276 'L"' + CHROMIUM_MANDATORY_SUBKEY + '";\n' | 269 'L"' + CHROMIUM_POLICY_KEY + '";\n' |
| 277 'const wchar_t kRegistryRecommendedSubKey[] = ' | |
| 278 'L"' + CHROMIUM_RECOMMENDED_SUBKEY + '";\n' | |
| 279 '#endif\n\n') | 270 '#endif\n\n') |
| 280 | 271 |
| 281 f.write('bool IsDeprecatedPolicy(const std::string& policy) {\n' | 272 f.write('bool IsDeprecatedPolicy(const std::string& policy) {\n' |
| 282 ' for (size_t i = 0; i < arraysize(kDeprecatedPolicyList);' | 273 ' for (size_t i = 0; i < arraysize(kDeprecatedPolicyList);' |
| 283 ' ++i) {\n' | 274 ' ++i) {\n' |
| 284 ' if (policy == kDeprecatedPolicyList[i])\n' | 275 ' if (policy == kDeprecatedPolicyList[i])\n' |
| 285 ' return true;\n' | 276 ' return true;\n' |
| 286 ' }\n' | 277 ' }\n' |
| 287 ' return false;\n' | 278 ' return false;\n' |
| 288 '}\n' | 279 '}\n' |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 508 def _WriteCloudPolicyDecoder(policies, os, f): | 499 def _WriteCloudPolicyDecoder(policies, os, f): |
| 509 f.write(CPP_HEAD) | 500 f.write(CPP_HEAD) |
| 510 for policy in policies: | 501 for policy in policies: |
| 511 if policy.is_supported and not policy.is_device_only: | 502 if policy.is_supported and not policy.is_device_only: |
| 512 _WritePolicyCode(f, policy) | 503 _WritePolicyCode(f, policy) |
| 513 f.write(CPP_FOOT) | 504 f.write(CPP_FOOT) |
| 514 | 505 |
| 515 | 506 |
| 516 if __name__ == '__main__': | 507 if __name__ == '__main__': |
| 517 sys.exit(main()) | 508 sys.exit(main()) |
| OLD | NEW |