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 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 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 self._lookup_path[:] = self._lookup_path[:-len(path)] | 224 self._lookup_path[:] = self._lookup_path[:-len(path)] |
225 return scope() | 225 return scope() |
226 | 226 |
227 | 227 |
228 class _JSCModel(object): | 228 class _JSCModel(object): |
229 '''Uses a Model from the JSON Schema Compiler and generates a dict that | 229 '''Uses a Model from the JSON Schema Compiler and generates a dict that |
230 a Handlebar template can use for a data source. | 230 a Handlebar template can use for a data source. |
231 ''' | 231 ''' |
232 | 232 |
233 def __init__(self, | 233 def __init__(self, |
| 234 api_models, |
234 namespace, | 235 namespace, |
235 availability_finder, | 236 availability_finder, |
236 json_cache, | 237 json_cache, |
237 template_cache, | 238 template_cache, |
238 features_bundle, | 239 features_bundle, |
239 event_byname_future): | 240 event_byname_future): |
| 241 self._content_script_apis = api_models.GetContentScriptAPIs().Get() |
240 self._availability = availability_finder.GetAPIAvailability(namespace.name) | 242 self._availability = availability_finder.GetAPIAvailability(namespace.name) |
241 self._current_node = _APINodeCursor(availability_finder, namespace.name) | 243 self._current_node = _APINodeCursor(availability_finder, namespace.name) |
242 self._api_availabilities = json_cache.GetFromFile( | 244 self._api_availabilities = json_cache.GetFromFile( |
243 posixpath.join(JSON_TEMPLATES, 'api_availabilities.json')) | 245 posixpath.join(JSON_TEMPLATES, 'api_availabilities.json')) |
244 self._intro_tables = json_cache.GetFromFile( | 246 self._intro_tables = json_cache.GetFromFile( |
245 posixpath.join(JSON_TEMPLATES, 'intro_tables.json')) | 247 posixpath.join(JSON_TEMPLATES, 'intro_tables.json')) |
246 self._api_features = features_bundle.GetAPIFeatures() | 248 self._api_features = features_bundle.GetAPIFeatures() |
247 self._template_cache = template_cache | 249 self._template_cache = template_cache |
248 self._event_byname_future = event_byname_future | 250 self._event_byname_future = event_byname_future |
249 self._namespace = namespace | 251 self._namespace = namespace |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
485 else: | 487 else: |
486 dst_dict['simple_type'] = type_.property_type.name | 488 dst_dict['simple_type'] = type_.property_type.name |
487 | 489 |
488 def _GetIntroTableList(self): | 490 def _GetIntroTableList(self): |
489 '''Create a generic data structure that can be traversed by the templates | 491 '''Create a generic data structure that can be traversed by the templates |
490 to create an API intro table. | 492 to create an API intro table. |
491 ''' | 493 ''' |
492 intro_rows = [ | 494 intro_rows = [ |
493 self._GetIntroDescriptionRow(), | 495 self._GetIntroDescriptionRow(), |
494 self._GetIntroAvailabilityRow() | 496 self._GetIntroAvailabilityRow() |
495 ] + self._GetIntroDependencyRows() | 497 ] + self._GetIntroDependencyRows() + self._GetIntroContentScriptRow() |
496 | 498 |
497 # Add rows using data from intro_tables.json, overriding any existing rows | 499 # Add rows using data from intro_tables.json, overriding any existing rows |
498 # if they share the same 'title' attribute. | 500 # if they share the same 'title' attribute. |
499 row_titles = [row['title'] for row in intro_rows] | 501 row_titles = [row['title'] for row in intro_rows] |
500 for misc_row in self._GetMiscIntroRows(): | 502 for misc_row in self._GetMiscIntroRows(): |
501 if misc_row['title'] in row_titles: | 503 if misc_row['title'] in row_titles: |
502 intro_rows[row_titles.index(misc_row['title'])] = misc_row | 504 intro_rows[row_titles.index(misc_row['title'])] = misc_row |
503 else: | 505 else: |
504 intro_rows.append(misc_row) | 506 intro_rows.append(misc_row) |
505 | 507 |
506 return intro_rows | 508 return intro_rows |
507 | 509 |
508 def _GetAvailabilityTemplate(self, status=None, version=None, scheduled=None): | 510 def _GetAvailabilityTemplate(self, status=None, version=None, scheduled=None): |
509 '''Returns an object that the templates use to display availability | 511 '''Returns an object that the templates use to display availability |
510 information. | 512 information. |
511 ''' | 513 ''' |
512 if status is None: | 514 if status is None: |
513 availability_info = self._current_node.GetAvailability() | 515 availability_info = self._current_node.GetAvailability() |
514 if availability_info is None: | 516 if availability_info is None: |
515 return None | 517 return None |
516 status = availability_info.channel | 518 status = availability_info.channel |
517 version = availability_info.version | 519 version = availability_info.version |
518 return { | 520 return { |
519 'partial': self._template_cache.GetFromFile( | 521 'partial': self._template_cache.GetFromFile( |
520 '%sintro_tables/%s_message.html' % (PRIVATE_TEMPLATES, status)).Get(), | 522 '%sintro_tables/%s_message.html' % (PRIVATE_TEMPLATES, status)).Get(), |
521 'scheduled': scheduled, | 523 'scheduled': scheduled, |
522 'version': version | 524 'version': version |
523 } | 525 } |
524 | 526 |
| 527 def _GetIntroContentScriptRow(self): |
| 528 content_script_support = self._content_script_apis.get(self._namespace.name) |
| 529 if content_script_support is None: |
| 530 return [] |
| 531 return [{ |
| 532 'title': 'Content Scripts', |
| 533 'content': [{ |
| 534 'partial': self._template_cache.GetFromFile( |
| 535 posixpath.join(PRIVATE_TEMPLATES, |
| 536 'intro_tables', |
| 537 'content_scripts.html')).Get(), |
| 538 'contentScriptSupport': content_script_support |
| 539 }] |
| 540 }] |
| 541 |
525 def _GetIntroDescriptionRow(self): | 542 def _GetIntroDescriptionRow(self): |
526 ''' Generates the 'Description' row data for an API intro table. | 543 ''' Generates the 'Description' row data for an API intro table. |
527 ''' | 544 ''' |
528 return { | 545 return { |
529 'title': 'Description', | 546 'title': 'Description', |
530 'content': [ | 547 'content': [ |
531 { 'text': self._namespace.description } | 548 { 'text': self._namespace.description } |
532 ] | 549 ] |
533 } | 550 } |
534 | 551 |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
681 | 698 |
682 def _GetSchemaModel(self, platform, api_name): | 699 def _GetSchemaModel(self, platform, api_name): |
683 object_store_key = '/'.join((platform, api_name)) | 700 object_store_key = '/'.join((platform, api_name)) |
684 jsc_model_future = self._model_cache.Get(object_store_key) | 701 jsc_model_future = self._model_cache.Get(object_store_key) |
685 model_future = self._platform_bundle.GetAPIModels(platform).GetModel( | 702 model_future = self._platform_bundle.GetAPIModels(platform).GetModel( |
686 api_name) | 703 api_name) |
687 def resolve(): | 704 def resolve(): |
688 jsc_model = jsc_model_future.Get() | 705 jsc_model = jsc_model_future.Get() |
689 if jsc_model is None: | 706 if jsc_model is None: |
690 jsc_model = _JSCModel( | 707 jsc_model = _JSCModel( |
| 708 self._platform_bundle.GetAPIModels(platform), |
691 model_future.Get(), | 709 model_future.Get(), |
692 self._platform_bundle.GetAvailabilityFinder(platform), | 710 self._platform_bundle.GetAvailabilityFinder(platform), |
693 self._json_cache, | 711 self._json_cache, |
694 self._template_cache, | 712 self._template_cache, |
695 self._platform_bundle.GetFeaturesBundle(platform), | 713 self._platform_bundle.GetFeaturesBundle(platform), |
696 self._LoadEventByName(platform)).ToDict() | 714 self._LoadEventByName(platform)).ToDict() |
697 self._model_cache.Set(object_store_key, jsc_model) | 715 self._model_cache.Set(object_store_key, jsc_model) |
698 return jsc_model | 716 return jsc_model |
699 return Future(callback=resolve) | 717 return Future(callback=resolve) |
700 | 718 |
(...skipping 17 matching lines...) Expand all Loading... |
718 getter = lambda: 0 | 736 getter = lambda: 0 |
719 getter.get = lambda api_name: self._GetImpl(platform, api_name).Get() | 737 getter.get = lambda api_name: self._GetImpl(platform, api_name).Get() |
720 return getter | 738 return getter |
721 | 739 |
722 def Cron(self): | 740 def Cron(self): |
723 futures = [] | 741 futures = [] |
724 for platform in GetPlatforms(): | 742 for platform in GetPlatforms(): |
725 futures += [self._GetImpl(platform, name) | 743 futures += [self._GetImpl(platform, name) |
726 for name in self._platform_bundle.GetAPIModels(platform).GetNames()] | 744 for name in self._platform_bundle.GetAPIModels(platform).GetNames()] |
727 return Collect(futures, except_pass=FileNotFoundError) | 745 return Collect(futures, except_pass=FileNotFoundError) |
OLD | NEW |