diff --git a/BUILD.gn b/BUILD.gn index 340958c0626..e60df090bb6 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -3,6 +3,8 @@ # 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( + "//brave/browser/brave_vpn/win/brave_vpn_wireguard_service/allowlist.gni") import("//brave/build/config.gni") import("//brave/components/brave_vpn/common/buildflags/buildflags.gni") import("//build/config/locales.gni") @@ -663,3 +665,26 @@ if (is_redirect_cc_build) { deps = [ "//brave/tools/redirect_cc" ] } } +if (is_win && enable_resource_allowlist_generation) { + # Merge chrome_resource_allowlist and wireguard resources allowlist to keep + # wireguard resources in pak files. + action("merge_allowlists") { + deps = [ + "//brave/browser/brave_vpn/win/brave_vpn_wireguard_service:wireguard_resource_allowlist", + "//chrome:resource_allowlist", + ] + + script = "//brave//resources/brave_allowlist.py" + source_allowlist = "$root_gen_dir/chrome/chrome_resource_allowlist.txt" + args = [ + "--repack_allowlist", + rebase_path(source_allowlist, root_build_dir), + "--brave_allowlist", + rebase_path(wireguard_resource_allowlist_file, root_build_dir), + "--output", + rebase_path(brave_allowlist_file, root_build_dir), + ] + + outputs = [ brave_allowlist_file ] + } +} diff --git a/browser/brave_vpn/win/brave_vpn_wireguard_service/BUILD.gn b/browser/brave_vpn/win/brave_vpn_wireguard_service/BUILD.gn index b8e04cb8459..b57fe68cf7f 100644 --- a/browser/brave_vpn/win/brave_vpn_wireguard_service/BUILD.gn +++ b/browser/brave_vpn/win/brave_vpn_wireguard_service/BUILD.gn @@ -3,9 +3,13 @@ # 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( + "//brave/browser/brave_vpn/win/brave_vpn_wireguard_service/allowlist.gni") import("//brave/build/config.gni") +import("//build/toolchain/gcc_toolchain.gni") import("//build/util/process_version.gni") import("//chrome/process_version_rc_template.gni") +import("//tools/resources/generate_resource_allowlist.gni") assert(is_win) @@ -17,7 +21,21 @@ copy("brave_vpn_wireguard_binaries") { outputs = [ "$root_out_dir/{{source_file_part}}" ] } +group("wireguard_service") { + deps = [ ":brave_vpn_wireguard_service" ] + if (enable_resource_allowlist_generation) { + deps += [ ":wireguard_resource_allowlist" ] + } +} + +generate_resource_allowlist("wireguard_resource_allowlist") { + deps = [ ":brave_vpn_wireguard_service" ] + inputs = [ "$root_out_dir/brave_vpn_wireguard_service.exe.pdb" ] + output = wireguard_resource_allowlist_file +} + executable("brave_vpn_wireguard_service") { + visibility = [ ":*" ] sources = [ "brave_vpn_wireguard_service.rc", "brave_wireguard_service_crash_reporter_client.cc", diff --git a/browser/brave_vpn/win/brave_vpn_wireguard_service/allowlist.gni b/browser/brave_vpn/win/brave_vpn_wireguard_service/allowlist.gni new file mode 100644 index 00000000000..6ba2e7b4792 --- /dev/null +++ b/browser/brave_vpn/win/brave_vpn_wireguard_service/allowlist.gni @@ -0,0 +1,9 @@ +# Copyright (c) 2023 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/. + +# Brave VPN Wireguard service allowlist file contains resource ids from +# brave_vpn_wireguard_service.exe. +wireguard_resource_allowlist_file = + "$root_gen_dir/wireguard_resources_allowlist.txt" diff --git a/browser/brave_vpn/win/brave_vpn_wireguard_service/status_tray/BUILD.gn b/browser/brave_vpn/win/brave_vpn_wireguard_service/status_tray/BUILD.gn index 1d059854cdf..4358235da81 100644 --- a/browser/brave_vpn/win/brave_vpn_wireguard_service/status_tray/BUILD.gn +++ b/browser/brave_vpn/win/brave_vpn_wireguard_service/status_tray/BUILD.gn @@ -3,10 +3,11 @@ # 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("//build/toolchain/gcc_toolchain.gni") + source_set("status_tray") { sources = [ "brave_vpn_tray_command_ids.h", - "brave_vpn_tray_strings_en.h", "status_tray_runner.cc", "status_tray_runner.h", ] @@ -19,12 +20,13 @@ source_set("status_tray") { "//brave/components/brave_vpn/common/win", "//brave/components/brave_vpn/common/wireguard/win", "//brave/components/resources:strings_grit", - "//chrome:packed_resources", "//ui/base", "//ui/native_theme", "//ui/native_theme:native_theme_browser", ] - + if (!enable_resource_allowlist_generation) { + deps += [ "//chrome:packed_resources" ] + } libs = [ "shell32.lib" ] } diff --git a/browser/brave_vpn/win/brave_vpn_wireguard_service/status_tray/brave_vpn_tray_strings_en.h b/browser/brave_vpn/win/brave_vpn_wireguard_service/status_tray/brave_vpn_tray_strings_en.h deleted file mode 100644 index e1b4c448da9..00000000000 --- a/browser/brave_vpn/win/brave_vpn_wireguard_service/status_tray/brave_vpn_tray_strings_en.h +++ /dev/null @@ -1,25 +0,0 @@ -/* Copyright (c) 2023 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/. */ - -#ifndef BRAVE_BROWSER_BRAVE_VPN_WIN_BRAVE_VPN_WIREGUARD_SERVICE_STATUS_TRAY_BRAVE_VPN_TRAY_STRINGS_EN_H_ -#define BRAVE_BROWSER_BRAVE_VPN_WIN_BRAVE_VPN_WIREGUARD_SERVICE_STATUS_TRAY_BRAVE_VPN_TRAY_STRINGS_EN_H_ - -namespace brave { -// TODO(spylogsster): Replace by localized solution -// https://github.com/brave/brave-browser/issues/30959 -constexpr char16_t kBraveVpnIconTooltip[] = u"Brave VPN: Disconnected"; -constexpr char16_t kBraveVpnIconTooltipConnected[] = u"Brave VPN: Connected"; -constexpr char16_t kBraveVpnIconTooltipError[] = u"Brave VPN: Error"; -constexpr char16_t kBraveVpnStatusItemName[] = u"Status: "; -constexpr char16_t kBraveVpnConnectItemName[] = u"Connect"; -constexpr char16_t kBraveVpnDisconnectItemName[] = u"Disconnect"; -constexpr char16_t kBraveVpnManageAccountItemName[] = u"Manage Account"; -constexpr char16_t kBraveVpnAboutItemName[] = u"About Brave VPN"; -constexpr char16_t kBraveVpnRemoveItemName[] = u"Remove icon"; -constexpr char16_t kBraveVpnActiveText[] = u"Active"; -constexpr char16_t kBraveVpnInactiveText[] = u"Inactive"; -} // namespace brave - -#endif // BRAVE_BROWSER_BRAVE_VPN_WIN_BRAVE_VPN_WIREGUARD_SERVICE_STATUS_TRAY_BRAVE_VPN_TRAY_STRINGS_EN_H_ diff --git a/browser/brave_vpn/win/brave_vpn_wireguard_service/status_tray/status_tray_runner.cc b/browser/brave_vpn/win/brave_vpn_wireguard_service/status_tray/status_tray_runner.cc index 0e67186a1c4..d5093e30e38 100644 --- a/browser/brave_vpn/win/brave_vpn_wireguard_service/status_tray/status_tray_runner.cc +++ b/browser/brave_vpn/win/brave_vpn_wireguard_service/status_tray/status_tray_runner.cc @@ -22,7 +22,6 @@ #include "base/task/single_thread_task_executor.h" #include "base/task/thread_pool/thread_pool_instance.h" #include "brave/browser/brave_vpn/win/brave_vpn_wireguard_service/status_tray/brave_vpn_tray_command_ids.h" -#include "brave/browser/brave_vpn/win/brave_vpn_wireguard_service/status_tray/brave_vpn_tray_strings_en.h" #include "brave/browser/brave_vpn/win/brave_vpn_wireguard_service/status_tray/resources/resource.h" #include "brave/browser/brave_vpn/win/brave_vpn_wireguard_service/status_tray/status_icon/icon_utils.h" #include "brave/browser/brave_vpn/win/brave_vpn_wireguard_service/status_tray/status_icon/status_icon.h" @@ -59,17 +58,19 @@ void OpenURLInBrowser(const char* url) { } std::u16string GetVpnStatusLabel(bool active) { - std::u16string label = brave::kBraveVpnStatusItemName; - label += (active ? brave::kBraveVpnActiveText : brave::kBraveVpnInactiveText); - return label; + return l10n_util::GetStringUTF16( + active ? IDS_BRAVE_VPN_WIREGUARD_TRAY_STATUS_ITEM_ACTIVE + : IDS_BRAVE_VPN_WIREGUARD_TRAY_STATUS_ITEM_INACTIVE); } std::u16string GetStatusIconTooltip(bool connected, bool error) { if (error) { - return brave::kBraveVpnIconTooltipError; + return l10n_util::GetStringUTF16( + IDS_BRAVE_VPN_WIREGUARD_TRAY_ICON_TOOLTIP_ERROR); } - return connected ? brave::kBraveVpnIconTooltipConnected - : brave::kBraveVpnIconTooltip; + return l10n_util::GetStringUTF16( + connected ? IDS_BRAVE_VPN_WIREGUARD_TRAY_ICON_TOOLTIP_CONNECTED + : IDS_BRAVE_VPN_WIREGUARD_TRAY_ICON_TOOLTIP_DISCONNECTED); } gfx::ImageSkia GetStatusTrayIcon(bool connected, bool error) { @@ -151,17 +152,24 @@ void StatusTrayRunner::OnMenuWillShow(ui::SimpleMenuModel* source) { source->SetEnabledAt(0, false); if (connected) { source->AddItem(IDC_BRAVE_VPN_TRAY_DISCONNECT_VPN_ITEM, - brave::kBraveVpnDisconnectItemName); + l10n_util::GetStringUTF16( + IDS_BRAVE_VPN_WIREGUARD_TRAY_DISCONNECT_ITEM)); } else { - source->AddItem(IDC_BRAVE_VPN_TRAY_CONNECT_VPN_ITEM, - brave::kBraveVpnConnectItemName); + source->AddItem( + IDC_BRAVE_VPN_TRAY_CONNECT_VPN_ITEM, + l10n_util::GetStringUTF16(IDS_BRAVE_VPN_WIREGUARD_TRAY_CONNECT_ITEM)); } source->AddSeparator(ui::NORMAL_SEPARATOR); source->AddItem(IDC_BRAVE_VPN_TRAY_MANAGE_ACCOUNT_ITEM, - brave::kBraveVpnManageAccountItemName); - source->AddItem(IDC_BRAVE_VPN_TRAY_ABOUT_ITEM, brave::kBraveVpnAboutItemName); + l10n_util::GetStringUTF16( + IDS_BRAVE_VPN_WIREGUARD_TRAY_MANAGE_ACCOUNT_ITEM)); + source->AddItem( + IDC_BRAVE_VPN_TRAY_ABOUT_ITEM, + l10n_util::GetStringUTF16(IDS_BRAVE_VPN_WIREGUARD_TRAY_ABOUT_ITEM)); source->AddSeparator(ui::NORMAL_SEPARATOR); - source->AddItem(IDC_BRAVE_VPN_TRAY_EXIT_ICON, brave::kBraveVpnRemoveItemName); + source->AddItem( + IDC_BRAVE_VPN_TRAY_EXIT_ICON, + l10n_util::GetStringUTF16(IDS_BRAVE_VPN_WIREGUARD_TRAY_REMOVE_ICON_ITEM)); } void StatusTrayRunner::OnConnected(bool success) { diff --git a/build/config/brave_build.gni b/build/config/brave_build.gni index ea91a955cdf..bb2395dade8 100644 --- a/build/config/brave_build.gni +++ b/build/config/brave_build.gni @@ -24,4 +24,5 @@ import("//brave/components/sync_device_info/sources.gni") import("//brave/components/update_client/sources.gni") import("//brave/installer/linux/sources.gni") import("//brave/net/sources.gni") +import("//brave/resources/allowlist.gni") import("//brave/third_party/blink/renderer/includes.gni") diff --git a/build/win/BUILD.gn b/build/win/BUILD.gn index e3f307c0a51..01c9a34a834 100644 --- a/build/win/BUILD.gn +++ b/build/win/BUILD.gn @@ -11,9 +11,8 @@ group("brave") { ":copy_exe", ":copy_pdb", ] - data_deps = [] if (enable_brave_vpn) { - data_deps += [ "//brave/browser/brave_vpn/win/brave_vpn_wireguard_service" ] + deps = [ "//brave/browser/brave_vpn/win/brave_vpn_wireguard_service:wireguard_service" ] } } diff --git a/patches/chrome-BUILD.gn.patch b/patches/chrome-BUILD.gn.patch index 5a54d4f2da5..ef04d34b7d7 100644 --- a/patches/chrome-BUILD.gn.patch +++ b/patches/chrome-BUILD.gn.patch @@ -1,5 +1,5 @@ diff --git a/chrome/BUILD.gn b/chrome/BUILD.gn -index a0db274a53134fb1f1085185fc1030f6bc78917b..9f5ac285bdf4dd9d8c6285df70c744dd0f302610 100644 +index a0db274a53134fb1f1085185fc1030f6bc78917b..b9bb51e48160cc9fabd833959359b1631a6c1b9f 100644 --- a/chrome/BUILD.gn +++ b/chrome/BUILD.gn @@ -201,6 +201,7 @@ if (!is_android && !is_mac) { @@ -110,3 +110,11 @@ index a0db274a53134fb1f1085185fc1030f6bc78917b..9f5ac285bdf4dd9d8c6285df70c744dd ] } +@@ -1612,6 +1623,7 @@ if (!is_android) { + if (enable_resource_allowlist_generation) { + repack_allowlist = _chrome_resource_allowlist + deps = [ ":resource_allowlist" ] ++ repack_allowlist = brave_allowlist_file deps += [ "//brave:merge_allowlists" ] + } + + if (is_chrome_branded && !is_mac) { diff --git a/resources/allowlist.gni b/resources/allowlist.gni new file mode 100644 index 00000000000..bdc3e0c80d2 --- /dev/null +++ b/resources/allowlist.gni @@ -0,0 +1,8 @@ +# Copyright (c) 2023 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/. + +# Allowlist file used by brave resources, created after merging chrome allowlist +# and brave resources. +brave_allowlist_file = "${root_gen_dir}/brave_resources_allowlist.txt" diff --git a/resources/brave_allowlist.py b/resources/brave_allowlist.py new file mode 100755 index 00000000000..8d7510ecc21 --- /dev/null +++ b/resources/brave_allowlist.py @@ -0,0 +1,58 @@ +#!/usr/bin/env python3 +# Copyright (c) 2023 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 argparse +import sys +import os + + +# Merges 2 allowlists (repack_allowlist + brave_allowlist = output file) to +# a new file that contains both resources. Filters duplicated resources ids. +def main(): + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument('--repack_allowlist', + help='Path to the repack allowist.', + required=True, + metavar='FILE') + parser.add_argument('--brave_allowlist', + help='Path to the brave repack allowist.', + required=True, + metavar='FILE') + parser.add_argument('--output', + help='Path to the brave output allowist.', + required=True, + metavar='FILE') + + args = parser.parse_args() + + if not os.path.exists(args.repack_allowlist): + print('Repack allowlist not found: {}'.format(args.repack_allowlist)) + return 1 + + if not os.path.exists(args.brave_allowlist): + print('Brave allowlist not found: {}'.format(args.brave_allowlist)) + return 1 + + unique = set() + with open(args.repack_allowlist, 'r') as f: + for line in f.readlines(): + unique = unique | set(line.split()[:2]) + + with open(args.brave_allowlist, 'r') as f: + for line in f.readlines(): + unique = unique | set(line.split()[:2]) + + if os.path.exists(args.output): + os.remove(args.output) + + with open(args.output, 'w') as f: + for num in unique: + f.write(str(num) + '\n') + return 0 + + +if __name__ == '__main__': + sys.exit(main())