Commit 7b9eaf96 authored by knn's avatar knn Committed by Commit bot

Relanding Add i18n support for Android App Restrictions.

Reason for revert:
Changing the first output of grd file caused build to fail due to a bad depfile. Now depfile depends on a stampfile instead of first output.
Hence this also adds an additional grit roll from r187 to r188.

Effective grit roll from r186:r188

188: Allow depending on stamp for grit files.
187: Add a Policy template writer that generates Android resources which can be exposed through Android's App Restriction Schema.

Original issue's description:
> Revert of Add i18n support for Android App Restrictions. (patchset #7 id:120001 of https://codereview.chromium.org/865573002/)
>
> Reason for revert:
> Broke some GN builds, e.g.:
>
> http://build.chromium.org/p/chromium.linux/builders/Linux%20GN/builds/24483/steps/compile/logs/stdio
> http://build.chromium.org/p/chromium.chromiumos/builders/Linux%20ChromiumOS%20GN/builds/11092/steps/compile/logs/stdio
>
> ninja: Entering directory `/mnt/data/b/build/slave/Linux_GN/build/src/out/Release'
> ninja:error: expected depfile 'gen/chrome/policy_templates.d' to mention 'gen/chrome/app/policy/common/html/am/chrome_policy_list.html', got 'gen/chrome/app/policy/linux/examples/chrome.json'
>
>
> Committed: https://crrev.com/27ee0fa9afe9cb97016e532bd0cecd1b011251b9
> Cr-Commit-Position: refs/heads/master@{#319773}

BUG=450548

Review URL: https://codereview.chromium.org/997523002

Cr-Commit-Position: refs/heads/master@{#322366}
parent 544064fe
......@@ -161,7 +161,7 @@ deps = {
Var('chromium_git') + '/external/snappy.git' + '@' + '762bb32f0c9d2f31ba4958c7c0933d22e80c20bf',
'src/tools/grit':
Var('chromium_git') + '/external/grit-i18n.git' + '@' + '0287c187b11ed53590254e4d817e836a44a7a1a7', # from svn revision 186
Var('chromium_git') + '/external/grit-i18n.git' + '@' + '0ac6d137916c4d7a45ae7d61f892652a1a4cce33', # from svn revision 188
'src/tools/gyp':
Var('chromium_git') + '/external/gyp.git' + '@' + 'd174d75bf69c682cb62af9187879e01513b35e52',
......
......@@ -12,7 +12,6 @@
'grit_out_dir': '<(SHARED_INTERMEDIATE_DIR)/chrome',
'policy_out_dir': '<(SHARED_INTERMEDIATE_DIR)/policy',
'protoc_out_dir': '<(SHARED_INTERMEDIATE_DIR)/protoc_out',
'android_resources_out_dir': '<(policy_out_dir)/android_resources',
'generate_policy_source_script_path':
'policy/tools/generate_policy_source.py',
'policy_constant_header_path':
......@@ -22,9 +21,7 @@
'protobuf_decoder_path':
'<(policy_out_dir)/policy/cloud_policy_generated.cc',
'app_restrictions_path':
'<(android_resources_out_dir)/xml-v21/app_restrictions.xml',
'app_resources_path':
'<(android_resources_out_dir)/values-v21/restriction_values.xml',
'<(policy_out_dir)/app_restrictions.xml',
# This is the "full" protobuf, which defines one protobuf message per
# policy. It is also the format currently used by the server.
'chrome_settings_proto_path':
......@@ -115,7 +112,6 @@
'<(chrome_settings_proto_path)',
'<(cloud_policy_proto_path)',
'<(app_restrictions_path)',
'<(app_resources_path)',
],
'action_name': 'generate_policy_source',
'action': [
......@@ -127,7 +123,6 @@
'--cloud-policy-protobuf=<(cloud_policy_proto_path)',
'--cloud-policy-decoder=<(protobuf_decoder_path)',
'--app-restrictions-definition=<(app_restrictions_path)',
'--app-restrictions-resources=<(app_resources_path)',
'<(OS)',
'<(chromeos)',
'policy/resources/policy_templates.json',
......@@ -137,7 +132,6 @@
['OS!="android"', {
'outputs!': [
'<(app_restrictions_path)',
'<(app_resources_path)',
],
}],
],
......@@ -372,7 +366,7 @@
},
],
}],
['OS=="win" or OS=="mac" or OS=="linux"', {
['OS!="ios"', {
'targets': [
{
# policy_templates has different inputs and outputs, so it can't use
......
......@@ -47,9 +47,6 @@ if (enable_configuration_policy) {
# build puts everything into the following directory. We do the same for now.
policy_gen_dir = "$root_gen_dir/policy"
# Directory for generating Android App Restrictions resources
android_resources_gen_dir = "$policy_gen_dir/android_resources"
# This protobuf is equivalent to chrome_settings.proto but shares messages
# for policies of the same type, so that less classes have to be generated
# and compiled.
......@@ -62,10 +59,7 @@ if (enable_configuration_policy) {
constants_header_path = "$policy_gen_dir/policy_constants.h"
constants_source_path = "$policy_gen_dir/policy_constants.cc"
protobuf_decoder_path = "$policy_gen_dir/cloud_policy_generated.cc"
app_restrictions_path =
"$android_resources_gen_dir/xml-v21/app_restrictions.xml"
app_resources_path =
"$android_resources_gen_dir/values-v21/restriction_values.xml"
app_restrictions_path = "$policy_gen_dir/app_restrictions.xml"
action("cloud_policy_code_generate") {
script = "tools/generate_policy_source.py"
......@@ -86,14 +80,10 @@ if (enable_configuration_policy) {
chrome_settings_proto_path,
cloud_policy_proto_path,
app_restrictions_path,
app_resources_path,
]
if (current_os != "android") {
outputs -= [
app_restrictions_path,
app_resources_path,
]
if (target_os != "android") {
outputs -= [ app_restrictions_path ]
}
args = [
......@@ -109,14 +99,41 @@ if (enable_configuration_policy) {
rebase_path(protobuf_decoder_path, root_build_dir),
"--app-restrictions-definition=" +
rebase_path(app_restrictions_path, root_build_dir),
"--app-restrictions-resources=" +
rebase_path(app_resources_path, root_build_dir),
current_os,
target_os,
chromeos_flag,
rebase_path("resources/policy_templates.json", root_build_dir),
]
}
grit("policy_templates") {
import("resources/policy_templates.gni")
source = "resources/policy_templates.grd"
use_qualified_include = true
depend_on_stamp = true
output_dir = "$root_gen_dir/chrome"
outputs = policy_templates_doc_outputs
if (is_android) {
outputs += policy_templates_android_outputs
}
if (is_linux) {
outputs += policy_templates_linux_outputs
}
if (is_mac) {
outputs += policy_templates_mac_outputs
# TODO(knn) : Move this out once more targets use this.
if (is_chrome_branded) {
mac_bundle_id = "com.google.Chrome"
} else {
mac_bundle_id = "org.chromium.Chromium"
}
defines = [ "mac_bundle_id=$mac_bundle_id" ]
}
if (is_win) {
outputs += policy_templates_windows_outputs
}
}
proto_library("cloud_policy_proto_generated_compile") {
sources = [
cloud_policy_proto_path,
......@@ -220,4 +237,4 @@ if (enable_configuration_policy) {
]
}
}
#TODO(GYP) policy templates, chrome_manifest_bundle
#TODO(GYP) chrome_manifest_bundle
This diff is collapsed.
......@@ -7327,6 +7327,10 @@
'desc': '''Caption text of the field 'mac/linux preference name' in the summary chart of a policy in the generated documentation''',
'text': '''Mac/Linux preference name:'''
},
'doc_android_restriction_name': {
'desc': '''Caption text of the field 'android restriction name' in the summary chart of a policy in the generated documentation''',
'text': '''Android restriction name:'''
},
'doc_supported_on': {
'desc': '''Caption text of the list of 'products, platforms and versions where this policy is supported' in the summary chart of a policy in the generated documentation''',
'text': '''Supported on:'''
......
......@@ -28,34 +28,33 @@ CHROMIUM_POLICY_KEY = 'SOFTWARE\\\\Policies\\\\Chromium'
class PolicyDetails:
"""Parses a policy template and caches all its details."""
# Maps policy types to a tuple with 5 other types:
# Maps policy types to a tuple with 4 other types:
# - the equivalent base::Value::Type or 'TYPE_EXTERNAL' if the policy
# references external data
# - the equivalent Protobuf field type
# - the name of one of the protobufs for shared policy types
# - the equivalent type in Android's App Restriction Schema
# - whether the equivalent app restriction type needs supporting resources
# TODO(joaodasilva): refactor the 'dict' type into a more generic 'json' type
# that can also be used to represent lists of other JSON objects.
TYPE_MAP = {
'dict': ('TYPE_DICTIONARY', 'string', 'String',
'string', False),
'string'),
'external': ('TYPE_EXTERNAL', 'string', 'String',
'invalid', False),
'invalid'),
'int': ('TYPE_INTEGER', 'int64', 'Integer',
'integer', False),
'integer'),
'int-enum': ('TYPE_INTEGER', 'int64', 'Integer',
'choice', True),
'choice'),
'list': ('TYPE_LIST', 'StringList', 'StringList',
'string', False),
'string'),
'main': ('TYPE_BOOLEAN', 'bool', 'Boolean',
'bool', False),
'bool'),
'string': ('TYPE_STRING', 'string', 'String',
'string', False),
'string'),
'string-enum': ('TYPE_STRING', 'string', 'String',
'choice', True),
'choice'),
'string-enum-list': ('TYPE_LIST', 'StringList', 'StringList',
'multi-select', True),
'multi-select'),
}
class EnumItem:
......@@ -98,8 +97,7 @@ class PolicyDetails:
raise NotImplementedError('Unknown policy type for %s: %s' %
(policy['name'], policy['type']))
self.policy_type, self.protobuf_type, self.policy_protobuf_type, \
self.restriction_type, self.has_restriction_resources = \
PolicyDetails.TYPE_MAP[policy['type']]
self.restriction_type = PolicyDetails.TYPE_MAP[policy['type']]
self.schema = policy['schema']
self.desc = '\n'.join(
......@@ -154,12 +152,6 @@ def main():
help='generate an XML file as specified by '
'Android\'s App Restriction Schema',
metavar='FILE')
parser.add_option('--arr', '--app-restrictions-resources',
dest='app_resources_path',
help='generate an XML file with resources supporting the '
'restrictions defined in --app-restrictions-definition '
'parameter',
metavar='FILE')
(opts, args) = parser.parse_args()
......@@ -191,7 +183,6 @@ def main():
if os == 'android':
GenerateFile(opts.app_restrictions_path, _WriteAppRestrictions, xml=True)
GenerateFile(opts.app_resources_path, _WriteResourcesForPolicies, xml=True)
return 0
......@@ -1007,14 +998,6 @@ def _WriteCloudPolicyDecoder(policies, os, f):
f.write(CPP_FOOT)
def _EscapeResourceString(raw_resource):
if type(raw_resource) == int:
return raw_resource
return xml_escape(raw_resource)\
.replace('\\', '\\\\')\
.replace('\"','\\\"')\
.replace('\'','\\\'')
def _WriteAppRestrictions(policies, os, f):
def WriteRestrictionCommon(key):
......@@ -1031,7 +1014,7 @@ def _WriteAppRestrictions(policies, os, f):
policy_name = policy.name
WriteRestrictionCommon(policy_name)
if policy.has_restriction_resources:
if policy.items is not None:
WriteItemsDefinition(policy_name)
f.write(' android:restrictionType="%s"/>' % policy.restriction_type)
......@@ -1045,44 +1028,5 @@ def _WriteAppRestrictions(policies, os, f):
WriteAppRestriction(policy)
f.write('</restrictions>')
def _WriteResourcesForPolicies(policies, os, f):
# TODO(knn): Update this to support i18n.
def WriteString(key, value):
f.write(' <string name="%s">%s</string>\n'
% (key, _EscapeResourceString(value)))
def WriteItems(key, items):
if items:
f.write(' <string-array name="%sEntries">\n' % key)
for item in items:
f.write(' <item>%s</item>\n' %
_EscapeResourceString(item.caption))
f.write(' </string-array>\n')
f.write(' <string-array name="%sValues">\n' % key)
for item in items:
f.write(' <item>%s</item>\n' % _EscapeResourceString(item.value))
f.write(' </string-array>\n')
def WriteResourceForPolicy(policy):
policy_name = policy.name
WriteString(policy_name + 'Title', policy.caption)
# Get the first line of the policy description.
description = policy.desc.split('\n', 1)[0]
WriteString(policy_name + 'Desc', description)
if policy.has_restriction_resources:
WriteItems(policy_name, policy.items)
# _WriteResourcesForPolicies body
f.write('<resources>\n\n')
for policy in policies:
if policy.is_supported and policy.restriction_type != 'invalid':
WriteResourceForPolicy(policy)
f.write('</resources>')
if __name__ == '__main__':
sys.exit(main())
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