Index: chrome/common/extensions/docs/server2/api_models.py |
diff --git a/chrome/common/extensions/docs/server2/api_models.py b/chrome/common/extensions/docs/server2/api_models.py |
index 673dc434661fe18a297217db4f0bbf02d84716c2..0551abc751b9b16b835b5c6b1c4411ba3f126217 100644 |
--- a/chrome/common/extensions/docs/server2/api_models.py |
+++ b/chrome/common/extensions/docs/server2/api_models.py |
@@ -7,9 +7,10 @@ import posixpath |
from compiled_file_system import SingleFile, Unicode |
from docs_server_utils import StringIdentity |
from extensions_paths import API_PATHS |
-from features_bundle import HasParentFeature |
+from features_bundle import HasParentFeature, GetParentFeature |
from file_system import FileNotFoundError |
from future import Collect, Future |
+from operator import itemgetter |
from platform_util import PlatformToExtensionType |
from schema_util import ProcessSchema |
from third_party.json_schema_compiler.json_schema import DeleteNodes |
@@ -24,11 +25,13 @@ class APIModels(object): |
features_bundle, |
compiled_fs_factory, |
file_system, |
+ object_store_creator, |
platform): |
self._features_bundle = features_bundle |
self._platform = PlatformToExtensionType(platform) |
self._model_cache = compiled_fs_factory.Create( |
file_system, self._CreateAPIModel, APIModels, category=self._platform) |
+ self._object_store = object_store_creator.Create(APIModels) |
@SingleFile |
@Unicode |
@@ -97,6 +100,69 @@ class APIModels(object): |
futures[0].Get() |
return Future(callback=resolve) |
+ def GetContentScriptsAPIs(self): |
not at google - send to devlin
2014/07/09 02:55:55
s/GetContentScriptsAPIs/GetContentScriptAPIs/
|
+ '''Creates a dict of APIs and nodes supported by content scripts in |
+ this format: |
+ |
+ { |
+ 'extension': { |
+ 'name': 'extension', |
not at google - send to devlin
2014/07/09 02:55:55
Can we return an actual type rather than a diction
|
+ 'fullSupport': False, |
not at google - send to devlin
2014/07/09 02:55:55
'allNodes' might be more consistent with 'supporte
|
+ 'supportedNodes': [{ |
+ 'parent': 'extension', |
+ 'node': sendMessage |
+ }, |
+ ... |
+ ] |
+ }, |
+ ... |
+ } |
+ ''' |
+ content_script_apis_future = self._object_store.Get('content_script_apis') |
+ api_features_future = self._features_bundle.GetAPIFeatures() |
+ def resolve(): |
+ content_script_apis = content_script_apis_future.Get() |
+ api_features = api_features_future.Get() |
not at google - send to devlin
2014/07/09 02:55:55
you don't need to resolve this is if content_scrip
|
+ if content_script_apis is not None: |
+ return content_script_apis |
+ |
+ content_script_apis = {} |
+ for feature in api_features.itervalues(): |
+ # Gets all the features that have 'content_script' in their context. |
+ if 'content_script' in feature.get('contexts', ()): |
not at google - send to devlin
2014/07/09 02:55:55
early-continue
|
+ parent = GetParentFeature(feature['name'], feature, api_features) |
+ # If it has no parent, then the API is fully supported. |
+ if parent is None: |
+ content_script_apis[feature['name']] = { |
+ 'name': feature['name'], |
+ 'fullSupport': True, |
+ 'supportedNodes': [] |
+ } |
+ else: |
+ # Creates a dict for the individual node. |
+ node = {'parent': parent, 'node': feature['name'][len(parent) + 1:]} |
+ # Initializes the supportedNodes list if it doesn't exist yet. |
+ if parent not in content_script_apis: |
+ content_script_apis[parent] = { |
+ 'name': parent, |
+ 'fullSupport': False, |
+ 'supportedNodes': [node] |
+ } |
+ else: |
+ content_script_apis[parent]['supportedNodes'].append(node) |
+ |
+ # Sort all of the supportedNodes. |
+ for content_script_api in content_script_apis.itervalues(): |
+ if content_script_api['supportedNodes']: |
+ content_script_api['supportedNodes'].sort(key=itemgetter('node')) |
+ # Annotate the first and last ones for use in the templates. |
+ content_script_api['supportedNodes'][0]['first'] = True |
+ content_script_api['supportedNodes'][-1]['last'] = True |
+ |
+ self._object_store.Set('content_script_apis', content_script_apis) |
+ return content_script_apis |
+ return Future(callback=resolve) |
+ |
def Cron(self): |
futures = [self.GetModel(name) for name in self.GetNames()] |
return Collect(futures, except_pass=(FileNotFoundError, ValueError)) |