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 666 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
677 """Converts a JSON object into a base::Value entry. Returns a tuple, the first | 677 """Converts a JSON object into a base::Value entry. Returns a tuple, the first |
678 entry being a list of declaration statements to define the variable, the | 678 entry being a list of declaration statements to define the variable, the |
679 second entry being a way to access the variable. | 679 second entry being a way to access the variable. |
680 | 680 |
681 If no definition is needed, the first return value will be an empty list. If | 681 If no definition is needed, the first return value will be an empty list. If |
682 any error occurs, the second return value will be None (ie, no way to fetch | 682 any error occurs, the second return value will be None (ie, no way to fetch |
683 the value). | 683 the value). |
684 | 684 |
685 |value|: The deserialized value to convert to base::Value.""" | 685 |value|: The deserialized value to convert to base::Value.""" |
686 if type(value) == bool or type(value) == int: | 686 if type(value) == bool or type(value) == int: |
687 return [], 'base::MakeUnique<base::FundamentalValue>(%s)' %\ | 687 return [], 'base::MakeUnique<base::Value>(%s)' %\ |
688 json.dumps(value) | 688 json.dumps(value) |
689 elif type(value) == str: | 689 elif type(value) == str: |
690 return [], 'base::MakeUnique<base::StringValue>("%s")' % value | 690 return [], 'base::MakeUnique<base::StringValue>("%s")' % value |
691 elif type(value) == list: | 691 elif type(value) == list: |
692 setup = ['auto default_value = base::MakeUnique<base::ListValue>();'] | 692 setup = ['auto default_value = base::MakeUnique<base::ListValue>();'] |
693 for entry in value: | 693 for entry in value: |
694 decl, fetch = _GenerateDefaultValue(entry) | 694 decl, fetch = _GenerateDefaultValue(entry) |
695 # Nested lists are not supported. | 695 # Nested lists are not supported. |
696 if decl: | 696 if decl: |
697 return [], None | 697 return [], None |
(...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1126 std::unique_ptr<base::Value> DecodeIntegerValue( | 1126 std::unique_ptr<base::Value> DecodeIntegerValue( |
1127 google::protobuf::int64 value) { | 1127 google::protobuf::int64 value) { |
1128 if (value < std::numeric_limits<int>::min() || | 1128 if (value < std::numeric_limits<int>::min() || |
1129 value > std::numeric_limits<int>::max()) { | 1129 value > std::numeric_limits<int>::max()) { |
1130 LOG(WARNING) << "Integer value " << value | 1130 LOG(WARNING) << "Integer value " << value |
1131 << " out of numeric limits, ignoring."; | 1131 << " out of numeric limits, ignoring."; |
1132 return nullptr; | 1132 return nullptr; |
1133 } | 1133 } |
1134 | 1134 |
1135 return base::WrapUnique( | 1135 return base::WrapUnique( |
1136 new base::FundamentalValue(static_cast<int>(value))); | 1136 new base::Value(static_cast<int>(value))); |
1137 } | 1137 } |
1138 | 1138 |
1139 std::unique_ptr<base::ListValue> DecodeStringList( | 1139 std::unique_ptr<base::ListValue> DecodeStringList( |
1140 const em::StringList& string_list) { | 1140 const em::StringList& string_list) { |
1141 std::unique_ptr<base::ListValue> list_value(new base::ListValue); | 1141 std::unique_ptr<base::ListValue> list_value(new base::ListValue); |
1142 for (const auto& entry : string_list.entries()) | 1142 for (const auto& entry : string_list.entries()) |
1143 list_value->AppendString(entry); | 1143 list_value->AppendString(entry); |
1144 return list_value; | 1144 return list_value; |
1145 } | 1145 } |
1146 | 1146 |
(...skipping 16 matching lines...) Expand all Loading... |
1163 | 1163 |
1164 | 1164 |
1165 CPP_FOOT = '''} | 1165 CPP_FOOT = '''} |
1166 | 1166 |
1167 } // namespace policy | 1167 } // namespace policy |
1168 ''' | 1168 ''' |
1169 | 1169 |
1170 | 1170 |
1171 def _CreateValue(type, arg): | 1171 def _CreateValue(type, arg): |
1172 if type == 'Type::BOOLEAN': | 1172 if type == 'Type::BOOLEAN': |
1173 return 'new base::FundamentalValue(%s)' % arg | 1173 return 'new base::Value(%s)' % arg |
1174 elif type == 'Type::INTEGER': | 1174 elif type == 'Type::INTEGER': |
1175 return 'DecodeIntegerValue(%s)' % arg | 1175 return 'DecodeIntegerValue(%s)' % arg |
1176 elif type == 'Type::STRING': | 1176 elif type == 'Type::STRING': |
1177 return 'new base::StringValue(%s)' % arg | 1177 return 'new base::StringValue(%s)' % arg |
1178 elif type == 'Type::LIST': | 1178 elif type == 'Type::LIST': |
1179 return 'DecodeStringList(%s)' % arg | 1179 return 'DecodeStringList(%s)' % arg |
1180 elif type == 'Type::DICTIONARY' or type == 'TYPE_EXTERNAL': | 1180 elif type == 'Type::DICTIONARY' or type == 'TYPE_EXTERNAL': |
1181 return 'DecodeJson(%s)' % arg | 1181 return 'DecodeJson(%s)' % arg |
1182 else: | 1182 else: |
1183 raise NotImplementedError('Unknown type %s' % type) | 1183 raise NotImplementedError('Unknown type %s' % type) |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1268 f.write('<restrictions xmlns:android="' | 1268 f.write('<restrictions xmlns:android="' |
1269 'http://schemas.android.com/apk/res/android">\n\n') | 1269 'http://schemas.android.com/apk/res/android">\n\n') |
1270 for policy in policies: | 1270 for policy in policies: |
1271 if (policy.is_supported and policy.restriction_type != 'invalid' and | 1271 if (policy.is_supported and policy.restriction_type != 'invalid' and |
1272 not policy.is_deprecated and not policy.is_future): | 1272 not policy.is_deprecated and not policy.is_future): |
1273 WriteAppRestriction(policy) | 1273 WriteAppRestriction(policy) |
1274 f.write('</restrictions>') | 1274 f.write('</restrictions>') |
1275 | 1275 |
1276 if __name__ == '__main__': | 1276 if __name__ == '__main__': |
1277 sys.exit(main()) | 1277 sys.exit(main()) |
OLD | NEW |