diff --git a/BUILD.gn b/BUILD.gn index d7aaed989335..9731a442e281 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -218,7 +218,10 @@ group("create_dist") { } if (is_win) { - deps += [ "build/win:create_signed_installer" ] + deps += [ + "//brave/build/win:create_signed_installer", + "//brave/components/policy:pack_policy_templates", + ] if (build_omaha) { deps += [ "//brave/vendor/omaha" ] diff --git a/chromium_src/components/policy/tools/template_writers/writer_configuration.py b/chromium_src/components/policy/tools/template_writers/writer_configuration.py new file mode 100644 index 000000000000..5951be07f4a7 --- /dev/null +++ b/chromium_src/components/policy/tools/template_writers/writer_configuration.py @@ -0,0 +1,52 @@ +# Copyright (c) 2022 The Brave Authors. All rights reserved. +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this file, +# You can obtain one at https://mozilla.org/MPL/2.0/. + +import override_utils + +@override_utils.override_function(globals()) +def GetConfigurationForBuild(original_function, defines): + base = original_function(defines) + return _merge_dicts(_BRAVE_VALUES, base) + +_BRAVE_VALUES = { + 'build': 'brave', + 'app_name': 'Brave', + 'doc_url': + 'https://support.brave.com/hc/en-us/articles/360039248271-Group-Policy', + 'frame_name': 'Brave Frame', + 'webview_name': 'Brave WebView', + 'win_config': { + 'win': { + 'reg_mandatory_key_name': 'Software\\Policies\\BraveSoftware\\Brave', + 'reg_recommended_key_name': + 'Software\\Policies\\BraveSoftware\\Brave\\Recommended', + 'mandatory_category_path': ['Brave:Cat_Brave', 'brave'], + 'recommended_category_path': ['Brave:Cat_Brave', 'brave_recommended'], + 'category_path_strings': { + 'brave': 'Brave', + 'brave_recommended': + 'Brave - {doc_recommended}' + }, + 'namespace': 'BraveSoftware.Policies.Brave', + }, + }, + # The string 'Brave' is defined in brave.adml for ADMX, but ADM doesn't + # support external references, so we define this map here. + 'adm_category_path_strings': { + 'Brave:Cat_Brave': 'Brave' + }, + 'admx_prefix': 'brave', + 'admx_using_namespaces': { + 'Brave': 'BraveSoftware.Policies' # prefix: namespace + }, + 'linux_policy_path': '/etc/brave/policies/', + 'bundle_id': 'com.brave.ios.core', +} + +def _merge_dicts(src, dst): + result = dict(dst) + for k, v in src.items(): + result[k] = _merge_dicts(v, dst.get(k, {})) if isinstance(v, dict) else v + return result diff --git a/chromium_src/tools/grit/grit/gather/policy_json.py b/chromium_src/tools/grit/grit/gather/policy_json.py new file mode 100644 index 000000000000..88a176d5dc36 --- /dev/null +++ b/chromium_src/tools/grit/grit/gather/policy_json.py @@ -0,0 +1,15 @@ +# Copyright (c) 2022 The Brave Authors. All rights reserved. +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this file, +# You can obtain one at https://mozilla.org/MPL/2.0/. + +import override_utils + +@override_utils.override_method(PolicyJson) +def SetDefines(self, _, defines): + self._config = { + 'build': 'brave', + 'app_name': 'Brave', + 'frame_name': 'Brave Frame', + 'os_name': 'Google Chrome OS' + } diff --git a/components/policy/BUILD.gn b/components/policy/BUILD.gn new file mode 100644 index 000000000000..96863041c2d0 --- /dev/null +++ b/components/policy/BUILD.gn @@ -0,0 +1,17 @@ +if (is_win) { + action("pack_policy_templates") { + chrome_pack_policy_templates = "//components/policy:pack_policy_templates" + deps = [ chrome_pack_policy_templates ] + script = "pack_policy_templates.py" + chrome_policy_templates_zip = + get_label_info(chrome_pack_policy_templates, "root_out_dir") + + "/policy_templates.zip" + inputs = [ chrome_policy_templates_zip ] + output_zip_file = "$root_out_dir/brave_policy_templates.zip" + outputs = [ output_zip_file ] + args = [ + rebase_path(chrome_policy_templates_zip, root_build_dir), + rebase_path(output_zip_file, root_build_dir), + ] + } +} diff --git a/components/policy/pack_policy_templates.py b/components/policy/pack_policy_templates.py new file mode 100644 index 000000000000..af4564844ecf --- /dev/null +++ b/components/policy/pack_policy_templates.py @@ -0,0 +1,52 @@ +#!/usr/bin/env python3 +# Copyright (c) 2022 The Brave Authors. All rights reserved. +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this file, +# You can obtain one at https://mozilla.org/MPL/2.0/. + +""" +Create a Zip file of Windows Group Policy templates similar to Chrome's. +""" + +import argparse +import os + +from os.path import join, exists, relpath +from tempfile import TemporaryDirectory +from zipfile import ZipFile + +def main(): + chrome_policy_zip, dest_zip = _get_args() + _pack_policy_templates(chrome_policy_zip, dest_zip) + +def _get_args(): + parser = argparse.ArgumentParser() + parser.add_argument('chrome_policy_zip', + help="Path to Chrome's policy_templates.zip") + parser.add_argument('dest_zip', + help="Path to the Zip file to be created") + args = parser.parse_args() + return args.chrome_policy_zip, args.dest_zip + +def _pack_policy_templates(chrome_policy_zip, dest_zip): + with TemporaryDirectory() as tmp_dir: + with ZipFile(chrome_policy_zip) as src_zip: + src_zip.extract('VERSION', tmp_dir) + namelist = src_zip.namelist() + for dir_ in ('windows/adm/', 'windows/admx/', 'windows/examples/'): + src_zip.extractall(tmp_dir, (n for n in namelist if n.startswith(dir_))) + + # Some sanity checks: + assert exists(join(tmp_dir, 'windows/adm/en-US/chrome.adm')) + assert exists(join(tmp_dir, 'windows/admx/chrome.admx')) + assert exists(join(tmp_dir, 'windows/admx/en-US/chrome.adml')) + + with ZipFile(dest_zip, 'w') as dest_zipfile: + for dirpath, _, filenames in os.walk(tmp_dir): + for filename in filenames: + filepath = join(dirpath, filename) + arcname = relpath(filepath, tmp_dir).replace('chrome', 'brave') + dest_zipfile.write(filepath, arcname=arcname) + +if __name__ == '__main__': + main() diff --git a/patches/components-policy-tools-template_writers-writer_configuration.py.patch b/patches/components-policy-tools-template_writers-writer_configuration.py.patch new file mode 100644 index 000000000000..916731bff8ce --- /dev/null +++ b/patches/components-policy-tools-template_writers-writer_configuration.py.patch @@ -0,0 +1,9 @@ +diff --git a/components/policy/tools/template_writers/writer_configuration.py b/components/policy/tools/template_writers/writer_configuration.py +index 259e467fee3e9280c512db87ab8f48ed09c20ed3..1e6b41f7853e1a5062c6a9e9c527da9c06e6a9d6 100755 +--- a/components/policy/tools/template_writers/writer_configuration.py ++++ b/components/policy/tools/template_writers/writer_configuration.py +@@ -131,3 +131,4 @@ def GetConfigurationForBuild(defines): + config['mac_bundle_id'] = defines['mac_bundle_id'] + config['android_webview_restriction_prefix'] = 'com.android.browser:' + return config ++from import_inline import inline_file_from_src; inline_file_from_src("brave/chromium_src/components/policy/tools/template_writers/writer_configuration.py", globals(), locals()) diff --git a/patches/tools-grit-grit-gather-policy_json.py.patch b/patches/tools-grit-grit-gather-policy_json.py.patch new file mode 100644 index 000000000000..d9a55b2220fa --- /dev/null +++ b/patches/tools-grit-grit-gather-policy_json.py.patch @@ -0,0 +1,9 @@ +diff --git a/tools/grit/grit/gather/policy_json.py b/tools/grit/grit/gather/policy_json.py +index dc50b9f5e68e2616810e9f451c2dbdaf94a0fe8e..e0a6c341e8b8e618ba6809e49f672078a4395f39 100644 +--- a/tools/grit/grit/gather/policy_json.py ++++ b/tools/grit/grit/gather/policy_json.py +@@ -330,3 +330,4 @@ class PolicyJson(skeleton_gatherer.SkeletonGatherer): + } + else: + raise Exception('Unknown build') ++from import_inline import inline_file_from_src; inline_file_from_src("brave/chromium_src/tools/grit/grit/gather/policy_json.py", globals(), locals())