Chromium Code Reviews| Index: chrome/common/extensions/docs/server2/api_features.py |
| diff --git a/chrome/common/extensions/docs/server2/api_features.py b/chrome/common/extensions/docs/server2/api_features.py |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..b08bf44fd2f59436fb9c9b182990c0be457457ca |
| --- /dev/null |
| +++ b/chrome/common/extensions/docs/server2/api_features.py |
| @@ -0,0 +1,59 @@ |
| +# 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 copy import deepcopy |
| + |
| +from features import Features |
| +import features_utility |
| +from third_party.json_schema_compiler.json_parse import Parse |
| + |
| +def _GetExtensionTypesRecursive(feature, feature_set): |
| + extension_types = feature.get('extension_types') |
| + if extension_types is None: |
| + dependencies = feature.get('dependencies') |
| + # No specific constraints == available on all platforms! |
|
not at google - send to devlin
2013/09/23 18:31:30
this... should never happen. but what *can* happen
|
| + if dependencies is None: |
| + return set(('platform_app', 'extension')) |
| + extension_types = set() |
| + for dependency in dependencies: |
| + dep_type, dep_name = dependency.split(':') |
| + dependency_features = feature_set[dep_type] |
| + dependency_feature = dependency_features.get(dep_name) |
| + # If the dependency can't be resolved, it is inaccessible and therefore |
| + # so is this API feature. |
| + if dependency_feature is None: |
| + return set() |
| + extension_types = extension_types.union( |
| + _GetExtensionTypesRecursive(dependency_features.get(dep_name), |
| + feature_set)) |
| + return set(extension_types) |
| + |
| +class APIFeatures(Features): |
| + '''Subclass of Features that can dig into dependencies to deduce the feature's |
| + supported extension types. |
| + ''' |
| + def __init__(self, |
| + compiled_fs_factory, |
| + api_features_path, |
| + manifest_features, |
| + permission_features): |
| + self._manifest_features = manifest_features |
| + self._permission_features = permission_features |
| + super(APIFeatures, self).__init__(compiled_fs_factory, api_features_path) |
| + |
| + def FilterByPlatform(self, features, platform): |
| + '''Filter API features by supported platform using data from feature |
| + dependencies if necessary.''' |
| + feature_set = { |
| + 'api': features, |
| + 'manifest': self._manifest_features.get('all'), |
| + 'permission': self._permission_features.get('all'), |
| + } |
| + filtered_features = {} |
| + for name, feature in features.iteritems(): |
| + platforms = features_utility.GetPlatformSetForExtensionTypes( |
| + _GetExtensionTypesRecursive(feature, feature_set)) |
| + if not platform or platform in platforms: |
| + filtered_features[name] = deepcopy(feature) |
| + return filtered_features |