| 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, attrgetter |
| 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 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_scripts_apis = self._platform_bundle.GetAPIModels( |
| 36 'extensions').GetContentScriptAPIs().Get() |
| 37 content_scripts_apis_list = [] |
| 38 for api_name, content_script_api in content_scripts_apis.iteritems(): |
| 39 if self._platform_bundle.GetAPICategorizer('extensions').IsDocumented( |
| 40 api_name): |
| 41 content_scripts_apis_list.append(content_script_api) |
| 42 content_scripts_apis_list.sort(key=attrgetter('name')) |
| 43 return content_scripts_apis_list |
| 44 |
| 34 def make_dict_for_platform(platform): | 45 def make_dict_for_platform(platform): |
| 35 platform_dict = { | 46 platform_dict = { |
| 36 'chrome': {'stable': [], 'beta': [], 'dev': [], 'trunk': []}, | 47 'chrome': {'stable': [], 'beta': [], 'dev': [], 'trunk': []}, |
| 37 } | 48 } |
| 38 private_apis = [] | 49 private_apis = [] |
| 39 experimental_apis = [] | 50 experimental_apis = [] |
| 40 all_apis = [] | 51 all_apis = [] |
| 41 for api_name, api_model in self._platform_bundle.GetAPIModels( | 52 for api_name, api_model in self._platform_bundle.GetAPIModels( |
| 42 platform).IterModels(): | 53 platform).IterModels(): |
| 43 if not self._platform_bundle.GetAPICategorizer(platform).IsDocumented( | 54 if not self._platform_bundle.GetAPICategorizer(platform).IsDocumented( |
| (...skipping 26 matching lines...) Expand all Loading... |
| 70 platform_dict['chrome'][channel] = apis_by_channel | 81 platform_dict['chrome'][channel] = apis_by_channel |
| 71 | 82 |
| 72 for key, apis in (('all', all_apis), | 83 for key, apis in (('all', all_apis), |
| 73 ('private', private_apis), | 84 ('private', private_apis), |
| 74 ('experimental', experimental_apis)): | 85 ('experimental', experimental_apis)): |
| 75 apis.sort(key=itemgetter('name')) | 86 apis.sort(key=itemgetter('name')) |
| 76 MarkLast(apis) | 87 MarkLast(apis) |
| 77 platform_dict[key] = apis | 88 platform_dict[key] = apis |
| 78 | 89 |
| 79 return platform_dict | 90 return platform_dict |
| 80 return dict((platform, make_dict_for_platform(platform)) | 91 api_dict = dict((platform, make_dict_for_platform(platform)) |
| 81 for platform in GetPlatforms()) | 92 for platform in GetPlatforms()) |
| 93 api_dict['content_scripts'] = make_list_for_content_scripts() |
| 94 return api_dict |
| 82 | 95 |
| 83 def _GetCachedAPIData(self): | 96 def _GetCachedAPIData(self): |
| 84 data_future = self._object_store.Get('api_data') | 97 data_future = self._object_store.Get('api_data') |
| 85 def resolve(): | 98 def resolve(): |
| 86 data = data_future.Get() | 99 data = data_future.Get() |
| 87 if data is None: | 100 if data is None: |
| 88 data = self._GenerateAPIDict() | 101 data = self._GenerateAPIDict() |
| 89 self._object_store.Set('api_data', data) | 102 self._object_store.Set('api_data', data) |
| 90 return data | 103 return data |
| 91 return Future(callback=resolve) | 104 return Future(callback=resolve) |
| 92 | 105 |
| 93 def get(self, key): | 106 def get(self, key): |
| 94 return self._GetCachedAPIData().Get().get(key) | 107 return self._GetCachedAPIData().Get().get(key) |
| 95 | 108 |
| 96 def Cron(self): | 109 def Cron(self): |
| 97 return self._GetCachedAPIData() | 110 return self._GetCachedAPIData() |
| OLD | NEW |