Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 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 data_source import DataSource | 5 from data_source import DataSource |
| 6 from future import Future | 6 from future import Future |
| 7 from operator import itemgetter | 7 from operator import itemgetter |
| 8 from platform_util import GetPlatforms | 8 from platform_util import GetPlatforms |
| 9 | 9 |
| 10 from docs_server_utils import MarkLast | 10 from docs_server_utils import MarkFirst, MarkLast |
| 11 | 11 |
| 12 class APIListDataSource(DataSource): | 12 class APIListDataSource(DataSource): |
| 13 """ This class creates a list of chrome.* APIs and chrome.experimental.* APIs | 13 """ This class creates a list of chrome.* APIs and chrome.experimental.* APIs |
| 14 for extensions and apps that are used in the api_index.html, | 14 for extensions and apps that are used in the api_index.html, |
| 15 experimental.html, and private_apis.html pages. | 15 experimental.html, and private_apis.html pages. |
| 16 | 16 |
| 17 An API is considered listable if it is listed in _api_features.json, | 17 An API is considered listable if it is listed in _api_features.json, |
| 18 it has a corresponding HTML file in the public template path, and one of | 18 it has a corresponding HTML file in the public template path, and one of |
| 19 the following conditions is met: | 19 the following conditions is met: |
| 20 - It has no "dependencies" or "extension_types" properties in _api_features | 20 - It has no "dependencies" or "extension_types" properties in _api_features |
| 21 - It has an "extension_types" property in _api_features with either/both | 21 - It has an "extension_types" property in _api_features with either/both |
| 22 "extension"/"platform_app" values present. | 22 "extension"/"platform_app" values present. |
| 23 - It has a dependency in _{api,manifest,permission}_features with an | 23 - It has a dependency in _{api,manifest,permission}_features with an |
| 24 "extension_types" property where either/both "extension"/"platform_app" | 24 "extension_types" property where either/both "extension"/"platform_app" |
| 25 values are present. | 25 values are present. |
| 26 """ | 26 """ |
| 27 def __init__(self, server_instance, _): | 27 def __init__(self, server_instance, _): |
| 28 self._platform_bundle = server_instance.platform_bundle | 28 self._platform_bundle = server_instance.platform_bundle |
| 29 self._object_store = server_instance.object_store_creator.Create( | 29 self._object_store = server_instance.object_store_creator.Create( |
| 30 # Update the model when the API or Features model updates. | 30 # Update the model when the API or Features model updates. |
| 31 APIListDataSource, category=self._platform_bundle.GetIdentity()) | 31 APIListDataSource, category=self._platform_bundle.GetIdentity()) |
| 32 | 32 |
| 33 def _GenerateAPIDict(self): | 33 def _GenerateAPIDict(self): |
| 34 def make_list_for_content_scripts(): | |
| 35 content_script_apis = self._platform_bundle.GetAPIModels( | |
| 36 'extensions').GetContentScriptAPIs().Get() | |
| 37 content_script_apis_list = [csa.__dict__ for api_name, csa in | |
| 38 content_script_apis.iteritems() if | |
| 39 self._platform_bundle.GetAPICategorizer( | |
| 40 'extensions').IsDocumented(api_name)] | |
| 41 content_script_apis_list.sort(key=itemgetter('name')) | |
| 42 for csa in content_script_apis_list: | |
| 43 restricted_nodes = csa['restrictedTo'] | |
| 44 if restricted_nodes: | |
| 45 restricted_nodes.sort(key=itemgetter('node')) | |
| 46 MarkFirst(restricted_nodes) | |
| 47 MarkLast(restricted_nodes) | |
|
not at google - send to devlin
2014/07/16 00:32:20
could you
else:
del csa['restrictedTo']
here.
| |
| 48 return content_script_apis_list | |
| 49 | |
| 34 def make_dict_for_platform(platform): | 50 def make_dict_for_platform(platform): |
| 35 platform_dict = { | 51 platform_dict = { |
| 36 'chrome': {'stable': [], 'beta': [], 'dev': [], 'trunk': []}, | 52 'chrome': {'stable': [], 'beta': [], 'dev': [], 'trunk': []}, |
| 37 } | 53 } |
| 38 private_apis = [] | 54 private_apis = [] |
| 39 experimental_apis = [] | 55 experimental_apis = [] |
| 40 all_apis = [] | 56 all_apis = [] |
| 41 for api_name, api_model in self._platform_bundle.GetAPIModels( | 57 for api_name, api_model in self._platform_bundle.GetAPIModels( |
| 42 platform).IterModels(): | 58 platform).IterModels(): |
| 43 if not self._platform_bundle.GetAPICategorizer(platform).IsDocumented( | 59 if not self._platform_bundle.GetAPICategorizer(platform).IsDocumented( |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 70 platform_dict['chrome'][channel] = apis_by_channel | 86 platform_dict['chrome'][channel] = apis_by_channel |
| 71 | 87 |
| 72 for key, apis in (('all', all_apis), | 88 for key, apis in (('all', all_apis), |
| 73 ('private', private_apis), | 89 ('private', private_apis), |
| 74 ('experimental', experimental_apis)): | 90 ('experimental', experimental_apis)): |
| 75 apis.sort(key=itemgetter('name')) | 91 apis.sort(key=itemgetter('name')) |
| 76 MarkLast(apis) | 92 MarkLast(apis) |
| 77 platform_dict[key] = apis | 93 platform_dict[key] = apis |
| 78 | 94 |
| 79 return platform_dict | 95 return platform_dict |
| 80 return dict((platform, make_dict_for_platform(platform)) | 96 api_dict = dict((platform, make_dict_for_platform(platform)) |
| 81 for platform in GetPlatforms()) | 97 for platform in GetPlatforms()) |
| 98 api_dict['content_scripts'] = make_list_for_content_scripts() | |
| 99 return api_dict | |
| 82 | 100 |
| 83 def _GetCachedAPIData(self): | 101 def _GetCachedAPIData(self): |
| 84 data_future = self._object_store.Get('api_data') | 102 data_future = self._object_store.Get('api_data') |
| 85 def resolve(): | 103 def resolve(): |
| 86 data = data_future.Get() | 104 data = data_future.Get() |
| 87 if data is None: | 105 if data is None: |
| 88 data = self._GenerateAPIDict() | 106 data = self._GenerateAPIDict() |
| 89 self._object_store.Set('api_data', data) | 107 self._object_store.Set('api_data', data) |
| 90 return data | 108 return data |
| 91 return Future(callback=resolve) | 109 return Future(callback=resolve) |
| 92 | 110 |
| 93 def get(self, key): | 111 def get(self, key): |
| 94 return self._GetCachedAPIData().Get().get(key) | 112 return self._GetCachedAPIData().Get().get(key) |
| 95 | 113 |
| 96 def Cron(self): | 114 def Cron(self): |
| 97 return self._GetCachedAPIData() | 115 return self._GetCachedAPIData() |
| OLD | NEW |