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