Chromium Code Reviews| Index: chrome/common/extensions/docs/server2/permission_features.py |
| diff --git a/chrome/common/extensions/docs/server2/permission_features.py b/chrome/common/extensions/docs/server2/permission_features.py |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..d1aa93540a3cf619b36e4722cf0f77a99f04971c |
| --- /dev/null |
| +++ b/chrome/common/extensions/docs/server2/permission_features.py |
| @@ -0,0 +1,82 @@ |
| +# Copyright 2013 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. |
| + |
| +from itertools import ifilter |
| +from operator import itemgetter |
| + |
| +from features import Features |
| +import features_utility |
| +from third_party.json_schema_compiler.json_parse import Parse |
| + |
| +def _ListifyPermissions(permissions): |
|
not at google - send to devlin
2013/09/23 18:31:30
this should be in the permission_data_source since
|
| + '''Filter out any permissions that do not have a description or with a name |
| + that ends with Private then sort permissions features by name into a list. |
| + ''' |
| + def filter_permissions(perm): |
| + return 'description' in perm and not perm['name'].endswith('Private') |
| + |
| + return sorted( |
| + ifilter(filter_permissions, permissions.values()), |
| + key=itemgetter('name')) |
| + |
| +def _AddDependencyDescriptions(permissions, api_features, template_data_source): |
| + '''Use |api_features| to determine the dependencies APIs have on |permission|. |
| + Add a description to the permission based on those dependencies. |
| + ''' |
| + for permission in permissions: |
| + # Don't overwrite the description created by expanding a partial template. |
| + if 'partial' in permission or not permission['platforms']: |
| + continue |
| + has_deps = False |
| + if name in api_features: |
| + for dependency in api_features[name].get('dependencies', ()): |
| + if dependency.startswith('permission:'): |
| + has_deps = True |
| + if has_deps: |
| + permission['partial'] = 'permissions/generic_description' |
| + |
| + for permission in permissions: |
| + # Turn partial templates into descriptions, ensure anchors are set. |
| + if not 'anchor' in permission: |
| + permission['anchor'] = permission['name'] |
| + if 'partial' in permission: |
| + permission['description'] = self._template_data_source.get( |
| + permission['partial']) |
| + del permission['partial'] |
| + |
| +class PermissionFeatures(Features): |
| + '''Subclass of Features to provide permission descriptions derived from API |
| + dependencies and filter private or undescribed permissions. |
| + ''' |
| + def __init__(self, |
| + compiled_fs_factory, |
| + permission_features_path, |
| + file_system, |
| + permissions_json_path): |
| + self._file_system = file_system |
| + self._permissions_json_path = permissions_json_path |
| + self._template_data_source = None |
| + super(PermissionFeatures, self).__init__(compiled_fs_factory, |
| + permission_features_path) |
| + |
| + def Parse(self, features_json): |
| + permissions_json = Parse( |
| + self._file_system.ReadSingle(self._permissions_json_path)) |
| + permission_features = features_utility.MergedWith( |
| + features_utility.Parse(features_json), permissions_json) |
| + return permission_features |
| + |
| + def CreateCache(self, features): |
| + return { |
| + 'declare_apps': _ListifyPermissions( |
| + self.FilterByPlatform(features, 'apps')), |
| + 'declare_extensions': _ListifyPermissions( |
| + self.FilterByPlatform(features, 'extensions')) |
| + } |
|
not at google - send to devlin
2013/09/23 18:31:30
so... this overrides CreateCache from Features?
i
|
| + |
| + def AddDependencyDescriptions(self, api_features, template_data_source): |
| + for platform in ('declare_apps', 'declare_extensions'): |
| + _AddDependencyDescriptions(self.get(platform), |
| + api_features, |
| + template_data_source) |