OLD | NEW |
---|---|
(Empty) | |
1 # Copyright 2013 The Chromium Authors. All rights reserved. | |
2 # Use of this source code is governed by a BSD-style license that can be | |
3 # found in the LICENSE file. | |
4 | |
5 from copy import deepcopy | |
6 | |
7 from features import Features | |
8 import features_utility | |
9 from third_party.json_schema_compiler.json_parse import Parse | |
10 | |
11 def _GetExtensionTypesRecursive(feature, feature_set): | |
12 extension_types = feature.get('extension_types') | |
13 if extension_types is None: | |
14 dependencies = feature.get('dependencies') | |
15 # 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
| |
16 if dependencies is None: | |
17 return set(('platform_app', 'extension')) | |
18 extension_types = set() | |
19 for dependency in dependencies: | |
20 dep_type, dep_name = dependency.split(':') | |
21 dependency_features = feature_set[dep_type] | |
22 dependency_feature = dependency_features.get(dep_name) | |
23 # If the dependency can't be resolved, it is inaccessible and therefore | |
24 # so is this API feature. | |
25 if dependency_feature is None: | |
26 return set() | |
27 extension_types = extension_types.union( | |
28 _GetExtensionTypesRecursive(dependency_features.get(dep_name), | |
29 feature_set)) | |
30 return set(extension_types) | |
31 | |
32 class APIFeatures(Features): | |
33 '''Subclass of Features that can dig into dependencies to deduce the feature's | |
34 supported extension types. | |
35 ''' | |
36 def __init__(self, | |
37 compiled_fs_factory, | |
38 api_features_path, | |
39 manifest_features, | |
40 permission_features): | |
41 self._manifest_features = manifest_features | |
42 self._permission_features = permission_features | |
43 super(APIFeatures, self).__init__(compiled_fs_factory, api_features_path) | |
44 | |
45 def FilterByPlatform(self, features, platform): | |
46 '''Filter API features by supported platform using data from feature | |
47 dependencies if necessary.''' | |
48 feature_set = { | |
49 'api': features, | |
50 'manifest': self._manifest_features.get('all'), | |
51 'permission': self._permission_features.get('all'), | |
52 } | |
53 filtered_features = {} | |
54 for name, feature in features.iteritems(): | |
55 platforms = features_utility.GetPlatformSetForExtensionTypes( | |
56 _GetExtensionTypesRecursive(feature, feature_set)) | |
57 if not platform or platform in platforms: | |
58 filtered_features[name] = deepcopy(feature) | |
59 return filtered_features | |
OLD | NEW |