diff options
13 files changed, 277 insertions, 199 deletions
diff --git a/chrome/app/policy/policy_templates.grd b/chrome/app/policy/policy_templates.grd index 08cd727..0a44fd1 100644 --- a/chrome/app/policy/policy_templates.grd +++ b/chrome/app/policy/policy_templates.grd @@ -705,13 +705,17 @@ templates and will be translated for each locale. --> desc="Caption text of the field 'mac/linux preference name' in the summary chart of a policy in the generated documentation"> Mac/Linux preference name: </message> - <message name="IDS_POLICY_DOC_SUPPORTED_ON_PLATFORMS" - desc="Caption text of the list of 'platforms where this policy is supported' in the summary chart of a policy in the generated documentation"> - Supported on platforms: + <message name="IDS_POLICY_DOC_SUPPORTED_ON" + desc="Caption text of the list of 'products, platforms and versions where this policy is supported' in the summary chart of a policy in the generated documentation"> + Supported on: </message> - <message name="IDS_POLICY_DOC_SUPPORTED_IN_PRODUCTS" - desc="Caption text of the list of 'products where this policy is supported' in the summary chart of a policy in the generated documentation"> - Supported in products: + <message name="IDS_POLICY_DOC_SINCE_VERSION" + desc="Text in the summary chart of a policy that specifies the version number in which the policy was introduced."> + since version <ph name="SINCE_VERSION">$6<ex>8</ex></ph> + </message> + <message name="IDS_POLICY_DOC_UNTIL_VERSION" + desc="Text in the summary chart of a policy that specifies the version number after which the policy was dropped."> + until version <ph name="UNTIL_VERSION">$6<ex>10</ex></ph> </message> <message name="IDS_POLICY_DOC_SUPPORTED_FEATURES" desc="Caption text of the list of 'policy features that this policy supports' in the summary chart of a policy in the generated documentation"> diff --git a/chrome/app/policy/policy_templates.json b/chrome/app/policy/policy_templates.json index 7d06fbd..5d51b44 100644 --- a/chrome/app/policy/policy_templates.json +++ b/chrome/app/policy/policy_templates.json @@ -58,13 +58,28 @@ # # Annotations: # Each policy has metadata under the key 'annotations'. -# These values are only used for the generated documentation, except for -# 'platforms', that is also used for filtering policies. It is a list -# enumerating the platforms on which Chrome supports the given policy. -# In a given template, only those policies are included that are compatible -# with the target OS of that template. -# Windows: ADM,ADMX,ADML -# Mac: plist,plist_strings +# These values are only used for the generated documentation. +# +# Products and versions: +# Each policy has the list of products and version numbers where it is +# supported under the key 'supported_on'. Each item of this list has the +# form of 'product:since_version-until_version', which means that support +# for the policy in 'product' was introduced in 'since_version' and removed +# after 'until_version'. Product names may contain a suffix specifying a +# platform name, e.g.: 'chrome.win' is read as 'Chrome on Windows'. Version +# numbers can be any string that does not contain ':' or '-' characters. +# +# Currently supported product names: +# 'chrome_frame', 'chrome_os' +# 'chrome.win', 'chrome.linux', 'chrome.mac', 'chrome.*' +# For example if 'chrome.*:5-10' is specified for a policy, then it should +# be read as: +# 'chrome.linux:5-10,chrome.mac:5-10,chrome.win:5-10' +# The product name also affects in which templates will the policy be included. +# chrome.*, chrome.win, chrome_frame -> ADM,ADMX,ADML,doc +# chrome.*, chrome.linux -> JSON,doc +# chrome.*, chrome.mac -> plist, plist_strings,doc +# everything else -> doc # 'policy_definitions': [ { @@ -74,9 +89,8 @@ { 'name': 'HomepageLocation', 'type': 'string', + 'supported_on': ['chrome.*:8-'], 'annotations': { - 'platforms': ['linux', 'mac', 'win'], - 'products': ['chrome'], 'features': {'dynamic_refresh': 1}, 'example_value': 'http://chromium.org', } @@ -84,9 +98,8 @@ { 'name': 'HomepageIsNewTabPage', 'type': 'main', + 'supported_on': ['chrome.*:8-'], 'annotations': { - 'platforms': ['linux', 'mac', 'win'], - 'products': ['chrome'], 'features': {'dynamic_refresh': 1}, 'example_value': True, } @@ -96,9 +109,8 @@ { 'name': 'ApplicationLocaleValue', 'type': 'string', + 'supported_on': ['chrome.win:8-'], 'annotations': { - 'platforms': ['win'], - 'products': ['chrome'], 'features': {'dynamic_refresh': 0}, 'example_value': 'en', }, @@ -106,9 +118,8 @@ { 'name': 'AlternateErrorPagesEnabled', 'type': 'main', + 'supported_on': ['chrome.*:8-'], 'annotations': { - 'platforms': ['linux', 'mac', 'win'], - 'products': ['chrome'], 'features': {'dynamic_refresh': 1}, 'example_value': True, }, @@ -116,9 +127,8 @@ { 'name': 'SearchSuggestEnabled', 'type': 'main', + 'supported_on': ['chrome.*:8-'], 'annotations': { - 'platforms': ['linux', 'mac', 'win'], - 'products': ['chrome'], 'features': {'dynamic_refresh': 1}, 'example_value': True, } @@ -126,9 +136,8 @@ { 'name': 'DnsPrefetchingEnabled', 'type': 'main', + 'supported_on': ['chrome.*:8-'], 'annotations': { - 'platforms': ['linux', 'mac', 'win'], - 'products': ['chrome'], 'features': {'dynamic_refresh': 1}, 'example_value': True, } @@ -136,9 +145,8 @@ { 'name': 'DisableSpdy', 'type': 'main', + 'supported_on': ['chrome.*:8-'], 'annotations': { - 'platforms': ['linux', 'mac', 'win'], - 'products': ['chrome'], 'features': {'dynamic_refresh': 1}, 'example_value': True, } @@ -146,9 +154,8 @@ { 'name': 'JavascriptEnabled', 'type': 'main', + 'supported_on': ['chrome.*:8-'], 'annotations': { - 'platforms': ['linux', 'mac', 'win'], - 'products': ['chrome'], 'features': {'dynamic_refresh': 0}, 'example_value': True, } @@ -156,9 +163,8 @@ { 'name': 'SavingBrowserHistoryDisabled', 'type': 'main', + 'supported_on': ['chrome.*:8-'], 'annotations': { - 'platforms': ['linux', 'mac', 'win'], - 'products': ['chrome'], 'features': {'dynamic_refresh': 1}, 'example_value': True, } @@ -166,9 +172,8 @@ { 'name': 'PrintingEnabled', 'type': 'main', + 'supported_on': ['chrome.*:8-'], 'annotations': { - 'platforms': ['linux', 'mac', 'win'], - 'products': ['chrome'], 'features': {'dynamic_refresh': 1}, 'example_value': True, } @@ -176,9 +181,8 @@ { 'name': 'SafeBrowsingEnabled', 'type': 'main', + 'supported_on': ['chrome.*:8-'], 'annotations': { - 'platforms': ['linux', 'mac', 'win'], - 'products': ['chrome'], 'features': {'dynamic_refresh': 0}, 'example_value': True, } @@ -186,9 +190,8 @@ { 'name': 'MetricsReportingEnabled', 'type': 'main', + 'supported_on': ['chrome.*:8-'], 'annotations': { - 'platforms': ['linux', 'mac', 'win'], - 'products': ['chrome'], 'features': {'dynamic_refresh': 0}, 'example_value': True, 'problem_href': @@ -202,9 +205,8 @@ 'policies': [{ 'name': 'PasswordManagerEnabled', 'type': 'main', + 'supported_on': ['chrome.*:8-'], 'annotations': { - 'platforms': ['linux', 'mac', 'win'], - 'products': ['chrome'], 'features': {'dynamic_refresh': 1}, 'example_value': True, } @@ -212,9 +214,8 @@ { 'name': 'PasswordManagerAllowShowPasswords', 'type': 'main', + 'supported_on': ['chrome.*:8-'], 'annotations': { - 'platforms': ['linux', 'mac', 'win'], - 'products': ['chrome'], 'features': {'dynamic_refresh': 1}, 'example_value': False, } @@ -223,9 +224,8 @@ { 'name': 'AutoFillEnabled', 'type': 'main', + 'supported_on': ['chrome.*:8-'], 'annotations': { - 'platforms': ['linux', 'mac', 'win'], - 'products': ['chrome'], 'features': {'dynamic_refresh': 1}, 'example_value': False, } @@ -233,9 +233,8 @@ { 'name': 'DisabledPlugins', 'type': 'list', + 'supported_on': ['chrome.*:8-'], 'annotations': { - 'platforms': ['linux', 'mac', 'win'], - 'products': ['chrome'], 'features': {'dynamic_refresh': 1}, 'example_value': ['Java', 'Shockwave Flash', 'Chrome PDF Viewer'], } @@ -243,9 +242,8 @@ { 'name': 'SyncDisabled', 'type': 'main', + 'supported_on': ['chrome.*:8-'], 'annotations': { - 'platforms': ['linux', 'mac', 'win'], - 'products': ['chrome'], 'features': {'dynamic_refresh': 1}, 'example_value': True, } @@ -263,9 +261,8 @@ {'name': 'ProxyServerManual', 'value': '2'}, {'name': 'ProxyServerUseSystem', 'value': '3'}, ], + 'supported_on': ['chrome.*:8-'], 'annotations': { - 'platforms': ['linux', 'mac', 'win'], - 'products': ['chrome'], 'features': {'dynamic_refresh': 0}, 'example_value': 2, } @@ -273,9 +270,8 @@ { 'name': 'ProxyServer', 'type': 'string', + 'supported_on': ['chrome.*:8-'], 'annotations': { - 'platforms': ['linux', 'mac', 'win'], - 'products': ['chrome'], 'features': {'dynamic_refresh': 0}, 'example_value': '123.123.123.123:8080', } @@ -283,9 +279,8 @@ { 'name': 'ProxyPacUrl', 'type': 'string', + 'supported_on': ['chrome.*:8-'], 'annotations': { - 'platforms': ['linux', 'mac', 'win'], - 'products': ['chrome'], 'features': {'dynamic_refresh': 0}, 'example_value': 'http://internal.site/example.pac' } @@ -293,9 +288,8 @@ { 'name': 'ProxyBypassList', 'type': 'string', + 'supported_on': ['chrome.*:8-'], 'annotations': { - 'platforms': ['linux', 'mac', 'win'], - 'products': ['chrome'], 'features': {'dynamic_refresh': 0}, 'example_value': 'http://www.example1.com,' @@ -311,9 +305,8 @@ { 'name': 'AuthSchemes', 'type': 'string', + 'supported_on': ['chrome.*:9-'], 'annotations': { - 'platforms': ['linux', 'mac', 'win'], - 'products': ['chrome'], 'features': {'dynamic_refresh': 0}, 'example_value': 'basic,digest,ntlm,negotiate', } @@ -321,9 +314,8 @@ { 'name': 'DisableAuthNegotiateCnameLookup', 'type': 'main', + 'supported_on': ['chrome.*:9-'], 'annotations': { - 'platforms': ['linux', 'mac', 'win'], - 'products': ['chrome'], 'features': {'dynamic_refresh': 0}, 'example_value': False, } @@ -331,9 +323,8 @@ { 'name': 'EnableAuthNegotiatePort', 'type': 'main', + 'supported_on': ['chrome.*:9-'], 'annotations': { - 'platforms': ['linux', 'mac', 'win'], - 'products': ['chrome'], 'features': {'dynamic_refresh': 0}, 'example_value': False, } @@ -341,9 +332,8 @@ { 'name': 'AuthServerWhitelist', 'type': 'string', + 'supported_on': ['chrome.*:9-'], 'annotations': { - 'platforms': ['linux', 'mac', 'win'], - 'products': ['chrome'], 'features': {'dynamic_refresh': 0}, 'example_value': '*example.com,foobar.com,*baz', } @@ -351,9 +341,8 @@ { 'name': 'AuthNegotiateDelegateWhitelist', 'type': 'string', + 'supported_on': ['chrome.*:9-'], 'annotations': { - 'platforms': ['linux', 'mac', 'win'], - 'products': ['chrome'], 'features': {'dynamic_refresh': 0}, 'example_value': 'foobar.example.com', } @@ -361,9 +350,8 @@ { 'name': 'GSSAPILibraryName', 'type': 'string', + 'supported_on': ['chrome.linux:9-', 'chrome.mac:9-'], 'annotations': { - 'platforms': ['linux', 'mac'], - 'products': ['chrome'], 'features': {'dynamic_refresh': 0}, 'example_value': 'libgssapi_krb5.so.2', } @@ -376,9 +364,8 @@ 'policies': [{ 'name': 'ExtensionInstallBlacklist', 'type': 'list', + 'supported_on': ['chrome.*:8-'], 'annotations': { - 'platforms': ['linux', 'mac', 'win'], - 'products': ['chrome'], 'features': {'dynamic_refresh': 1}, 'example_value': ['extension_id1', 'extension_id2'] } @@ -386,33 +373,30 @@ { 'name': 'ExtensionInstallWhitelist', 'type': 'list', + 'supported_on': ['chrome.*:8-'], 'annotations': { - 'platforms': ['linux', 'mac', 'win'], - 'products': ['chrome'], 'features': {'dynamic_refresh': 1}, 'example_value': ['extension_id1', 'extension_id2'] } }, { - 'name': 'ExtensionInstallForcelist', - 'type': 'list', - 'annotations': { - 'platforms': ['linux', 'mac', 'win'], - 'products': ['chrome'], + 'name': 'ExtensionInstallForcelist', + 'type': 'list', + 'supported_on': ['chrome.*:9-'], + 'annotations': { 'features': {'dynamic_refresh': 0}, 'example_value': [ 'lcncmkcnkcdbbanbjakcencbaoegdjlp;' 'https://clients2.google.com/service/update2/crx' - ] - } + ] + } }] }, { 'name': 'ShowHomeButton', 'type': 'main', + 'supported_on': ['chrome.*:8-'], 'annotations': { - 'platforms': ['linux', 'mac', 'win'], - 'products': ['chrome'], 'features': {'dynamic_refresh': 1}, 'example_value': True } @@ -420,11 +404,10 @@ { 'name': 'DeveloperToolsDisabled', 'type': 'main', + 'supported_on': ['chrome.*:9-'], 'annotations': { - 'platforms': ['linux', 'mac', 'win'], - 'products': ['chrome'], - 'features': {'dynamic_refresh': 1}, - 'example_value': False, + 'features': {'dynamic_refresh': 1}, + 'example_value': False, } }, { @@ -438,18 +421,16 @@ {'name': 'RestoreOnStartupIsLastSession', 'value': '1'}, {'name': 'RestoreOnStartupIsURLs', 'value': '4'}, ], + 'supported_on': ['chrome.*:8-'], 'annotations': { - 'platforms': ['linux', 'mac', 'win'], - 'products': ['chrome'], 'features': {'dynamic_refresh': 1}, 'example_value': 4, } },{ 'name': 'RestoreOnStartupURLs', 'type': 'list', + 'supported_on': ['chrome.*:8-'], 'annotations': { - 'platforms': ['linux', 'mac', 'win'], - 'products': ['chrome'], 'features': {'dynamic_refresh': 1}, 'example_value': ['http://example.com', 'http://chromium.org'], } @@ -462,9 +443,8 @@ { 'name': 'DefaultSearchProviderEnabled', 'type': 'main', + 'supported_on': ['chrome.*:8-'], 'annotations': { - 'platforms': ['linux', 'mac', 'win'], - 'products': ['chrome'], 'features': {'dynamic_refresh': 1}, 'example_value': True, } @@ -472,9 +452,8 @@ { 'name': 'DefaultSearchProviderName', 'type': 'string', + 'supported_on': ['chrome.*:8-'], 'annotations': { - 'platforms': ['linux', 'mac', 'win'], - 'products': ['chrome'], 'features': {'dynamic_refresh': 1}, 'example_value': 'My Intranet Search', } @@ -482,9 +461,8 @@ { 'name': 'DefaultSearchProviderKeyword', 'type': 'string', + 'supported_on': ['chrome.*:8-'], 'annotations': { - 'platforms': ['linux', 'mac', 'win'], - 'products': ['chrome'], 'features': {'dynamic_refresh': 1}, 'example_value': 'mis', } @@ -492,9 +470,8 @@ { 'name': 'DefaultSearchProviderSearchURL', 'type': 'string', + 'supported_on': ['chrome.*:8-'], 'annotations': { - 'platforms': ['linux', 'mac', 'win'], - 'products': ['chrome'], 'features': {'dynamic_refresh': 1}, 'example_value': 'http://search.my.company/search?q={searchTerms}', } @@ -502,9 +479,8 @@ { 'name': 'DefaultSearchProviderSuggestURL', 'type': 'string', + 'supported_on': ['chrome.*:8-'], 'annotations': { - 'platforms': ['linux', 'mac', 'win'], - 'products': ['chrome'], 'features': {'dynamic_refresh': 1}, 'example_value': 'http://search.my.company/suggest?q={searchTerms}', } @@ -512,9 +488,8 @@ { 'name': 'DefaultSearchProviderIconURL', 'type': 'string', + 'supported_on': ['chrome.*:8-'], 'annotations': { - 'platforms': ['linux', 'mac', 'win'], - 'products': ['chrome'], 'features': {'dynamic_refresh': 1}, 'example_value': 'http://search.my.company/favicon.ico', } @@ -522,9 +497,8 @@ { 'name': 'DefaultSearchProviderEncodings', 'type': 'list', + 'supported_on': ['chrome.*:8-'], 'annotations': { - 'platforms': ['linux', 'mac', 'win'], - 'products': ['chrome'], 'features': {'dynamic_refresh': 1}, 'example_value': ['UTF-8', 'UTF-16', 'GB2312', 'ISO-8859-1'] } @@ -541,27 +515,24 @@ {'name': 'RenderInHost', 'value': '0'}, {'name': 'RenderInChromeFrame', 'value': '1'}, ], + 'supported_on': ['chrome_frame:8-'], 'annotations': { - 'platforms': ['win'], - 'products': ['chrome_frame'], 'features': {'dynamic_refresh': 0}, 'example_value': 1, } }, { 'name': 'RenderInChromeFrameList', 'type': 'list', + 'supported_on': ['chrome_frame:8-'], 'annotations': { - 'platforms': ['win'], - 'products': ['chrome_frame'], 'features': {'dynamic_refresh': 0}, 'example_value': ['http://www.example.com', 'http://www.example.edu'], } }, { 'name': 'RenderInHostList', 'type': 'list', + 'supported_on': ['chrome_frame:8-'], 'annotations': { - 'platforms': ['win'], - 'products': ['chrome_frame'], 'features': {'dynamic_refresh': 0}, 'example_value': ['http://www.example.com', 'http://www.example.edu'], } @@ -573,9 +544,8 @@ 'policies': [{ 'name': 'ChromeFrameContentTypes', 'type': 'list', + 'supported_on': ['chrome_frame:8-'], 'annotations': { - 'platforms': ['win'], - 'products': ['chrome_frame'], 'features': {'dynamic_refresh': 0}, 'example_value': ['text/xml', 'application/xml'], } @@ -584,9 +554,8 @@ { 'name': 'ChromeOsLockOnIdleSuspend', 'type': 'main', + 'supported_on': ['chrome_os:0.9.79.0-'], 'annotations': { - 'platforms': ['chrome_os'], - 'products': ['chrome_os'], 'features': {'dynamic_refresh': 1}, 'example_value': True, } diff --git a/tools/grit/grit/format/policy_templates/policy_template_generator.py b/tools/grit/grit/format/policy_templates/policy_template_generator.py index a678ef1..3b2447e 100644 --- a/tools/grit/grit/format/policy_templates/policy_template_generator.py +++ b/tools/grit/grit/format/policy_templates/policy_template_generator.py @@ -3,6 +3,9 @@ # found in the LICENSE file. +import copy + + def GetPolicySortingKey(policy): '''Extracts a sorting key from a policy. These keys can be used for list.sort() methods to sort policies. @@ -42,10 +45,10 @@ class PolicyTemplateGenerator: content. ''' # List of all the policies: - self._policy_definitions = policy_definitions + self._policy_definitions = copy.deepcopy(policy_definitions) # Localized messages to be inserted to the policy_definitions structure: self._messages = messages - self._AddMessagesToPolicyList(self._policy_definitions) + self._ProcessPolicyList(self._policy_definitions) self._SortPolicies(self._policy_definitions) def _SortPolicies(self, policy_list): @@ -59,6 +62,56 @@ class PolicyTemplateGenerator: ''' policy_list.sort(key=GetPolicySortingKey) + def _ProcessSupportedOn(self, supported_on): + '''Parses and converts the string items of the list of supported platforms + into dictionaries. + + Args: + supported_on: The list of supported platforms. E.g.: + ['chrome.win:8-10', 'chrome_frame:10-'] + + Returns: + supported_on: The list with its items converted to dictionaries. E.g.: + [{ + 'product': 'chrome', + 'platform': 'win', + 'since_version': '8', + 'until_version': '10' + }, { + 'product': 'chrome_frame', + 'platform': 'win', + 'since_version': '10', + 'until_version': '' + }] + ''' + result = [] + for supported_on_item in supported_on: + product_platform_part, version_part = supported_on_item.split(':') + if '.' in product_platform_part: + product, platform = product_platform_part.split('.') + if platform == '*': + # e.g.: 'chrome.*:8-10' + platforms = ['linux', 'mac', 'win'] + else: + # e.g.: 'chrome.win:-10' + platforms = [platform] + else: + # e.g.: 'chrome_frame:7-' + product = product_platform_part + platform = { + 'chrome_os': 'chrome_os', + 'chrome_frame': 'win' + }[product] + platforms = [platform] + since_version, until_version = version_part.split('-') + result.append({ + 'product': product, + 'platforms': platforms, + 'since_version': since_version, + 'until_version': until_version + }) + return result + def _AddMessageToItem(self, item_name, item, message_name, default=None): '''Adds a localized message string to an item of the policy data structure @@ -85,8 +138,9 @@ class PolicyTemplateGenerator: raise Exception('No localized message for %s (missing %s).' % (item_name, long_message_name)) - def _AddMessagesToPolicy(self, policy): + def _ProcessPolicy(self, policy): '''Adds localized message strings to a policy or group. + Also breaks up the content of 'supported_on' attribute into a list. Args: policy: The data structure of the policy or group, that will get message @@ -99,23 +153,26 @@ class PolicyTemplateGenerator: # 'label', that defaults to 'caption'. self._AddMessageToItem( policy['name'], policy, 'label', policy['caption']) + policy['supported_on'] = self._ProcessSupportedOn( + policy['supported_on']) if policy['type'] == 'group': - self._AddMessagesToPolicyList(policy['policies']) + self._ProcessPolicyList(policy['policies']) elif policy['type'] == 'enum': # Iterate through all the items of an enum-type policy, and add captions. for item in policy['items']: self._AddMessageToItem('ENUM_' + item['name'], item, 'caption') - def _AddMessagesToPolicyList(self, policy_list): + def _ProcessPolicyList(self, policy_list): '''Adds localized message strings to each item in a list of policies and - groups. + groups. Also breaks up the content of 'supported_on' attributes into lists + of dictionaries. Args: policy_list: A list of policies and groups. Message strings will be added for each item and to their child items, recursively. ''' for policy in policy_list: - self._AddMessagesToPolicy(policy) + self._ProcessPolicy(policy) def GetTemplateText(self, template_writer): '''Generates the text of the template from the arguments given diff --git a/tools/grit/grit/format/policy_templates/policy_template_generator_unittest.py b/tools/grit/grit/format/policy_templates/policy_template_generator_unittest.py index 7401a6d..5a73cf72 100644 --- a/tools/grit/grit/format/policy_templates/policy_template_generator_unittest.py +++ b/tools/grit/grit/format/policy_templates/policy_template_generator_unittest.py @@ -97,15 +97,15 @@ class PolicyTemplateGeneratorUnittest(unittest.TestCase): policies_mock = [ { 'name': 'Group1', 'type': 'group', - 'policies': [{'name': 'TAG1', 'type': 'mock'}] + 'policies': [{'name': 'TAG1', 'type': 'mock', 'supported_on': []}] }, { 'name': 'Group2', 'type': 'group', - 'policies': [{'name': 'TAG2', 'type': 'mock'}] + 'policies': [{'name': 'TAG2', 'type': 'mock', 'supported_on': []}] }, { 'name': 'Group3', 'type': 'group', - 'policies': [{'name': 'TAG3', 'type': 'mock'}] + 'policies': [{'name': 'TAG3', 'type': 'mock', 'supported_on': []}] }, ] class LocalMockWriter(mock_writer.MockWriter): @@ -150,15 +150,15 @@ class PolicyTemplateGeneratorUnittest(unittest.TestCase): 'name': 'Group1', 'type': 'group', 'policies': [ - {'name': 'Group1Policy1', 'type': 'string'}, - {'name': 'Group1Policy2', 'type': 'string'}, + {'name': 'Group1Policy1', 'type': 'string', 'supported_on': []}, + {'name': 'Group1Policy2', 'type': 'string', 'supported_on': []}, ] }, { 'name': 'Group2', 'type': 'group', 'policies': [ - {'name': 'Group2Policy3', 'type': 'string'}, + {'name': 'Group2Policy3', 'type': 'string', 'supported_on': []}, ] } ] @@ -194,8 +194,8 @@ class PolicyTemplateGeneratorUnittest(unittest.TestCase): 'name': 'Group1', 'type': 'group', 'policies': [ - {'name': 'Policy1', 'type': 'string'}, - {'name': 'Policy2', 'type': 'string'} + {'name': 'Policy1', 'type': 'string', 'supported_on': []}, + {'name': 'Policy2', 'type': 'string', 'supported_on': []} ] } ] @@ -225,6 +225,7 @@ class PolicyTemplateGeneratorUnittest(unittest.TestCase): policy_defs_mock = [{ 'name': 'Policy1', 'type': 'enum', + 'supported_on': [], 'items': [ {'name': 'item1', 'value': '0'}, {'name': 'item2', 'value': '1'}, @@ -248,12 +249,12 @@ class PolicyTemplateGeneratorUnittest(unittest.TestCase): { 'name': 'Group1Policy1', 'type': 'string', - 'annotations': {'platforms': ['aaa', 'bbb', 'ccc']} + 'supported_on': ['chrome.aaa:8-', 'chrome.bbb:8-', 'chrome.ccc:8-'] }, { 'name': 'Group1Policy2', 'type': 'string', - 'annotations': {'platforms': ['ddd']} + 'supported_on': ['chrome.ddd:8-'] }, ] },{ @@ -263,13 +264,13 @@ class PolicyTemplateGeneratorUnittest(unittest.TestCase): { 'name': 'Group2Policy3', 'type': 'string', - 'annotations': {'platforms': ['eee']} + 'supported_on': ['chrome.eee:8-'] }, ] },{ 'name': 'SinglePolicy', 'type': 'int', - 'annotations': {'platforms': ['eee']} + 'supported_on': ['chrome.eee:8-'] }] # This writer accumulates the list of policies it is asked to write. # This list is stored in the result_list member variable and can @@ -308,42 +309,42 @@ class PolicyTemplateGeneratorUnittest(unittest.TestCase): def testSorting(self): # Tests that policies are sorted correctly. policy_defs = [ - {'name': 'zp', 'type': 'string', 'caption': 'a1'}, + {'name': 'zp', 'type': 'string', 'caption': 'a1', 'supported_on': []}, { 'type': 'group', 'caption': 'z_group1_caption', 'name': 'group1', 'policies': [ - {'name': 'z0', 'type': 'string'}, - {'name': 'a0', 'type': 'string'} + {'name': 'z0', 'type': 'string', 'supported_on': []}, + {'name': 'a0', 'type': 'string', 'supported_on': []} ] }, { 'type': 'group', 'caption': 'b_group2_caption', 'name': 'group2', - 'policies': [{'name': 'q', 'type': 'string'}], + 'policies': [{'name': 'q', 'type': 'string', 'supported_on': []}], }, - {'name': 'ap', 'type': 'string', 'caption': 'a2'} + {'name': 'ap', 'type': 'string', 'caption': 'a2', 'supported_on': []} ] sorted_policy_defs = [ { 'type': 'group', 'caption': 'b_group2_caption', 'name': 'group2', - 'policies': [{'name': 'q', 'type': 'string'}], + 'policies': [{'name': 'q', 'type': 'string', 'supported_on': []}], }, { 'type': 'group', 'caption': 'z_group1_caption', 'name': 'group1', 'policies': [ - {'name': 'z0', 'type': 'string'}, - {'name': 'a0', 'type': 'string'} + {'name': 'z0', 'type': 'string', 'supported_on': []}, + {'name': 'a0', 'type': 'string', 'supported_on': []} ] }, - {'name': 'ap', 'type': 'string', 'caption': 'a2'}, - {'name': 'zp', 'type': 'string', 'caption': 'a1'}, + {'name': 'ap', 'type': 'string', 'caption': 'a2', 'supported_on': []}, + {'name': 'zp', 'type': 'string', 'caption': 'a1', 'supported_on': []}, ] ptg = policy_template_generator.PolicyTemplateGenerator([], []) ptg._SortPolicies(policy_defs) @@ -354,8 +355,8 @@ class PolicyTemplateGeneratorUnittest(unittest.TestCase): def testSortingInvoked(self): # Tests that policy-sorting happens before passing policies to the writer. policy_defs = [ - {'name': 'zp', 'type': 'string'}, - {'name': 'ap', 'type': 'string'} + {'name': 'zp', 'type': 'string', 'supported_on': []}, + {'name': 'ap', 'type': 'string', 'supported_on': []} ] class LocalMockWriter(mock_writer.MockWriter): def __init__(self): diff --git a/tools/grit/grit/format/policy_templates/writers/adm_writer_unittest.py b/tools/grit/grit/format/policy_templates/writers/adm_writer_unittest.py index 6c75d2b..b823aae 100644 --- a/tools/grit/grit/format/policy_templates/writers/adm_writer_unittest.py +++ b/tools/grit/grit/format/policy_templates/writers/adm_writer_unittest.py @@ -69,7 +69,7 @@ chromium="Chromium"''' { 'name': 'MainPolicy', 'type': 'main', - 'annotations': {'platforms': ['win']} + 'supported_on': ['chrome.win:8-'] }, ], 'placeholders': [], @@ -115,7 +115,7 @@ MainPolicy_Explain="Description of main."''' { 'name': 'StringPolicy', 'type': 'string', - 'annotations': {'platforms': ['win']} + 'supported_on': ['chrome.win:8-'] }, ], 'placeholders': [], @@ -166,7 +166,7 @@ StringPolicy_Part="Caption of policy." {'name': 'ProxyServerDisabled', 'value': '0'}, {'name': 'ProxyServerAutoDetect', 'value': '1'}, ], - 'annotations': {'platforms': ['win']} + 'supported_on': ['chrome.win:8-'] }, ], 'placeholders': [], @@ -223,7 +223,7 @@ ProxyServerAutoDetect_DropDown="Option2" { 'name': 'ListPolicy', 'type': 'list', - 'annotations': {'platforms': ['win']} + 'supported_on': ['chrome.win:8-'] }, ], 'placeholders': [], @@ -276,7 +276,7 @@ ListPolicy_Part="Value caption of list policy." 'policies': [{ 'name': 'NonWinPolicy', 'type': 'list', - 'annotations': {'platforms': ['linux', 'mac']} + 'supported_on': ['chrome.linux:8-', 'chrome.mac:8-'] }], }, ], @@ -314,11 +314,11 @@ chromium="Chromium" 'policies': [{ 'name': 'Policy1', 'type': 'list', - 'annotations': {'platforms': ['win']} + 'supported_on': ['chrome.win:8-'] },{ 'name': 'Policy2', 'type': 'string', - 'annotations': {'platforms': ['win']} + 'supported_on': ['chrome.win:8-'] }], }, ], diff --git a/tools/grit/grit/format/policy_templates/writers/adml_writer_unittest.py b/tools/grit/grit/format/policy_templates/writers/adml_writer_unittest.py index 04a16f5..dd4d42e 100644 --- a/tools/grit/grit/format/policy_templates/writers/adml_writer_unittest.py +++ b/tools/grit/grit/format/policy_templates/writers/adml_writer_unittest.py @@ -242,14 +242,14 @@ class AdmlWriterTest(xml_writer_base_unittest.XmlWriterBaseTest): def testPlatform(self): # Test that the writer correctly chooses policies of platform Windows. self.assertTrue(self.writer.IsPolicySupported({ - 'annotations': { - 'platforms': ['win', 'zzz', 'aaa'] - } + 'supported_on': [ + {'platforms': ['win', 'zzz']}, {'platforms': ['aaa']} + ] })) self.assertFalse(self.writer.IsPolicySupported({ - 'annotations': { - 'platforms': ['mac', 'linux', 'aaa'] - } + 'supported_on': [ + {'platforms': ['mac', 'linux']}, {'platforms': ['aaa']} + ] })) diff --git a/tools/grit/grit/format/policy_templates/writers/admx_writer_unittest.py b/tools/grit/grit/format/policy_templates/writers/admx_writer_unittest.py index b964a25..c645be0 100644 --- a/tools/grit/grit/format/policy_templates/writers/admx_writer_unittest.py +++ b/tools/grit/grit/format/policy_templates/writers/admx_writer_unittest.py @@ -264,14 +264,14 @@ class AdmxWriterTest(xml_writer_base_unittest.XmlWriterBaseTest): def testPlatform(self): # Test that the writer correctly chooses policies of platform Windows. self.assertTrue(self.writer.IsPolicySupported({ - 'annotations': { - 'platforms': ['win', 'zzz', 'aaa'] - } + 'supported_on': [ + {'platforms': ['win', 'zzz']}, {'platforms': ['aaa']} + ] })) self.assertFalse(self.writer.IsPolicySupported({ - 'annotations': { - 'platforms': ['mac', 'linux', 'aaa'] - } + 'supported_on': [ + {'platforms': ['mac', 'linux']}, {'platforms': ['aaa']} + ] })) diff --git a/tools/grit/grit/format/policy_templates/writers/doc_writer.py b/tools/grit/grit/format/policy_templates/writers/doc_writer.py index 279f374..1f4afe7 100644 --- a/tools/grit/grit/format/policy_templates/writers/doc_writer.py +++ b/tools/grit/grit/format/policy_templates/writers/doc_writer.py @@ -14,7 +14,7 @@ def GetWriter(config, messages): See the constructor of TemplateWriter for description of arguments. ''' - return DocWriter(['mac', 'linux', 'win'], config, messages) + return DocWriter(['*'], config, messages) class DocWriter(xml_formatted_writer.XMLFormattedWriter): @@ -286,6 +286,32 @@ class DocWriter(xml_formatted_writer.XMLFormattedWriter): self._AddStyledElement(dl, 'dt', ['dt'], {}, term) return self._AddStyledElement(dl, 'dd', definition_style, {}, definition) + def _AddSupportedOnList(self, parent, supported_on_list): + '''Creates a HTML list containing the platforms, products and versions + that are specified in the list of supported_on. + + Args: + parent: The DOM node for which the list will be added. + supported_on_list: The list of supported products, as a list of + dictionaries. + ''' + ul = self._AddStyledElement(parent, 'ul', ['ul']) + for supported_on in supported_on_list: + text = [] + product = supported_on['product'] + platforms = supported_on['platforms'] + text.append(self._PRODUCT_MAP[product]) + text.append('(%s)' % + self._MapListToString(self._PLATFORM_MAP, platforms)) + if supported_on['since_version']: + since_version = self._GetLocalizedMessage('since_version') + text.append(since_version.replace('$6', supported_on['since_version'])) + if supported_on['until_version']: + until_version = self._GetLocalizedMessage('until_version') + text.append(until_version.replace('$6', supported_on['until_version'])) + # Add the list element: + self.AddElement(ul, 'li', {}, ' '.join(text)) + def _AddPolicyDetails(self, parent, policy): '''Adds the list of attributes of a policy to the HTML DOM node parent. It will have the form: @@ -315,14 +341,8 @@ class DocWriter(xml_formatted_writer.XMLFormattedWriter): 'mac_linux_pref_name', policy['name'], ['.monospace']) - self._AddPolicyAttribute( - dl, - 'supported_on_platforms', - self._MapListToString(self._PLATFORM_MAP, annotations['platforms'])) - self._AddPolicyAttribute( - dl, - 'supported_in_products', - self._MapListToString(self._PRODUCT_MAP, annotations['products'])) + dd = self._AddPolicyAttribute(dl, 'supported_on') + self._AddSupportedOnList(dd, policy['supported_on']) dd = self._AddPolicyAttribute(dl, 'supported_features') self._AddFeatures(dd, policy) dd = self._AddPolicyAttribute(dl, 'description') @@ -491,6 +511,7 @@ class DocWriter(xml_formatted_writer.XMLFormattedWriter): '.pre': 'white-space: pre;', 'div.note': 'border: 2px solid black; padding: 5px; margin: 5px;', 'div.group_desc': 'margin-top: 20px; margin-bottom: 20px;', + 'ul': 'padding-left: 0px; margin-left: 0px;' } # A simple regexp to search for URLs. It is enough for now. diff --git a/tools/grit/grit/format/policy_templates/writers/doc_writer_unittest.py b/tools/grit/grit/format/policy_templates/writers/doc_writer_unittest.py index 15ccc68..8f1ec8c 100644 --- a/tools/grit/grit/format/policy_templates/writers/doc_writer_unittest.py +++ b/tools/grit/grit/format/policy_templates/writers/doc_writer_unittest.py @@ -283,13 +283,18 @@ MockKey\\PolicyName\\1 = "Bar"</dd><dt>Linux:</dt><dd style="style_.mo 'name': 'TestPolicyName', 'caption': 'TestPolicyCaption', 'desc': 'TestPolicyDesc', - 'annotations': { + 'supported_on': [{ + 'product': 'chrome', 'platforms': ['win'], - 'products': ['chrome'], + 'since_version': '8', + 'until_version': '', + }], + 'annotations': { 'features': {'dynamic_refresh': 0}, 'example_value': False } } + self.writer.messages.msg_dict['since_version'] = '...$6...' self.writer._AddPolicyDetails(self.doc_root, policy) self.assertEquals( self.doc_root.toxml(), @@ -299,8 +304,12 @@ MockKey\\PolicyName\\1 = "Bar"</dd><dt>Linux:</dt><dd style="style_.mo '<dd style="style_.monospace;">MockKey\TestPolicyName</dd>' '<dt style="style_dt;">_test_mac_linux_pref_name</dt>' '<dd style="style_.monospace;">TestPolicyName</dd>' - '<dt style="style_dt;">_test_supported_on_platforms</dt><dd>Windows</dd>' - '<dt style="style_dt;">_test_supported_in_products</dt><dd>Chrome</dd>' + '<dt style="style_dt;">_test_supported_on</dt>' + '<dd>' + '<ul style="style_ul;">' + '<li>Chrome (Windows) ...8...</li>' + '</ul>' + '</dd>' '<dt style="style_dt;">_test_supported_features</dt>' '<dd>Dynamic Policy Refresh: _test_not_supported</dd>' '<dt style="style_dt;">_test_description</dt><dd>TestPolicyDesc</dd>' @@ -363,13 +372,18 @@ MockKey\\PolicyName\\1 = "Bar"</dd><dt>Linux:</dt><dd style="style_.mo 'caption': 'PolicyCaption', 'desc': 'PolicyDesc', 'type': 'string', - 'annotations': { + 'supported_on': [{ + 'product': 'chrome', 'platforms': ['win'], - 'products': ['chrome'], + 'since_version': '7', + 'until_version': '', + }], + 'annotations': { 'features': {'dynamic_refresh': 0}, 'example_value': False } } + self.writer.messages.msg_dict['since_version'] = '..$6..' self.writer._AddPolicySection(self.doc_root, policy) self.assertEquals( self.doc_root.toxml(), @@ -384,10 +398,12 @@ MockKey\\PolicyName\\1 = "Bar"</dd><dt>Linux:</dt><dd style="style_.mo '<dd style="style_.monospace;">MockKey\\PolicyName</dd>' '<dt style="style_dt;">_test_mac_linux_pref_name</dt>' '<dd style="style_.monospace;">PolicyName</dd>' - '<dt style="style_dt;">_test_supported_on_platforms</dt>' - '<dd>Windows</dd>' - '<dt style="style_dt;">_test_supported_in_products</dt>' - '<dd>Chrome</dd>' + '<dt style="style_dt;">_test_supported_on</dt>' + '<dd>' + '<ul style="style_ul;">' + '<li>Chrome (Windows) ..7..</li>' + '</ul>' + '</dd>' '<dt style="style_dt;">_test_supported_features</dt>' '<dd>Dynamic Policy Refresh: _test_not_supported</dd>' '<dt style="style_dt;">_test_description</dt>' diff --git a/tools/grit/grit/format/policy_templates/writers/json_writer_unittest.py b/tools/grit/grit/format/policy_templates/writers/json_writer_unittest.py index 35d84f0..bce4c87 100644 --- a/tools/grit/grit/format/policy_templates/writers/json_writer_unittest.py +++ b/tools/grit/grit/format/policy_templates/writers/json_writer_unittest.py @@ -52,8 +52,8 @@ class JsonWriterUnittest(writer_unittest_common.WriterUnittestCommon): ' {' ' "name": "MainPolicy",' ' "type": "main",' + ' "supported_on": ["chrome.linux:8-"],' ' "annotations": {' - ' "platforms": ["linux"],' ' "example_value": True' ' }' ' },' @@ -79,8 +79,8 @@ class JsonWriterUnittest(writer_unittest_common.WriterUnittestCommon): ' {' ' "name": "StringPolicy",' ' "type": "string",' + ' "supported_on": ["chrome.linux:8-"],' ' "annotations": {' - ' "platforms": ["linux"],' ' "example_value": "hello, world!"' ' }' ' },' @@ -110,8 +110,8 @@ class JsonWriterUnittest(writer_unittest_common.WriterUnittestCommon): ' {"name": "ProxyServerDisabled", "value": "0"},' ' {"name": "ProxyServerAutoDetect", "value": "1"},' ' ],' + ' "supported_on": ["chrome.linux:8-"],' ' "annotations": {' - ' "platforms": ["linux"],' ' "example_value": "1"' ' }' ' },' @@ -141,8 +141,8 @@ class JsonWriterUnittest(writer_unittest_common.WriterUnittestCommon): ' {' ' "name": "ListPolicy",' ' "type": "list",' + ' "supported_on": ["chrome.linux:8-"],' ' "annotations": {' - ' "platforms": ["linux"],' ' "example_value": ["foo", "bar"]' ' }' ' },' @@ -170,8 +170,8 @@ class JsonWriterUnittest(writer_unittest_common.WriterUnittestCommon): ' {' ' "name": "NonLinuxPolicy",' ' "type": "list",' + ' "supported_on": ["chrome.mac:8-"],' ' "annotations": {' - ' "platforms": ["win"],' ' "example_value": ["a"]' ' }' ' },' @@ -197,15 +197,15 @@ class JsonWriterUnittest(writer_unittest_common.WriterUnittestCommon): ' "policies": [{' ' "name": "Policy1",' ' "type": "list",' + ' "supported_on": ["chrome.linux:8-"],' ' "annotations": {' - ' "platforms": ["linux"],' ' "example_value": ["a", "b"]' ' }' ' },{' ' "name": "Policy2",' ' "type": "string",' + ' "supported_on": ["chrome.linux:8-"],' ' "annotations": {' - ' "platforms": ["linux"],' ' "example_value": "c"' ' }' ' }],' diff --git a/tools/grit/grit/format/policy_templates/writers/plist_strings_writer_unittest.py b/tools/grit/grit/format/policy_templates/writers/plist_strings_writer_unittest.py index 6df8f84..1fc19c8 100644 --- a/tools/grit/grit/format/policy_templates/writers/plist_strings_writer_unittest.py +++ b/tools/grit/grit/format/policy_templates/writers/plist_strings_writer_unittest.py @@ -57,7 +57,7 @@ class PListStringsWriterUnittest(writer_unittest_common.WriterUnittestCommon): 'policies': [{ 'name': 'MainPolicy', 'type': 'main', - 'annotations': {'platforms': ['mac']}, + 'supported_on': ['chrome.mac:8-'], }], }, ], @@ -96,7 +96,7 @@ class PListStringsWriterUnittest(writer_unittest_common.WriterUnittestCommon): 'policies': [{ 'name': 'StringPolicy', 'type': 'string', - 'annotations': {'platforms': ['mac']}, + 'supported_on': ['chrome.mac:8-'], }], }, ], @@ -141,7 +141,7 @@ With a newline.</message> {'name': 'ProxyServerDisabled', 'value': '0'}, {'name': 'ProxyServerAutoDetect', 'value': '1'}, ], - 'annotations': {'platforms': ['mac']}, + 'supported_on': ['chrome.mac:8-'], }], }, ], @@ -184,7 +184,7 @@ With a newline.</message> 'policies': [{ 'name': 'NonMacPolicy', 'type': 'string', - 'annotations': {'platforms': ['win', 'linux']}, + 'supported_on': ['chrome_os:8-'], }], }, ], diff --git a/tools/grit/grit/format/policy_templates/writers/plist_writer_unittest.py b/tools/grit/grit/format/policy_templates/writers/plist_writer_unittest.py index bcebcaa..88240cd 100644 --- a/tools/grit/grit/format/policy_templates/writers/plist_writer_unittest.py +++ b/tools/grit/grit/format/policy_templates/writers/plist_writer_unittest.py @@ -88,7 +88,7 @@ class PListWriterUnittest(writer_unittest_common.WriterUnittestCommon): 'policies': [{ 'name': 'MainPolicy', 'type': 'main', - 'annotations': {'platforms': ['mac']}, + 'supported_on': ['chrome.mac:8-'], }], }, ], @@ -137,7 +137,7 @@ class PListWriterUnittest(writer_unittest_common.WriterUnittestCommon): 'policies': [{ 'name': 'StringPolicy', 'type': 'string', - 'annotations': {'platforms': ['mac']}, + 'supported_on': ['chrome.mac:8-'], }], }, ], @@ -190,7 +190,7 @@ class PListWriterUnittest(writer_unittest_common.WriterUnittestCommon): {'name': 'ProxyServerDisabled', 'value': '0'}, {'name': 'ProxyServerAutoDetect', 'value': '1'}, ], - 'annotations': {'platforms': ['mac']}, + 'supported_on': ['chrome.mac:8-'], }], }, ], @@ -247,7 +247,7 @@ class PListWriterUnittest(writer_unittest_common.WriterUnittestCommon): 'policies': [{ 'name': 'NonMacPolicy', 'type': 'string', - 'annotations': {'platforms': ['win', 'linux']}, + 'supported_on': ['chrome.linux:8-', 'chrome.win:7-'], }], }, ], diff --git a/tools/grit/grit/format/policy_templates/writers/template_writer.py b/tools/grit/grit/format/policy_templates/writers/template_writer.py index aa4f233..8b742d5 100644 --- a/tools/grit/grit/format/policy_templates/writers/template_writer.py +++ b/tools/grit/grit/format/policy_templates/writers/template_writer.py @@ -3,6 +3,9 @@ # found in the LICENSE file. +import itertools + + class TemplateWriter(object): '''Abstract base class for writing policy templates in various formats. The methods of this class will be called by PolicyTemplateGenerator. @@ -32,6 +35,9 @@ class TemplateWriter(object): def IsPolicySupported(self, policy): '''Checks if the given policy is supported by the writer. + In other words, the set of platforms supported by the writer + has a common subset with the set of platforms that support + the policy. Args: policy: The dictionary of the policy. @@ -39,9 +45,13 @@ class TemplateWriter(object): Returns: True if the writer chooses to include 'policy' in its output. ''' - for platform in self.platforms: - if platform in policy['annotations']['platforms']: - return True + if '*' in self.platforms: + # Currently chrome_os is only catched here. + return True + for supported_on in policy['supported_on']: + for supported_on_platform in supported_on['platforms']: + if supported_on_platform in self.platforms: + return True return False def _GetPoliciesForWriter(self, group): |