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

Side by Side 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: Rebase/Address comments 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 unified diff | Download patch
OLDNEW
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 copy import copy 5 from copy import copy
6 import logging 6 import logging
7 import os 7 import os
8 import posixpath 8 import posixpath
9 9
10 from data_source import DataSource 10 from data_source import DataSource
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 def __repr__(self): 259 def __repr__(self):
260 return '%s > %s' % (self._namespace_name, ' > '.join(self._lookup_path)) 260 return '%s > %s' % (self._namespace_name, ' > '.join(self._lookup_path))
261 261
262 262
263 class _JSCModel(object): 263 class _JSCModel(object):
264 '''Uses a Model from the JSON Schema Compiler and generates a dict that 264 '''Uses a Model from the JSON Schema Compiler and generates a dict that
265 a Handlebar template can use for a data source. 265 a Handlebar template can use for a data source.
266 ''' 266 '''
267 267
268 def __init__(self, 268 def __init__(self,
269 api_models,
269 namespace, 270 namespace,
270 availability_finder, 271 availability_finder,
271 json_cache, 272 json_cache,
272 template_cache, 273 template_cache,
273 features_bundle, 274 features_bundle,
274 event_byname_future): 275 event_byname_future):
276 self._content_script_apis = api_models.GetContentScriptAPIs().Get()
not at google - send to devlin 2014/07/16 00:32:20 come to think of it, if you pass the content scrip
275 self._availability = availability_finder.GetAPIAvailability(namespace.name) 277 self._availability = availability_finder.GetAPIAvailability(namespace.name)
276 self._current_node = _APINodeCursor(availability_finder, namespace.name) 278 self._current_node = _APINodeCursor(availability_finder, namespace.name)
277 self._api_availabilities = json_cache.GetFromFile( 279 self._api_availabilities = json_cache.GetFromFile(
278 posixpath.join(JSON_TEMPLATES, 'api_availabilities.json')) 280 posixpath.join(JSON_TEMPLATES, 'api_availabilities.json'))
279 self._intro_tables = json_cache.GetFromFile( 281 self._intro_tables = json_cache.GetFromFile(
280 posixpath.join(JSON_TEMPLATES, 'intro_tables.json')) 282 posixpath.join(JSON_TEMPLATES, 'intro_tables.json'))
281 self._api_features = features_bundle.GetAPIFeatures() 283 self._api_features = features_bundle.GetAPIFeatures()
282 self._template_cache = template_cache 284 self._template_cache = template_cache
283 self._event_byname_future = event_byname_future 285 self._event_byname_future = event_byname_future
284 self._namespace = namespace 286 self._namespace = namespace
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
537 else: 539 else:
538 dst_dict['simple_type'] = type_.property_type.name 540 dst_dict['simple_type'] = type_.property_type.name
539 541
540 def _GetIntroTableList(self): 542 def _GetIntroTableList(self):
541 '''Create a generic data structure that can be traversed by the templates 543 '''Create a generic data structure that can be traversed by the templates
542 to create an API intro table. 544 to create an API intro table.
543 ''' 545 '''
544 intro_rows = [ 546 intro_rows = [
545 self._GetIntroDescriptionRow(), 547 self._GetIntroDescriptionRow(),
546 self._GetIntroAvailabilityRow() 548 self._GetIntroAvailabilityRow()
547 ] + self._GetIntroDependencyRows() 549 ] + self._GetIntroDependencyRows() + self._GetIntroContentScriptRow()
548 550
549 # Add rows using data from intro_tables.json, overriding any existing rows 551 # Add rows using data from intro_tables.json, overriding any existing rows
550 # if they share the same 'title' attribute. 552 # if they share the same 'title' attribute.
551 row_titles = [row['title'] for row in intro_rows] 553 row_titles = [row['title'] for row in intro_rows]
552 for misc_row in self._GetMiscIntroRows(): 554 for misc_row in self._GetMiscIntroRows():
553 if misc_row['title'] in row_titles: 555 if misc_row['title'] in row_titles:
554 intro_rows[row_titles.index(misc_row['title'])] = misc_row 556 intro_rows[row_titles.index(misc_row['title'])] = misc_row
555 else: 557 else:
556 intro_rows.append(misc_row) 558 intro_rows.append(misc_row)
557 559
558 return intro_rows 560 return intro_rows
559 561
560 def _GetAvailabilityTemplate(self, status=None, version=None, scheduled=None): 562 def _GetAvailabilityTemplate(self, status=None, version=None, scheduled=None):
561 '''Returns an object that the templates use to display availability 563 '''Returns an object that the templates use to display availability
562 information. 564 information.
563 ''' 565 '''
564 if status is None: 566 if status is None:
565 availability_info = self._current_node.GetAvailability() 567 availability_info = self._current_node.GetAvailability()
566 if availability_info is None: 568 if availability_info is None:
567 return None 569 return None
568 status = availability_info.channel 570 status = availability_info.channel
569 version = availability_info.version 571 version = availability_info.version
570 return { 572 return {
571 'partial': self._template_cache.GetFromFile( 573 'partial': self._template_cache.GetFromFile(
572 '%sintro_tables/%s_message.html' % (PRIVATE_TEMPLATES, status)).Get(), 574 '%sintro_tables/%s_message.html' % (PRIVATE_TEMPLATES, status)).Get(),
573 'scheduled': scheduled, 575 'scheduled': scheduled,
574 'version': version 576 'version': version
575 } 577 }
576 578
579 def _GetIntroContentScriptRow(self):
580 content_script_support = self._content_script_apis.get(self._namespace.name)
581 if content_script_support is None:
582 return []
583 return [{
584 'title': 'Content Scripts',
585 'content': [{
586 'partial': self._template_cache.GetFromFile(
587 posixpath.join(PRIVATE_TEMPLATES,
588 'intro_tables',
589 'content_scripts.html')).Get(),
590 'contentScriptSupport': content_script_support.__dict__
591 }]
592 }]
593
577 def _GetIntroDescriptionRow(self): 594 def _GetIntroDescriptionRow(self):
578 ''' Generates the 'Description' row data for an API intro table. 595 ''' Generates the 'Description' row data for an API intro table.
579 ''' 596 '''
580 return { 597 return {
581 'title': 'Description', 598 'title': 'Description',
582 'content': [ 599 'content': [
583 { 'text': self._namespace.description } 600 { 'text': self._namespace.description }
584 ] 601 ]
585 } 602 }
586 603
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
726 from Event in events.json. 743 from Event in events.json.
727 ''' 744 '''
728 if platform not in self._event_byname_futures: 745 if platform not in self._event_byname_futures:
729 future = self._GetSchemaModel(platform, 'events') 746 future = self._GetSchemaModel(platform, 'events')
730 self._event_byname_futures[platform] = Future( 747 self._event_byname_futures[platform] = Future(
731 callback=lambda: _GetEventByNameFromEvents(future.Get())) 748 callback=lambda: _GetEventByNameFromEvents(future.Get()))
732 return self._event_byname_futures[platform] 749 return self._event_byname_futures[platform]
733 750
734 def _GetSchemaModel(self, platform, api_name): 751 def _GetSchemaModel(self, platform, api_name):
735 object_store_key = '/'.join((platform, api_name)) 752 object_store_key = '/'.join((platform, api_name))
736 jsc_model_future = self._model_cache.Get(object_store_key) 753 jsc_model_future = self._model_cache.Get(object_store_key)
not at google - send to devlin 2014/07/16 00:32:20 i.e. this async fetching.
737 model_future = self._platform_bundle.GetAPIModels(platform).GetModel( 754 model_future = self._platform_bundle.GetAPIModels(platform).GetModel(
738 api_name) 755 api_name)
739 def resolve(): 756 def resolve():
740 jsc_model = jsc_model_future.Get() 757 jsc_model = jsc_model_future.Get()
741 if jsc_model is None: 758 if jsc_model is None:
742 jsc_model = _JSCModel( 759 jsc_model = _JSCModel(
760 self._platform_bundle.GetAPIModels(platform),
743 model_future.Get(), 761 model_future.Get(),
744 self._platform_bundle.GetAvailabilityFinder(platform), 762 self._platform_bundle.GetAvailabilityFinder(platform),
745 self._json_cache, 763 self._json_cache,
746 self._template_cache, 764 self._template_cache,
747 self._platform_bundle.GetFeaturesBundle(platform), 765 self._platform_bundle.GetFeaturesBundle(platform),
748 self._LoadEventByName(platform)).ToDict() 766 self._LoadEventByName(platform)).ToDict()
749 self._model_cache.Set(object_store_key, jsc_model) 767 self._model_cache.Set(object_store_key, jsc_model)
750 return jsc_model 768 return jsc_model
751 return Future(callback=resolve) 769 return Future(callback=resolve)
752 770
(...skipping 17 matching lines...) Expand all
770 getter = lambda: 0 788 getter = lambda: 0
771 getter.get = lambda api_name: self._GetImpl(platform, api_name).Get() 789 getter.get = lambda api_name: self._GetImpl(platform, api_name).Get()
772 return getter 790 return getter
773 791
774 def Cron(self): 792 def Cron(self):
775 futures = [] 793 futures = []
776 for platform in GetPlatforms(): 794 for platform in GetPlatforms():
777 futures += [self._GetImpl(platform, name) 795 futures += [self._GetImpl(platform, name)
778 for name in self._platform_bundle.GetAPIModels(platform).GetNames()] 796 for name in self._platform_bundle.GetAPIModels(platform).GetNames()]
779 return Collect(futures, except_pass=FileNotFoundError) 797 return Collect(futures, except_pass=FileNotFoundError)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698