Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(21)

Side by Side Diff: chrome/common/extensions/docs/server2/features_bundle.py

Issue 375133002: Docserver: Display API features that are available to content scripts (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Nits Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 # Copyright 2013 The Chromium Authors. All rights reserved. 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 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 from copy import copy 5 from copy import copy
6 6
7 from branch_utility import BranchUtility 7 from branch_utility import BranchUtility
8 from compiled_file_system import SingleFile, Unicode 8 from compiled_file_system import SingleFile, Unicode
9 from docs_server_utils import StringIdentity 9 from docs_server_utils import StringIdentity
10 from extensions_paths import API_PATHS, JSON_TEMPLATES 10 from extensions_paths import API_PATHS, JSON_TEMPLATES
11 from file_system import FileNotFoundError 11 from file_system import FileNotFoundError
12 from future import Future 12 from future import Future
13 from path_util import Join 13 from path_util import Join
14 from platform_util import GetExtensionTypes, PlatformToExtensionType 14 from platform_util import GetExtensionTypes, PlatformToExtensionType
15 from third_party.json_schema_compiler.json_parse import Parse 15 from third_party.json_schema_compiler.json_parse import Parse
16 16
17 17
18 _API_FEATURES = '_api_features.json' 18 _API_FEATURES = '_api_features.json'
19 _MANIFEST_FEATURES = '_manifest_features.json' 19 _MANIFEST_FEATURES = '_manifest_features.json'
20 _PERMISSION_FEATURES = '_permission_features.json' 20 _PERMISSION_FEATURES = '_permission_features.json'
21 21
22 22
23 def HasParentFeature(feature_name, feature, all_feature_names): 23 def HasParent(feature_name, feature, all_feature_names):
24 # A feature has a parent if it has a . in its name, its parent exists, 24 # A feature has a parent if it has a . in its name, its parent exists,
25 # and it does not explicitly specify that it has no parent. 25 # and it does not explicitly specify that it has no parent.
26 return ('.' in feature_name and 26 return ('.' in feature_name and
27 feature_name.rsplit('.', 1)[0] in all_feature_names and 27 feature_name.rsplit('.', 1)[0] in all_feature_names and
28 not feature.get('noparent')) 28 not feature.get('noparent'))
29 29
30 30
31 def GetParentFeature(feature_name, feature, all_feature_names): 31 def GetParentName(feature_name, feature, all_feature_names):
32 '''Returns the name of the parent feature, or None if it does not have a 32 '''Returns the name of the parent feature, or None if it does not have a
33 parent. 33 parent.
34 ''' 34 '''
35 if not HasParentFeature(feature_name, feature, all_feature_names): 35 if not HasParent(feature_name, feature, all_feature_names):
36 return None 36 return None
37 return feature_name.rsplit('.', 1)[0] 37 return feature_name.rsplit('.', 1)[0]
38 38
39 39
40 def _CreateFeaturesFromJSONFutures(json_futures): 40 def _CreateFeaturesFromJSONFutures(json_futures):
41 '''Returns a dict of features. The value of each feature is a list with 41 '''Returns a dict of features. The value of each feature is a list with
42 all of its possible values. 42 all of its possible values.
43 ''' 43 '''
44 def ignore_feature(name, value): 44 def ignore_feature(name, value):
45 '''Returns true if this feature should be ignored. Features are ignored if 45 '''Returns true if this feature should be ignored. Features are ignored if
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 inherit_valid_platform = 'extension_types' not in value 115 inherit_valid_platform = 'extension_types' not in value
116 if inherit_valid_platform: 116 if inherit_valid_platform:
117 valid_platform = None 117 valid_platform = None
118 else: 118 else:
119 valid_platform = (value['extension_types'] == 'all' or 119 valid_platform = (value['extension_types'] == 'all' or
120 platform in value['extension_types']) 120 platform in value['extension_types'])
121 inherit_channel = 'channel' not in value 121 inherit_channel = 'channel' not in value
122 channel = value.get('channel') 122 channel = value.get('channel')
123 123
124 dependencies = value.get('dependencies', []) 124 dependencies = value.get('dependencies', [])
125 parent = GetParentFeature( 125 parent = GetParentName(
126 feature_name, value, features_map[features_type]['all_names']) 126 feature_name, value, features_map[features_type]['all_names'])
127 if parent is not None: 127 if parent is not None:
128 # The parent data needs to be resolved so the child can inherit it. 128 # The parent data needs to be resolved so the child can inherit it.
129 if parent in features_map[features_type].get('unresolved', ()): 129 if parent in features_map[features_type].get('unresolved', ()):
130 return False, None 130 return False, None
131 value = _CopyParentFeatureValues( 131 value = _CopyParentFeatureValues(
132 value, features_map[features_type]['resolved'].get(parent)) 132 value, features_map[features_type]['resolved'].get(parent))
133 # Add the parent as a dependency to ensure proper platform filtering. 133 # Add the parent as a dependency to ensure proper platform filtering.
134 dependencies.append(features_type + ':' + parent) 134 dependencies.append(features_type + ':' + parent)
135 135
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 cache['resolved'][feature_name] = feature 361 cache['resolved'][feature_name] = feature
362 362
363 for key in to_remove: 363 for key in to_remove:
364 del cache['unresolved'][key] 364 del cache['unresolved'][key]
365 365
366 for cache_type, cache in features_map.iteritems(): 366 for cache_type, cache in features_map.iteritems():
367 self._object_store.Set(cache_type, cache['resolved']) 367 self._object_store.Set(cache_type, cache['resolved'])
368 return features_map[features_type]['resolved'] 368 return features_map[features_type]['resolved']
369 369
370 return Future(callback=resolve) 370 return Future(callback=resolve)
OLDNEW
« no previous file with comments | « chrome/common/extensions/docs/server2/docs_server_utils.py ('k') | chrome/common/extensions/docs/server2/platform_bundle.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698