Commit b1b4faa5 authored by cduvall@chromium.org's avatar cduvall@chromium.org

Extensions Docs Server: Pull info from _permission_features.json

APIDataSource now pulls info from _permission_features.json and displays it in
the 'Permissions' section.

BUG=131095

Review URL: https://chromiumcodereview.appspot.com/10827063

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@149000 0039d316-1c4b-4281-b951-d872f2087c98
parent 790cc105
......@@ -19,6 +19,7 @@ class APIDataSource(object):
def __init__(self, cache_builder, base_path):
self._json_cache = cache_builder.build(self._LoadJsonAPI)
self._idl_cache = cache_builder.build(self._LoadIdlAPI)
self._permissions_cache = cache_builder.build(self._LoadPermissions)
self._base_path = base_path
def _LoadJsonAPI(self, api):
......@@ -31,6 +32,28 @@ class APIDataSource(object):
generator = HandlebarDictGenerator(idl_schema.IDLSchema(idl).process()[0])
return generator.Generate()
def _LoadPermissions(self, perms_json):
return json.loads(json_comment_eater.Nom(perms_json))
def _GetFeature(self, path):
# Remove 'experimental_' from path name to match the keys in
# _permissions_features.json.
path = path.replace('experimental_', '')
try:
perms = self._permissions_cache.GetFromFile(
self._base_path + '/_permission_features.json')
api_perms = perms.get(path, None)
if api_perms['channel'] == 'dev':
api_perms['dev'] = True
return api_perms
except Exception:
return None
def _AddPermissionsDict(self, api_dict, path):
return_dict = { 'permissions': self._GetFeature(path) }
return_dict.update(api_dict)
return return_dict
def __getitem__(self, key):
return self.get(key)
......@@ -40,10 +63,12 @@ class APIDataSource(object):
json_path = unix_name + '.json'
idl_path = unix_name + '.idl'
try:
return self._json_cache.GetFromFile(self._base_path + '/' + json_path)
return self._AddPermissionsDict(self._json_cache.GetFromFile(
self._base_path + '/' + json_path), path)
except Exception:
try:
return self._idl_cache.GetFromFile(self._base_path + '/' + idl_path)
return self._AddPermissionsDict(self._idl_cache.GetFromFile(
self._base_path + '/' + idl_path), path)
except Exception as e:
logging.warn(e)
return None
......@@ -25,6 +25,7 @@ class APIDataSourceTest(unittest.TestCase):
# Take the dict out of the list.
expected = json.loads(self._ReadLocalFile('expected_test_file.json'))
expected.update({ 'permissions': None })
self.assertEqual(expected, data_source['test_file'])
self.assertEqual(expected, data_source['testFile'])
self.assertEqual(expected, data_source['testFile.html'])
......
......@@ -11,6 +11,16 @@
{{+partials.sidenav}}
<div id="gc-pagecontent">
<h1 class="page_title">chrome.{{api.name}}</h1>
{{?api.permissions.dev}}
<p class="warning">
<em>Warning:</em> This API is still under development. It is only
available for Chrome users on the
<span>
<strong>dev</strong>
<a href="http://www.chromium.org/getting-involved/dev-channel">early
release channel</a>.</span>
</p>
{{/api.permissions.dev}}
{{+partials.table_of_contents toc:intro.toc}}
{{- This is unindented because it contains <pre> tags -}}
{{+intro.intro}}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment