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