Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7034)

Unified Diff: chrome/common/extensions/docs/server2/api_data_source.py

Issue 375133002: Docserver: Display API features that are available to content scripts (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/common/extensions/docs/server2/api_data_source.py
diff --git a/chrome/common/extensions/docs/server2/api_data_source.py b/chrome/common/extensions/docs/server2/api_data_source.py
index aaea1ab2a1e50fa4b28bc6fb70cf8be6624ab855..cb5ac3f7b3c6853bd86d057fa1ebdb68424944a3 100644
--- a/chrome/common/extensions/docs/server2/api_data_source.py
+++ b/chrome/common/extensions/docs/server2/api_data_source.py
@@ -8,11 +8,12 @@ import os
import posixpath
from data_source import DataSource
-from docs_server_utils import StringIdentity
+from docs_server_utils import StringIdentity, MarkFirst, MarkLast
from environment import IsPreviewServer, IsReleaseServer
from extensions_paths import JSON_TEMPLATES, PRIVATE_TEMPLATES
from file_system import FileNotFoundError
from future import Future, Collect
+from operator import itemgetter
from platform_util import GetPlatforms
import third_party.json_schema_compiler.json_parse as json_parse
import third_party.json_schema_compiler.model as model
@@ -266,12 +267,14 @@ class _JSCModel(object):
'''
def __init__(self,
+ content_script_apis,
namespace,
availability_finder,
json_cache,
template_cache,
features_bundle,
event_byname_future):
+ self._content_script_apis = content_script_apis
self._availability = availability_finder.GetAPIAvailability(namespace.name)
self._current_node = _APINodeCursor(availability_finder, namespace.name)
self._api_availabilities = json_cache.GetFromFile(
@@ -544,7 +547,7 @@ class _JSCModel(object):
intro_rows = [
self._GetIntroDescriptionRow(),
self._GetIntroAvailabilityRow()
- ] + self._GetIntroDependencyRows()
+ ] + self._GetIntroDependencyRows() + self._GetIntroContentScriptRow()
# Add rows using data from intro_tables.json, overriding any existing rows
# if they share the same 'title' attribute.
@@ -574,6 +577,25 @@ class _JSCModel(object):
'version': version
}
+ def _GetIntroContentScriptRow(self):
+ content_script_support = self._content_script_apis.get(self._namespace.name)
+ if content_script_support is None:
+ return []
+ if content_script_support.restrictedTo:
ahernandez 2014/07/16 20:35:34 Should this code be moved into a function somewher
not at google - send to devlin 2014/07/21 17:51:19 maybe, though I can't think of an appropriate plac
+ content_script_support.restrictedTo.sort(key=itemgetter('node'))
+ MarkFirst(content_script_support.restrictedTo)
+ MarkLast(content_script_support.restrictedTo)
+ return [{
+ 'title': 'Content Scripts',
+ 'content': [{
+ 'partial': self._template_cache.GetFromFile(
+ posixpath.join(PRIVATE_TEMPLATES,
+ 'intro_tables',
+ 'content_scripts.html')).Get(),
+ 'contentScriptSupport': content_script_support.__dict__
+ }]
+ }]
+
def _GetIntroDescriptionRow(self):
''' Generates the 'Description' row data for an API intro table.
'''
@@ -733,13 +755,15 @@ class APIDataSource(DataSource):
def _GetSchemaModel(self, platform, api_name):
object_store_key = '/'.join((platform, api_name))
+ api_models = self._platform_bundle.GetAPIModels(platform)
jsc_model_future = self._model_cache.Get(object_store_key)
- model_future = self._platform_bundle.GetAPIModels(platform).GetModel(
- api_name)
+ model_future = api_models.GetModel(api_name)
+ content_script_apis_future = api_models.GetContentScriptAPIs()
def resolve():
jsc_model = jsc_model_future.Get()
if jsc_model is None:
jsc_model = _JSCModel(
+ content_script_apis_future.Get(),
model_future.Get(),
self._platform_bundle.GetAvailabilityFinder(platform),
self._json_cache,

Powered by Google App Engine
This is Rietveld 408576698